OSDN Git Service

na-get-lib,レポジトリタイプの追加。
[applistation/AppliStation.git] / na-get-lib / NaGet.SubCommands / NaGetUninstall.cs
1 using System;\r
2 using NaGet.Packages.Install;\r
3 using NaGet.Packages;\r
4 using NaGet.Net;\r
5 \r
6 namespace NaGet.SubCommands\r
7 {\r
8         public class NaGetUninstall : NaGetTaskSet\r
9         {\r
10                 private bool done = false;\r
11                 \r
12                 private int currentTaskSetIndex = -1;\r
13                 \r
14                 private PackageListsManager pkgListMan;\r
15                 \r
16                 /// <summary>\r
17                 /// \83A\83\93\83C\83\93\83X\83g\81[\83\8b\82·\82é\83p\83b\83P\81[\83W\r
18                 /// </summary>\r
19                 public Uninstallation[] Uninstallations;\r
20                 \r
21                 /// <summary>\r
22                 /// \83R\83\93\83X\83g\83\89\83N\83^\r
23                 /// </summary>\r
24                 /// <param name="pkgs">\83A\83\93\83C\83\93\83X\83g\81[\83\8b\82·\82é\83p\83b\83P\81[\83W</param>\r
25                 public NaGetUninstall(PackageListsManager pkgMan, InstalledPackage[] pkgs)\r
26                 {\r
27                         pkgListMan = pkgMan;\r
28                         \r
29                         Uninstallations = new Uninstallation[pkgs.Length];\r
30                         for (int i = 0; i < pkgs.Length; i++) {\r
31                                 Uninstallations[i] = new Uninstallation(pkgs[i]);\r
32                         }\r
33                         \r
34                         initializeMainTaskSetNames();\r
35                 }\r
36                 \r
37                 /// <summary>\r
38                 /// \83R\83\93\83X\83g\83\89\83N\83^\r
39                 /// </summary>\r
40                 /// <param name="uninstallations">\83A\83\93\83C\83\93\83X\83g\81[\83\8b\8f\88\97\9d\82Ì\94z\97ñ</param>\r
41                 public NaGetUninstall(PackageListsManager pkgMan, Uninstallation[] uninstallations)\r
42                 {\r
43                         pkgListMan = pkgMan;\r
44                         \r
45                         Uninstallations = uninstallations;\r
46                         initializeMainTaskSetNames();\r
47                 }\r
48                 \r
49                 private void initializeMainTaskSetNames()\r
50                 {\r
51                         System.Collections.Generic.List<string> taskSetNames = new System.Collections.Generic.List<string>();\r
52                         \r
53                         for (int i =0; i < Uninstallations.Length; i++) {\r
54                                 taskSetNames.Add(string.Format("\83A\83\93\83C\83\93\83X\83g\81[\83\8b: {0}", Uninstallations[i].ToString()));\r
55                         }\r
56                         taskSetNames.Add(string.Format("\83\8a\83X\83g\8dX\90V: {0}", NaGet.Env.ArchiveInstalledPackageListFile));\r
57                         taskSetNames.Add(string.Format("\83\8a\83X\83g\8dX\90V: {0}", NaGet.Env.SystemInstalledPackageListFile));\r
58                         \r
59                         TaskSetNames = taskSetNames.ToArray();\r
60                 }\r
61                 \r
62                 public override void Run()\r
63                 {\r
64                         currentTaskSetIndex ++;\r
65                         RaiseTaskSetEvent(NaGetTaskSetEventType.STARTED, "\83A\83\93\83C\83\93\83X\83g\81[\83\8b\8f\88\97\9d\8aJ\8en");\r
66                         \r
67                         foreach (Uninstallation uninst in Uninstallations) {\r
68                                 RaiseTaskSetEvent(NaGetTaskSetEventType.STARTED_TASKSET, uninst.ToString());\r
69                                 \r
70                                 if (uninst.Installed) {\r
71                                         try {\r
72                                                 uninst.OutputDataReceived += this.ReceivedOutputData;\r
73                                                 uninst.ErrorDataReceived += this.ReceivedErrorData;\r
74                                                 int exitCode = uninst.Uninstall();\r
75                                                 if (exitCode != 0) {\r
76                                                         RaiseTaskSetEvent(NaGetTaskSetEventType.WARNING, "\83A\83\93\83C\83\93\83X\83g\81[\83\8b\82ª\90³\8fí\82É\8fI\82¦\82Ä\82¢\82È\82¢\89Â\94\\90«\82ª\82 \82è\82Ü\82·\81B\83A\83\93\83C\83\93\83X\83g\81[\83\89\82Ì\8fI\97¹\83R\81[\83h:"+exitCode);\r
77                                                 }\r
78                                         } catch (Exception e) {\r
79                                                 RaiseTaskSetEvent(NaGetTaskSetEventType.ERROR, e.Message);\r
80                                                 done = true;\r
81                                                 return;\r
82                                         }\r
83                                 } else {\r
84                                         RaiseTaskSetEvent(NaGetTaskSetEventType.WARNING, string.Format("{0}\82Í\8aù\82É\83A\83\93\83C\83\93\83X\83g\81[\83\8b\82³\82ê\82Ä\82¢\82é\82©\81A\83\\83t\83g\82Ì\91\8dÝ\82ð\8am\94F\82Å\82«\82Ü\82¹\82ñ\82Å\82µ\82½", uninst));\r
85                                 }\r
86                                 \r
87                                 RaiseTaskSetEvent(NaGetTaskSetEventType.COMPLETED_TASKSET, uninst.ToString());\r
88                         }\r
89                         \r
90                         runLocalUpdate();\r
91                         \r
92                         done = true;\r
93                         \r
94                         RaiseTaskSetEvent(NaGetTaskSetEventType.COMPLETED, "\8fI\97¹", 100);\r
95                 }\r
96                 \r
97                 private void runLocalUpdate()\r
98                 {\r
99                         // \83C\83\93\83X\83g\81[\83\8b\83g\83\8a\83X\83g\82Ì\8dX\90V\r
100                         RaiseTaskSetEvent(NaGetTaskSetEventType.STARTED_TASKSET, TaskSetNames[currentTaskSetIndex]);\r
101                         pkgListMan.DetectInstalledPkgs();\r
102                         pkgListMan.SaveInstalledPackageList();\r
103                         currentTaskSetIndex++;\r
104                         RaiseTaskSetEvent(NaGetTaskSetEventType.COMPLETED_TASKSET, TaskSetNames[currentTaskSetIndex-1]);\r
105                 \r
106                         // \83V\83X\83e\83\80\82É\83C\83\93\83X\83g\81[\83\8b\82³\82ê\82Ä\82¢\82é\83\8a\83X\83g\82Ì\8dX\90V\r
107                         RaiseTaskSetEvent(NaGetTaskSetEventType.STARTED_TASKSET, TaskSetNames[currentTaskSetIndex]);\r
108                         pkgListMan.DetectSystemInstalledPkgs();\r
109                         pkgListMan.SaveSystemInstalledPackageList();\r
110                         currentTaskSetIndex++;\r
111                         RaiseTaskSetEvent(NaGetTaskSetEventType.COMPLETED_TASKSET, TaskSetNames[currentTaskSetIndex-1]);\r
112                 }\r
113                 \r
114                 public override bool Done {\r
115                         get { return done; }\r
116                 }\r
117                                 \r
118                 public override int CurrentTaskSetIndex {\r
119                         get { return currentTaskSetIndex; }\r
120                 }\r
121         }\r
122 }\r