OSDN Git Service

na-get-lib,all-getについてアップデート処理を新方式(NaGetUpdate2)に変更。
authorttp <ttp@users.sourceforge.jp>
Fri, 6 May 2011 12:01:09 +0000 (21:01 +0900)
committerttp <ttp@users.sourceforge.jp>
Fri, 6 May 2011 12:01:09 +0000 (21:01 +0900)
all-get/Main.cs
na-get-lib/NaGet.SubCommands.SubTask/DownloadSubTask.cs
na-get-lib/NaGet.SubCommands.SubTask/LocalUpdateSubTask.cs
na-get-lib/NaGet.SubCommands/NaGetUpdate2.cs [new file with mode: 0644]
na-get-lib/na-get-lib.csproj

index 39420c9..1091025 100644 (file)
@@ -96,7 +96,7 @@ namespace AllGet
                \r
                public void update(bool downloadPackageListFlag)\r
                {\r
-                       NaGet.SubCommands.NaGetUpdate tasks = new NaGet.SubCommands.NaGetUpdate(pkgListMan, downloadPackageListFlag);\r
+                       NaGet.SubCommands.NaGetUpdate2 tasks = new NaGet.SubCommands.NaGetUpdate2(pkgListMan, downloadPackageListFlag);\r
                        tasks.TaskEventRaised += delegate(object sender, TaskEventArgs e) { \r
                                switch (e.Type) {\r
 //                                     case NaGetTaskSetEventType.COMPLETED_TASKSET\r
@@ -119,8 +119,27 @@ namespace AllGet
                                                break;\r
                                }\r
                        };\r
-                       DownloadListener dl = new DownloadListener();\r
-                       tasks.Downloader.DownloadEventRaised += dl.OnDownload;\r
+                       tasks.SubTaskEventRaised += delegate (object sender, TaskEventArgs e) {\r
+                               if (sender is NaGet.SubCommands.SubTask.DownloadSubTask) {\r
+                                       if (e.Type == TaskEventType.STARTED) {\r
+                                               Console.WriteLine();\r
+                                       }\r
+                                       \r
+                                       int origPosX = Console.CursorLeft;\r
+                                       for (int i = 0; i < Console.WindowWidth - 1; i++) {\r
+                                               Console.Write(' ');\r
+                                       }\r
+                                       Console.CursorLeft = origPosX;\r
+                                       \r
+                                       if (e.Type == TaskEventType.PING) {\r
+                                               int origPos = Console.CursorLeft;\r
+                                               Console.Write(e.TaskMessage);\r
+                                               Console.CursorLeft = origPos;\r
+                                       } else {\r
+                                               Console.WriteLine(e.TaskMessage);\r
+                                       }\r
+                               }\r
+                       };\r
                        \r
                        tasks.Run();\r
                }\r
index e24ad4f..69d0019 100644 (file)
@@ -70,6 +70,11 @@ namespace NaGet.SubCommands.SubTask
                        this.downloadedFileName = null;
                }
                
+               public DownloadSubTask(string url, string filepath, IWebProxy proxy)
+                       : this(new Uri(url), filepath, proxy)
+               {
+               }
+               
                /// <summary>
                /// コンストラクタ
                /// </summary>
@@ -79,6 +84,11 @@ namespace NaGet.SubCommands.SubTask
                        : this(url, filepath, NaGet.Env.WebProxy)
                {
                }
+               
+               public DownloadSubTask(string url, string filepath)
+                       : this(new Uri(url), filepath, NaGet.Env.WebProxy)
+               {
+               }
        
                /// <summary>
                /// ダウンロード時にHTTPヘッダなどから取得した本来のファイル名
