OSDN Git Service

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