OSDN Git Service

na-get-lib,provider.list.txtからrepos.list.xmlへ移行
[applistation/AppliStation.git] / na-get-lib / NaGet.SubCommands / NaGetUpdate.cs
index 9807e1a..56efa21 100644 (file)
@@ -9,7 +9,7 @@ namespace NaGet.SubCommands
 {\r
        public class NaGetUpdate : NaGetTaskSet\r
        {\r
-               private ProviderList providerList;\r
+               private RepositoriesList repoList;\r
                \r
                private PackageListsManager pkgListMan;\r
                \r
@@ -56,10 +56,17 @@ namespace NaGet.SubCommands
                        \r
                        System.Collections.Generic.List<string> taskSetNames = new System.Collections.Generic.List<string>();\r
                        if (downloadPackageLists) {\r
-                               providerList = new ProviderList(NaGet.Env.ProviderListFile);\r
+                               if ((! File.Exists(NaGet.Env.RepositoriesListFile)) && File.Exists(NaGet.Env.ProviderListFile)) {\r
+                                       // repos.list.xmlがなくてprovider.list.txtがあるとき、マイグレートする。\r
+                                       repoList = RepositoriesList.MigrateFromProviderListTxt(NaGet.Env.ProviderListFile);\r
+                                       NaGet.Utils.PutSerializeObject(NaGet.Env.RepositoriesListFile, repoList);\r
+                               } else {\r
+                                       // repos.list.xmlがあるとき、そこからよみとる。\r
+                                       repoList = NaGet.Utils.GetDeserializedObject<RepositoriesList>(NaGet.Env.RepositoriesListFile);\r
+                               }\r
                                \r
-                               foreach (string url in providerList.Urls) {\r
-                                       taskSetNames.Add(string.Format("リスト取得: {0}", url));\r
+                               foreach (RepositoryReference repo in repoList.Repositories) {\r
+                                       taskSetNames.Add(string.Format("リスト取得: {0}", repo.Url.Href));\r
                                }\r
                                taskSetNames.Add(string.Format("リスト更新: {0}", NaGet.Env.PackageListFile));\r
                        }\r
@@ -90,7 +97,7 @@ namespace NaGet.SubCommands
                                                        RaiseTaskSetEvent(NaGetTaskSetEventType.WARNING, "ネットワークに接続できませんでした。ネットワークが切断されているか、ファイアウォールによって遮断された可能性があります。");\r
                                                }\r
                                        } finally {\r
-                                               currentTaskSetIndex = providerList.Urls.Length + 1;\r
+                                               currentTaskSetIndex = repoList.Repositories.Length + 1;\r
                                        }\r
                                        packageListsDownloaded = true;\r
                                }\r
@@ -106,14 +113,19 @@ namespace NaGet.SubCommands
                private void runDownloadPackages()\r
                {\r
                        PackageList<Package> avaiablePackageList = new PackageList<Package>();\r
-                       foreach(string provider in providerList.Urls) {\r
+                       foreach(RepositoryReference repo in repoList.Repositories) {\r
                                RaiseTaskSetEvent(NaGetTaskSetEventType.STARTED_TASKSET, TaskSetNames[currentTaskSetIndex]);\r
                                \r
                                string tmpfileName = Path.GetTempFileName();\r
                                try {\r
-                                       Downloader.Download(provider, tmpfileName);\r
+                                       Downloader.Download(repo.Url.Href, tmpfileName);\r
+                                       \r
+                                       PackageList<Package> pkgList = NaGet.Utils.GetDeserializedObject<PackageList<Package>>(tmpfileName);\r
+                                       \r
+                                       // RepositoryReferenceの名前を読み込む // TODO RepositoryReferenceの名前を読み込む処理はここでいいのか?\r
+                                       repo.Name = (string.IsNullOrEmpty(pkgList.Name))? repo.Name : pkgList.Name;\r
                                        \r
-                                       avaiablePackageList.AddPackages(NaGet.Utils.GetDeserializedObject<PackageList<Package>>(tmpfileName).Packages);\r
+                                       avaiablePackageList.AddPackages(pkgList.Packages);\r
                                } finally {\r
                                        if (File.Exists(tmpfileName)) {\r
                                                File.Delete(tmpfileName);\r
@@ -124,6 +136,11 @@ namespace NaGet.SubCommands
                                RaiseTaskSetEvent(NaGetTaskSetEventType.COMPLETED_TASKSET, TaskSetNames[currentTaskSetIndex-1]);\r
                        }\r
                        \r
+                       // TODO 暫定的にかならず常にrepositoryリストに書き込む。\r
+                       if ( true ) {\r
+                               NaGet.Utils.PutSerializeObject(NaGet.Env.RepositoriesListFile, repoList);\r
+                       }\r
+                       \r
                        RaiseTaskSetEvent(NaGetTaskSetEventType.STARTED_TASKSET, TaskSetNames[currentTaskSetIndex]);\r
                        pkgListMan.availablePkgList = avaiablePackageList; // Mediatorのリストを更新\r
                        pkgListMan.SaveAvailablePackageList();\r