-using System;\r
+using System;\r
using System.Drawing;\r
using System.Windows.Forms;\r
using NaGet.Packages;\r
this.Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath);\r
}\r
\r
- void PackageListViewSelectedIndexChanged(object sender, EventArgs e)\r
+ private void ShowInfoToDetailBoxFor(Package pkg)\r
{\r
- bool installBtnEnabled = false;\r
- bool uninstallBtnEnabled = false;\r
- \r
detailBox.Clear();\r
- foreach (ListViewItem item in packageListView.SelectedItems) {\r
- Package pkg = (Package) item.Tag;\r
- \r
- bool isInstalledPackage = pkg is InstalledPackage;\r
- uninstallBtnEnabled = isInstalledPackage;\r
- installBtnEnabled = ! isInstalledPackage;\r
+ \r
+ detailBox.SelectionFont = new Font(detailBox.Font.FontFamily, 12);\r
+ detailBox.SelectedText += string.Format("{0} ({1})\r\n", pkg.Name, pkg.Version);\r
+ if (! string.IsNullOrEmpty(pkg.Tags) ) {\r
+ detailBox.SelectionFont = new Font(detailBox.Font.FontFamily, 8);\r
+ detailBox.SelectedText += string.Format("タグ: {0}\r\n", pkg.Tags);\r
+ }\r
+ if (pkg is InstalledPackage) {\r
+ InstalledPackage iPkg = (InstalledPackage) pkg;\r
+ System.Text.StringBuilder sb = new System.Text.StringBuilder();\r
+ if (iPkg.UninstallInfo.InstallDate != null) {\r
+ sb.AppendFormat("インストールした日: {0:d} ", iPkg.UninstallInfo.InstallDate.Value);\r
+ }\r
+ if (iPkg.UninstallInfo.EstimatedSize > 0) {\r
+ sb.AppendFormat("サイズ: {0} ", NaGet.Utils.FormatSize(iPkg.UninstallInfo.EstimatedSize*1024));\r
+ }\r
\r
- detailBox.SelectionFont = new Font(detailBox.Font.FontFamily, 12);\r
- detailBox.SelectedText += string.Format("{0} ({1})\r\n", pkg.Name, pkg.Version);\r
- if (! string.IsNullOrEmpty(pkg.Tags) ) {\r
+ if (sb.Length > 0) {\r
detailBox.SelectionFont = new Font(detailBox.Font.FontFamily, 8);\r
- detailBox.SelectedText += string.Format("\83^\83O: {0}\r\n", pkg.Tags);\r
+ detailBox.SelectedText += sb.ToString();\r
+ detailBox.SelectedText += "\r\n";\r
}\r
- if (isInstalledPackage) {\r
- InstalledPackage iPkg = (InstalledPackage) pkg;\r
- System.Text.StringBuilder sb = new System.Text.StringBuilder();\r
- if (iPkg.UninstallInfo.InstallDate != null) {\r
- sb.AppendFormat("\83C\83\93\83X\83g\81[\83\8b\82µ\82½\93ú: {0:d} ", iPkg.UninstallInfo.InstallDate.Value);\r
- }\r
- if (iPkg.UninstallInfo.EstimatedSize > 0) {\r
- sb.AppendFormat("\83T\83C\83Y: {0} ", NaGet.Utils.FormatSize(iPkg.UninstallInfo.EstimatedSize*1024));\r
- }\r
- \r
- if (sb.Length > 0) {\r
- detailBox.SelectionFont = new Font(detailBox.Font.FontFamily, 8);\r
- detailBox.SelectedText += sb.ToString();\r
- detailBox.SelectedText += "\r\n";\r
- }\r
- }\r
- detailBox.SelectionFont = detailBox.Font;\r
- if (pkg.Url != null && pkg.Url.Href != null) {\r
- detailBox.SelectedText += "\8cö\8e®\83T\83C\83g: " + pkg.Url.Href + "\r\n";\r
+ }\r
+ detailBox.SelectionFont = detailBox.Font;\r
+ if (pkg.Url != null && pkg.Url.Href != null) {\r
+ detailBox.SelectedText += "公式サイト: " + pkg.Url.Href + "\r\n";\r
+ }\r
+ detailBox.SelectedText += pkg.Summary;\r
+ }\r
+ \r
+ void PackageListViewSelectedIndexChanged(object sender, EventArgs e)\r
+ {\r
+ uint installPkgCount = 0;\r
+ uint uninstallPkgCount = 0;\r
+ bool installBtnEnabled, uninstallBtnEnabled;\r
+ \r
+ Package[] selectedPkgs = SelectedPackages<Package>();\r
+ foreach (Package pkg in selectedPkgs) {\r
+ if (pkg is InstalledPackage) {\r
+ uninstallPkgCount ++;\r
+ } else {\r
+ installPkgCount ++;\r
}\r
- detailBox.SelectedText += pkg.Summary;\r
- \r
- break;\r
}\r
+ installBtnEnabled = (installPkgCount > 0) && (uninstallPkgCount == 0);\r
+ uninstallBtnEnabled = (uninstallPkgCount == 1) && (installPkgCount == 0);\r
\r
uninstallToolStripButton.Visible = uninstallBtnEnabled;\r
installToolStripButton.Visible = installBtnEnabled;\r
packageCommandsToolStripSeparator.Visible = uninstallBtnEnabled || installBtnEnabled;\r
\r
- if (packageListView.SelectedItems.Count <= 0) {\r
- detailBox.SelectionFont = detailBox.Font;\r
- int count = packageListView.Items.Count;\r
- detailBox.Text = (count > 0) ? string.Format("{0}\8cÂ\82Ì\83\\83t\83g\82ª\82 \82è\82Ü\82·\81B", count)\r
- : "\8aY\93\96\82·\82é\83\\83t\83g\82ª\82 \82è\82Ü\82¹\82ñ\81B";\r
+ switch (selectedPkgs.Length) {\r
+ case 0:\r
+ detailBox.SelectionFont = detailBox.Font;\r
+ int count = packageListView.Items.Count;\r
+ detailBox.Text = (count > 0) ? string.Format("{0}個のソフトがあります。", count)\r
+ : "該当するソフトがありません。";\r
+ break;\r
+ case 1:\r
+ ShowInfoToDetailBoxFor(selectedPkgs[0]);\r
+ break;\r
+ default: // case 2 and over:\r
+ detailBox.SelectionFont = detailBox.Font;\r
+ detailBox.Text = (installBtnEnabled)? string.Format("{0}個のソフトが選択されています。", installPkgCount) :\r
+ (uninstallBtnEnabled)? string.Format("{0}個のインストール済みのソフトが選択されています。", uninstallPkgCount) :\r
+ string.Format("{0}個のソフトが選択されています。\r\n(うち{1}個はインストール済み、{2}個はインストール可能)", installPkgCount+uninstallPkgCount, uninstallPkgCount, installPkgCount);\r
+ break;\r
}\r
\r
detailBox.SelectionStart = 0;\r
}\r
AppliStation.Util.NativeMethods.ColumnHeader_SetSortState(packageListView, e.Column, order);\r
\r
- // \83\\81[\83g\91Î\8fÛ\97ñ\82Ì\90F\95t\82¯\r
+ // ソート対象列の色付け\r
try {\r
// SendMessage(hWnd, LVM_SETSELECTEDCOLUMN, column, NULL);\r
AppliStation.Util.NativeMethods.SendMessage(packageListView.Handle, 0x1000+140, (uint) e.Column, 0);\r
installedSysPackageFilterToolStripMenuItem.Image = ((Icon)(resources.GetObject("sysinstalled.Icon"))).ToBitmap();\r
}\r
\r
- #region PackageFilter\8aÖ\98A\r
+ #region PackageFilter関連\r
\r
private enum PackageFilterIndex : int\r
{\r
\r
if (currentPackageFilter == PackageFilterIndex.All || currentPackageFilter == PackageFilterIndex.NotInstalled) {\r
foreach (Package pkg in pkgListsMan.AvailablePkgList.Search(searchTextBox.Text)) {\r
- if (Installation.GetPreferInstallerIndex(pkg) >= 0) { // \83C\83\93\83X\83g\81[\83\8b\89Â\94\\r
+ if (Installation.GetPreferInstallerIndex(pkg) >= 0) { // インストール可能\r
if (currentPackageFilter == PackageFilterIndex.NotInstalled &&\r
(pkgListsMan.InstalledPkgList.GetPackageForName(pkg.Name) != null||\r
pkgListsMan.SystemInstalledPkgList.GetPackageForName(pkg.Name) != null) ) {\r
- continue; // \83C\83\93\83X\83g\81[\83\8b\8dÏ\82Ý\82Í\8e\9f\82Ì\83\8b\81[\83v\82Ö(\96¢\83C\83\93\83X\83g\81[\83\8b\83\\83t\83g\92\8a\8fo\8e\9e)\r
+ continue; // インストール済みは次のループへ(未インストールソフト抽出時)\r
}\r
\r
ListViewItem item = new ListViewItem(new string[]{pkg.Name, pkg.Version, pkg.Summary});\r
AppliStation.Util.ExecutionProgressViewer prog = new AppliStation.Util.ExecutionProgressViewer();\r
prog.Shown += delegate(object sender2, EventArgs e2) {\r
NaGet.SubCommands.NaGetUpdate tasks = new NaGet.SubCommands.NaGetUpdate(pkgListsMan, downloadPackageListsFlag);\r
- tasks.Downloader = prog.Downloader;\r
prog.SetTaskSet(tasks);\r
prog.Refresh();\r
prog.StartTaskSet();\r
};\r
- prog.Text = "\83\8a\83X\83g\82Ì\8dX\90V";\r
+ prog.Text = "リストの更新";\r
prog.ShowDialog(this);\r
}\r
\r
UpdatePackageList();\r
}\r
\r
- #region searchTextBox\82Ü\82í\82è\r
+ #region searchTextBoxまわり\r
\r
void SearchTextBoxKeyPress(object sender, KeyPressEventArgs e)\r
{\r
\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
- tasks.Downloader = prog.Downloader;\r
+ NaGet.SubCommands.NaGetInstall tasks = new NaGet.SubCommands.NaGetInstall(pkgListsMan, insts);\r
prog.SetTaskSet(tasks);\r
prog.Refresh();\r
prog.StartTaskSet();\r
};\r
- prog.Text = string.Format("\83\\83t\83g\83E\83F\83A\82Ì\83C\83\93\83X\83g\81[\83\8b");\r
+ prog.Text = string.Format("ソフトウェアのインストール");\r
prog.ShowDialog(this);\r
}\r
\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
+ MessageBox.Show(ex.Message, "インストール", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
+ \r
if (File.Exists(tmpfileName)) {\r
File.Delete(tmpfileName);\r
}\r
+ this.setWindowEnabled(true);\r
}\r
}\r
\r
prog.Refresh();\r
prog.StartTaskSet();\r
};\r
- prog.Text = string.Format("\83\\83t\83g\83E\83F\83A\82Ì\83A\83\93\83C\83\93\83X\83g\81[\83\8b");\r
+ prog.Text = string.Format("ソフトウェアのアンインストール");\r
prog.ShowDialog(this);\r
}\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
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
+ MessageBox.Show(ex.Message, "アンインストール", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
+ \r
+ this.setWindowEnabled(true);\r
if (File.Exists(tmpfileName)) {\r
File.Delete(tmpfileName);\r
}\r
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
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})のプロパティ", pkg.Name, pkg.Version);\r
\r
form.ShowDialog(this);\r
\r
\r
void PackageListContextMenuStripOpening(object sender, System.ComponentModel.CancelEventArgs e)\r
{\r
- // \91I\91ð\82³\82ê\82Ä\82¢\82È\82¢\82È\82ç\8aJ\82©\82È\82¢\r
- if (packageListView.SelectedItems.Count <= 0) {\r
+ // メニューアイテムのインストール/アンインストールの表示はツールストリップに同じ\r
+ installToolStripMenuItem.Visible = installToolStripButton.Visible;\r
+ uninstallToolStripMenuItem.Visible = uninstallToolStripButton.Visible;\r
+ \r
+ // インストールもアンインストールもできない状態ならば、メニューを表示しない\r
+ if (! (installToolStripButton.Visible || uninstallToolStripButton.Visible)) {\r
e.Cancel = true;\r
return;\r
}\r
\r
- foreach (Package pkg in SelectedPackages<Package>()) {\r
+ // 選択パッケージが1つのとき\r
+ bool selectionIsOnlyOne = packageListView.SelectedItems.Count == 1;\r
+ if (selectionIsOnlyOne) {\r
+ Package pkg = SelectedPackage<Package>();\r
bool isInstalledPackage = pkg is InstalledPackage;\r
\r
- 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に&が含まれているときはエンコード\r
webOfficialToolStripMenuItem.Enabled = ! (pkg.Url == null || string.IsNullOrEmpty(pkg.Url.Href));\r
// webGoogleSearchToolStripMenuItem always active.\r
\r
openInstalledDirectoryStripMenuItem.Visible = isInstalledPackage &&\r
( (pkg.Type == InstallerType.ARCHIVE) || Directory.Exists(((InstalledPackage) pkg).UninstallInfo.InstallLocation) );\r
-\r
- break;\r
}\r
+ \r
+ toolStripSeparator1.Visible = selectionIsOnlyOne;\r
+ webResourcesToolStripMenuItem.Visible = selectionIsOnlyOne;\r
+ if (! selectionIsOnlyOne) openInstalledDirectoryStripMenuItem.Visible = false;\r
+ propertiesToolStripMenuItem.Visible = selectionIsOnlyOne;\r
}\r
\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
pkgs.AddRange(getUpdatedPackages(pkgListsMan.SystemInstalledPkgList, avaiablePackageList, verComp));\r
\r
if (pkgs.Count <= 0) {\r
- MessageBox.Show(this, "\8dX\90V\82³\82ê\82½\83\\83t\83g\82Í\82 \82è\82Ü\82¹\82ñ", "\83\\83t\83g\82Ì\8dX\90V");\r
+ MessageBox.Show(this, "更新されたソフトはありません", "ソフトの更新");\r
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
}\r
\r
/// <summary>\r
- /// \83C\83\93\83X\83g\81[\83\8b\82·\82é\82æ\82¤\91I\91ð\82³\82ê\82½\83p\83b\83P\81[\83W\82Ì\94z\97ñ\r
+ /// インストールするよう選択されたパッケージの配列\r
/// </summary>\r
public TPackage[] SelectedPackages<TPackage>() where TPackage : Package\r
{\r
- List<TPackage> pkgs = new List<TPackage>();\r
- foreach (ListViewItem item in packageListView.SelectedItems) {\r
- pkgs.Add((TPackage) item.Tag);\r
- }\r
- \r
- return pkgs.ToArray();\r
+ List<TPackage> pkgs = new List<TPackage>();\r
+ foreach (ListViewItem item in packageListView.SelectedItems) {\r
+ pkgs.Add((TPackage) item.Tag);\r
+ }\r
+ \r
+ return pkgs.ToArray();\r
+ }\r
+ \r
+ /// <summary>\r
+ /// インストールするよう選択されたパッケージをひとつ返す。\r
+ /// </summary>\r
+ /// <returns>選択されたパッケージ(選択されていないときはnull)</returns>\r
+ public TPackage SelectedPackage<TPackage>() where TPackage : Package\r
+ {\r
+ foreach (ListViewItem item in packageListView.SelectedItems) {\r
+ return (TPackage) item.Tag;\r
+ }\r
+ return null;\r
+ }\r
+ \r
+ /// <summary>\r
+ /// 自ウィンドウの有効無効(Enabled)を(必要あればInvokeして)実行する \r
+ /// </summary>\r
+ /// <param name="enabled">有効か否か。Enabledの値に入れられる</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