3 using System.Collections.Generic;
6 using NaGet.Packages.Install;
7 using NaGet.SubCommands;
8 using NaGet.SubCommands.SubTask;
11 namespace NaGet.SubCommands
16 public class NaGetUpdate2 : NaGetTaskSet2
18 private PackageListsManager pkgListMan = null;
20 private bool downloadPackageLists = true;
22 private RepositoriesList repoList = null;
24 private IList<string> tempRepoFiles = null;
26 public NaGetUpdate2(PackageListsManager pkgListMan)
27 : this(pkgListMan, true)
34 /// <param name="pkgMan">参照パッケージマネージャ</param>
35 /// <param name="downloadPackageListsFlag">リストをダウンロードするか?</param>
36 public NaGetUpdate2(PackageListsManager pkgMan, bool downloadPackageListsFlag)
38 this.pkgListMan = pkgMan;
39 this.downloadPackageLists = downloadPackageListsFlag;
43 if (this.downloadPackageLists) {
44 // repos.list.xmlがあるとき、そこからよみとる。
45 repoList = NaGet.Utils.GetDeserializedObject<RepositoriesList>(NaGet.Env.RepositoriesListFile);
46 tempRepoFiles = new List<string>();
48 foreach (RepositoryInfo repo in repoList.EnabledRepositories) {
49 string filepath = Path.GetTempFileName();
51 tempRepoFiles.Add(filepath);
52 registSubTask(string.Format("リスト取得: {0}", repo.Url.Href),
53 new DownloadSubTask(repo.Url.Href, filepath));
55 registSubTask(string.Format("リスト更新: {0}", NaGet.Env.PackageListFile),
56 new FunctionalSubTask<object>(runUpdatePackageListFile, null));
58 registSubTask("インストール済みのソフトリスト更新",
59 new LocalUpdateSubTask(this.pkgListMan));
62 public override void Run()
65 RaiseTaskSetEvent(TaskEventType.STARTED, string.Empty);
68 while (hasMoreSubTask) {
69 RaiseTaskSetEvent(TaskEventType.STARTED_SUBTASK, currentSubTaskName);
71 RaiseTaskSetEvent(TaskEventType.COMPLETED_SUBTASK, currentSubTaskName);
73 NotifyGoToNextSubTask();
75 } catch (TaskCanceledException) {
77 } catch (Exception e) {
78 RaiseTaskSetEvent(TaskEventType.ERROR, e.Message);
85 RaiseTaskSetEvent(TaskEventType.CANCELED, "キャンセルされました");
88 RaiseTaskSetEvent(TaskEventType.COMPLETED, string.Empty);
92 private void runUpdatePackageListFile(object dummy)
95 PackageList<Package> avaiablePackageList = new PackageList<Package>();
97 // かならず常にrepositoryリストに書き込む。
98 NaGet.Utils.PutSerializeObject(NaGet.Env.RepositoriesListFile, repoList);
100 foreach (RepositoryInfo repo in repoList.EnabledRepositories) {
101 if (repo.Type == RepositoryType.APPLISTATION_NATIVE_XML_1_0) {
103 string tmpfileName = tempRepoFiles[i];
104 PackageList<Package> pkgList = NaGet.Utils.GetDeserializedObject<PackageList<Package>>(tmpfileName);
105 pkgList.FixPackageListName(); // PackageListNameとの紐付けを行う
107 // RepositoryReferenceの名前を読み込む
108 repo.Name = (string.IsNullOrEmpty(pkgList.Name))? repo.Name : pkgList.Name;
110 avaiablePackageList.AddPackages(pkgList);
111 } catch (InvalidOperationException) {
112 RaiseTaskSetEvent(TaskEventType.ERROR, string.Format("レポジトリ'{0}'はAppliStation Native XML softlist形式ではありません。", repo.Name ?? repo.Url.Href));
115 RaiseTaskSetEvent(TaskEventType.WARNING, string.Format("レポジトリ'{0}'の設定が不正です。", repo.Name ?? repo.Url.Href));
120 pkgListMan.availablePkgList = avaiablePackageList; // Mediatorのリストを更新
121 pkgListMan.SaveAvailablePackageList();
124 private void runDeleteTempFiles()
126 if (tempRepoFiles != null) {
127 foreach (string file in tempRepoFiles) {
128 if (File.Exists(file)) {
135 public override bool Cancelable {
137 return !cancelCalled && Running && isDuringDownloading;
141 private bool isDuringDownloading {
143 return Running && (currentSubTask is DownloadSubTask);