X-Git-Url: http://git.sourceforge.jp/view?a=blobdiff_plain;ds=sidebyside;f=AppliStation%2FPackageListViewForm.cs;h=5d3e318dce14babeffd65b3348fd070df6ae0aaf;hb=1de4f60dc16fd25652dbe310374ed1e9cd6df055;hp=2098e9f297a18492dd21c1d75dae55546f038add;hpb=881e9661bbb89bbe072fd3b9c49f2718a38e843c;p=applistation%2FAppliStation.git diff --git a/AppliStation/PackageListViewForm.cs b/AppliStation/PackageListViewForm.cs index 2098e9f..5d3e318 100644 --- a/AppliStation/PackageListViewForm.cs +++ b/AppliStation/PackageListViewForm.cs @@ -108,11 +108,13 @@ namespace AppliStation webResourceToolStripMenuItem.Visible = (pkgCount == 1); uninstallToolStripMenuItem.Visible = uninstallBtnEnabled; installToolStripMenuItem.Visible = installBtnEnabled; + downloadToolStripMenuItem.Visible = (pkgCount > 0); // detailBoxのメッセージ設定 switch (pkgCount) { case 0: int count = packageListView.Items.Count; + detailBox.Clear(); detailBox.Text = (count > 0) ? string.Format("{0}個のソフトがあります。", count) : "該当するソフトがありません。"; break; @@ -120,6 +122,7 @@ namespace AppliStation ShowInfoToDetailBoxFor(packageListView.SelectedPackage); break; default: // case 2 and over: + detailBox.Clear(); detailBox.Text = (installBtnEnabled)? string.Format("{0}個のソフトが選択されています。", installPkgCount) : (uninstallBtnEnabled)? string.Format("{0}個のインストール済みのソフトが選択されています。", uninstallPkgCount) : string.Format("{0}個のソフトが選択されています。\r\n(うち{1}個はインストール済み、{2}個はインストール可能)", pkgCount, uninstallPkgCount, installPkgCount); @@ -252,6 +255,125 @@ namespace AppliStation UpdatePackageList(); } + void SoftCollectionFileImportToolStripMenuItemClick(object sender, EventArgs e) + { + string pwd = Directory.GetCurrentDirectory(); + + OpenFileDialog fd = new OpenFileDialog(); + fd.Filter = "ソフトコレクションファイル (*.txt)|*.txt"; + fd.DefaultExt = "txt"; + fd.CheckFileExists = true; + fd.CheckPathExists = true; + fd.Multiselect = false; + fd.ShowDialog(); + if (fd.FileNames.Length > 0) { + string filepath = Path.GetFullPath(fd.FileName); + Directory.SetCurrentDirectory(pwd); // ファイルダイアログで変わったカレントディレクトリを戻す + + IList pkgs; + IList invalid; + + try { + PackageCollectionFileData collectionData = new PackageCollectionFileData(); + collectionData.load(filepath); + collectionData.generatePackages(pkgListsMan, out pkgs, out invalid); + + if (invalid.Count > 0) { + DialogResult result = MessageBox.Show("一部読み込みの失敗したパッケージがありますが続行しますか?", "インポート", MessageBoxButtons.OKCancel, MessageBoxIcon.Error); + if (result != DialogResult.OK) { + return; + } + } + } catch (IOException) { + MessageBox.Show("ファイルの読み込みに失敗しました", "インポート", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + { + InstallationConfirmForm confirm = new InstallationConfirmForm(); + confirm.PkgListsManager = pkgListsMan; + confirm.Installations = Installation.ConvertInstallations( NaGet.Utils.IEnumerable2Array(pkgs) ); + confirm.UseRunas = confirm.GetShouldUseRunas(); + DialogResult result = confirm.ShowDialog(this); + + if (result == DialogResult.OK) { + Installation[] insts = confirm.CheckedInstallations; + + if (confirm.UseRunas) { + installRunasActionInvoke(insts); + } else { + installActionInvoke(insts); + } + + UpdatePackageList(); + } + } + } else { + Directory.SetCurrentDirectory(pwd); // ファイルダイアログで変わったカレントディレクトリを戻す + } + } + + void SoftCollectionFileExportToolStripMenuItemClick(object sender, EventArgs e) + { + string pwd = Directory.GetCurrentDirectory(); + string[] softtargets = new string[]{"PCにインストールされたソフト", "AppliStation内でインストールされたソフト", "インストールされたソフトすべて"}; + int softtargetid = softtargets.Length - 1; + + { + AppliStation.Util.OptionDialog optdialog = AppliStation.Util.OptionDialog.createOptionDialog( + "ソフトコレクションファイルに出力するソフトの種類を選択してください。", "エクスポート", "エクスポートするソフト", + System.Drawing.SystemIcons.Question, MessageBoxButtons.OKCancel, + softtargets, softtargets.Length-1); + if (optdialog.ShowDialog(this) != DialogResult.OK) { + return; // canceled + } else if (optdialog.UserInputValue != null) { + softtargetid = (int) optdialog.UserInputValue; + } + } + + SaveFileDialog fd = new SaveFileDialog(); + fd.Filter = "ソフトコレクションファイル (*.txt)|*.txt"; + fd.DefaultExt = "txt"; + fd.CheckPathExists = true; + fd.OverwritePrompt = true; + fd.ShowDialog(); + if (fd.FileNames.Length > 0) { + string filepath = Path.GetFullPath(fd.FileName); + Directory.SetCurrentDirectory(pwd); // ファイルダイアログで変わったカレントディレクトリを戻す + + PackageCollectionFileData collectionData = new PackageCollectionFileData(); + + switch (softtargetid) { + case 0: // PCにインストール + collectionData.loadPackages(pkgListsMan.SystemInstalledPkgList.GetEnumerator()); + break; + case 1: // AppliStation内にインストール + collectionData.loadPackages(pkgListsMan.InstalledPkgList.GetEnumerator()); + break; + case 2: // すべて + default: + collectionData.loadPackages(pkgListsMan.GetAllInstalledPackages()); + break; + } + + try { + collectionData.saveAs(fd.FileName); + } catch (UnauthorizedAccessException) { + if ((File.GetAttributes(fd.FileName) & FileAttributes.ReadOnly) != 0) { + MessageBox.Show("読み取り専用属性が設定されています。\n別のファイルを指定してください。", "エクスポート", MessageBoxButtons.OK, MessageBoxIcon.Error); + } else { + MessageBox.Show("ファイルへの書き込みが許可されていません。\n別のファイルを指定してください。", "エクスポート", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + return; + } catch (IOException) { + MessageBox.Show("ファイルの書き込みに失敗しました", "エクスポート", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + } else { + Directory.SetCurrentDirectory(pwd); // ファイルダイアログで変わったカレントディレクトリを戻す + } + } + void OptionToolStripMenuItemClick(object sender, EventArgs e) { UserPrefForm userPrefForm = new UserPrefForm(); @@ -426,6 +548,27 @@ namespace AppliStation } } + internal void downloadActionInvoke(Installation[] pkgs) + { + AppliStation.Util.ExecutionProgressViewer prog = new AppliStation.Util.ExecutionProgressViewer(); + prog.Shown += delegate(object sender2, EventArgs e2) { + NaGet.SubCommands.NaGetDownloadToCache tasks = new NaGet.SubCommands.NaGetDownloadToCache(pkgListsMan, pkgs); + prog.SetTaskSet(tasks); + prog.Refresh(); + prog.StartTaskSet(); + }; + prog.Text = string.Format("キャッシュへのダウンロード"); + prog.ShowDialog(this); + } + + void DownloadToolStripMenuItemClick(object sender, EventArgs e) + { + Installation[] insts = Installation.ConvertInstallations( NaGet.Utils.IEnumerable2Array(packageListView.SelectedPackages) ); + + downloadActionInvoke(insts); + + UpdatePackageList(); + } void WebOfficialMenuItemClick(object sender, EventArgs e) { @@ -464,8 +607,8 @@ namespace AppliStation if (pkg != null) { if (pkg.Type == InstallerType.ARCHIVE || pkg.Type == InstallerType.ITSELF) { System.Diagnostics.Process.Start(Path.Combine(NaGet.Env.ArchiveProgramFiles, pkg.Name)); - } else if (Directory.Exists(pkg.discoverInstalledLocation())) { - System.Diagnostics.Process.Start(pkg.discoverInstalledLocation()); + } else if (Directory.Exists(pkg.DiscoverInstalledLocation())) { + System.Diagnostics.Process.Start(pkg.DiscoverInstalledLocation()); } } } @@ -502,11 +645,11 @@ namespace AppliStation bool launcherMenuItemVisible = (pkg.Type == InstallerType.ARCHIVE) || (pkg.Type == InstallerType.ITSELF) || - Directory.Exists(iPkg.discoverInstalledLocation()); + Directory.Exists(iPkg.DiscoverInstalledLocation()); launcherMenuItem.Visible = launcherMenuItemVisible; if (launcherMenuItemVisible) { - launcherMenuItem.BaseFolderPath = iPkg.discoverInstalledLocation(); + launcherMenuItem.BaseFolderPath = iPkg.DiscoverInstalledLocation(); } } else { launcherMenuItem.Visible = false; @@ -540,7 +683,6 @@ namespace AppliStation packageListContextMenuStripSeparator.Visible = selectionIsOnlyOne; webResourceToolStripMenuItem.Visible = selectionIsOnlyOne; propertiesToolStripMenuItem.Visible = hasSelection; - viewStyleToolStripMenuItem.Visible = ! hasSelection; columnToolStripMenuItem.Visible = (! hasSelection) && (packageListView.View == View.Details); } @@ -559,7 +701,15 @@ namespace AppliStation void WebResourceCommonContextMenuStripOpening(object sender, System.ComponentModel.CancelEventArgs e) { Package pkg = packageListView.SelectedPackage; - webOfficialMenuItem.Enabled = (pkg != null && pkg.Url != null && !string.IsNullOrEmpty(pkg.Url.Href)); + + if (pkg != null && pkg.Url != null && !string.IsNullOrEmpty(pkg.Url.Href)) { + webOfficialMenuItem.Enabled = true; + webOfficialMenuItem.ToolTipText = pkg.Url.Href; + } else { + webOfficialMenuItem.Enabled = false; + webOfficialMenuItem.ToolTipText = null; + } + // webGoogleSearchMenuItem always active. } @@ -647,24 +797,10 @@ namespace AppliStation } } - void ViewStyleCommonToolStripMenuItemClick(object sender, EventArgs e) - { - viewStyleDetailToolStripMenuItem.Checked = (sender == viewStyleDetailToolStripMenuItem); - viewStyleListToolStripMenuItem.Checked = (sender == viewStyleListToolStripMenuItem); - viewStyleTileToolStripMenuItem.Checked = (sender == viewStyleTileToolStripMenuItem); - - if (sender == viewStyleDetailToolStripMenuItem) { - packageListView.View = View.Details; - } else if (sender == viewStyleListToolStripMenuItem) { - packageListView.View = View.List; - } else if (sender == viewStyleTileToolStripMenuItem) { - packageListView.View = View.Tile; - } - } - void ColumnCommonToolStripMenuItemClick(object sender, EventArgs e) { packageListView.BeginUpdate(); + ColumnHeader sortcolumn = packageListView.SortColumn; // 列の追加と削除 foreach (ToolStripItem item in columnToolStripMenuItem.DropDownItems) { @@ -675,6 +811,9 @@ namespace AppliStation foreach (ColumnHeader header in packageListView.Columns) { if (header.Tag == menu.Tag) { exists = true; + if (sortcolumn == header) { + packageListView.SortColumn = sortcolumn = null; + } if (menu.Checked == false) { packageListView.Columns.Remove(header); } @@ -692,6 +831,8 @@ namespace AppliStation } } + AppliStation.Util.NativeMethods.ColumnHeader_SetSortState(packageListView, (sortcolumn != null)? sortcolumn.Index : -1, SortOrder.None); + packageListView.UpdateItems(); packageListView.EndUpdate();