OSDN Git Service

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