From 19a4b02b3e0433abb9f401d8e2d8ca88696801f1 Mon Sep 17 00:00:00 2001 From: ttp Date: Sat, 29 Nov 2008 10:31:09 +0000 Subject: [PATCH 1/1] =?utf8?q?AppliStation-GUI,=E8=87=AA=E5=B7=B1=E3=82=A4?= =?utf8?q?=E3=83=B3=E3=82=B9=E3=83=88=E3=83=BC=E3=83=AB=E3=81=AE=E3=83=86?= =?utf8?q?=E3=82=B9=E3=83=88=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit とりあえず動いている。これからは、AppliStationをAppliStationで更新した後に起動すれば勝手に書き換えられる。 更新時にスプラッシュが表示されないとか、あやしいのでデバッグMessageBox.Show付き git-svn-id: http://localhost/svn/AppliStation/trunk@994 34ed2c89-c49f-4a4b-abdb-c318350108cf --- AppliStation/Program.cs | 63 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/AppliStation/Program.cs b/AppliStation/Program.cs index 381deae..9427ff1 100644 --- a/AppliStation/Program.cs +++ b/AppliStation/Program.cs @@ -72,6 +72,56 @@ namespace AppliStation } } + void RunUpdateAppliStation() + { + System.Threading.Thread.Sleep(5000); /* 5sec待って呼び出しもとの終了を待つ */ + + string newAppliStationDir = Application.StartupPath; + string targetDir = Environment.CurrentDirectory; + foreach (string file in Directory.GetFiles(newAppliStationDir)) { + string ext = Path.GetExtension(file).ToLower(); + if ((ext == ".exe") || (ext == ".dll") || + (ext == ".pdb") || (ext == ".png")) { + File.Copy(file, Path.Combine(targetDir, Path.GetFileName(file)), true); + } + } +MessageBox.Show("Installation is completed."); + System.Threading.Thread.Sleep(10); + System.Diagnostics.Process.Start(Path.Combine(targetDir, Path.GetFileName(Application.ExecutablePath))); + hideSplashScreen(); + //Application.Exit(); // Do nothing = exit + } + + /// + /// AppliStationの自己更新を行う。アーカイブインストーラによってあらかじめインストールされたファイルを、 + /// カレントディレクトリにコピーするよう新しいAppliStation.exeを呼ぶ。 + /// コピー元がないまたはそれが新しくないならば何もしない。 + /// + /// 更新をしたときtrueをかえす。 + private bool autoUpdateAppliStation() + { + if (string.IsNullOrEmpty(appArgs["cmd"].ToString())) { + string newAppliStationDir = Path.Combine(NaGet.Env.ArchiveProgramFiles, "AppliStation"); + string thisAppliStation = Application.ExecutablePath; + + if (Directory.Exists(newAppliStationDir)) { + string newAppliStation = Path.Combine(newAppliStationDir, Path.GetFileName(thisAppliStation)); + +MessageBox.Show(string.Format("{0}\r\n{1}", newAppliStation, File.Exists(newAppliStation))); +MessageBox.Show(string.Format("{0}\r\n{1}", File.GetLastWriteTime(thisAppliStation), File.GetLastWriteTime(newAppliStation))); +MessageBox.Show(string.Format("{0}", File.GetLastWriteTime(thisAppliStation) < File.GetLastWriteTime(newAppliStation))); + + if ( File.Exists(newAppliStation) && + (File.GetLastWriteTime(thisAppliStation) < File.GetLastWriteTime(newAppliStation)) ) { + + System.Diagnostics.Process.Start(newAppliStation, "--cmd=updateAppliStation"); + return true; + } + } + } + return false; + } + private void hideSplashScreen() { if (splashScreen != null && splashScreen.Visible) { @@ -89,6 +139,16 @@ namespace AppliStation return; } + // cmd引数がないときに更新処理を試みる。 + // cmd引数があるときに更新しないのは、AppliStationから「管理者で実行」などで呼び出された場合に + // 更新処理にならないようにするため。 + if ( string.IsNullOrEmpty((string) appArgs["cmd"]) && + autoUpdateAppliStation() ) { + // アップデートしたときは起動しない + return; + } + + switch ((string) appArgs["cmd"]) { case "install": RunInstall(); @@ -96,6 +156,9 @@ namespace AppliStation case "uninstall": RunUninstall(); break; + case "updateAppliStation": + RunUpdateAppliStation(); + break; default: RunNormal(); break; -- 2.11.0