OSDN Git Service

na-get-lib,複数ソフトインストールかつハッシュ検証失敗したとき、ハッシュ検証成功したソフトの状態がおかしくなる不具合を修正
[applistation/AppliStation.git] / AppliStation / PackageListViewForm.cs
index 6ee1e35..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
@@ -315,11 +316,30 @@ namespace AppliStation
                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
@@ -327,10 +347,28 @@ namespace AppliStation
                                \r
                                PackageCollectionFileData collectionData = new PackageCollectionFileData();\r
                                \r
-                               collectionData.loadPackages(pkgListsMan.GetAllInstalledPackages());\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
@@ -378,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
@@ -448,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
@@ -514,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
@@ -658,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