diff --git a/RotationSolver.Basic/Configuration/PluginConfiguration.cs b/RotationSolver.Basic/Configuration/PluginConfiguration.cs index 27c0c6da2..75ddafc44 100644 --- a/RotationSolver.Basic/Configuration/PluginConfiguration.cs +++ b/RotationSolver.Basic/Configuration/PluginConfiguration.cs @@ -159,10 +159,9 @@ public class PluginConfiguration : IPluginConfiguration public bool InDebug = false; public bool AutoUpdateLibs = true; - public string[] OtherLibs = new string[0]; - public (string, string)[] OtherLibsUrl = new(string, string)[] + public string[] OtherLibs = new string[] { - ("ArchiDog1998", "RotationSolver"), + "https://github.com/ArchiDog1998/RotationSolver/releases/latest/download/latest.zip", }; public List TargetingTypes { get; set; } = new List(); diff --git a/RotationSolver/RotationSolverPlugin.cs b/RotationSolver/RotationSolverPlugin.cs index 727095a89..ae4c67cfe 100644 --- a/RotationSolver/RotationSolverPlugin.cs +++ b/RotationSolver/RotationSolverPlugin.cs @@ -2,6 +2,7 @@ using Dalamud.Game.Text.SeStringHandling; using Dalamud.Game.Text.SeStringHandling.Payloads; using Dalamud.Interface.Windowing; +using Dalamud.Logging; using Dalamud.Plugin; using FFXIVClientStructs.Havok; using RotationSolver.Basic.Configuration; @@ -70,24 +71,12 @@ public unsafe RotationSolverPlugin(DalamudPluginInterface pluginInterface) ChangeUITranslation(); RotationUpdater.GetAllCustomRotations(); + RotationHelper.LoadList(); LinkPayload = pluginInterface.AddChatLinkHandler(0, (id, str) => { if(id == 0) OpenConfigWindow(); }); - - using (var client = new HttpClient()) - { - try - { - var bts = client.GetByteArrayAsync("https://raw.githubusercontent.com/ArchiDog1998/RotationSolver/main/Recources/whiteList.json"); - RotationHelper.AllowedAssembly = JsonConvert.DeserializeObject(Encoding.Default.GetString(bts.Result)); - - client.GetByteArrayAsync("https://raw.githubusercontent.com/ArchiDog1998/RotationSolver/main/Recources/defaultList.json"); - RotationHelper.DefaultAssembly = JsonConvert.DeserializeObject(Encoding.Default.GetString(bts.Result)); - } - catch { } - } } diff --git a/RotationSolver/UI/RotationConfigWindow_Major.cs b/RotationSolver/UI/RotationConfigWindow_Major.cs index bcb5defa3..29f030ee1 100644 --- a/RotationSolver/UI/RotationConfigWindow_Major.cs +++ b/RotationSolver/UI/RotationConfigWindow_Major.cs @@ -1,6 +1,7 @@ using Dalamud.Interface.Windowing; using ImGuiNET; using RotationSolver.Localization; +using RotationSolver.Updaters; using System.Collections; using System.Text; @@ -63,6 +64,17 @@ public override unsafe void Draw() if (Service.Config.InDebug && ImGui.BeginTabItem("Debug")) { + ImGui.Text(RotationUpdater.message); + + foreach (var item in RotationHelper.DefaultAssembly) + { + ImGui.Text(item); + } + foreach (var item in RotationHelper.AllowedAssembly) + { + ImGui.Text(item); + } + DrawDebugTab(); ImGui.EndTabItem(); } diff --git a/RotationSolver/Updaters/RotationUpdater.cs b/RotationSolver/Updaters/RotationUpdater.cs index 0b6bd2be7..e744bd82a 100644 --- a/RotationSolver/Updaters/RotationUpdater.cs +++ b/RotationSolver/Updaters/RotationUpdater.cs @@ -1,5 +1,7 @@ using Dalamud.Logging; using RotationSolver.Localization; +using System; +using System.Text; namespace RotationSolver.Updaters; @@ -12,21 +14,55 @@ public record CustomRotationGroup(ClassJobID jobId, ClassJobID[] classJobIds, IC internal static SortedList AuthorHashes { get; private set; } = new SortedList(); static CustomRotationGroup[] _customRotations { get; set; } = new CustomRotationGroup[0]; - static readonly string[] _locs = new string[] { "RotationSolver.dll", "RotationSolver.Basic.dll" }; + public static string message = string.Empty; - - public static void GetAllCustomRotations() + public static async void GetAllCustomRotations() { - var directories = Service.Config.OtherLibs - .Select(s => s.Trim()).Append(Path.GetDirectoryName(Assembly.GetAssembly(typeof(ICustomRotation)).Location)); + var relayFolder = Service.Interface.ConfigDirectory.FullName; + if (!Directory.Exists(relayFolder)) Directory.CreateDirectory(relayFolder); + + using (var client = new HttpClient()) + { + foreach (var url in Service.Config.OtherLibs) + { + var valid = Uri.TryCreate(url, UriKind.RelativeOrAbsolute, out var uriResult) + && (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps); + if (!valid) continue; + + try + { + var fileName = url.Split('/').LastOrDefault(); + if (string.IsNullOrEmpty(fileName)) continue; + if (Path.GetExtension(fileName) != ".dll") continue; + var filePath = Path.Combine(relayFolder, fileName); + + //Download + using (HttpResponseMessage response = await client.GetAsync(url)) + { + await response.Content.CopyToAsync(new FileStream(filePath, File.Exists(filePath) + ? FileMode.Open : FileMode.CreateNew)); + } + + PluginLog.Log($"Successfully download the {filePath}"); + } + catch (Exception ex) + { + PluginLog.LogError(ex, $"failed to download from {url}"); + } + } + } + + var directories = Service.Config.OtherLibs + .Where(Directory.Exists) + .Append(Path.GetDirectoryName(Assembly.GetAssembly(typeof(ICustomRotation)).Location)) + .Append(relayFolder); var assemblies = from dir in directories where Directory.Exists(dir) from l in Directory.GetFiles(dir, "*.dll") - where !_locs.Any(l.Contains) select RotationLoadContext.LoadFrom(l); - PluginLog.Log("Try to load rotations from these assemblies.", assemblies.Select(a => a.FullName)); + PluginLog.Log("Try to load rotations from these assemblies.\n" + string.Join('\n', assemblies.Select(a => "- " + a.FullName))); AuthorHashes = new SortedList( (from a in assemblies