OSDN Git Service

AppliStation-All,826b1b613118e370d33ec78c21e052a5733291d3 の修正漏れ(レジストリのキーのタイプが想定しているのと...
[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                         pkgListMan.LoadPackageLists();\r
84                 }\r
85                 \r
86                 public void Update()\r
87                 {\r
88                         update(true);\r
89                 }\r
90                 \r
91                 public void LocalUpdate()\r
92                 {\r
93                         update(false);\r
94                 }\r
95                 \r
96                 public void update(bool downloadPackageListFlag)\r
97                 {\r
98                         NaGet.SubCommands.NaGetUpdate tasks = new NaGet.SubCommands.NaGetUpdate(pkgListMan, downloadPackageListFlag);\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                         DownloadListener dl = new DownloadListener();\r
122                         tasks.Downloader.DownloadEventRaised += dl.OnDownload;\r
123                         \r
124                         tasks.Run();\r
125                 }\r
126                 \r
127                 public void CheckUpgrade()\r
128                 {\r
129                         PackageList<Package> packageList = pkgListMan.AvailablePkgList;\r
130                         \r
131                         VersionComparetor verComp = new VersionComparetor();\r
132                         \r
133                         foreach (InstalledPackage pkg in pkgListMan.InstalledPkgList) {\r
134                                 Package avaiablePkg = packageList.GetPackageForName(pkg.Name);\r
135                                 \r
136                                 if (avaiablePkg != null) {\r
137                                         if (verComp.Compare(pkg.Version, avaiablePkg.Version) < 0 &&\r
138                                             pkgListMan.InstalledPkgList.GetPackageForPackage(pkg.Name, avaiablePkg.Version) == null) {\r
139                                                 \r
140                                                 Console.WriteLine("{0} ({1}) => ({2})", pkg.Name, pkg.Version, avaiablePkg.Version);\r
141                                         }\r
142                                 }\r
143                         }\r
144                         foreach (InstalledPackage pkg in pkgListMan.SystemInstalledPkgList) {\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                                                 \r
151                                                 Console.WriteLine("{0} ({1})@sys => ({2})", pkg.Name, pkg.Version, avaiablePkg.Version);\r
152                                         }\r
153                                 }\r
154                         }\r
155                 }\r
156                 \r
157                 public void Search(string keys)\r
158                 {\r
159                         foreach(Package package in pkgListMan.AvailablePkgList.Search(keys)) {\r
160                                 Console.WriteLine("{0} ({1}) - {2}", package.Name, package.Version, package.Summary);\r
161                         }\r
162                         \r
163                         foreach(InstalledPackage package in pkgListMan.InstalledPkgList.Search(keys)) {\r
164                                 Console.WriteLine("{0} ({1})[@install] - {2}", package.Name, package.Version, package.Summary);\r
165                         }\r
166                         \r
167                         foreach(InstalledPackage package in pkgListMan.SystemInstalledPkgList.Search(keys)) {\r
168                                 Console.WriteLine("{0} ({1})[@sys] - {2}", package.Name, package.Version, package.Summary);\r
169                         }\r
170                 }\r
171                 \r
172                 public void Show(string packagename)\r
173                 {\r
174                         PackageList<Package> allPkgs = new PackageList<Package>();\r
175                         allPkgs.AddPackages(pkgListMan.GetAllPackages());\r
176                         \r
177                         foreach (Package pkg in allPkgs.GetPackagesForName(packagename)) {\r
178                                 Console.WriteLine("Package: {0}", pkg.Name);\r
179                                 Console.WriteLine("Version: {0}", pkg.Version);\r
180                                 Console.WriteLine("Summary: {0}", pkg.Summary);\r
181                                 if (pkg.Url != null) Console.WriteLine("Website: {0}", pkg.Url.Href);\r
182                                 if (pkg.Tags != null) Console.WriteLine("Tag: {0}", pkg.Tags.ToLower());\r
183                                 Console.WriteLine("Type: {0}", pkg.Type);\r
184                                 if (pkg.License != null) Console.WriteLine("License: {0}", pkg.License);\r
185                                 if (pkg is InstalledPackage) Console.WriteLine("State: Installed");\r
186                                 Console.WriteLine("Repository: {0}", pkg.PackageListName);\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(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(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                         Installation[] depInstallations;\r
292                         {\r
293                                 Installation[] resolved;\r
294                                 DependeciesResolver.ResolveInstallations(installations, pkgListMan, out resolved, out depInstallations);\r
295                                 installations = resolved;\r
296                         }\r
297                         \r
298                         Console.WriteLine("The following packages will be downloaded:");\r
299                         Console.WriteLine("  {0}", Installation.ToString(installations));\r
300                         if (AllGet.Util.Confirm("Do you want to continue [Y/n]?", true) == false) {\r
301                                 Console.WriteLine("Abort.");\r
302                                 Environment.Exit(0);\r
303                         }\r
304                         \r
305                         NaGet.SubCommands.NaGetInstall tasks = new NaGet.SubCommands.NaGetInstall(pkgListMan, installations);\r
306                         tasks.TaskQueryRaised += delegate(object sender, NaGetTaskQueryArgs e) {\r
307                                 char result = '\u0000';\r
308                                 if (e.SelectionFlag == (NaGetTaskQueryResult.CONTINUE | NaGetTaskQueryResult.RETRY | NaGetTaskQueryResult.CANCEL)) {\r
309                                         result = AllGet.Util.Query(e.Message + " [y/R/n]?", "yrn", 'r');\r
310                                 } else if (e.SelectionFlag == (NaGetTaskQueryResult.RETRY | NaGetTaskQueryResult.CANCEL)) {\r
311                                         result = AllGet.Util.Query(e.Message + " [R/n]?", "rn", 'r');\r
312                                 } else if (e.SelectionFlag == NaGetTaskQueryResult.CONTINUE) {\r
313                                         result = AllGet.Util.Query(e.Message + " [Y]?", "y", 'y');\r
314                                 } else {\r
315                                         result = AllGet.Util.Query(e.Message + " [Y/n]?", "yn", 'y');\r
316                                 }\r
317                                 \r
318                                 switch (result) {\r
319                                         case 'y':\r
320                                                 return NaGetTaskQueryResult.CONTINUE;\r
321                                         case 'n':\r
322                                                 return NaGetTaskQueryResult.CANCEL;\r
323                                         case 'r':\r
324                                                 return NaGetTaskQueryResult.RETRY;\r
325                                         default:\r
326                                                 return NaGetTaskQueryResult.CANCELED_AUTOMATICALLY;\r
327                                 }\r
328                         };\r
329                         tasks.TaskSetRaised += delegate(object sender, NaGetTaskSetEventArgs e) { \r
330                                 switch (e.Type) {\r
331 //                                      case NaGetTaskSetEventType.COMPLETED_TASKSET\r
332 //                                              break;\r
333                                         case NaGetTaskSetEventType.COMPLETED:\r
334                                                 Console.WriteLine("Done.");\r
335                                                 break;\r
336                                         case NaGetTaskSetEventType.STARTED_TASKSET:\r
337                                                 Console.Write("  " + e.TaskMessage);\r
338                                                 break;\r
339                                         case NaGetTaskSetEventType.COMPLETED_TASKSET:\r
340                                                 Console.WriteLine(" ... Done. [{0}%]", (int) e.TaskProgressPercent);\r
341                                                 break;\r
342                                         case NaGetTaskSetEventType.INFO:\r
343                                                 Console.WriteLine("  " + e.TaskMessage);\r
344                                                 break;\r
345                                         case NaGetTaskSetEventType.ERROR:\r
346                                         case NaGetTaskSetEventType.WARNING:\r
347                                                 Console.WriteLine("  [Error] " + e.TaskMessage);\r
348                                                 break;\r
349                                 }\r
350                         };\r
351                         DownloadListener dl = new DownloadListener();\r
352                         tasks.Downloader.DownloadEventRaised += dl.OnDownload;\r
353                         \r
354                         tasks.Run();\r
355                 }\r
356                 \r
357                 public void Remove(string[] packagenames)\r
358                 {\r
359                         if (! NaGet.Utils.IsAdministrators()) {\r
360                                 Console.WriteLine("W: you are not administrators!");\r
361                         }\r
362                         \r
363                         this.LocalUpdate();\r
364                         \r
365                         PackageList<InstalledPackage> installedPkgList = new PackageList<InstalledPackage>();\r
366                         installedPkgList.AddPackages(pkgListMan.GetAllInstalledPackages());\r
367                         \r
368                         Uninstallation[] uninstallations = new Uninstallation[packagenames.Length];\r
369                         for (int i = 0; i < packagenames.Length; i++) {\r
370                                 InstalledPackage pkg = installedPkgList.GetPackageForName(packagenames[i]);\r
371                                 \r
372                                 if (pkg == null) {\r
373                                         Console.WriteLine("E: could not found package " + packagenames[i]);\r
374                                         Environment.Exit(1);\r
375                                 }\r
376                                 \r
377                                 uninstallations[i] = new Uninstallation(pkg);\r
378                         }\r
379                         \r
380 //                      if (AllGet.Util.Confirm("Do you want to continue [Y/n]?", true) == false) {\r
381 //                              Console.WriteLine("Abort.");\r
382 //                              Environment.Exit(0);\r
383 //                      }\r
384                         \r
385                         NaGet.SubCommands.NaGetUninstall tasks = new NaGet.SubCommands.NaGetUninstall(pkgListMan, uninstallations);\r
386                         tasks.TaskSetRaised += delegate(object sender, NaGetTaskSetEventArgs e) { \r
387                                 switch (e.Type) {\r
388 //                                      case NaGetTaskSetEventType.COMPLETED_TASKSET\r
389 //                                              break;\r
390                                         case NaGetTaskSetEventType.COMPLETED:\r
391                                                 Console.WriteLine("Done.");\r
392                                                 break;\r
393                                         case NaGetTaskSetEventType.STARTED_TASKSET:\r
394                                                 Console.Write("  " + e.TaskMessage);\r
395                                                 break;\r
396                                         case NaGetTaskSetEventType.COMPLETED_TASKSET:\r
397                                                 Console.WriteLine(" ... Done. [{0}%]", (int) e.TaskProgressPercent);\r
398                                                 break;\r
399                                         case NaGetTaskSetEventType.INFO:\r
400                                                 Console.WriteLine("  " + e.TaskMessage);\r
401                                                 break;\r
402                                         case NaGetTaskSetEventType.ERROR:\r
403                                         case NaGetTaskSetEventType.WARNING:\r
404                                                 Console.WriteLine("  [Error] " + e.TaskMessage);\r
405                                                 break;\r
406                                 }\r
407                         };\r
408                         \r
409                         tasks.Run();\r
410                 }\r
411                 \r
412                 public void CleanCache(string[] packages)\r
413                 {\r
414                         if (! Directory.Exists(NaGet.Env.ArchiveFolderPath)) {\r
415                                 return; \r
416                         }\r
417                         \r
418                         int i = 0;\r
419                         if (packages.Length == 0) {\r
420                                 foreach (string folder in Directory.GetDirectories(NaGet.Env.ArchiveFolderPath)) {\r
421                                         Directory.Delete(folder, true);\r
422                                         i ++;\r
423                                 }\r
424                         } else {\r
425                                 foreach (string package in packages) {\r
426                                         foreach (string folder in Directory.GetDirectories(NaGet.Env.ArchiveFolderPath, package+"*", SearchOption.TopDirectoryOnly)) {\r
427                                                 Directory.Delete(folder, true);\r
428                                                 i ++;\r
429                                         }\r
430                                 }\r
431                         }\r
432                         if (i > 0) {\r
433                                 Console.WriteLine("... Done.");\r
434                         }\r
435                 }\r
436                 \r
437                 public void Help()\r
438                 {\r
439                         string executeFileName = System.AppDomain.CurrentDomain.FriendlyName;\r
440                         Console.Write("Usage:");\r
441                         \r
442                         Console.WriteLine("\t{0} update|localupdate", executeFileName);\r
443                         Console.WriteLine("\t{0} search|show pkg1 [pkg2 ...]", executeFileName);\r
444                         Console.WriteLine("\t{0} cleancache [pkg ...]", executeFileName);\r
445                         Console.WriteLine("\t{0} download pkg1 [pkg2 ...]", executeFileName);\r
446                         Console.WriteLine("\t{0} [--quiet] install|uninstall pkg1 [pkg2 ...]", executeFileName);\r
447                         Console.WriteLine();\r
448                         Console.WriteLine("{0} is a simple command line interface for downloading and "+\r
449                                           "installing packages. The most frequently used commands are update "+\r
450                                           "and install.", executeFileName);\r
451                         Console.WriteLine();\r
452                         Console.WriteLine("Commands:");\r
453                         Console.WriteLine("   update - Retrieve new lists of packages");\r
454                         Console.WriteLine("   localupdate - Update installed-soft-list only");\r
455                         Console.WriteLine("   checkupgrade - Show upgraded-soft list");\r
456                         Console.WriteLine("   search - Search the package list for not a regex pattern");\r
457                         Console.WriteLine("   show - Show package detail");\r
458                         Console.WriteLine("   cleancache - Clear cached archived file(s)");\r
459                         Console.WriteLine("   download - Download only - do NOT install or unpack archives");\r
460                         Console.WriteLine("   install - Install new packages");\r
461                         Console.WriteLine("   remove - Uninstall packages");\r
462                         Console.WriteLine();\r
463                 }\r
464                 \r
465                 public void FooBar()\r
466                 {\r
467                         foreach (InstalledPackage pkg in pkgListMan.SystemInstalledPkgList) {\r
468                                 Console.WriteLine("{0} : {1}", pkg.Name, pkg.UninstallInfo.UninstallString);\r
469                         }\r
470                 }\r
471                 \r
472                 public void Hoge()\r
473                 {\r
474                         foreach (UninstallInformation uInfo in RegistriedUninstallers.Uninstallers) {\r
475                                 if (! uInfo.IsOSPatch && ! uInfo.IsSystemComponent) {\r
476                                         Console.WriteLine("{0}", uInfo.DisplayName);\r
477                                 }\r
478                         }\r
479                 }\r
480                 \r
481                 public void Moo()\r
482                 {\r
483                         // TODO スーパー牛さんパワー化\r
484                         \r
485                         string executeFileName = System.AppDomain.CurrentDomain.FriendlyName;\r
486                         Console.WriteLine("誰か {0} をスーパー牛さんパワー化してくれ", executeFileName);\r
487                 }\r
488                 \r
489                 [STAThread]\r
490                 public static void Main(string[] args)\r
491                 {\r
492                         // アーカイブSYSTEM32をパスに足す\r
493                         NaGet.Utils.AddDirectoryToPath(NaGet.Env.ArchiveSystem32);\r
494                         \r
495                         MainClass mc = new MainClass();\r
496                         \r
497                         if (args.Length == 0) {\r
498                                 mc.Help();\r
499                                 \r
500                                 Environment.Exit(1);\r
501                         } else {\r
502                                 try {\r
503                                         NaGet.ArgParser argParser = new NaGet.ArgParser();\r
504                                         argParser["quiet"] = false;\r
505                                         args = argParser.Parse(args);\r
506                                         mc.silent = (bool) argParser["quiet"];\r
507                                 } catch (ApplicationException e) {\r
508                                         Console.WriteLine(e.Message);\r
509                                         Environment.Exit(1);\r
510                                 }\r
511                         }\r
512                         \r
513                         // 引数ごとに操作を決定\r
514                         switch (args[0])\r
515                         {\r
516                                 case "update":\r
517                                         if (args.Length != 1) {\r
518                                                 Console.WriteLine("E: The update command takes no arguments");\r
519                                                 Environment.Exit(1);\r
520                                         }\r
521                                         mc.Update();\r
522                                         break;\r
523                                 case "localupate":\r
524                                         if (args.Length != 1) {\r
525                                                 Console.WriteLine("E: The update command takes no arguments");\r
526                                                 Environment.Exit(1);\r
527                                         }\r
528                                         mc.LocalUpdate();\r
529                                         break;\r
530                                 case "search":\r
531                                         if (args.Length <= 1) {\r
532                                                 Console.WriteLine("E: You must give exactly one pattern");\r
533                                                 Environment.Exit(1);\r
534                                         }\r
535                                         \r
536                                         mc.Search(string.Join(" ", args, 1, args.Length - 1));\r
537                                         break;\r
538                                 case "show":\r
539                                         if (args.Length <= 1) {\r
540                                                 Console.WriteLine("E: You must give exactly one pattern");\r
541                                                 Environment.Exit(1);\r
542                                         }\r
543                                         \r
544                                         for (int i = 1; i < args.Length; i++) {\r
545                                                 mc.Show(args[i]);\r
546                                         }\r
547                                         break;\r
548                                 case "download":\r
549                                         if (args.Length <= 1) {\r
550                                                 Console.WriteLine("E: Invalid operation download");\r
551                                                 Environment.Exit(1);\r
552                                         } else {\r
553                                                 string[] packages = new string[args.Length - 1];\r
554                                                 Array.Copy(args, 1, packages, 0, packages.Length);\r
555                                                 \r
556                                                 mc.Download(packages);\r
557                                         }\r
558                                         break;\r
559                                 case "install":\r
560                                         if (args.Length <= 1) {\r
561                                                 Console.WriteLine("E: Invalid operation install");\r
562                                                 Environment.Exit(1);\r
563                                         } else {\r
564                                                 string[] packages = new string[args.Length - 1];\r
565                                                 Array.Copy(args, 1, packages, 0, packages.Length);\r
566                                                 \r
567                                                 mc.Install(packages);\r
568                                         }\r
569                                         break;\r
570                                 case "checkupgrade":\r
571                                         mc.CheckUpgrade();\r
572                                         break;\r
573                                 case "remove":\r
574                                         if (args.Length <= 1) {\r
575                                                 Console.WriteLine("E: Invalid operation remove");\r
576                                                 Environment.Exit(1);\r
577                                         } else {\r
578                                                 string[] packages = new string[args.Length - 1];\r
579                                                 Array.Copy(args, 1, packages, 0, packages.Length);\r
580                                                 \r
581                                                 mc.Remove(packages);\r
582                                         }\r
583                                         break;\r
584                                 case "cleancache":\r
585                                         {\r
586                                                 string[] packages = new string[args.Length - 1];\r
587                                                 Array.Copy(args, 1, packages, 0, packages.Length);\r
588                                                 \r
589                                                 mc.CleanCache(packages);\r
590                                         }\r
591                                         break;\r
592                                 case "foobar":\r
593                                         mc.FooBar();\r
594                                         break;\r
595                                 case "hoge":\r
596                                         mc.Hoge();\r
597                                         break;\r
598                                 case "moo":\r
599                                         mc.Moo();\r
600                                         break;\r
601                                 default:\r
602                                         mc.Help();\r
603                                         \r
604                                         Environment.Exit(1);\r
605                                         break;\r
606                         }\r
607                 }\r
608         }\r
609 }\r