index cf69532..f729241 100644 (file)
@@ -6,7 +6,7 @@ namespace NaGet.SubCommands.SubTask
 {
        public class LocalUpdateSubTask : NaGetSubTask
        {
-               PackageListsManager pkgListMan;
+               private PackageListsManager pkgListMan;
                
                public LocalUpdateSubTask(PackageListsManager pkgListMan)
                {
@@ -16,7 +16,7 @@ namespace NaGet.SubCommands.SubTask
                public override void Run()
                {
                        NotifyStarted();
-                       RaiseTaskSetEvent(TaskEventType.STARTED, "リスト更新", 0);
+                       RaiseTaskSetEvent(TaskEventType.STARTED, "ã\82¤ã\83³ã\82¹ã\83\88ã\83¼ã\83«æ¸\88ã\81¿ã\83\95ã\82¡ã\82¤ã\83«ã\83ªã\82¹ã\83\88æ\9b´æ\96°", 0);
                        
                        pkgListMan.DetectInstalledPkgs();
                        pkgListMan.SaveInstalledPackageList();
@@ -26,7 +26,7 @@ namespace NaGet.SubCommands.SubTask
                        pkgListMan.SaveSystemInstalledPackageList();
                        RaiseTaskSetEvent(TaskEventType.INFO, string.Format("{0} を更新しました", NaGet.Env.SystemInstalledPackageListFile), 100);
                        
-                       RaiseTaskSetEvent(TaskEventType.COMPLETED, "リスト更新", 100);
+                       RaiseTaskSetEvent(TaskEventType.COMPLETED, "ã\82¤ã\83³ã\82¹ã\83\88ã\83¼ã\83«æ¸\88ã\81¿ã\83\95ã\82¡ã\82¤ã\83«ã\83ªã\82¹ã\83\88æ\9b´æ\96°", 100);
                        NotifyCompleted();
                }
        }
diff --git a/na-get-lib/NaGet.SubCommands/NaGetUpdate2.cs b/na-get-lib/NaGet.SubCommands/NaGetUpdate2.cs
new file mode 100644 (file)
index 0000000..83048bc
--- /dev/null
@@ -0,0 +1,140 @@
+using System;
+using System.IO;
+using System.Collections.Generic;
+using System.Net;
+using NaGet.Packages;
+using NaGet.Packages.Install;
+using NaGet.Net;
+using NaGet.SubCommands;
+using NaGet.SubCommands.SubTask;
+using NaGet.Tasks;
+
+namespace NaGet.SubCommands
+{
+       /// <summary>
+       /// ソフトリストなどのアップデート処理
+       /// </summary>
+       public class NaGetUpdate2 : NaGetTaskSet2
+       {
+               private PackageListsManager pkgListMan = null;
+               
+               private bool downloadPackageLists = true;
+               
+               private RepositoriesList repoList = null;
+               
+               private IList<string> tempRepoFiles = null;
+               
+               public NaGetUpdate2(PackageListsManager pkgListMan)
+                       : this(pkgListMan, true)
+               {
+               }
+               
+               /// <summary>
+               /// コンストラクタ
+               /// </summary>
+               /// <param name="pkgMan">参照パッケージマネージャ</param>
+               /// <param name="downloadPackageListsFlag">リストをダウンロードするか?</param>
+               public NaGetUpdate2(PackageListsManager pkgMan, bool downloadPackageListsFlag)
+               {
+                       this.pkgListMan = pkgMan;
+                       this.downloadPackageLists = downloadPackageListsFlag;
+                       
+                       // taskセットの初期化
+                       initSubTask();
+                       if (this.downloadPackageLists) {
+                               // repos.list.xmlがあるとき、そこからよみとる。
+                               repoList = NaGet.Utils.GetDeserializedObject<RepositoriesList>(NaGet.Env.RepositoriesListFile);
+                               tempRepoFiles = new List<string>();
+                               
+                               foreach (RepositoryInfo repo in repoList.EnabledRepositories) {
+                                       string filepath = Path.GetTempFileName();
+                                       
+                                       tempRepoFiles.Add(filepath);
+                                       registSubTask(string.Format("リスト取得: {0}", repo.Url.Href),
+                                                     new DownloadSubTask(repo.Url.Href, filepath));
+                               }
+                               registSubTask(string.Format("リスト更新: {0}", NaGet.Env.PackageListFile),
+                                             new FunctionalSubTask(runUpdatePackageListFile, null));
+                       }
+                       registSubTask("インストール済みのソフトリスト更新",
+                                     new LocalUpdateSubTask(this.pkgListMan));
+               }
+               
+               public override void Run()
+               {
+                       NotifyStarted();
+                       try {
+                               while (hasMoreSubTask) {
+                                       RaiseTaskSetEvent(TaskEventType.STARTED_SUBTASK, currentSubTaskName);
+                                       currentSubTask.Run();
+                                       RaiseTaskSetEvent(TaskEventType.COMPLETED_SUBTASK, currentSubTaskName);
+                                       
+                                       NotifyGoToNextSubTask();
+                               }
+                       } finally {
+                               runDeleteTempFiles();
+                               if (cancelCalled) {
+                                       NotifyCancelled();
+                               } else {
+                                       NotifyCompleted();
+                               }
+                       }
+               }
+               
+               private void runUpdatePackageListFile(object dummy)
+               {
+                       int i = 0;
+                       PackageList<Package> avaiablePackageList = new PackageList<Package>();
+                       
+                       // かならず常にrepositoryリストに書き込む。
+                       NaGet.Utils.PutSerializeObject(NaGet.Env.RepositoriesListFile, repoList);
+                       
+                       foreach (RepositoryInfo repo in repoList.EnabledRepositories) {
+                               if (repo.Type == RepositoryType.APPLISTATION_NATIVE_XML_1_0) {
+                                       try {
+                                               string tmpfileName = tempRepoFiles[i];
+                                               PackageList<Package> pkgList = NaGet.Utils.GetDeserializedObject<PackageList<Package>>(tmpfileName);
+                                               pkgList.FixPackageListName(); // PackageListNameとの紐付けを行う
+                                               
+                                               // RepositoryReferenceの名前を読み込む
+                                               repo.Name = (string.IsNullOrEmpty(pkgList.Name))? repo.Name : pkgList.Name;
+                                               
+                                               avaiablePackageList.AddPackages(pkgList);
+                                       } catch (InvalidOperationException) {
+                                               RaiseTaskSetEvent(TaskEventType.ERROR, string.Format("レポジトリ'{0}'はAppliStation Native XML softlist形式ではありません。", repo.Name ?? repo.Url.Href));
+                                       }
+                               } else {
+                                       RaiseTaskSetEvent(TaskEventType.WARNING, string.Format("レポジトリ'{0}'の設定が不正です。", repo.Name ?? repo.Url.Href));
+                               }
+                               i++;
+                       }
+                       
+                       pkgListMan.availablePkgList = avaiablePackageList; // Mediatorのリストを更新
+                       pkgListMan.SaveAvailablePackageList();
+               }
+               
+               private void runDeleteTempFiles()
+               {
+                       if (tempRepoFiles != null) {
+                               foreach (string file in tempRepoFiles) {
+                                       if (File.Exists(file)) {
+                                               File.Delete(file);
+                                       }
+                               }
+                       }
+               }
+               
+               public override bool Cancelable {
+                       get {
+                               return !cancelCalled && Running && isDuringDownloading;
+                       }
+               }
+               
+               private bool isDuringDownloading {
+                       get {
+                               return Running && (currentSubTask is DownloadSubTask);
+                       }
+               }
+               
+       }
+}
index 62c3dda..fd356a1 100644 (file)
     <Compile Include="NaGet.Packages\VersionComparetor.cs" />\r
     <Compile Include="NaGet.SubCommands.SubTask\FunctionalSubTask.cs" />\r
     <Compile Include="NaGet.SubCommands.SubTask\DownloadSubTask.cs" />\r
+    <Compile Include="NaGet.SubCommands.SubTask\LocalUpdateSubTask.cs" />\r
     <Compile Include="NaGet.SubCommands.SubTask\NaGetSubTask.cs" />\r
     <Compile Include="NaGet.SubCommands\NaGetDownloadToCache.cs" />\r
     <Compile Include="NaGet.SubCommands\NaGetInstall.cs" />\r
     <Compile Include="NaGet.SubCommands\NaGetTaskSet.cs" />\r
     <Compile Include="NaGet.SubCommands\NaGetTaskSet2.cs" />\r
     <Compile Include="NaGet.SubCommands\NaGetUninstall.cs" />\r
+    <Compile Include="NaGet.SubCommands\NaGetUpdate2.cs" />\r
     <Compile Include="NaGet.Tasks\Task.cs" />\r
     <Compile Include="NaGet.Tasks\TaskCanceledException.cs" />\r
     <Compile Include="NaGet.Tasks\TaskEventArgs.cs" />\r
@@ -94,7 +96,6 @@
     <Compile Include="NaGet.Packages.Install\UninstallInformation.cs" />\r
     <Compile Include="NaGet.Packages.Install\InstalledPackage.cs" />\r
     <Compile Include="NaGet.SubCommands\NaGetUpdate.cs" />\r
-    <None Include="NaGet.SubCommands.SubTask\LocalUpdateSubTask.cs" />\r
   </ItemGroup>\r
   <ItemGroup>\r
     <Folder Include="NaGet.InteropServices" />\r