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;
///
- /// AvP[VÌIvV
+ /// ã¢ããªã±ã¼ã·ã§ã³ã®ãªãã·ã§ã³
///
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("\tgwè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("\tgwè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ÌfUCð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;