X-Git-Url: http://git.sourceforge.jp/view?p=applistation%2FAppliStation.git;a=blobdiff_plain;f=AppliStation%2FProgram.cs;h=466944d282a3c0da9e9e14e27324ae1f536d5829;hp=9b16164a5e6c43295d5fc1a1a8b1cc49b8fd2aee;hb=HEAD;hpb=d77e489a312afb2db4612269f7275c6ac1fd17cc diff --git a/AppliStation/Program.cs b/AppliStation/Program.cs index 9b16164..466944d 100644 --- a/AppliStation/Program.cs +++ b/AppliStation/Program.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Windows.Forms; using System.IO; @@ -12,24 +12,22 @@ namespace AppliStation PackageListViewForm form; /// - /// ƒAƒvƒŠƒP[ƒVƒ‡ƒ“‚̃IƒvƒVƒ‡ƒ“ + /// アプリケーションのオプション /// Dictionary appArgs; - string[] restAppArgs; - public Program() { appArgs = new Dictionary(); appArgs["noupdate"] = false; appArgs["cmd"] = string.Empty; appArgs["pkgsref"] = string.Empty; - - form = new PackageListViewForm(); + appArgs["instsref"] = string.Empty; } void RunNormal() { + form = new PackageListViewForm(); form.Load += delegate(object sender, EventArgs e) { hideSplashScreen(); form.updateActionInvoke(((bool)appArgs["noupdate"]) != true); @@ -42,15 +40,17 @@ namespace AppliStation void RunInstall() { try { - NaGet.Packages.Package[] pkgs = NaGet.Utils.GetDeserializedObject((string) appArgs["pkgsref"]); + NaGet.Packages.Install.Installation[] insts = NaGet.Utils.GetDeserializedObject((string) appArgs["instsref"]); + form = new PackageListViewForm(); + form.UpdatePackageList(); hideSplashScreen(); - form.installActionInvoke(pkgs); + form.installActionInvoke(insts); } catch (UnauthorizedAccessException e) { - MessageBox.Show(string.Format("ŠÇ—ŽÒŒ ŒÀ‚ɏ¸Ši‚µ‚Ä‚¢‚È‚¢‚©AŽÀsŒ ŒÀ‚É–â‘肪‚ ‚è‚Ü‚·B\n(Ú×:{0})", e.Message), + MessageBox.Show(string.Format("管理者権限に昇格していないか、実行権限に問題があります。\n(詳細:{0})", e.Message), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (FileNotFoundException e) { - MessageBox.Show(string.Format("ƒ\ƒtƒgŽw’èƒtƒ@ƒCƒ‹{0}‚ªŒ©‚‚©‚è‚Ü‚¹‚ñ", e.FileName), + MessageBox.Show(string.Format("ソフト指定ファイル{0}が見つかりません", e.FileName), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } } @@ -60,17 +60,84 @@ namespace AppliStation try { NaGet.Packages.Install.InstalledPackage[] pkgs = NaGet.Utils.GetDeserializedObject((string) appArgs["pkgsref"]); + form = new PackageListViewForm(); + form.UpdatePackageList(); hideSplashScreen(); form.uninstallActionInvoke(pkgs); } catch (UnauthorizedAccessException e) { - MessageBox.Show(string.Format("ŠÇ—ŽÒŒ ŒÀ‚ɏ¸Ši‚µ‚Ä‚¢‚È‚¢‚©AŽÀsŒ ŒÀ‚É–â‘肪‚ ‚è‚Ü‚·B\n(Ú×:{0})", e.Message), + MessageBox.Show(string.Format("管理者権限に昇格していないか、実行権限に問題があります。\n(詳細:{0})", e.Message), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (FileNotFoundException e) { - MessageBox.Show(string.Format("ƒ\ƒtƒgŽw’èƒtƒ@ƒCƒ‹{0}‚ªŒ©‚‚©‚è‚Ü‚¹‚ñ", e.FileName), + MessageBox.Show(string.Format("ソフト指定ファイル{0}が見つかりません", e.FileName), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } } + void RunUpdateAppliStation() + { + if ( splashScreen == null ) { + splashScreen = createAndOpenSplashScreen(); + } + + 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")) { + while (true) { /* loop for retry */ + try { + File.Copy(file, Path.Combine(targetDir, Path.GetFileName(file)), true); + break; + } catch (IOException ex) { + DialogResult result = MessageBox.Show(string.Format("AppliStationの更新に失敗しました。\r\n\r\n{0}", ex.Message), + "AppliStation", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error); + if (result == DialogResult.Retry) { + continue; /* retry */ + } else { + MessageBox.Show("AppliStationの更新は中断されました。", "AppliStation", MessageBoxButtons.OK, MessageBoxIcon.Error); + hideSplashScreen(); + return; + } + } + } + } + } + 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)); + + 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) { @@ -81,7 +148,22 @@ namespace AppliStation public void Run(string[] args) { - parseArgs(args); + try { + parseArgs(args); + } catch (ApplicationException e) { + MessageBox.Show(e.Message, "AppliStation 起動引数エラー", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + // cmd引数がないときに更新処理を試みる。 + // cmd引数があるときに更新しないのは、AppliStationから「管理者で実行」などで呼び出された場合に + // 更新処理にならないようにするため。 + if ( string.IsNullOrEmpty((string) appArgs["cmd"]) && + autoUpdateAppliStation() ) { + // アップデートしたときは起動しない + return; + } + switch ((string) appArgs["cmd"]) { case "install": @@ -90,6 +172,9 @@ namespace AppliStation case "uninstall": RunUninstall(); break; + case "updateAppliStation": + RunUpdateAppliStation(); + break; default: RunNormal(); break; @@ -98,8 +183,22 @@ namespace AppliStation private void parseArgs(string[] args) { - ArgParse parser = new ArgParse(appArgs); - restAppArgs = parser.Parse(args); + NaGet.ArgParser parser = new NaGet.ArgParser(appArgs); + string[] restAppArgs = parser.Parse(args); + } + + private static Form createAndOpenSplashScreen() + { + System.Drawing.Bitmap bitmap; + + bitmap = new System.Drawing.Bitmap(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "SplashScreen.png")); + Form splashScreen = AppliStation.Util.SprashScreenLayered.CreateSprashScreenLayered(bitmap, System.Drawing.Color.Black); + + splashScreen.Text = "AppliStation"; + splashScreen.Icon = System.Drawing.Icon.ExtractAssociatedIcon(Application.ExecutablePath); + splashScreen.Show(); + + return splashScreen; } [STAThread] @@ -108,22 +207,21 @@ namespace AppliStation Form splashScreen = null; try { - if (args.Length <= 0) { // HACK ˆø”ƒp[ƒX‚ÌŽžŠÔ‚³‚¦‘Ò‚Ä‚È‚¢‚̂ňø”‚Ì—L–³‚Å•\Ž¦‚ð”»’f - splashScreen = new Form(); - splashScreen.FormBorderStyle = FormBorderStyle.None; - splashScreen.BackgroundImage = System.Drawing.Bitmap.FromFile(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "SplashScreen.png")); - splashScreen.Size = splashScreen.BackgroundImage.Size; - splashScreen.ShowIcon = false; - splashScreen.ShowInTaskbar = false; - splashScreen.StartPosition = FormStartPosition.CenterScreen; - splashScreen.Show(); + if (args.Length <= 0) { // HACK 引数パースの時間さえ待てないので引数の有無で表示を判断 + splashScreen = createAndOpenSplashScreen(); } - ToolStripManager.VisualStylesEnabled = false; // ToolStrip‚ªLuna‚Ղ­‚È‚ç‚È‚¢‚悤‚É - Application.EnableVisualStyles(); // Luna‚âVista‚̃fƒUƒCƒ“‚ð—LŒø‚É + // アーカイブSYSTEM32をパスに足す + NaGet.Utils.AddDirectoryToPath(NaGet.Env.ArchiveSystem32); - Application.ThreadException += AppliStation.Util.ExceptionDialogForm.Application_ThrowException; - System.Threading.Thread.GetDomain().UnhandledException += AppliStation.Util.ExceptionDialogForm.Application_ThrowException; + ToolStripManager.VisualStylesEnabled = false; // ToolStripがLunaで青くならないように + Application.EnableVisualStyles(); // LunaやVistaのデザインを有効に + + // デバッガがアタッチしていないなら、Exceptionを自力でハンドルする + if (! System.Diagnostics.Debugger.IsAttached) { + Application.ThreadException += AppliStation.Util.ExceptionDialogForm.Application_ThrowException; + System.Threading.Thread.GetDomain().UnhandledException += AppliStation.Util.ExceptionDialogForm.Application_ThrowException; + } Program prog = new Program(); prog.splashScreen = splashScreen;