OSDN Git Service

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