OSDN Git Service

AppliStation-All,アセンブリバージョンを1.4.3に
[applistation/AppliStation.git] / na-get-lib / NaGet.SubCommands.SubTask / LocalUpdateSubTask.cs
1 using System;
2 using System.IO;
3 using NaGet.Tasks;
4 using NaGet.Packages;
5
6 namespace NaGet.SubCommands.SubTask
7 {
8         public class LocalUpdateSubTask : NaGetSubTask
9         {
10                 private PackageListsManager pkgListMan;
11                 
12                 public LocalUpdateSubTask(PackageListsManager pkgListMan)
13                 {
14                         this.pkgListMan = pkgListMan;
15                 }
16                 
17                 public override void Run()
18                 {
19                         NotifyStarted();
20                         RaiseTaskSetEvent(TaskEventType.STARTED, "インストール済みファイルリスト更新", 0);
21                         
22                         try {
23                                 pkgListMan.DetectInstalledPkgs();
24                         } catch (PackageInformationFileAccessException e) {
25                                 recoverExceptionAtDetectInstalledPkgs(e);
26                         }
27                         pkgListMan.SaveInstalledPackageList();
28                         RaiseTaskSetEvent(TaskEventType.INFO, string.Format("{0} を更新しました", NaGet.Env.ArchiveInstalledPackageListFile), 50);
29                         
30                         pkgListMan.DetectSystemInstalledPkgs();
31                         pkgListMan.SaveSystemInstalledPackageList();
32                         RaiseTaskSetEvent(TaskEventType.INFO, string.Format("{0} を更新しました", NaGet.Env.SystemInstalledPackageListFile), 100);
33                         
34                         RaiseTaskSetEvent(TaskEventType.COMPLETED, "インストール済みファイルリスト更新", 100);
35                         NotifyCompleted();
36                 }
37                 
38                 private void recoverExceptionAtDetectInstalledPkgs(PackageInformationFileAccessException e)
39                 {
40                         RaiseTaskSetEvent(TaskEventType.WARNING, string.Format("{0} が読み込めませんでした", e.FilePath), -1);
41                         
42                         string dirPath = Path.GetDirectoryName(e.FilePath);
43                         if (Directory.Exists(dirPath)) {
44                                 NaGet.Utils.SetAttributeRecursive(dirPath, FileAttributes.Normal);
45                                 Directory.Delete(dirPath, true);
46                                 RaiseTaskSetEvent(TaskEventType.WARNING, string.Format("{0}を削除しました。", Path.GetDirectoryName(e.FilePath)), -1);
47                                 
48                                 pkgListMan.DetectInstalledPkgs();
49                         } else {
50                                 throw e;
51                         }
52                 }
53         }
54 }