OSDN Git Service

AppliStation-GUI,インストール確認ダイアログの大規模リファクタリング(改名)
[applistation/AppliStation.git] / AppliStation / PackageListViewForm.cs
index c67ff5b..432f619 100644 (file)
@@ -326,11 +326,11 @@ namespace AppliStation
                \r
                #endregion\r
                \r
-               internal void installActionInvoke(Package[] pkgs)\r
+               internal void installActionInvoke(Installation[] insts)\r
                {\r
                        AppliStation.Util.ExecutionProgressViewer prog = new AppliStation.Util.ExecutionProgressViewer();\r
                        prog.Shown += delegate(object sender2, EventArgs e2) {\r
-                               NaGet.SubCommands.NaGetInstall tasks = new NaGet.SubCommands.NaGetInstall(pkgListsMan, pkgs);\r
+                               NaGet.SubCommands.NaGetInstall tasks = new NaGet.SubCommands.NaGetInstall(pkgListsMan, insts);\r
                                tasks.Downloader = prog.Downloader;\r
                                prog.SetTaskSet(tasks);\r
                                prog.Refresh();\r
@@ -342,51 +342,59 @@ namespace AppliStation
                \r
                void InstallToolStripButtonClick(object sender, EventArgs e)\r
                {\r
-                       PackagesInstallConfirmForm confirm = new PackagesInstallConfirmForm();\r
+                       InstallationConfirmForm confirm = new InstallationConfirmForm();\r
                        confirm.PkgListsManager = pkgListsMan;\r
-                       confirm.Packages = SelectedPackages<Package>();\r
+                       confirm.Installations = Installation.ConvertInstallations(SelectedPackages<Package>());\r
                        confirm.UseRunas = confirm.GetShouldUseRunas();\r
                        DialogResult result = confirm.ShowDialog(this);\r
                        \r
                        if (result == DialogResult.OK) {\r
-                               Package[] instPkgs = confirm.CheckedPackages;\r
+                               Installation[] insts = confirm.CheckedInstallations;\r
                                \r
                                if (confirm.UseRunas) {\r
-                                       this.Enabled = false;\r
-                                       installRunasActionInvoke(instPkgs);\r
-                                       this.Enabled = true;\r
-                                       this.Focus();\r
+                                       installRunasActionInvoke(insts);\r
                                } else {\r
-                                       installActionInvoke(instPkgs);\r
+                                       installActionInvoke(insts);\r
                                }\r
                                \r
                                UpdatePackageList();\r
                        }\r
                }\r
                \r
-               public void installRunasActionInvoke(Package[] pkgs)\r
+               public void installRunasActionInvoke(Installation[] insts)\r
                {\r
-                       string tmpfileName = System.IO.Path.GetTempFileName();\r
+                       this.setWindowEnabled(false);\r
+                       \r
+                       string tmpfileName = Path.GetTempFileName();\r
                        try {\r
-                               NaGet.Utils.PutSerializeObject(tmpfileName, pkgs);\r
+                               NaGet.Utils.PutSerializeObject(tmpfileName, insts);\r
                                \r
                                System.Diagnostics.ProcessStartInfo procInfo = new System.Diagnostics.ProcessStartInfo();\r
                                procInfo.FileName = Application.ExecutablePath;\r
-                               procInfo.Arguments = string.Format("--noupdate --cmd=install \"--pkgsref={0}\"", tmpfileName);\r
+                               procInfo.Arguments = string.Format("--noupdate --cmd=install \"--instsref={0}\"", tmpfileName);\r
                                procInfo.Verb = "runas";\r
                                procInfo.WorkingDirectory = Environment.CurrentDirectory;\r
                                \r
-                               using (System.Diagnostics.Process hProc = System.Diagnostics.Process.Start(procInfo)) {\r
-                                       hProc.WaitForExit();\r
-                               }\r
-                               \r
-                               pkgListsMan.LoadPackageLists();\r
+                               System.Diagnostics.Process hProc = System.Diagnostics.Process.Start(procInfo);\r
+                               hProc.EnableRaisingEvents = true;\r
+                               hProc.SynchronizingObject = this;\r
+                               hProc.Exited += delegate(object sender, EventArgs e) {\r
+                                       pkgListsMan.LoadPackageLists();\r
+                                       \r
+                                       this.setWindowEnabled(true);\r
+                                       this.BringToFront();\r
+                                       \r
+                                       if (File.Exists(tmpfileName)) {\r
+                                               File.Delete(tmpfileName);\r
+                                       }\r
+                               };\r
                        } catch (System.ComponentModel.Win32Exception ex) {\r
                                MessageBox.Show(ex.Message, "\83C\83\93\83X\83g\81[\83\8b", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
-                       } finally {\r
+                               \r
                                if (File.Exists(tmpfileName)) {\r
                                        File.Delete(tmpfileName);\r
                                }\r
+                               this.setWindowEnabled(true);\r
                        }\r
                }\r
                \r
@@ -404,8 +412,10 @@ namespace AppliStation
                }\r
                \r
                internal void uninstallRunasActionInvoke(InstalledPackage[] pkgs)\r
-               {\r
-                       string tmpfileName = System.IO.Path.GetTempFileName();\r
+               {                       \r
+                       this.setWindowEnabled(false);\r
+                       \r
+                       string tmpfileName = Path.GetTempFileName();\r
                        try {\r
                                NaGet.Utils.PutSerializeObject(tmpfileName, pkgs);\r
                                \r
@@ -415,14 +425,23 @@ namespace AppliStation
                                procInfo.Verb = "runas";\r
                                procInfo.WorkingDirectory = Environment.CurrentDirectory;\r
                                \r
-                               using (System.Diagnostics.Process hProc = System.Diagnostics.Process.Start(procInfo)) {\r
-                                       hProc.WaitForExit();\r
-                               }\r
-                               \r
-                               pkgListsMan.LoadPackageLists();\r
+                               System.Diagnostics.Process hProc = System.Diagnostics.Process.Start(procInfo);\r
+                               hProc.EnableRaisingEvents = true;\r
+                               hProc.SynchronizingObject = this;\r
+                               hProc.Exited += delegate(object sender, EventArgs e) {\r
+                                       pkgListsMan.LoadPackageLists();\r
+                                       \r
+                                       this.setWindowEnabled(true);\r
+                                       this.BringToFront();\r
+                                       \r
+                                       if (File.Exists(tmpfileName)) {\r
+                                               File.Delete(tmpfileName);\r
+                                       }\r
+                               };\r
                        } catch (System.ComponentModel.Win32Exception ex) {\r
                                MessageBox.Show(ex.Message, "\83A\83\93\83C\83\93\83X\83g\81[\83\8b", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
-                       } finally {\r
+                               \r
+                               this.setWindowEnabled(true);\r
                                if (File.Exists(tmpfileName)) {\r
                                        File.Delete(tmpfileName);\r
                                }\r
@@ -443,10 +462,7 @@ namespace AppliStation
                                InstalledPackage[] instPkgs = new InstalledPackage[]{confirm.UninstallPackage};\r
                                \r
                                if (confirm.UseRunas) {\r
-                                       this.Enabled = false;\r
                                        uninstallRunasActionInvoke(instPkgs);\r
-                                       this.Enabled = true;\r
-                                       this.Focus();\r
                                } else {\r
                                        uninstallActionInvoke(instPkgs);\r
                                }\r
@@ -499,7 +515,7 @@ namespace AppliStation
                        foreach (Package pkg in SelectedPackages<Package>()) {\r
                                PackageInfoForm form = new PackageInfoForm();\r
                                form.SelectedObject = pkg;\r
-                               form.Text = pkg.ToString() + "\82Ì\83v\83\8d\83p\83e\83B";\r
+                               form.Text = string.Format("{0}({1})\82Ì\83v\83\8d\83p\83e\83B", pkg.Name, pkg.Version);\r
                                \r
                                form.ShowDialog(this);\r
 \r
@@ -521,7 +537,9 @@ namespace AppliStation
                                installToolStripMenuItem.Visible = ! isInstalledPackage;\r
                                uninstallToolStripMenuItem.Visible = isInstalledPackage;\r
                                \r
-                               webResourcesToolStripMenuItem.Text = string.Format(webResourcesToolStripMenuItem.Tag.ToString(), pkg.Name);\r
+                               webResourcesToolStripMenuItem.Text = string.Format(\r
+                                       webResourcesToolStripMenuItem.Tag.ToString(),\r
+                                       pkg.Name.Replace("&", "&&")); // pkg.Name\82É&\82ª\8aÜ\82Ü\82ê\82Ä\82¢\82é\82Æ\82«\82Í\83G\83\93\83R\81[\83h\r
                                webOfficialToolStripMenuItem.Enabled = ! (pkg.Url == null || string.IsNullOrEmpty(pkg.Url.Href));\r
                                // webGoogleSearchToolStripMenuItem always active.\r
                                \r
@@ -534,7 +552,7 @@ namespace AppliStation
                \r
                private IEnumerable<Package> getUpdatedPackages(PackageList<InstalledPackage> installedPkgList, PackageList<Package> avaiablePkgList, IComparer<string> verComp)\r
                {\r
-                       foreach (InstalledPackage pkg in installedPkgList.Packages) {\r
+                       foreach (InstalledPackage pkg in installedPkgList) {\r
                                Package avaiablePkg = avaiablePkgList.GetPackageForName(pkg.Name);\r
                                \r
                                if (avaiablePkgList != null) {\r
@@ -561,20 +579,18 @@ namespace AppliStation
                                return;\r
                        }\r
                        \r
-                       PackagesInstallConfirmForm confirm = new PackagesInstallConfirmForm();\r
+                       InstallationConfirmForm confirm = new InstallationConfirmForm();\r
                        confirm.PkgListsManager = pkgListsMan;\r
-                       confirm.Packages = pkgs.ToArray();\r
+                       confirm.Installations = Installation.ConvertInstallations(pkgs.ToArray());\r
                        DialogResult result = confirm.ShowDialog(this);\r
                        \r
                        if (result == DialogResult.OK) {\r
-                               Package[] instPkgs = confirm.CheckedPackages;\r
+                               Installation[] insts = confirm.CheckedInstallations;\r
                                \r
                                if (confirm.UseRunas) {\r
-                                       this.Enabled = false;\r
-                                       installRunasActionInvoke(instPkgs);\r
-                                       this.Enabled = true;\r
+                                       installRunasActionInvoke(insts);\r
                                } else {\r
-                                       installActionInvoke(instPkgs);\r
+                                       installActionInvoke(insts);\r
                                }\r
                                \r
                                UpdatePackageList();\r
@@ -599,6 +615,23 @@ namespace AppliStation
                                \r
                                return pkgs.ToArray();\r
                }\r
+               \r
+               /// <summary>\r
+               /// \8e©\83E\83B\83\93\83h\83E\82Ì\97L\8cø\96³\8cø(Enabled)\82ð(\95K\97v\82 \82ê\82ÎInvoke\82µ\82Ä)\8eÀ\8ds\82·\82é \r
+               /// </summary>\r
+               /// <param name="enabled">\97L\8cø\82©\94Û\82©\81BEnabled\82Ì\92l\82É\93ü\82ê\82ç\82ê\82é</param>\r
+               private void setWindowEnabled(bool enabled)\r
+               {\r
+                       MethodInvoker process = (MethodInvoker) delegate() {\r
+                               this.Enabled = enabled;\r
+                       };\r
+                       \r
+                       if (InvokeRequired) {\r
+                               Invoke(process);\r
+                       } else {\r
+                               process.Invoke();\r
+                       }\r
+               }\r
        }\r
 \r
 }\r