OSDN Git Service

AppliStation\PackageInfoForm.resx 追加
[applistation/AppliStation.git] / AppliStation / Program.cs
1 using System;\r
2 using System.Collections.Generic;\r
3 using System.Windows.Forms;\r
4 using System.IO;\r
5 \r
6 namespace AppliStation\r
7 {\r
8         class Program\r
9         {\r
10                 Form splashScreen;\r
11                 \r
12                 PackageListViewForm form;\r
13                 \r
14                 /// <summary>\r
15                 /// \83A\83v\83\8a\83P\81[\83V\83\87\83\93\82Ì\83I\83v\83V\83\87\83\93\r
16                 /// </summary>\r
17                 Dictionary<string, object> appArgs;\r
18                 \r
19                 string[] restAppArgs;\r
20                 \r
21                 public Program()\r
22                 {\r
23                         appArgs = new Dictionary<string, object>();\r
24                         appArgs["noupdate"] = false;\r
25                         appArgs["cmd"] = string.Empty;\r
26                         appArgs["pkgsref"] = string.Empty;\r
27                         appArgs["instsref"] = string.Empty;\r
28                         \r
29                         form = new PackageListViewForm();\r
30                 }\r
31                 \r
32                 void RunNormal()\r
33                 {\r
34                         form.Load += delegate(object sender, EventArgs e) {\r
35                                 hideSplashScreen();\r
36                                 form.updateActionInvoke(((bool)appArgs["noupdate"]) != true);\r
37                                 \r
38                                 form.UpdatePackageList();\r
39                         };\r
40                         Application.Run(form);\r
41                 }\r
42                 \r
43                 void RunInstall()\r
44                 {\r
45                         try {\r
46                                 NaGet.Packages.Install.Installation[] insts = NaGet.Utils.GetDeserializedObject<NaGet.Packages.Install.Installation[]>((string) appArgs["instsref"]);\r
47                                 \r
48                                 hideSplashScreen();\r
49                                 form.installActionInvoke(insts);\r
50                         } catch (UnauthorizedAccessException e) {\r
51                                 MessageBox.Show(string.Format("\8aÇ\97\9d\8eÒ\8c \8cÀ\82É\8f¸\8ai\82µ\82Ä\82¢\82È\82¢\82©\81A\8eÀ\8ds\8c \8cÀ\82É\96â\91è\82ª\82 \82è\82Ü\82·\81B\n(\8fÚ\8d×:{0})", e.Message),\r
52                                                 Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);\r
53                         } catch (FileNotFoundException e) {\r
54                                 MessageBox.Show(string.Format("\83\\83t\83g\8ew\92è\83t\83@\83C\83\8b{0}\82ª\8c©\82Â\82©\82è\82Ü\82¹\82ñ", e.FileName),\r
55                                                 Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);\r
56                         }\r
57                 }\r
58                 \r
59                 void RunUninstall()\r
60                 {\r
61                         try {\r
62                                 NaGet.Packages.Install.InstalledPackage[] pkgs = NaGet.Utils.GetDeserializedObject<NaGet.Packages.Install.InstalledPackage[]>((string) appArgs["pkgsref"]);\r
63                                 \r
64                                 hideSplashScreen();\r
65                                 form.uninstallActionInvoke(pkgs);\r
66                         } catch (UnauthorizedAccessException e) {\r
67                                 MessageBox.Show(string.Format("\8aÇ\97\9d\8eÒ\8c \8cÀ\82É\8f¸\8ai\82µ\82Ä\82¢\82È\82¢\82©\81A\8eÀ\8ds\8c \8cÀ\82É\96â\91è\82ª\82 \82è\82Ü\82·\81B\n(\8fÚ\8d×:{0})", e.Message),\r
68                                                 Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);\r
69                         } catch (FileNotFoundException e) {\r
70                                 MessageBox.Show(string.Format("\83\\83t\83g\8ew\92è\83t\83@\83C\83\8b{0}\82ª\8c©\82Â\82©\82è\82Ü\82¹\82ñ", e.FileName),\r
71                                                 Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);\r
72                         }\r
73                 }\r
74                 \r
75                 private void hideSplashScreen()\r
76                 {\r
77                         if (splashScreen != null && splashScreen.Visible) {\r
78                                 splashScreen.Hide();\r
79                                 splashScreen.Dispose();\r
80                         }\r
81                 }\r
82                 \r
83                 public void Run(string[] args)\r
84                 {\r
85                         parseArgs(args);\r
86                         \r
87                         switch ((string) appArgs["cmd"]) {\r
88                                 case "install":\r
89                                         RunInstall();\r
90                                         break;\r
91                                 case "uninstall":\r
92                                         RunUninstall();\r
93                                         break;\r
94                                 default:\r
95                                         RunNormal();\r
96                                         break;\r
97                         }\r
98                 }\r
99                 \r
100                 private void parseArgs(string[] args)\r
101                 {\r
102                         NaGet.ArgParser parser = new NaGet.ArgParser(appArgs);\r
103                         restAppArgs = parser.Parse(args);\r
104                 }\r
105                 \r
106                 [STAThread]\r
107                 public static void Main(string[] args)\r
108                 {\r
109                         Form splashScreen = null;\r
110                         \r
111                         try {\r
112                                 if (args.Length <= 0) { // HACK \88ø\90\94\83p\81[\83X\82Ì\8e\9e\8aÔ\82³\82¦\91Ò\82Ä\82È\82¢\82Ì\82Å\88ø\90\94\82Ì\97L\96³\82Å\95\\8e¦\82ð\94»\92f\r
113                                         splashScreen = new Form();\r
114                                         splashScreen.FormBorderStyle = FormBorderStyle.None;\r
115                                         splashScreen.BackgroundImage = System.Drawing.Bitmap.FromFile(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "SplashScreen.png"));\r
116                                         splashScreen.Size = splashScreen.BackgroundImage.Size;\r
117                                         splashScreen.ShowIcon = false;\r
118                                         splashScreen.ShowInTaskbar = false;\r
119                                         splashScreen.StartPosition = FormStartPosition.CenterScreen;\r
120                                         splashScreen.Show();\r
121                                 }\r
122                                 \r
123                                 ToolStripManager.VisualStylesEnabled = false; // ToolStrip\82ªLuna\82Å\90Â\82­\82È\82ç\82È\82¢\82æ\82¤\82É\r
124                                 Application.EnableVisualStyles(); // Luna\82âVista\82Ì\83f\83U\83C\83\93\82ð\97L\8cø\82É\r
125                                 \r
126                                 Application.ThreadException += AppliStation.Util.ExceptionDialogForm.Application_ThrowException;\r
127                                 System.Threading.Thread.GetDomain().UnhandledException += AppliStation.Util.ExceptionDialogForm.Application_ThrowException;\r
128                                 \r
129                                 Program prog = new Program();\r
130                                 prog.splashScreen = splashScreen;\r
131                                 prog.Run(args);\r
132                         } catch (Exception e) {\r
133                                 AppliStation.Util.ExceptionDialogForm.Application_ThrowException(null, new System.Threading.ThreadExceptionEventArgs(e));\r
134                         } finally {\r
135                                 if (splashScreen != null) {\r
136                                         splashScreen.Dispose();\r
137                                 }\r
138                         }\r
139                 }\r
140         }\r
141 }\r