From e6947e0cb8dff56a3502e05c18a3b856c613c499 Mon Sep 17 00:00:00 2001 From: goat <16760685+goaaats@users.noreply.github.com> Date: Mon, 14 Dec 2020 17:58:39 +0100 Subject: [PATCH] feat: implement logic for third party repo --- Dalamud/Plugin/PluginInstallerWindow.cs | 3 +++ Dalamud/Plugin/PluginRepository.cs | 25 ++++++++++++++++++------- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/Dalamud/Plugin/PluginInstallerWindow.cs b/Dalamud/Plugin/PluginInstallerWindow.cs index ebeabc990..30fc5bd32 100644 --- a/Dalamud/Plugin/PluginInstallerWindow.cs +++ b/Dalamud/Plugin/PluginInstallerWindow.cs @@ -132,6 +132,9 @@ namespace Dalamud.Plugin } else if (this.dalamud.PluginRepository.State == PluginRepository.InitializationState.Fail) { ImGui.Text(Loc.Localize("InstallerDownloadFailed", "Download failed.")); } + else if (this.dalamud.PluginRepository.State == PluginRepository.InitializationState.FailThirdRepo) { + ImGui.Text(Loc.Localize("InstallerDownloadFailedThird", "One of your third party repos is unreachable or there is no internet connection.")); + } else { if (this.pluginListAvailable == null) { var hiddenPlugins = this.dalamud.PluginManager.Plugins.Where( diff --git a/Dalamud/Plugin/PluginRepository.cs b/Dalamud/Plugin/PluginRepository.cs index ef06fec30..1612ed8ea 100644 --- a/Dalamud/Plugin/PluginRepository.cs +++ b/Dalamud/Plugin/PluginRepository.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Globalization; using System.IO; using System.IO.Compression; using System.Linq; @@ -16,7 +17,6 @@ namespace Dalamud.Plugin private string PluginFunctionBaseUrl => "https://us-central1-xl-functions.cloudfunctions.net/download-plugin/?plugin={0}&isUpdate={1}&isTesting={2}"; private string PluginMasterUrl => "https://raw.githubusercontent.com/goatcorp/DalamudPlugins/master/pluginmaster.json"; - private readonly Dalamud dalamud; private string pluginDirectory; public ReadOnlyCollection PluginMaster; @@ -25,7 +25,8 @@ namespace Dalamud.Plugin Unknown, InProgress, Success, - Fail + Fail, + FailThirdRepo } public InitializationState State { get; private set; } @@ -43,20 +44,30 @@ namespace Dalamud.Plugin State = InitializationState.InProgress; + var allPlugins = new List(); + + var repos = this.dalamud.Configuration.ThirdRepoList.Where(x => x.IsEnabled).Select(x => x.Url) + .Prepend(PluginMasterUrl).ToArray(); + try { using var client = new WebClient(); - var data = client.DownloadString(PluginMasterUrl); + foreach (var repo in repos) { + Log.Information("[PLUGINR] Fetching repo: {0}", repo); + + var data = client.DownloadString(repo); - var unsortedPluginMaster = JsonConvert.DeserializeObject>(data); - unsortedPluginMaster.Sort((a, b) => a.Name.CompareTo(b.Name)); - this.PluginMaster = unsortedPluginMaster.AsReadOnly(); + var unsortedPluginMaster = JsonConvert.DeserializeObject>(data); + allPlugins.AddRange(unsortedPluginMaster); + } + this.PluginMaster = allPlugins.AsReadOnly(); State = InitializationState.Success; } catch (Exception ex) { Log.Error(ex, "Could not download PluginMaster"); - State = InitializationState.Fail; + + State = repos.Length > 1 ? InitializationState.FailThirdRepo : InitializationState.Fail; } }).ContinueWith(t => { if (t.IsFaulted)