mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-13 20:24:16 +01:00
feat: plugin updates, more installer stuff
This commit is contained in:
parent
bef5a35fd9
commit
3640d30cc7
5 changed files with 100 additions and 21 deletions
|
|
@ -329,6 +329,11 @@ namespace Dalamud {
|
||||||
HelpMessage = "Draw dev menu DEBUG",
|
HelpMessage = "Draw dev menu DEBUG",
|
||||||
ShowInHelp = false
|
ShowInHelp = false
|
||||||
});
|
});
|
||||||
|
|
||||||
|
CommandManager.AddHandler("/xlplugins", new CommandInfo(OnOpenInstallerCommand)
|
||||||
|
{
|
||||||
|
HelpMessage = "Open the plugin installer"
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnUnloadCommand(string command, string arguments) {
|
private void OnUnloadCommand(string command, string arguments) {
|
||||||
|
|
@ -550,6 +555,11 @@ namespace Dalamud {
|
||||||
this.isImguiDrawDevMenu = true;
|
this.isImguiDrawDevMenu = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnOpenInstallerCommand(string command, string arguments) {
|
||||||
|
this.pluginWindow = new PluginInstallerWindow(this.PluginManager, this.StartInfo.PluginDirectory, this.StartInfo.GameVersion);
|
||||||
|
this.isImguiDrawPluginWindow = true;
|
||||||
|
}
|
||||||
|
|
||||||
private int RouletteSlugToKey(string slug) => slug.ToLower() switch {
|
private int RouletteSlugToKey(string slug) => slug.ToLower() switch {
|
||||||
"leveling" => 1,
|
"leveling" => 1,
|
||||||
"506070" => 2,
|
"506070" => 2,
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@
|
||||||
<EmbeddedResource Include="Resources\eye.png" />
|
<EmbeddedResource Include="Resources\eye.png" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Lumina" Version="1.0.0" />
|
<PackageReference Include="Lumina" Version="1.1.1" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
|
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
|
||||||
<PackageReference Include="PropertyChanged.Fody" Version="2.6.1" />
|
<PackageReference Include="PropertyChanged.Fody" Version="2.6.1" />
|
||||||
<PackageReference Include="Serilog" Version="2.6.0" />
|
<PackageReference Include="Serilog" Version="2.6.0" />
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ namespace Dalamud.Plugin
|
||||||
public string InternalName { get; set; }
|
public string InternalName { get; set; }
|
||||||
public string AssemblyVersion { get; set; }
|
public string AssemblyVersion { get; set; }
|
||||||
public string Description { get; set; }
|
public string Description { get; set; }
|
||||||
public string ApplicableGameVersion { get; set; }
|
public string ApplicableVersion { get; set; }
|
||||||
|
public bool IsHide { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.IO.Compression;
|
using System.IO.Compression;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
@ -60,6 +61,53 @@ namespace Dalamud.Plugin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void UpdatePlugins() {
|
||||||
|
try {
|
||||||
|
var pluginsDirectory = new DirectoryInfo(this.pluginDirectory);
|
||||||
|
this.installStatus = PluginInstallStatus.Success;
|
||||||
|
foreach (var installed in pluginsDirectory.GetDirectories()) {
|
||||||
|
var versions = installed.GetDirectories();
|
||||||
|
|
||||||
|
if (versions.Length == 0) {
|
||||||
|
Log.Information("Has no versions: {0}", installed.FullName);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
var sortedVersions = versions.OrderBy(x => x.CreationTime);
|
||||||
|
var latest = sortedVersions.Last();
|
||||||
|
|
||||||
|
var localInfoFile = new FileInfo(Path.Combine(latest.FullName, $"{installed.Name}.json"));
|
||||||
|
|
||||||
|
if (!localInfoFile.Exists)
|
||||||
|
{
|
||||||
|
Log.Information("Has no definition: {0}", localInfoFile.FullName);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
var info = JsonConvert.DeserializeObject<PluginDefinition>(File.ReadAllText(localInfoFile.FullName));
|
||||||
|
|
||||||
|
var remoteInfo = this.pluginMaster.FirstOrDefault(x => x.Name == info.Name);
|
||||||
|
|
||||||
|
if (remoteInfo == null)
|
||||||
|
{
|
||||||
|
Log.Information("Is not in pluginmaster: {0}", info.Name);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (remoteInfo.AssemblyVersion != info.AssemblyVersion)
|
||||||
|
{
|
||||||
|
this.manager.DisablePlugin(info);
|
||||||
|
InstallPlugin(remoteInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Log.Error(e, "Plugin update failed hard.");
|
||||||
|
this.installStatus = PluginInstallStatus.Fail;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void InstallPlugin(PluginDefinition definition) {
|
private void InstallPlugin(PluginDefinition definition) {
|
||||||
try {
|
try {
|
||||||
var outputDir = new DirectoryInfo(Path.Combine(this.pluginDirectory, definition.InternalName, definition.AssemblyVersion));
|
var outputDir = new DirectoryInfo(Path.Combine(this.pluginDirectory, definition.InternalName, definition.AssemblyVersion));
|
||||||
|
|
@ -70,8 +118,7 @@ namespace Dalamud.Plugin
|
||||||
if (disabledFile.Exists)
|
if (disabledFile.Exists)
|
||||||
disabledFile.Delete();
|
disabledFile.Delete();
|
||||||
|
|
||||||
this.manager.LoadPluginFromAssembly(dllFile, false);
|
this.installStatus = this.manager.LoadPluginFromAssembly(dllFile, false) ? PluginInstallStatus.Success : PluginInstallStatus.Fail;
|
||||||
this.installStatus = PluginInstallStatus.Success;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -88,8 +135,7 @@ namespace Dalamud.Plugin
|
||||||
|
|
||||||
ZipFile.ExtractToDirectory(path, outputDir.FullName);
|
ZipFile.ExtractToDirectory(path, outputDir.FullName);
|
||||||
|
|
||||||
this.installStatus = PluginInstallStatus.Success;
|
this.installStatus = this.manager.LoadPluginFromAssembly(dllFile, false) ? PluginInstallStatus.Success : PluginInstallStatus.Fail;
|
||||||
this.manager.LoadPluginFromAssembly(dllFile, false);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.Error(e, "Plugin download failed hard.");
|
Log.Error(e, "Plugin download failed hard.");
|
||||||
this.installStatus = PluginInstallStatus.Fail;
|
this.installStatus = PluginInstallStatus.Fail;
|
||||||
|
|
@ -120,8 +166,11 @@ namespace Dalamud.Plugin
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
foreach (var pluginDefinition in this.pluginMaster) {
|
foreach (var pluginDefinition in this.pluginMaster) {
|
||||||
if (pluginDefinition.ApplicableGameVersion != this.gameVersion &&
|
if (pluginDefinition.ApplicableVersion != this.gameVersion &&
|
||||||
pluginDefinition.ApplicableGameVersion != "any")
|
pluginDefinition.ApplicableVersion != "any")
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (pluginDefinition.IsHide)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (ImGui.CollapsingHeader(pluginDefinition.Name)) {
|
if (ImGui.CollapsingHeader(pluginDefinition.Name)) {
|
||||||
|
|
@ -170,6 +219,9 @@ namespace Dalamud.Plugin
|
||||||
|
|
||||||
if (ImGui.Button("Open Configuration")) v2Plugin.OpenConfigUi?.Invoke(null, null);
|
if (ImGui.Button("Open Configuration")) v2Plugin.OpenConfigUi?.Invoke(null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ImGui.SameLine();
|
||||||
|
ImGui.TextColored(new Vector4(0.5f, 0.5f, 0.5f, 1.0f), $" v{pluginDefinition.AssemblyVersion}");
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui.Unindent();
|
ImGui.Unindent();
|
||||||
|
|
@ -183,17 +235,22 @@ namespace Dalamud.Plugin
|
||||||
|
|
||||||
ImGui.Separator();
|
ImGui.Separator();
|
||||||
|
|
||||||
if (ImGui.Button("Remove All"))
|
if (this.installStatus == PluginInstallStatus.InProgress) {
|
||||||
{
|
ImGui.Button("In progress...");
|
||||||
|
} else {
|
||||||
}
|
if (ImGui.Button("Update plugins"))
|
||||||
|
{
|
||||||
ImGui.SameLine();
|
this.installStatus = PluginInstallStatus.InProgress;
|
||||||
|
|
||||||
if (ImGui.Button("Open Plugin folder"))
|
|
||||||
{
|
|
||||||
|
|
||||||
|
Task.Run(() => UpdatePlugins()).ContinueWith(t => {
|
||||||
|
this.installStatus =
|
||||||
|
t.IsFaulted ? PluginInstallStatus.Fail : this.installStatus;
|
||||||
|
this.errorModalDrawing = this.installStatus == PluginInstallStatus.Fail;
|
||||||
|
this.errorModalOnNextFrame = this.installStatus == PluginInstallStatus.Fail;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ImGui.SameLine();
|
ImGui.SameLine();
|
||||||
|
|
||||||
|
|
@ -206,7 +263,7 @@ namespace Dalamud.Plugin
|
||||||
|
|
||||||
if (ImGui.BeginPopupModal("Installer failed", ref this.errorModalDrawing, ImGuiWindowFlags.AlwaysAutoResize))
|
if (ImGui.BeginPopupModal("Installer failed", ref this.errorModalDrawing, ImGuiWindowFlags.AlwaysAutoResize))
|
||||||
{
|
{
|
||||||
ImGui.Text("The plugin installer ran into an issue.");
|
ImGui.Text("The plugin installer ran into an issue or the plugin is incompatible.");
|
||||||
ImGui.Text("Please restart the game and report this error on our discord.");
|
ImGui.Text("Please restart the game and report this error on our discord.");
|
||||||
|
|
||||||
ImGui.Spacing();
|
ImGui.Spacing();
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ namespace Dalamud.Plugin
|
||||||
this.Plugins.Remove(thisPlugin);
|
this.Plugins.Remove(thisPlugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void LoadPluginFromAssembly(FileInfo dllFile, bool raw) {
|
public bool LoadPluginFromAssembly(FileInfo dllFile, bool raw) {
|
||||||
Log.Information("Loading assembly at {0}", dllFile);
|
Log.Information("Loading assembly at {0}", dllFile);
|
||||||
var assemblyName = AssemblyName.GetAssemblyName(dllFile.FullName);
|
var assemblyName = AssemblyName.GetAssemblyName(dllFile.FullName);
|
||||||
var pluginAssembly = Assembly.Load(assemblyName);
|
var pluginAssembly = Assembly.Load(assemblyName);
|
||||||
|
|
@ -90,7 +90,7 @@ namespace Dalamud.Plugin
|
||||||
|
|
||||||
if (disabledFile.Exists && !raw) {
|
if (disabledFile.Exists && !raw) {
|
||||||
Log.Information("Plugin {0} is disabled.", dllFile.FullName);
|
Log.Information("Plugin {0} is disabled.", dllFile.FullName);
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var defJsonFile = new FileInfo(Path.Combine(dllFile.Directory.FullName, $"{Path.GetFileNameWithoutExtension(dllFile.Name)}.json"));
|
var defJsonFile = new FileInfo(Path.Combine(dllFile.Directory.FullName, $"{Path.GetFileNameWithoutExtension(dllFile.Name)}.json"));
|
||||||
|
|
@ -103,11 +103,16 @@ namespace Dalamud.Plugin
|
||||||
pluginDef =
|
pluginDef =
|
||||||
JsonConvert.DeserializeObject<PluginDefinition>(
|
JsonConvert.DeserializeObject<PluginDefinition>(
|
||||||
File.ReadAllText(defJsonFile.FullName));
|
File.ReadAllText(defJsonFile.FullName));
|
||||||
|
|
||||||
|
if (pluginDef.ApplicableVersion != this.dalamud.StartInfo.GameVersion && pluginDef.ApplicableVersion != "any") {
|
||||||
|
Log.Information("Plugin {0} has not applicable version.", dllFile.FullName);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Log.Information("Plugin DLL {0} has no definition.", dllFile.FullName);
|
Log.Information("Plugin DLL {0} has no definition.", dllFile.FullName);
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var plugin = (IDalamudPlugin)Activator.CreateInstance(type);
|
var plugin = (IDalamudPlugin)Activator.CreateInstance(type);
|
||||||
|
|
@ -116,9 +121,15 @@ namespace Dalamud.Plugin
|
||||||
plugin.Initialize(dalamudInterface);
|
plugin.Initialize(dalamudInterface);
|
||||||
Log.Information("Loaded plugin: {0}", plugin.Name);
|
Log.Information("Loaded plugin: {0}", plugin.Name);
|
||||||
this.Plugins.Add((plugin, pluginDef, dalamudInterface));
|
this.Plugins.Add((plugin, pluginDef, dalamudInterface));
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Log.Information("Plugin DLL {0} has no plugin interface.", dllFile.FullName);
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadPluginsAt(DirectoryInfo folder, bool raw) {
|
private void LoadPluginsAt(DirectoryInfo folder, bool raw) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue