OSDN Git Service

na-get-lib,ダウンロードしたインストーラファイルの権限を落とす暫定コードを追加。
[applistation/AppliStation.git] / na-get-lib / NaGet.SubCommands / NaGetTaskSet.cs
1 using System;\r
2 \r
3 namespace NaGet.SubCommands\r
4 {\r
5         #region EventHandler<NaGetTaskSetEventArgs>\8aÖ\98A\r
6         \r
7         public class NaGetTaskSetEventArgs : NaGetEventArgs\r
8         {\r
9                 public NaGetTaskSetEventType Type;\r
10                 \r
11                 public NaGetTaskSetEventArgs(NaGetTaskSetEventType type, string message, float processPercent)\r
12                 {\r
13                         this.Type = type;\r
14                         this.TaskMessage = message;\r
15                         this.TaskProgressPercent = processPercent;\r
16                 }\r
17         }\r
18         \r
19         /// <summary>\r
20         /// \83^\83X\83N\82Ì\8eí\97Þ\r
21         /// </summary>\r
22         public enum NaGetTaskSetEventType\r
23         {\r
24                 /// <summary>\r
25                 /// \8aJ\8en\r
26                 /// </summary>\r
27                 STARTED,\r
28                 /// <summary>\r
29                 /// \8a®\97¹\82µ\82½(\82·\82×\82Ä\82ð\8a®\97¹)\r
30                 /// </summary>\r
31                 COMPLETED,\r
32                 /// <summary>\r
33                 /// \8dì\8bÆ\82ª\83L\83\83\83\93\83Z\83\8b\82³\82ê\82½\r
34                 /// </summary>\r
35                 CANCELED,\r
36                 /// <summary>\r
37                 /// \83G\83\89\81[\82ð\94­\90\82µ(\92\86\92f\82µ\82½)\r
38                 /// </summary>\r
39                 ERROR,\r
40                 /// <summary>\r
41                 /// \83G\83\89\81[\82ª\94­\90\82µ\82½\82ª\8cp\91±\r
42                 /// </summary>\r
43                 WARNING,\r
44                 /// <summary>\r
45                 /// \82»\82Ì\82Ù\82©\82Ì\8fî\95ñ\r
46                 /// </summary>\r
47                 INFO,\r
48                 /// <summary>\r
49                 /// \8dì\8bÆ\82ð\8aJ\8en\r
50                 /// </summary>\r
51                 STARTED_TASKSET,\r
52                 /// <summary>\r
53                 /// \8dì\8bÆ\82ð\8fI\97¹\r
54                 /// </summary>\r
55                 COMPLETED_TASKSET,\r
56         }\r
57         \r
58         #endregion\r
59         \r
60         #region NaGetTaskQueryHandler\8aÖ\98A\r
61         \r
62         public delegate NaGetTaskQueryResult NaGetTaskQueryHandler(object sender, NaGetTaskQueryArgs e);\r
63         \r
64         public class NaGetTaskQueryArgs\r
65         {\r
66                 /// <summary>\r
67                 /// \83^\83X\83N\82Ì\8c»\8bµ\82Ì\83\81\83b\83Z\81[\83W\r
68                 /// </summary>\r
69                 public string Message;\r
70                 \r
71                 /// <summary>\r
72                 /// \89ñ\93\9a\82Ì\8eí\97Þ\82Ì\83t\83\89\83O\r
73                 /// </summary>\r
74                 public NaGetTaskQueryResult SelectionFlag;\r
75                 \r
76                 public NaGetTaskQueryArgs(string message, NaGetTaskQueryResult selectionFlag)\r
77                 {\r
78                         this.Message = message;\r
79                         this.SelectionFlag = selectionFlag;\r
80                 }\r
81         }\r
82         \r
83         /// <summary>\r
84         /// \8e¿\96â\82Ì\93\9a\82¦\r
85         /// </summary>\r
86         [Flags()]\r
87         public enum NaGetTaskQueryResult : uint\r
88         {\r
89                 /// <summary>\r
90                 /// \8cp\91±(=OK)\r
91                 /// </summary>\r
92                 CONTINUE = 0x01,\r
93                 /// <summary>\r
94                 /// \8dÄ\8e\8e\8ds\r
95                 /// </summary>\r
96                 RETRY = 0x02,\r
97                 /// <summary>\r
98                 /// \83L\83\83\83\93\83Z\83\8b\81A\92\86\8e~\r
99                 /// </summary>\r
100                 CANCEL = 0x04,\r
101                 /// <summary>\r
102                 /// \8e©\93®\93I\82È\83L\83\83\83\93\83Z\83\8b(\83\86\81[\83U\82Ì\8eè\82Å\82Í\82È\82¢\82à\82Ì)\r
103                 /// </summary>\r
104                 CANCELED_AUTOMATICALLY = 0x00,\r
105         }\r
106         \r
107         \r
108         #endregion\r
109         \r
110         /// <summary>\r
111         /// NaGet\83^\83X\83N\8f\88\97\9d\82Ì\83p\83b\83N\r
112         /// </summary>\r
113         public abstract class NaGetTaskSet : NaGetTask\r
114         {\r
115                 /// <summary>\r
116                 /// \83^\83X\83N\8f\88\97\9d\82Ì\83C\83x\83\93\83g\83n\83\93\83h\83\89\r
117                 /// </summary>\r
118                 public event EventHandler<NaGetTaskSetEventArgs> TaskSetRaised;\r
119                 \r
120                 /// <summary>\r
121                 /// \83^\83X\83N\8f\88\97\9d\92\86\82Ì\8e¿\96â\82Ì\83n\83\93\83h\83\89\r
122                 /// </summary>\r
123                 public event NaGetTaskQueryHandler TaskQueryRaised;\r
124                 \r
125                 /// <summary>\r
126                 /// \95\8e\9a\97ñ\82Å\95\\8c»\82µ\82½\8dì\8bÆ\88ê\97\97\83\8a\83X\83g\r
127                 /// </summary>\r
128                 public string[] TaskSetNames;\r
129                 \r
130                 /// <summary>\r
131                 /// \8c»\8dÝ\8eÀ\8ds\92\86\82Ì\8dì\8bÆ\94Ô\8d\86\r
132                 /// </summary>\r
133                 public abstract int CurrentTaskSetIndex {\r
134                         get;\r
135                 }\r
136                 \r
137                 protected virtual void RaiseTaskSetEvent(NaGetTaskSetEventType type, string message)\r
138                 {\r
139                         float percent = (CurrentTaskSetIndex >= 0)? CurrentTaskSetIndex * 100 / TaskSetNames.Length : -1;\r
140                         RaiseTaskSetEvent(type, message, percent);\r
141                 }\r
142                 \r
143                 protected virtual void RaiseTaskSetEvent(NaGetTaskSetEventType type, string message, float percent)\r
144                 {\r
145                         if (TaskSetRaised != null) {\r
146                                 TaskSetRaised(this, new NaGetTaskSetEventArgs(type, message, percent));\r
147                         }\r
148                 }\r
149                 \r
150                 protected virtual void ReceivedErrorData(object sender, NaGet.Utils.AnyDataEventArgs<string> e)\r
151                 {\r
152                         if (! string.IsNullOrEmpty(e.Data)) {\r
153                                 RaiseTaskSetEvent(NaGetTaskSetEventType.WARNING, e.Data);\r
154                         }\r
155                 }\r
156                 \r
157                 protected virtual void ReceivedOutputData(object sender, NaGet.Utils.AnyDataEventArgs<string> e)\r
158                 {\r
159                         if (! string.IsNullOrEmpty(e.Data)) {\r
160                                 RaiseTaskSetEvent(NaGetTaskSetEventType.INFO, e.Data);\r
161                         }\r
162                 }\r
163                 \r
164                 protected virtual NaGetTaskQueryResult RaiseTaskSetQueryEvent(string message, NaGetTaskQueryResult selection)\r
165                 {\r
166                         if (TaskQueryRaised != null) {\r
167                                 return TaskQueryRaised(this, new NaGetTaskQueryArgs(message, selection));\r
168                         }\r
169                         return NaGetTaskQueryResult.CANCELED_AUTOMATICALLY;\r
170                 }\r
171                 \r
172                 public override bool Running {\r
173                         get { return CurrentTaskSetIndex >= 0 && !Done; }\r
174                 }\r
175         }\r
176 }\r