OSDN Git Service

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