OSDN Git Service

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