AppliStation
修订版 | 19a4b02b3e0433abb9f401d8e2d8ca88696801f1 (tree) |
---|---|
时间 | 2008-11-29 19:31:09 |
作者 | ttp <ttp@user...> |
Commiter | ttp |
AppliStation-GUI,自己インストールのテスト実装
とりあえず動いている。これからは、AppliStationをAppliStationで更新した後に起動すれば勝手に書き換えられる。
更新時にスプラッシュが表示されないとか、あやしいのでデバッグMessageBox.Show付き
git-svn-id: http://localhost/svn/AppliStation/trunk@994 34ed2c89-c49f-4a4b-abdb-c318350108cf
@@ -72,6 +72,56 @@ namespace AppliStation | ||
72 | 72 | } |
73 | 73 | } |
74 | 74 | |
75 | + void RunUpdateAppliStation() | |
76 | + { | |
77 | + System.Threading.Thread.Sleep(5000); /* 5sec待って呼び出しもとの終了を待つ */ | |
78 | + | |
79 | + string newAppliStationDir = Application.StartupPath; | |
80 | + string targetDir = Environment.CurrentDirectory; | |
81 | + foreach (string file in Directory.GetFiles(newAppliStationDir)) { | |
82 | + string ext = Path.GetExtension(file).ToLower(); | |
83 | + if ((ext == ".exe") || (ext == ".dll") || | |
84 | + (ext == ".pdb") || (ext == ".png")) { | |
85 | + File.Copy(file, Path.Combine(targetDir, Path.GetFileName(file)), true); | |
86 | + } | |
87 | + } | |
88 | +MessageBox.Show("Installation is completed."); | |
89 | + System.Threading.Thread.Sleep(10); | |
90 | + System.Diagnostics.Process.Start(Path.Combine(targetDir, Path.GetFileName(Application.ExecutablePath))); | |
91 | + hideSplashScreen(); | |
92 | + //Application.Exit(); // Do nothing = exit | |
93 | + } | |
94 | + | |
95 | + /// <summary> | |
96 | + /// AppliStationの自己更新を行う。アーカイブインストーラによってあらかじめインストールされたファイルを、 | |
97 | + /// カレントディレクトリにコピーするよう新しいAppliStation.exeを呼ぶ。 | |
98 | + /// コピー元がないまたはそれが新しくないならば何もしない。 | |
99 | + /// </summary> | |
100 | + /// <returns>更新をしたときtrueをかえす。</returns> | |
101 | + private bool autoUpdateAppliStation() | |
102 | + { | |
103 | + if (string.IsNullOrEmpty(appArgs["cmd"].ToString())) { | |
104 | + string newAppliStationDir = Path.Combine(NaGet.Env.ArchiveProgramFiles, "AppliStation"); | |
105 | + string thisAppliStation = Application.ExecutablePath; | |
106 | + | |
107 | + if (Directory.Exists(newAppliStationDir)) { | |
108 | + string newAppliStation = Path.Combine(newAppliStationDir, Path.GetFileName(thisAppliStation)); | |
109 | + | |
110 | +MessageBox.Show(string.Format("{0}\r\n{1}", newAppliStation, File.Exists(newAppliStation))); | |
111 | +MessageBox.Show(string.Format("{0}\r\n{1}", File.GetLastWriteTime(thisAppliStation), File.GetLastWriteTime(newAppliStation))); | |
112 | +MessageBox.Show(string.Format("{0}", File.GetLastWriteTime(thisAppliStation) < File.GetLastWriteTime(newAppliStation))); | |
113 | + | |
114 | + if ( File.Exists(newAppliStation) && | |
115 | + (File.GetLastWriteTime(thisAppliStation) < File.GetLastWriteTime(newAppliStation)) ) { | |
116 | + | |
117 | + System.Diagnostics.Process.Start(newAppliStation, "--cmd=updateAppliStation"); | |
118 | + return true; | |
119 | + } | |
120 | + } | |
121 | + } | |
122 | + return false; | |
123 | + } | |
124 | + | |
75 | 125 | private void hideSplashScreen() |
76 | 126 | { |
77 | 127 | if (splashScreen != null && splashScreen.Visible) { |
@@ -89,6 +139,16 @@ namespace AppliStation | ||
89 | 139 | return; |
90 | 140 | } |
91 | 141 | |
142 | + // cmd引数がないときに更新処理を試みる。 | |
143 | + // cmd引数があるときに更新しないのは、AppliStationから「管理者で実行」などで呼び出された場合に | |
144 | + // 更新処理にならないようにするため。 | |
145 | + if ( string.IsNullOrEmpty((string) appArgs["cmd"]) && | |
146 | + autoUpdateAppliStation() ) { | |
147 | + // アップデートしたときは起動しない | |
148 | + return; | |
149 | + } | |
150 | + | |
151 | + | |
92 | 152 | switch ((string) appArgs["cmd"]) { |
93 | 153 | case "install": |
94 | 154 | RunInstall(); |
@@ -96,6 +156,9 @@ namespace AppliStation | ||
96 | 156 | case "uninstall": |
97 | 157 | RunUninstall(); |
98 | 158 | break; |
159 | + case "updateAppliStation": | |
160 | + RunUpdateAppliStation(); | |
161 | + break; | |
99 | 162 | default: |
100 | 163 | RunNormal(); |
101 | 164 | break; |