2 using System.Collections.Generic;
\r
3 using System.Windows.Forms;
\r
6 namespace AppliStation
\r
12 PackageListViewForm form;
\r
17 Dictionary<string, object> appArgs;
\r
19 string[] restAppArgs;
\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
32 form = new PackageListViewForm();
\r
33 form.Load += delegate(object sender, EventArgs e) {
\r
35 form.updateActionInvoke(((bool)appArgs["noupdate"]) != true);
\r
37 form.UpdatePackageList();
\r
39 Application.Run(form);
\r
45 NaGet.Packages.Install.Installation[] insts = NaGet.Utils.GetDeserializedObject<NaGet.Packages.Install.Installation[]>((string) appArgs["instsref"]);
\r
47 form = new PackageListViewForm();
\r
49 form.installActionInvoke(insts);
\r
50 } catch (UnauthorizedAccessException e) {
\r
51 MessageBox.Show(string.Format("管理者権限に昇格していないか、実行権限に問題があります。\n(詳細:{0})", e.Message),
\r
52 Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
\r
53 } catch (FileNotFoundException e) {
\r
54 MessageBox.Show(string.Format("ソフト指定ファイル{0}が見つかりません", e.FileName),
\r
55 Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
\r
62 NaGet.Packages.Install.InstalledPackage[] pkgs = NaGet.Utils.GetDeserializedObject<NaGet.Packages.Install.InstalledPackage[]>((string) appArgs["pkgsref"]);
\r
64 form = new PackageListViewForm();
\r
66 form.uninstallActionInvoke(pkgs);
\r
67 } catch (UnauthorizedAccessException e) {
\r
68 MessageBox.Show(string.Format("管理者権限に昇格していないか、実行権限に問題があります。\n(詳細:{0})", e.Message),
\r
69 Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
\r
70 } catch (FileNotFoundException e) {
\r
71 MessageBox.Show(string.Format("ソフト指定ファイル{0}が見つかりません", e.FileName),
\r
72 Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
\r
76 void RunUpdateAppliStation()
\r
78 if ( splashScreen == null ) {
\r
79 splashScreen = createAndOpenSplashScreen();
\r
82 System.Threading.Thread.Sleep(5000); /* 5sec待って呼び出しもとの終了を待つ */
\r
84 string newAppliStationDir = Application.StartupPath;
\r
85 string targetDir = Environment.CurrentDirectory;
\r
87 foreach (string file in Directory.GetFiles(newAppliStationDir)) {
\r
88 string ext = Path.GetExtension(file).ToLower();
\r
89 if ((ext == ".exe") || (ext == ".dll") ||
\r
90 (ext == ".pdb") || (ext == ".png")) {
\r
91 while (true) { /* loop for retry */
\r
93 File.Copy(file, Path.Combine(targetDir, Path.GetFileName(file)), true);
\r
95 } catch (IOException ex) {
\r
96 DialogResult result = MessageBox.Show(string.Format("AppliStationの更新に失敗しました。\r\n\r\n{0}", ex.Message),
\r
97 "AppliStation", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
\r
98 if (result == DialogResult.Retry) {
\r
99 continue; /* retry */
\r
101 MessageBox.Show("AppliStationの更新は中断されました。", "AppliStation", MessageBoxButtons.OK, MessageBoxIcon.Error);
\r
102 hideSplashScreen();
\r
109 System.Threading.Thread.Sleep(10);
\r
110 System.Diagnostics.Process.Start(Path.Combine(targetDir, Path.GetFileName(Application.ExecutablePath)));
\r
111 hideSplashScreen();
\r
112 //Application.Exit(); // Do nothing = exit
\r
116 /// AppliStationの自己更新を行う。アーカイブインストーラによってあらかじめインストールされたファイルを、
\r
117 /// カレントディレクトリにコピーするよう新しいAppliStation.exeを呼ぶ。
\r
118 /// コピー元がないまたはそれが新しくないならば何もしない。
\r
120 /// <returns>更新をしたときtrueをかえす。</returns>
\r
121 private bool autoUpdateAppliStation()
\r
123 if (string.IsNullOrEmpty(appArgs["cmd"].ToString())) {
\r
124 string newAppliStationDir = Path.Combine(NaGet.Env.ArchiveProgramFiles, "AppliStation");
\r
125 string thisAppliStation = Application.ExecutablePath;
\r
127 if (Directory.Exists(newAppliStationDir)) {
\r
128 string newAppliStation = Path.Combine(newAppliStationDir, Path.GetFileName(thisAppliStation));
\r
130 if ( File.Exists(newAppliStation) &&
\r
131 (File.GetLastWriteTime(thisAppliStation) != File.GetLastWriteTime(newAppliStation)) ) {
\r
133 System.Diagnostics.Process.Start(newAppliStation, "--cmd=updateAppliStation");
\r
141 private void hideSplashScreen()
\r
143 if (splashScreen != null && splashScreen.Visible) {
\r
144 splashScreen.Hide();
\r
145 splashScreen.Dispose();
\r
149 public void Run(string[] args)
\r
153 } catch (ApplicationException e) {
\r
154 MessageBox.Show(e.Message, "AppliStation 起動引数エラー", MessageBoxButtons.OK, MessageBoxIcon.Error);
\r
158 // cmd引数がないときに更新処理を試みる。
\r
159 // cmd引数があるときに更新しないのは、AppliStationから「管理者で実行」などで呼び出された場合に
\r
160 // 更新処理にならないようにするため。
\r
161 if ( string.IsNullOrEmpty((string) appArgs["cmd"]) &&
\r
162 autoUpdateAppliStation() ) {
\r
163 // アップデートしたときは起動しない
\r
168 switch ((string) appArgs["cmd"]) {
\r
175 case "updateAppliStation":
\r
176 RunUpdateAppliStation();
\r
184 private void parseArgs(string[] args)
\r
186 NaGet.ArgParser parser = new NaGet.ArgParser(appArgs);
\r
187 restAppArgs = parser.Parse(args);
\r
190 private static Form createAndOpenSplashScreen()
\r
192 System.Drawing.Bitmap bitmap;
\r
194 bitmap = new System.Drawing.Bitmap(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "SplashScreen.png"));
\r
195 Form splashScreen = AppliStation.Util.SprashScreenLayered.CreateSprashScreenLayered(bitmap, System.Drawing.Color.Black);
\r
197 splashScreen.Text = "AppliStation";
\r
198 splashScreen.Icon = System.Drawing.Icon.ExtractAssociatedIcon(Application.ExecutablePath);
\r
199 splashScreen.Show();
\r
201 return splashScreen;
\r
205 public static void Main(string[] args)
\r
207 Form splashScreen = null;
\r
210 if (args.Length <= 0) { // HACK 引数パースの時間さえ待てないので引数の有無で表示を判断
\r
211 splashScreen = createAndOpenSplashScreen();
\r
214 // アーカイブSYSTEM32をパスに足す
\r
215 NaGet.Utils.AddDirectoryToPath(NaGet.Env.ArchiveSystem32);
\r
217 ToolStripManager.VisualStylesEnabled = false; // ToolStripがLunaで青くならないように
\r
218 Application.EnableVisualStyles(); // LunaやVistaのデザインを有効に
\r
220 // デバッガがアタッチしていないなら、Exceptionを自力でハンドルする
\r
221 if (! System.Diagnostics.Debugger.IsAttached) {
\r
222 Application.ThreadException += AppliStation.Util.ExceptionDialogForm.Application_ThrowException;
\r
223 System.Threading.Thread.GetDomain().UnhandledException += AppliStation.Util.ExceptionDialogForm.Application_ThrowException;
\r
226 Program prog = new Program();
\r
227 prog.splashScreen = splashScreen;
\r
229 } catch (Exception e) {
\r
230 AppliStation.Util.ExceptionDialogForm.Application_ThrowException(null, new System.Threading.ThreadExceptionEventArgs(e));
\r
232 if (splashScreen != null) {
\r
233 splashScreen.Dispose();
\r