OSDN Git Service

na-get-lib,複数ソフトインストールかつハッシュ検証失敗したとき、ハッシュ検証成功したソフトの状態がおかしくなる不具合を修正
[applistation/AppliStation.git] / AppliStation / PackageListViewForm.cs
index 3c01042..a66d9a6 100644 (file)
@@ -108,6 +108,7 @@ namespace AppliStation
                        webResourceToolStripMenuItem.Visible = (pkgCount == 1);\r
                        uninstallToolStripMenuItem.Visible = uninstallBtnEnabled;\r
                        installToolStripMenuItem.Visible = installBtnEnabled;\r
+                       downloadToolStripMenuItem.Visible = (pkgCount > 0);\r
                        \r
                        // detailBoxのメッセージ設定\r
                        switch (pkgCount) {\r
@@ -231,7 +232,7 @@ namespace AppliStation
                {\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
+                               NaGet.SubCommands.NaGetUpdate2 tasks = new NaGet.SubCommands.NaGetUpdate2(pkgListsMan, downloadPackageListsFlag);\r
                                prog.SetTaskSet(tasks);\r
                                prog.Refresh();\r
                                prog.StartTaskSet();\r
@@ -254,6 +255,129 @@ namespace AppliStation
                        UpdatePackageList();\r
                }\r
                \r
+               void SoftCollectionFileImportToolStripMenuItemClick(object sender, EventArgs e)\r
+               {\r
+                       string pwd = Directory.GetCurrentDirectory();\r
+                       \r
+                       OpenFileDialog fd = new OpenFileDialog();\r
+                       fd.Filter = "ソフトコレクションファイル (*.txt)|*.txt";\r
+                       fd.DefaultExt = "txt";\r
+                       fd.CheckFileExists = true;\r
+                       fd.CheckPathExists = true;\r
+                       fd.Multiselect = false;\r
+                       fd.ShowDialog();\r
+                       if (fd.FileNames.Length > 0) {\r
+                               string filepath = Path.GetFullPath(fd.FileName);\r
+                               Directory.SetCurrentDirectory(pwd); // ファイルダイアログで変わったカレントディレクトリを戻す\r
+                               \r
+                               IList<Package> pkgs;\r
+                               IList<string> invalid;\r
+                               \r
+                               try {\r
+                                       PackageCollectionFileData collectionData = new PackageCollectionFileData();\r
+                                       collectionData.load(filepath);\r
+                                       collectionData.generatePackages(pkgListsMan, out pkgs, out invalid);\r
+                                       \r
+                                       if (invalid.Count > 0) {\r
+                                               DialogResult result = MessageBox.Show("一部読み込みの失敗したパッケージがありますが続行しますか?", "インポート", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);\r
+                                               if (result != DialogResult.OK) {\r
+                                                       return;\r
+                                               }\r
+                                       }\r
+                               } catch (IOException) {\r
+                                       MessageBox.Show("ファイルの読み込みに失敗しました", "インポート", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
+                                       return;\r
+                               }\r
+                               \r
+                               {\r
+                                       InstallationConfirmForm confirm = new InstallationConfirmForm();\r
+                                       confirm.PkgListsManager = pkgListsMan;\r
+                                       confirm.Installations = Installation.ConvertInstallations( NaGet.Utils.IEnumerable2Array(pkgs) );\r
+                                       confirm.UseRunas = confirm.GetShouldUseRunas();\r
+                                       DialogResult result = confirm.ShowDialog(this);\r
+                                       \r
+                                       if (result == DialogResult.OK) {\r
+                                               Installation[] insts = confirm.CheckedInstallations;\r
+                                               \r
+                                               if (confirm.UseRunas) {\r
+                                                       installRunasActionInvoke(insts);\r
+                                               } else {\r
+                                                       installActionInvoke(insts);\r
+                                               }\r
+                                               \r
+                                               UpdatePackageList();\r
+                                       }\r
+                               }\r
+                       } else {\r
+                               Directory.SetCurrentDirectory(pwd); // ファイルダイアログで変わったカレントディレクトリを戻す\r
+                       }\r
+               }\r
+               \r
+               void SoftCollectionFileExportToolStripMenuItemClick(object sender, EventArgs e)\r
+               {\r
+                       string pwd = Directory.GetCurrentDirectory();\r
+                       string[] softtargets = new string[]{\r
+                               "PCにインストールされたソフト",\r
+                               "AppliStation内でインストールされたソフト",\r
+                               "インストールされたソフトすべて;PCとAppliStationにインストールされたソフトの両方"\r
+                       };\r
+                       int softtargetid = softtargets.Length - 1;\r
+                       \r
+                       {\r
+                               AppliStation.Util.OptionDialog optdialog = AppliStation.Util.OptionDialog.createCommandSelectionDialog(\r
+                                       "ソフトコレクションファイルに出力するソフトの種類を選択してください。", "エクスポート", "エクスポートするソフト",\r
+                                       System.Drawing.SystemIcons.Question,\r
+                                       softtargets, softtargets.Length-1);\r
+                               if (optdialog.ShowDialog(this) != DialogResult.OK) {\r
+                                       return; // canceled\r
+                               } else if (optdialog.UserInputValue != null) {\r
+                                       softtargetid = (int) optdialog.UserInputValue;\r
+                               }\r
+                       }\r
+                       \r
+                       SaveFileDialog fd = new SaveFileDialog();\r
+                       fd.Filter = "ソフトコレクションファイル (*.txt)|*.txt";\r
+                       fd.DefaultExt = "txt";\r
+                       fd.CheckPathExists = true;\r
+                       fd.OverwritePrompt = true;\r
+                       fd.ShowDialog();\r
+                       if (fd.FileNames.Length > 0) {\r
+                               string filepath = Path.GetFullPath(fd.FileName);\r
+                               Directory.SetCurrentDirectory(pwd); // ファイルダイアログで変わったカレントディレクトリを戻す\r
+                               \r
+                               PackageCollectionFileData collectionData = new PackageCollectionFileData();\r
+                               \r
+                               switch (softtargetid) {\r
+                                       case 0: // PCにインストール\r
+                                               collectionData.loadPackages(pkgListsMan.SystemInstalledPkgList.GetEnumerator());\r
+                                               break;\r
+                                       case 1: // AppliStation内にインストール\r
+                                               collectionData.loadPackages(pkgListsMan.InstalledPkgList.GetEnumerator());\r
+                                               break;\r
+                                       case 2: // すべて\r
+                                       default:\r
+                                               collectionData.loadPackages(pkgListsMan.GetAllInstalledPackages());\r
+                                               break;\r
+                               }\r
+                               \r
+                               try {\r
+                                       collectionData.saveAs(fd.FileName);\r
+                               } catch (UnauthorizedAccessException) {\r
+                                       if ((File.GetAttributes(fd.FileName) & FileAttributes.ReadOnly) != 0) {\r
+                                               MessageBox.Show("読み取り専用属性が設定されています。\n別のファイルを指定してください。", "エクスポート", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
+                                       } else {\r
+                                               MessageBox.Show("ファイルへの書き込みが許可されていません。\n別のファイルを指定してください。", "エクスポート", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
+                                       }\r
+                                       return;\r
+                               } catch (IOException) {\r
+                                       MessageBox.Show("ファイルの書き込みに失敗しました", "エクスポート", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
+                                       return;\r
+                               }\r
+                       } else {\r
+                               Directory.SetCurrentDirectory(pwd); // ファイルダイアログで変わったカレントディレクトリを戻す\r
+                       }\r
+               }\r
+               \r
                void OptionToolStripMenuItemClick(object sender, EventArgs e)\r
                {\r
                        UserPrefForm userPrefForm = new UserPrefForm();\r
@@ -292,7 +416,7 @@ namespace AppliStation
                {\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, insts);\r
+                               NaGet.SubCommands.NaGetInstall2 tasks = new NaGet.SubCommands.NaGetInstall2(pkgListsMan, insts);\r
                                prog.SetTaskSet(tasks);\r
                                prog.Refresh();\r
                                prog.StartTaskSet();\r
@@ -362,7 +486,7 @@ namespace AppliStation
                {\r
                        AppliStation.Util.ExecutionProgressViewer prog = new AppliStation.Util.ExecutionProgressViewer();\r
                        prog.Shown += delegate(object sender2, EventArgs e2) {\r
-                               NaGet.SubCommands.NaGetUninstall tasks = new NaGet.SubCommands.NaGetUninstall(pkgListsMan, pkgs);\r
+                               NaGet.SubCommands.NaGetUninstall2 tasks = new NaGet.SubCommands.NaGetUninstall2(pkgListsMan, pkgs);\r
                                prog.SetTaskSet(tasks);\r
                                prog.Refresh();\r
                                prog.StartTaskSet();\r
@@ -428,6 +552,27 @@ namespace AppliStation
                        }\r
                }\r
                \r
+               internal void downloadActionInvoke(Installation[] pkgs)\r
+               {\r
+                       AppliStation.Util.ExecutionProgressViewer prog = new AppliStation.Util.ExecutionProgressViewer();\r
+                       prog.Shown += delegate(object sender2, EventArgs e2) {\r
+                               NaGet.SubCommands.NaGetDownloadToCache2 tasks = new NaGet.SubCommands.NaGetDownloadToCache2(pkgListsMan, pkgs);\r
+                               prog.SetTaskSet(tasks);\r
+                               prog.Refresh();\r
+                               prog.StartTaskSet();\r
+                       };\r
+                       prog.Text = string.Format("キャッシュへのダウンロード");\r
+                       prog.ShowDialog(this);\r
+               }\r
+               \r
+               void DownloadToolStripMenuItemClick(object sender, EventArgs e)\r
+               {\r
+                       Installation[] insts = Installation.ConvertInstallations( NaGet.Utils.IEnumerable2Array(packageListView.SelectedPackages) );\r
+                       \r
+                       downloadActionInvoke(insts);\r
+                       \r
+                       UpdatePackageList();\r
+               }\r
                \r
                void WebOfficialMenuItemClick(object sender, EventArgs e)\r
                {\r
@@ -466,8 +611,8 @@ namespace AppliStation
                        if (pkg != null) {\r
                                if (pkg.Type == InstallerType.ARCHIVE || pkg.Type == InstallerType.ITSELF) {\r
                                        System.Diagnostics.Process.Start(Path.Combine(NaGet.Env.ArchiveProgramFiles, pkg.Name));\r
-                               } else if (Directory.Exists(pkg.discoverInstalledLocation())) {\r
-                                       System.Diagnostics.Process.Start(pkg.discoverInstalledLocation());\r
+                               } else if (Directory.Exists(pkg.DiscoverInstalledLocation())) {\r
+                                       System.Diagnostics.Process.Start(pkg.DiscoverInstalledLocation());\r
                                }\r
                        }\r
                }\r
@@ -504,11 +649,11 @@ namespace AppliStation
                                        bool launcherMenuItemVisible = \r
                                                (pkg.Type == InstallerType.ARCHIVE) ||\r
                                                (pkg.Type == InstallerType.ITSELF) ||\r
-                                               Directory.Exists(iPkg.discoverInstalledLocation());\r
+                                               Directory.Exists(iPkg.DiscoverInstalledLocation());\r
                                        \r
                                        launcherMenuItem.Visible = launcherMenuItemVisible;\r
                                        if (launcherMenuItemVisible) {\r
-                                               launcherMenuItem.BaseFolderPath = iPkg.discoverInstalledLocation();\r
+                                               launcherMenuItem.BaseFolderPath = iPkg.DiscoverInstalledLocation();\r
                                        }\r
                                } else {\r
                                        launcherMenuItem.Visible = false;\r
@@ -572,30 +717,10 @@ namespace AppliStation
                        // webGoogleSearchMenuItem always active.\r
                }\r
                \r
-               private IEnumerable<Package> getUpdatedPackages(PackageList<InstalledPackage> installedPkgList, PackageList<Package> avaiablePkgList, IComparer<string> verComp)\r
-               {\r
-                       foreach (InstalledPackage pkg in installedPkgList) {\r
-                               Package avaiablePkg = avaiablePkgList.GetPackageForName(pkg.Name);\r
-                               \r
-                               if (avaiablePkg != null) {\r
-                                       if (verComp.Compare(pkg.Version, avaiablePkg.Version) < 0 &&\r
-                                           installedPkgList.GetPackageForPackage(pkg.Name, avaiablePkg.Version) == null) {\r
-                                               \r
-                                               yield return avaiablePkg;\r
-                                       }\r
-                               }\r
-                       }\r
-               }\r
-               \r
                void UpgradeToolStripButtonClick(object sender, EventArgs e)\r
                {\r
-                       List<Package> pkgs;\r
-                       VersionComparetor verComp = new VersionComparetor();\r
-                       PackageList<Package> avaiablePackageList = pkgListsMan.AvailablePkgList;\r
-                       \r
-                       pkgs = NaGet.Utils.MergeList(\r
-                               getUpdatedPackages(pkgListsMan.InstalledPkgList, avaiablePackageList, verComp),\r
-                               getUpdatedPackages(pkgListsMan.SystemInstalledPkgList, avaiablePackageList, verComp)\r
+                       List<Package> pkgs = new List<Package>(\r
+                               UpgradeFinder.GetUpgradePackages(pkgListsMan)\r
                        );\r
                        \r
                        if (pkgs.Count <= 0) {\r