OSDN Git Service

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