OSDN Git Service

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