OSDN Git Service

all-get,all-getのヘルプに--silentオプションが使えることを書いた
[applistation/AppliStation.git] / all-get / Main.cs
1 // project created on 2007/09/08 at 20:20\r
2 using System;\r
3 using System.IO;\r
4 using System.Collections.Generic;\r
5 using NaGet.Net;\r
6 using NaGet.Packages;\r
7 using NaGet.Packages.Install;\r
8 using NaGet.SubCommands;\r
9 \r
10 namespace AllGet\r
11 {\r
12 \r
13         class DownloadListener\r
14         {\r
15                 private string line = null;\r
16                 \r
17                 /// <summary>\r
18                 /// lineのコンソール上における長さ\r
19                 /// </summary>\r
20                 private int lineWidth = 0;\r
21         \r
22                 public void OnDownload(object sender, DownloadEventArgs a) {\r
23                         if (line != null) {\r
24                                 lock (line) {\r
25                                         int newpos = (lineWidth <= 0)? 0 : Console.CursorLeft - lineWidth;\r
26                                         if (newpos < 0) newpos = 0;\r
27                                         \r
28                                         // 空白で埋める\r
29                                         Console.CursorLeft = newpos;\r
30                                         for (int i = 0; i < lineWidth && Console.CursorLeft < Console.BufferWidth; i++) {\r
31                                                 Console.Write(' ');\r
32                                         }\r
33                                         Console.CursorLeft = newpos;\r
34                                         \r
35                                         line = null; lineWidth = 0;\r
36                                 }\r
37                         }\r
38                         \r
39                         switch (a.Type) {\r
40                         case DownloadEventType.INITED:\r
41                                 line = "starting...";\r
42                                 break;\r
43                         case DownloadEventType.CONNECTED:\r
44                         case DownloadEventType.DOWNLOADING:\r
45                                 line = a.TaskMessage;\r
46                                 break;\r
47                         case DownloadEventType.COMPLETED:\r
48                                 //\r
49                                 line = null;\r
50                                 break;\r
51                         case DownloadEventType.ERROR:\r
52                                 Console.Write("interrupted! ERROR!");\r
53                                 line = null;\r
54                                 break;\r
55                         }\r
56                         \r
57                         if (line != null) {\r
58                                 int posOld = Console.CursorLeft;\r
59                                 Console.Write(line);\r
60                                 lineWidth = Console.CursorLeft - posOld;\r
61                         }\r
62                 }\r
63         }\r
64 \r
65         class MainClass\r
66         {\r
67                 private Downloader downloader;\r
68                 \r
69                 private PackageListsManager pkgListMan;\r
70                 \r
71                 /// <summary>\r
72                 /// サイレントインストールをするか否か\r
73                 /// </summary>\r
74                 private bool silent = false;\r
75                 \r
76                 public MainClass()\r
77                 {\r
78                         downloader = new Downloader();\r
79                         DownloadListener dl = new DownloadListener();\r
80                         downloader.DownloadEventRaised += new EventHandler<DownloadEventArgs>(dl.OnDownload);\r
81                         \r
82                         pkgListMan = new PackageListsManager();\r
83                 }\r
84                 \r
85                 public void Update()\r
86                 {\r
87                         update(true);\r
88                 }\r
89                 \r
90                 public void LocalUpdate()\r
91                 {\r
92                         update(false);\r
93                 }\r
94                 \r
95                 public void update(bool downloadPackageListFlag)\r
96                 {\r
97                         NaGet.SubCommands.NaGetUpdate tasks = new NaGet.SubCommands.NaGetUpdate(pkgListMan, downloadPackageListFlag);\r
98                         tasks.Downloader = this.downloader;\r
99                         tasks.TaskSetRaised += delegate(object sender, NaGetTaskSetEventArgs e) { \r
100                                 switch (e.Type) {\r
101 //                                      case NaGetTaskSetEventType.COMPLETED_TASKSET\r
102 //                                              break;\r
103                                         case NaGetTaskSetEventType.COMPLETED:\r
104                                                 Console.WriteLine("Done.");\r
105                                                 break;\r
106                                         case NaGetTaskSetEventType.STARTED_TASKSET:\r
107                                                 Console.Write("  " + e.TaskMessage);\r
108                                                 break;\r
109                                         case NaGetTaskSetEventType.COMPLETED_TASKSET:\r
110                                                 Console.WriteLine(" ... Done. [{0}%]", (int) e.TaskProgressPercent);\r
111                                                 break;\r
112                                         case NaGetTaskSetEventType.INFO:\r
113                                                 Console.WriteLine("  " + e.TaskMessage);\r
114                                                 break;\r
115                                         case NaGetTaskSetEventType.ERROR:\r
116                                         case NaGetTaskSetEventType.WARNING:\r
117                                                 Console.WriteLine("  [Error]" + e.TaskMessage);\r
118                                                 break;\r
119                                 }\r
120                         };\r
121                         \r
122                         tasks.Run();\r
123                 }\r
124                 \r
125                 public void CheckUpgrade()\r
126                 {\r
127                         PackageList<Package> packageList = pkgListMan.AvailablePkgList;\r
128                         \r
129                         VersionComparetor verComp = new VersionComparetor();\r
130                         \r
131                         foreach (InstalledPackage pkg in pkgListMan.InstalledPkgList.Packages) {\r
132                                 Package avaiablePkg = packageList.GetPackageForName(pkg.Name);\r
133                                 \r
134                                 if (avaiablePkg != null) {\r
135                                         if (verComp.Compare(pkg.Version, avaiablePkg.Version) < 0 &&\r
136                                             pkgListMan.InstalledPkgList.GetPackageForPackage(pkg.Name, avaiablePkg.Version) == null) {\r
137                                                 Console.ForegroundColor = ConsoleColor.Green;\r
138                                         }\r
139                                         \r
140                                         Console.WriteLine("{0} ({1}) => ({2})", pkg.Name, pkg.Version, avaiablePkg.Version);\r
141                                         Console.ResetColor();\r
142                                 }\r
143                         }\r
144                         foreach (InstalledPackage pkg in pkgListMan.SystemInstalledPkgList.Packages) {\r
145                                 Package avaiablePkg = packageList.GetPackageForName(pkg.Name);\r
146                                 \r
147                                 if (avaiablePkg != null) {\r
148                                         if (verComp.Compare(pkg.Version, avaiablePkg.Version) < 0 &&\r
149                                             pkgListMan.SystemInstalledPkgList.GetPackageForPackage(pkg.Name, avaiablePkg.Version) == null) {\r
150                                                 Console.ForegroundColor = ConsoleColor.Green;\r
151                                         }\r
152                                         \r
153                                         Console.WriteLine("{0} ({1})@sys => ({2})", pkg.Name, pkg.Version, avaiablePkg.Version);\r
154                                         Console.ResetColor();\r
155                                 }\r
156                         }\r
157                 }\r
158                 \r
159                 public void Search(string keys)\r
160                 {\r
161                         foreach(Package package in pkgListMan.AvailablePkgList.Search(keys)) {\r
162                                 Console.WriteLine("{0} ({1}) - {2}", package.Name, package.Version, package.Summary);\r
163                         }\r
164                         \r
165                         foreach(InstalledPackage package in pkgListMan.InstalledPkgList.Search(keys)) {\r
166                                 Console.WriteLine("{0} ({1})[@install] - {2}", package.Name, package.Version, package.Summary);\r
167                         }\r
168                         \r
169                         foreach(InstalledPackage package in pkgListMan.SystemInstalledPkgList.Search(keys)) {\r
170                                 Console.WriteLine("{0} ({1})[@sys] - {2}", package.Name, package.Version, package.Summary);\r
171                         }\r
172                 }\r
173                 \r
174                 public void Show(string packagename)\r
175                 {\r
176                         PackageList<Package> allPkgs = new PackageList<Package>();\r
177                         allPkgs.AddPackages(pkgListMan.GetAllPackages());\r
178                         \r
179                         foreach (Package pkg in allPkgs.GetPackagesForName(packagename)) {\r
180                                 Console.WriteLine("Package: {0}", pkg.Name);\r
181                                 Console.WriteLine("Version: {0}", pkg.Version);\r
182                                 if (pkg.Url != null) Console.WriteLine("Website: {0}", pkg.Url.Href);\r
183                                 if (pkg.Tags != null) Console.WriteLine("Tag: {0}", pkg.Tags.ToLower());\r
184                                 Console.WriteLine("Type: {0}", pkg.Type);\r
185                                 if (pkg.License != null) Console.WriteLine("License: {0}", pkg.License);\r
186                                 if (pkg is InstalledPackage) Console.WriteLine("State: Installed");\r
187                                 \r
188                                 if (pkg.Description != null) {\r
189                                         Console.WriteLine("Description:");\r
190                                         Console.WriteLine(pkg.Description);\r
191                                 }\r
192                                 Console.WriteLine();\r
193                         }\r
194                 }\r
195                 \r
196                 public void Download(string[] packagenames)\r
197                 {\r
198                         Installation[] installations = null;\r
199                         {\r
200                                 List<Package> downloadList = new List<Package>();\r
201                         \r
202                                 foreach(string packagename in packagenames) {\r
203                                         Package foundPackage = pkgListMan.AvailablePkgList.GetPackageForName(packagename);\r
204                                         if (foundPackage == null) {\r
205                                                 Console.WriteLine("E: Couldn't find package "+packagename);\r
206                                                 Environment.Exit(1);\r
207                                         }\r
208                                         if (! downloadList.Contains(foundPackage)) {\r
209                                                 downloadList.Add(foundPackage);\r
210                                         }\r
211                                 }\r
212                                 \r
213                                 installations = new Installation[downloadList.Count];\r
214                                 for (int i = 0; i < installations.Length; i++) {\r
215                                         installations[i] = new Installation((Package) downloadList[i]);\r
216                                 }\r
217                         }\r
218                         \r
219                         Console.WriteLine("The following packages will be downloaded:");\r
220                         Console.WriteLine("  {0}", Installation.ToString(installations));\r
221                         if (AllGet.Util.Confirm("Do you want to continue [Y/n]?", true) == false) {\r
222                                 Console.WriteLine("Abort.");\r
223                                 Environment.Exit(0);\r
224                         }\r
225                         \r
226                         {\r
227                                 int i = 0;\r
228                                 foreach (Installation inst in installations) {\r
229                                         i++;\r
230                                         \r
231                                         if (! inst.IsInstallablePackage()) {\r
232                                                 Console.WriteLine("E:{0} {1} can not be installed.", i, inst.ToString());\r
233                                                 continue;\r
234                                         }\r
235                                         \r
236                                         try {\r
237                                                 Console.Write("Get:{0} {1}", i, inst.ToString());\r
238                                                 inst.Download(downloader);\r
239                                                 Console.WriteLine(" ...Done");\r
240                                         } catch (Exception e) {\r
241                                                 Console.WriteLine("E: "+e.Message);\r
242                                                 throw new ApplicationException(string.Format("Failed to download {0}", inst.ToString()), e);\r
243                                         }\r
244                                 }\r
245                                 \r
246                                 i = 0;\r
247                                 foreach (Installation inst in installations) {\r
248                                         i++;\r
249                                         \r
250                                         if (inst.IsInstallablePackage() && inst.VerifyHashValues() == false) {\r
251                                                 Console.WriteLine("Verify:{0} {1} does not match hash value!", i, inst.ToString());\r
252                                         }\r
253                                 }\r
254                         }\r
255                 }\r
256                 \r
257                 public void Install(string[] packagenames)\r
258                 {\r
259                         if (! NaGet.Utils.IsAdministrators()) {\r
260                                 Console.WriteLine("W: you are not administrators!");\r
261                         }\r
262                         \r
263                         Installation[] installations = null;\r
264                         {\r
265                                 List<Package> downloadList = new List<Package>();\r
266                         \r
267                                 foreach(string packagename in packagenames) {\r
268                                         Package foundPackage = pkgListMan.AvailablePkgList.GetPackageForName(packagename);\r
269                                         if (foundPackage == null) {\r
270                                                 Console.WriteLine("E: Couldn't find package "+packagename);\r
271                                                 Environment.Exit(1);\r
272                                         }\r
273                                         if (! downloadList.Contains(foundPackage)) {\r
274                                                 downloadList.Add(foundPackage);\r
275                                         }\r
276                                 }\r
277                                 \r
278                                 installations = new Installation[downloadList.Count];\r
279                                 for (int i = 0; i < installations.Length; i++) {\r
280                                         installations[i] = new Installation((Package) downloadList[i]);\r
281                                         \r
282                                         installations[i].Silent = silent; // サイレントインストールのフラグの設定\r
283                                         \r
284                                         if (! installations[i].IsInstallablePackage()) {\r
285                                                 Console.WriteLine("E: Can not install package {0} to your PC.", installations[i].ToString());\r
286                                                 Environment.Exit(1);\r
287                                         }\r
288                                 }\r
289                         }\r
290                         \r
291                         Console.WriteLine("The following packages will be downloaded:");\r
292                         Console.WriteLine("  {0}", Installation.ToString(installations));\r
293                         if (AllGet.Util.Confirm("Do you want to continue [Y/n]?", true) == false) {\r
294                                 Console.WriteLine("Abort.");\r
295                                 Environment.Exit(0);\r
296                         }\r
297                         \r
298                         NaGet.SubCommands.NaGetInstall tasks = new NaGet.SubCommands.NaGetInstall(pkgListMan, installations);\r
299                         tasks.Downloader = this.downloader;\r
300                         tasks.TaskQueryRaised += delegate(object sender, NaGetTaskQueryArgs e) {\r
301                                 char result = '\u0000';\r
302                                 if (e.SelectionFlag == (NaGetTaskQueryResult.CONTINUE | NaGetTaskQueryResult.RETRY | NaGetTaskQueryResult.CANCEL)) {\r
303                                         result = AllGet.Util.Query(e.Message + " [y/R/n]?", "yrn", 'r');\r
304                                 } else if (e.SelectionFlag == (NaGetTaskQueryResult.RETRY | NaGetTaskQueryResult.CANCEL)) {\r
305                                         result = AllGet.Util.Query(e.Message + " [R/n]?", "rn", 'r');\r
306                                 } else if (e.SelectionFlag == NaGetTaskQueryResult.CONTINUE) {\r
307                                         result = AllGet.Util.Query(e.Message + " [Y]?", "y", 'y');\r
308                                 } else {\r
309                                         result = AllGet.Util.Query(e.Message + " [Y/n]?", "yn", 'y');\r
310                                 }\r
311                                 \r
312                                 switch (result) {\r
313                                         case 'y':\r
314                                                 return NaGetTaskQueryResult.CONTINUE;\r
315                                         case 'n':\r
316                                                 return NaGetTaskQueryResult.CANCEL;\r
317                                         case 'r':\r
318                                                 return NaGetTaskQueryResult.RETRY;\r
319                                         default:\r
320                                                 return NaGetTaskQueryResult.CANCELED_AUTOMATICALLY;\r
321                                 }\r
322                         };\r
323                         tasks.TaskSetRaised += delegate(object sender, NaGetTaskSetEventArgs e) { \r
324                                 switch (e.Type) {\r
325 //                                      case NaGetTaskSetEventType.COMPLETED_TASKSET\r
326 //                                              break;\r
327                                         case NaGetTaskSetEventType.COMPLETED:\r
328                                                 Console.WriteLine("Done.");\r
329                                                 break;\r
330                                         case NaGetTaskSetEventType.STARTED_TASKSET:\r
331                                                 Console.Write("  " + e.TaskMessage);\r
332                                                 break;\r
333                                         case NaGetTaskSetEventType.COMPLETED_TASKSET:\r
334                                                 Console.WriteLine(" ... Done. [{0}%]", (int) e.TaskProgressPercent);\r
335                                                 break;\r
336                                         case NaGetTaskSetEventType.INFO:\r
337                                                 Console.WriteLine("  " + e.TaskMessage);\r
338                                                 break;\r
339                                         case NaGetTaskSetEventType.ERROR:\r
340                                         case NaGetTaskSetEventType.WARNING:\r
341                                                 Console.WriteLine("  [Error] " + e.TaskMessage);\r
342                                                 break;\r
343                                 }\r
344                         };\r
345                         \r
346                         tasks.Run();\r
347                 }\r
348                 \r
349                 public void Remove(string[] packagenames)\r
350                 {\r
351                         if (! NaGet.Utils.IsAdministrators()) {\r
352                                 Console.WriteLine("W: you are not administrators!");\r
353                         }\r
354                         \r
355                         this.LocalUpdate();\r
356                         \r
357                         PackageList<InstalledPackage> installedPkgList = new PackageList<InstalledPackage>();\r
358                         installedPkgList.AddPackages(pkgListMan.GetAllInstalledPackages());\r
359                         \r
360                         Uninstallation[] uninstallations = new Uninstallation[packagenames.Length];\r
361                         for (int i = 0; i < packagenames.Length; i++) {\r
362                                 InstalledPackage pkg = installedPkgList.GetPackageForName(packagenames[i]);\r
363                                 \r
364                                 if (pkg == null) {\r
365                                         Console.WriteLine("E: could not found package " + packagenames[i]);\r
366                                         Environment.Exit(1);\r
367                                 }\r
368                                 \r
369                                 uninstallations[i] = new Uninstallation(pkg);\r
370                         }\r
371                         \r
372 //                      if (AllGet.Util.Confirm("Do you want to continue [Y/n]?", true) == false) {\r
373 //                              Console.WriteLine("Abort.");\r
374 //                              Environment.Exit(0);\r
375 //                      }\r
376                         \r
377                         NaGet.SubCommands.NaGetUninstall tasks = new NaGet.SubCommands.NaGetUninstall(pkgListMan, uninstallations);\r
378                         tasks.TaskSetRaised += delegate(object sender, NaGetTaskSetEventArgs e) { \r
379                                 switch (e.Type) {\r
380 //                                      case NaGetTaskSetEventType.COMPLETED_TASKSET\r
381 //                                              break;\r
382                                         case NaGetTaskSetEventType.COMPLETED:\r
383                                                 Console.WriteLine("Done.");\r
384                                                 break;\r
385                                         case NaGetTaskSetEventType.STARTED_TASKSET:\r
386                                                 Console.Write("  " + e.TaskMessage);\r
387                                                 break;\r
388                                         case NaGetTaskSetEventType.COMPLETED_TASKSET:\r
389                                                 Console.WriteLine(" ... Done. [{0}%]", (int) e.TaskProgressPercent);\r
390                                                 break;\r
391                                         case NaGetTaskSetEventType.INFO:\r
392                                                 Console.WriteLine("  " + e.TaskMessage);\r
393                                                 break;\r
394                                         case NaGetTaskSetEventType.ERROR:\r
395                                         case NaGetTaskSetEventType.WARNING:\r
396                                                 Console.WriteLine("  [Error] " + e.TaskMessage);\r
397                                                 break;\r
398                                 }\r
399                         };\r
400                         \r
401                         tasks.Run();\r
402                 }\r
403                 \r
404                 public void CleanCache(string[] packages)\r
405                 {\r
406                         if (! Directory.Exists(NaGet.Env.ArchiveFolderPath)) {\r
407                                 return; \r
408                         }\r
409                         \r
410                         int i = 0;\r
411                         if (packages.Length == 0) {\r
412                                 foreach (string folder in Directory.GetDirectories(NaGet.Env.ArchiveFolderPath)) {\r
413                                         Directory.Delete(folder, true);\r
414                                         i ++;\r
415                                 }\r
416                         } else {\r
417                                 foreach (string package in packages) {\r
418                                         foreach (string folder in Directory.GetDirectories(NaGet.Env.ArchiveFolderPath, package+"*", SearchOption.TopDirectoryOnly)) {\r
419                                                 Directory.Delete(folder, true);\r
420                                                 i ++;\r
421                                         }\r
422                                 }\r
423                         }\r
424                         if (i > 0) {\r
425                                 Console.WriteLine("... Done.");\r
426                         }\r
427                 }\r
428                 \r
429                 public void Help()\r
430                 {\r
431                         string executeFileName = System.AppDomain.CurrentDomain.FriendlyName;\r
432                         Console.Write("Usage:");\r
433                         \r
434                         Console.WriteLine("\t{0} update|localupdate", executeFileName);\r
435                         Console.WriteLine("\t{0} search|show pkg1 [pkg2 ...]", executeFileName);\r
436                         Console.WriteLine("\t{0} cleancache [pkg ...]", executeFileName);\r
437                         Console.WriteLine("\t{0} download pkg1 [pkg2 ...]", executeFileName);\r
438                         Console.WriteLine("\t{0} [--quiet] install|uninstall pkg1 [pkg2 ...]", executeFileName);\r
439                         Console.WriteLine();\r
440                         Console.WriteLine("{0} is a simple command line interface for downloading and "+\r
441                                           "installing packages. The most frequently used commands are update "+\r
442                                           "and install.", executeFileName);\r
443                         Console.WriteLine();\r
444                         Console.WriteLine("Commands:");\r
445                         Console.WriteLine("   update - Retrieve new lists of packages");\r
446                         Console.WriteLine("   localupdate - Update installed-soft-list only");\r
447                         Console.WriteLine("   checkupgrade - Show upgraded-soft list");\r
448                         Console.WriteLine("   search - Search the package list for not a regex pattern");\r
449                         Console.WriteLine("   show - Show package detail");\r
450                         Console.WriteLine("   cleancache - Clear cached archived file(s)");\r
451                         Console.WriteLine("   download - Download only - do NOT install or unpack archives");\r
452                         Console.WriteLine("   install - Install new packages");\r
453                         Console.WriteLine("   remove - Uninstall packages");\r
454                         Console.WriteLine();\r
455                 }\r
456                 \r
457                 public void FooBar()\r
458                 {\r
459                         foreach (InstalledPackage pkg in pkgListMan.SystemInstalledPkgList.Packages) {\r
460                                 Console.WriteLine("{0} : {1}", pkg.Name, pkg.UninstallInfo.UninstallString);\r
461                         }\r
462                 }\r
463                 \r
464                 public void Hoge()\r
465                 {\r
466                         foreach (UninstallInformation uInfo in RegistriedUninstallers.Uninstallers) {\r
467                                 if (! uInfo.IsOSPatch && ! uInfo.IsSystemComponent) {\r
468                                         Console.WriteLine("{0}", uInfo.DisplayName);\r
469                                 }\r
470                         }\r
471                 }\r
472                 \r
473                 public void Moo()\r
474                 {\r
475                         // TODO スーパー牛さんパワー化\r
476                         \r
477                         string executeFileName = System.AppDomain.CurrentDomain.FriendlyName;\r
478                         Console.WriteLine("誰か {0} をスーパー牛さんパワー化してくれ", executeFileName);\r
479                 }\r
480                 \r
481                 public static void Main(string[] args)\r
482                 {\r
483                         // アーカイブSYSTEM32をパスに足す\r
484                         NaGet.Utils.AddDirectoryToPath(NaGet.Env.ArchiveSystem32);\r
485                         \r
486                         MainClass mc = new MainClass();\r
487                         \r
488                         if (args.Length == 0) {\r
489                                 mc.Help();\r
490                                 \r
491                                 Environment.Exit(1);\r
492                         } else {\r
493                                 try {\r
494                                         NaGet.ArgParser argParser = new NaGet.ArgParser();\r
495                                         argParser["quiet"] = false;\r
496                                         args = argParser.Parse(args);\r
497                                         mc.silent = (bool) argParser["quiet"];\r
498                                 } catch (ApplicationException e) {\r
499                                         Console.WriteLine(e.Message);\r
500                                         Environment.Exit(1);\r
501                                 }\r
502                         }\r
503                         \r
504                         if (args[0] == "update") {\r
505                                 if (args.Length != 1) {\r
506                                         Console.WriteLine("E: The update command takes no arguments");\r
507                                         Environment.Exit(1);\r
508                                 }\r
509                                 mc.Update();\r
510                         } else if (args[0] == "localupdate") {\r
511                                 if (args.Length != 1) {\r
512                                         Console.WriteLine("E: The update command takes no arguments");\r
513                                         Environment.Exit(1);\r
514                                 }\r
515                                 mc.LocalUpdate();\r
516                         } else if (args[0] == "search") {\r
517                                 if (args.Length <= 1) {\r
518                                         Console.WriteLine("E: You must give exactly one pattern");\r
519                                         Environment.Exit(1);\r
520                                 }\r
521                                 \r
522                                 mc.Search(string.Join(" ", args, 1, args.Length - 1));\r
523                         } else if (args[0] == "show") {\r
524                                 if (args.Length <= 1) {\r
525                                         Console.WriteLine("E: You must give exactly one pattern");\r
526                                         Environment.Exit(1);\r
527                                 }\r
528                                 \r
529                                 for (int i = 1; i < args.Length; i++) {\r
530                                         mc.Show(args[i]);\r
531                                 }\r
532                         } else if (args[0] == "download") {\r
533                                 if (args.Length <= 1) {\r
534                                         Console.WriteLine("E: Invalid operation download");\r
535                                         Environment.Exit(1);\r
536                                 }\r
537                                 \r
538                                 string[] packages = new string[args.Length - 1];\r
539                                 Array.Copy(args, 1, packages, 0, packages.Length);\r
540                                 \r
541                                 mc.Download(packages);\r
542                         } else if (args[0] == "install") {\r
543                                 if (args.Length <= 1) {\r
544                                         Console.WriteLine("E: Invalid operation install");\r
545                                         Environment.Exit(1);\r
546                                 }\r
547                                 \r
548                                 string[] packages = new string[args.Length - 1];\r
549                                 Array.Copy(args, 1, packages, 0, packages.Length);\r
550                                 \r
551                                 mc.Install(packages);\r
552                         } else if (args[0] == "checkupgrade") {\r
553                                 mc.CheckUpgrade();\r
554                         } else if (args[0] == "remove") {\r
555                                 if (args.Length <= 1) {\r
556                                         Console.WriteLine("E: Invalid operation remove");\r
557                                         Environment.Exit(1);\r
558                                 }\r
559                                 \r
560                                 string[] packages = new string[args.Length - 1];\r
561                                 Array.Copy(args, 1, packages, 0, packages.Length);\r
562                                 \r
563                                 mc.Remove(packages);\r
564                         } else if (args[0] == "cleancache") {\r
565                                 string[] packages = new string[args.Length - 1];\r
566                                 Array.Copy(args, 1, packages, 0, packages.Length);\r
567                                 \r
568                                 mc.CleanCache(packages);\r
569                         } else if (args[0] == "foobar") {\r
570                                 mc.FooBar();\r
571                         } else if (args[0] == "hoge") {\r
572                                 mc.Hoge();\r
573                         } else if (args[0] == "moo") {\r
574                                 mc.Moo();\r
575                         } else {\r
576                                 mc.Help();\r
577                                 \r
578                                 Environment.Exit(1);\r
579                         }\r
580                 }\r
581         }\r
582 }\r