OSDN Git Service

na-get-lib,パフォーマンスチューニングなど(動作変更なし)
[applistation/AppliStation.git] / AppliStation / Program.cs
index 9427ff1..e08ba09 100644 (file)
@@ -25,12 +25,11 @@ namespace AppliStation
                        appArgs["cmd"] = string.Empty;\r
                        appArgs["pkgsref"] = string.Empty;\r
                        appArgs["instsref"] = string.Empty;\r
-                       \r
-                       form = new PackageListViewForm();\r
                }\r
                \r
                void RunNormal()\r
                {\r
+                       form = new PackageListViewForm();\r
                        form.Load += delegate(object sender, EventArgs e) {\r
                                hideSplashScreen();\r
                                form.updateActionInvoke(((bool)appArgs["noupdate"]) != true);\r
@@ -45,6 +44,7 @@ namespace AppliStation
                        try {\r
                                NaGet.Packages.Install.Installation[] insts = NaGet.Utils.GetDeserializedObject<NaGet.Packages.Install.Installation[]>((string) appArgs["instsref"]);\r
                                \r
+                               form = new PackageListViewForm();\r
                                hideSplashScreen();\r
                                form.installActionInvoke(insts);\r
                        } catch (UnauthorizedAccessException e) {\r
@@ -61,6 +61,7 @@ namespace AppliStation
                        try {\r
                                NaGet.Packages.Install.InstalledPackage[] pkgs = NaGet.Utils.GetDeserializedObject<NaGet.Packages.Install.InstalledPackage[]>((string) appArgs["pkgsref"]);\r
                                \r
+                               form = new PackageListViewForm();\r
                                hideSplashScreen();\r
                                form.uninstallActionInvoke(pkgs);\r
                        } catch (UnauthorizedAccessException e) {\r
@@ -74,18 +75,37 @@ namespace AppliStation
                \r
                void RunUpdateAppliStation()\r
                {\r
+                       if ( splashScreen == null ) {\r
+                               splashScreen = createAndOpenSplashScreen();\r
+                       }\r
+                       \r
                        System.Threading.Thread.Sleep(5000); /* 5sec待って呼び出しもとの終了を待つ */\r
                        \r
                        string newAppliStationDir = Application.StartupPath;\r
                        string targetDir = Environment.CurrentDirectory;\r
+                       \r
                        foreach (string file in Directory.GetFiles(newAppliStationDir)) {\r
                                string ext = Path.GetExtension(file).ToLower();\r
                                if ((ext == ".exe") || (ext == ".dll") ||\r
                                    (ext == ".pdb") || (ext == ".png")) {\r
-                                       File.Copy(file, Path.Combine(targetDir, Path.GetFileName(file)), true);\r
+                                       while (true) { /* loop for retry */\r
+                                               try {           \r
+                                                       File.Copy(file, Path.Combine(targetDir, Path.GetFileName(file)), true);\r
+                                                       break;\r
+                                               } catch (IOException ex) {\r
+                                                       DialogResult result = MessageBox.Show(string.Format("AppliStationの更新に失敗しました。\r\n\r\n{0}", ex.Message),\r
+                                                                                             "AppliStation", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);\r
+                                                       if (result == DialogResult.Retry) {\r
+                                                               continue; /* retry */\r
+                                                       } else {\r
+                                                               MessageBox.Show("AppliStationの更新は中断されました。", "AppliStation", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
+                                                               hideSplashScreen();\r
+                                                               return;\r
+                                                       }\r
+                                               }\r
+                                       }\r
                                }\r
                        }\r
-MessageBox.Show("Installation is completed.");\r
                        System.Threading.Thread.Sleep(10);\r
                        System.Diagnostics.Process.Start(Path.Combine(targetDir, Path.GetFileName(Application.ExecutablePath)));\r
                        hideSplashScreen();\r
@@ -106,14 +126,10 @@ MessageBox.Show("Installation is completed.");
                                \r
                                if (Directory.Exists(newAppliStationDir)) {\r
                                        string newAppliStation = Path.Combine(newAppliStationDir, Path.GetFileName(thisAppliStation));\r
-                                       \r
-MessageBox.Show(string.Format("{0}\r\n{1}", newAppliStation, File.Exists(newAppliStation)));\r
-MessageBox.Show(string.Format("{0}\r\n{1}", File.GetLastWriteTime(thisAppliStation), File.GetLastWriteTime(newAppliStation)));\r
-MessageBox.Show(string.Format("{0}", File.GetLastWriteTime(thisAppliStation) < File.GetLastWriteTime(newAppliStation)));\r
-                                       \r
+                                                                               \r
                                        if ( File.Exists(newAppliStation) &&\r
-                                           (File.GetLastWriteTime(thisAppliStation) < File.GetLastWriteTime(newAppliStation)) ) {\r
-\r
+                                           (File.GetLastWriteTime(thisAppliStation) != File.GetLastWriteTime(newAppliStation)) ) {\r
+                                               \r
                                                System.Diagnostics.Process.Start(newAppliStation, "--cmd=updateAppliStation");\r
                                                return true;\r
                                        }\r
@@ -171,6 +187,20 @@ MessageBox.Show(string.Format("{0}", File.GetLastWriteTime(thisAppliStation) < F
                        restAppArgs = parser.Parse(args);\r
                }\r
                \r
+               private static Form createAndOpenSplashScreen()\r
+               {\r
+                       System.Drawing.Bitmap bitmap;\r
+                       \r
+                       bitmap = new System.Drawing.Bitmap(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "SplashScreen.png"));\r
+                       Form splashScreen = AppliStation.Util.SprashScreenLayered.CreateSprashScreenLayered(bitmap, System.Drawing.Color.Black);\r
+                       \r
+                       splashScreen.Text = "AppliStation";\r
+                       splashScreen.Icon = System.Drawing.Icon.ExtractAssociatedIcon(Application.ExecutablePath);\r
+                       splashScreen.Show();\r
+                       \r
+                       return splashScreen;\r
+               }\r
+               \r
                [STAThread]\r
                public static void Main(string[] args)\r
                {\r
@@ -178,14 +208,7 @@ MessageBox.Show(string.Format("{0}", File.GetLastWriteTime(thisAppliStation) < F
                        \r
                        try {\r
                                if (args.Length <= 0) { // HACK 引数パースの時間さえ待てないので引数の有無で表示を判断\r
-                                       splashScreen = new Form();\r
-                                       splashScreen.FormBorderStyle = FormBorderStyle.None;\r
-                                       splashScreen.BackgroundImage = System.Drawing.Bitmap.FromFile(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "SplashScreen.png"));\r
-                                       splashScreen.Size = splashScreen.BackgroundImage.Size;\r
-                                       splashScreen.ShowIcon = false;\r
-                                       splashScreen.ShowInTaskbar = false;\r
-                                       splashScreen.StartPosition = FormStartPosition.CenterScreen;\r
-                                       splashScreen.Show();\r
+                                       splashScreen = createAndOpenSplashScreen();\r
                                }\r
                                \r
                                // アーカイブSYSTEM32をパスに足す\r
@@ -194,8 +217,11 @@ MessageBox.Show(string.Format("{0}", File.GetLastWriteTime(thisAppliStation) < F
                                ToolStripManager.VisualStylesEnabled = false; // ToolStripがLunaで青くならないように\r
                                Application.EnableVisualStyles(); // LunaやVistaのデザインを有効に\r
                                \r
-                               Application.ThreadException += AppliStation.Util.ExceptionDialogForm.Application_ThrowException;\r
-                               System.Threading.Thread.GetDomain().UnhandledException += AppliStation.Util.ExceptionDialogForm.Application_ThrowException;\r
+                               // デバッガがアタッチしていないなら、Exceptionを自力でハンドルする\r
+                               if (! System.Diagnostics.Debugger.IsAttached) {\r
+                                       Application.ThreadException += AppliStation.Util.ExceptionDialogForm.Application_ThrowException;\r
+                                       System.Threading.Thread.GetDomain().UnhandledException += AppliStation.Util.ExceptionDialogForm.Application_ThrowException;\r
+                               }\r
                                \r
                                Program prog = new Program();\r
                                prog.splashScreen = splashScreen;\r