OSDN Git Service

na-get-lib,チケット #26588 (ソフトウェアインストールの)異常終了後に AppliStation が起動不可になる問題の本対処
authorttp <ttp@users.sourceforge.jp>
Sat, 29 Oct 2011 08:47:08 +0000 (17:47 +0900)
committerttp <ttp@users.sourceforge.jp>
Sat, 29 Oct 2011 08:47:08 +0000 (17:47 +0900)
AppliStation/UserPrefForm.cs
na-get-lib/NaGet.Packages/PackageInformationFileAccessException.cs [new file with mode: 0644]
na-get-lib/NaGet.Packages/PackageListsManager.cs
na-get-lib/NaGet.SubCommands.SubTask/LocalUpdateSubTask.cs
na-get-lib/na-get-lib.csproj

index 8005bf3..3f6ff2b 100644 (file)
@@ -37,7 +37,11 @@ namespace AppliStation
                /// </summary>\r
                public void loadCurrentPref()\r
                {\r
-                       this.RepositoriesListSetting = NaGet.Utils.GetDeserializedObject<RepositoriesList>(NaGet.Env.RepositoriesListFile);\r
+                       try {\r
+                               this.RepositoriesListSetting = NaGet.Utils.GetDeserializedObject<RepositoriesList>(NaGet.Env.RepositoriesListFile);\r
+                       } catch {\r
+                               this.RepositoriesListSetting = new RepositoriesList();\r
+                       }\r
                        \r
                        NaGet.NaGetLibPref userPref = NaGet.Env.Pref;\r
                        this.ProxyAddress = userPref.ProxyAddress;\r
diff --git a/na-get-lib/NaGet.Packages/PackageInformationFileAccessException.cs b/na-get-lib/NaGet.Packages/PackageInformationFileAccessException.cs
new file mode 100644 (file)
index 0000000..62f1d04
--- /dev/null
@@ -0,0 +1,26 @@
+using System;
+using System.IO;
+
+namespace NaGet.Packages
+{
+       /// <summary>
+       /// パッケージ情報のファイルアクセスに関する例外
+       /// </summary>
+       public class PackageInformationFileAccessException : ApplicationException
+       {
+               string filePath;
+               
+               public PackageInformationFileAccessException(string msg, string filepath, Exception innerException)
+                       : base(msg, innerException)
+               {
+                       this.filePath = filepath;
+               }
+               
+               /// <summary>
+               /// パッケージ情報のファイルへのパス
+               /// </summary>
+               public string FilePath {
+                       get { return filePath; }
+               }
+       }
+}
index babf85e..cd950b7 100644 (file)
@@ -129,7 +129,10 @@ namespace NaGet.Packages
                                foreach (string path in NaGet.Utils.ExtendWildcardFile(NaGet.Env.ArchiveProgramFiles, Path.Combine("*", ".applistation.package.xml"))) {\r
                                        try {\r
                                                pkgList.AddPackage(NaGet.Utils.GetDeserializedObject<InstalledPackage>(path));\r
-                                       } catch (Exception) {\r
+                                       } catch (Exception e) {\r
+                                               throw new PackageInformationFileAccessException(\r
+                                                       string.Format("The information file of {0} is broken.", path),\r
+                                                       path, e);\r
                                        }\r
                                }\r
                                this.installedPkgList = pkgList;\r
index f729241..73c525c 100644 (file)
@@ -1,4 +1,5 @@
 using System;
+using System.IO;
 using NaGet.Tasks;
 using NaGet.Packages;
 
@@ -18,7 +19,11 @@ namespace NaGet.SubCommands.SubTask
                        NotifyStarted();
                        RaiseTaskSetEvent(TaskEventType.STARTED, "インストール済みファイルリスト更新", 0);
                        
-                       pkgListMan.DetectInstalledPkgs();
+                       try {
+                               pkgListMan.DetectInstalledPkgs();
+                       } catch (PackageInformationFileAccessException e) {
+                               recoverExceptionAtDetectInstalledPkgs(e);
+                       }
                        pkgListMan.SaveInstalledPackageList();
                        RaiseTaskSetEvent(TaskEventType.INFO, string.Format("{0} を更新しました", NaGet.Env.ArchiveInstalledPackageListFile), 50);
                        
@@ -29,5 +34,21 @@ namespace NaGet.SubCommands.SubTask
                        RaiseTaskSetEvent(TaskEventType.COMPLETED, "インストール済みファイルリスト更新", 100);
                        NotifyCompleted();
                }
+               
+               private void recoverExceptionAtDetectInstalledPkgs(PackageInformationFileAccessException e)
+               {
+                       RaiseTaskSetEvent(TaskEventType.WARNING, string.Format("{0} が読み込めませんでした", e.FilePath), -1);
+                       
+                       string dirPath = Path.GetDirectoryName(e.FilePath);
+                       if (Directory.Exists(dirPath)) {
+                               NaGet.Utils.SetAttributeRecursive(dirPath, FileAttributes.Normal);
+                               Directory.Delete(dirPath, true);
+                               RaiseTaskSetEvent(TaskEventType.WARNING, string.Format("{0}を削除しました。", Path.GetDirectoryName(e.FilePath)), -1);
+                               
+                               pkgListMan.DetectInstalledPkgs();
+                       } else {
+                               throw e;
+                       }
+               }
        }
 }
index 00c9baf..465bc5d 100644 (file)
@@ -65,6 +65,7 @@
     <Compile Include="NaGet.Packages.Install\InstallationLog.cs" />\r
     <Compile Include="NaGet.Packages.Install\UpgradeFinder.cs" />\r
     <Compile Include="NaGet.Packages\PackageCollectionFileData.cs" />\r
+    <Compile Include="NaGet.Packages\PackageInformationFileAccessException.cs" />\r
     <Compile Include="NaGet.Packages\PackageListsManager.cs" />\r
     <Compile Include="NaGet.Packages\RepositoriesList.cs" />\r
     <Compile Include="NaGet.Packages\VersionComparetor.cs" />\r