OSDN Git Service

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