feat: plugin testing stuff

This commit is contained in:
goat 2020-06-08 14:46:56 +02:00
parent cf08eaee87
commit a9fa629e0b
4 changed files with 32 additions and 31 deletions

View file

@ -75,8 +75,10 @@ namespace Dalamud.Injector {
Thread.Sleep(1000);
#if !DEBUG
// Inject exception handler
NativeInject(process);
#endif
}
private static void Inject(Process process, DalamudStartInfo info) {

View file

@ -143,7 +143,7 @@ namespace Dalamud {
this.PluginManager = new PluginManager(this, this.StartInfo.PluginDirectory, this.StartInfo.DefaultPluginDirectory);
this.PluginManager.LoadPlugins();
this.PluginRepository = new PluginRepository(PluginManager, this.StartInfo.PluginDirectory, this.StartInfo.GameVersion);
this.PluginRepository = new PluginRepository(this, this.StartInfo.PluginDirectory, this.StartInfo.GameVersion);
}
catch (Exception ex)
{
@ -296,7 +296,7 @@ namespace Dalamud {
{
if (ImGui.MenuItem("Open Plugin installer"))
{
this.pluginWindow = new PluginInstallerWindow(this.PluginManager, this.PluginRepository, this.StartInfo.GameVersion);
this.pluginWindow = new PluginInstallerWindow(this, this.StartInfo.GameVersion);
this.isImguiDrawPluginWindow = true;
}
if (ImGui.MenuItem("Open Plugin Stats")) {
@ -725,7 +725,7 @@ namespace Dalamud {
}
private void OnOpenInstallerCommand(string command, string arguments) {
this.pluginWindow = new PluginInstallerWindow(this.PluginManager, PluginRepository, this.StartInfo.GameVersion);
this.pluginWindow = new PluginInstallerWindow(this, this.StartInfo.GameVersion);
this.isImguiDrawPluginWindow = true;
}

View file

@ -19,10 +19,7 @@ using Serilog;
namespace Dalamud.Plugin
{
internal class PluginInstallerWindow {
private const string PluginRepoBaseUrl = "https://goaaats.github.io/DalamudPlugins/";
private PluginManager manager;
private PluginRepository repository;
private readonly Dalamud dalamud;
private string gameVersion;
private bool errorModalDrawing = true;
@ -41,10 +38,11 @@ namespace Dalamud.Plugin
private PluginInstallStatus installStatus = PluginInstallStatus.None;
public PluginInstallerWindow(PluginManager manager, PluginRepository repository, string gameVersion) {
this.manager = manager;
this.repository = repository;
public PluginInstallerWindow(Dalamud dalamud, string gameVersion) {
this.dalamud = dalamud;
this.gameVersion = gameVersion;
this.dalamud.PluginRepository.ReloadPluginMaster();
}
public bool Draw() {
@ -52,7 +50,7 @@ namespace Dalamud.Plugin
ImGui.SetNextWindowSize(new Vector2(750, 520));
ImGui.Begin(Loc.Localize("InstallerHeader", "Plugin Installer"), ref windowOpen,
ImGui.Begin(Loc.Localize("InstallerHeader", "Plugin Installer") + (this.dalamud.Configuration.DoPluginTest ? " (TESTING)" : string.Empty) + "###XlPluginInstaller", ref windowOpen,
ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoScrollbar);
ImGui.Text(Loc.Localize("InstallerHint", "This window allows you install and remove in-game plugins.\nThey are made by third-party developers."));
@ -62,14 +60,14 @@ namespace Dalamud.Plugin
ImGui.PushStyleVar(ImGuiStyleVar.ItemSpacing, new Vector2(1, 3));
if (this.repository.State == PluginRepository.InitializationState.InProgress) {
if (this.dalamud.PluginRepository.State == PluginRepository.InitializationState.InProgress) {
ImGui.Text(Loc.Localize("InstallerLoading", "Loading plugins..."));
} else if (this.repository.State == PluginRepository.InitializationState.Fail) {
} else if (this.dalamud.PluginRepository.State == PluginRepository.InitializationState.Fail) {
ImGui.Text(Loc.Localize("InstallerDownloadFailed", "Download failed."));
}
else
{
foreach (var pluginDefinition in this.repository.PluginMaster) {
foreach (var pluginDefinition in this.dalamud.PluginRepository.PluginMaster) {
if (pluginDefinition.ApplicableVersion != this.gameVersion &&
pluginDefinition.ApplicableVersion != "any")
continue;
@ -79,7 +77,7 @@ namespace Dalamud.Plugin
ImGui.PushID(pluginDefinition.InternalName + pluginDefinition.AssemblyVersion);
var isInstalled = this.manager.Plugins.Where(x => x.Definition != null).Any(
var isInstalled = this.dalamud.PluginManager.Plugins.Where(x => x.Definition != null).Any(
x => x.Definition.InternalName == pluginDefinition.InternalName);
var label = isInstalled ? Loc.Localize("InstallerInstalled", " (installed)") : string.Empty;
@ -109,7 +107,7 @@ namespace Dalamud.Plugin
if (ImGui.Button($"Install v{pluginDefinition.AssemblyVersion}")) {
this.installStatus = PluginInstallStatus.InProgress;
Task.Run(() => this.repository.InstallPlugin(pluginDefinition)).ContinueWith(t => {
Task.Run(() => this.dalamud.PluginRepository.InstallPlugin(pluginDefinition)).ContinueWith(t => {
this.installStatus =
t.Result ? PluginInstallStatus.Success : PluginInstallStatus.Fail;
this.installStatus =
@ -121,13 +119,13 @@ namespace Dalamud.Plugin
}
}
} else {
var installedPlugin = this.manager.Plugins.Where(x => x.Definition != null).First(
var installedPlugin = this.dalamud.PluginManager.Plugins.Where(x => x.Definition != null).First(
x => x.Definition.InternalName ==
pluginDefinition.InternalName);
if (ImGui.Button(Loc.Localize("InstallerDisable", "Disable")))
try {
this.manager.DisablePlugin(installedPlugin.Definition);
this.dalamud.PluginManager.DisablePlugin(installedPlugin.Definition);
} catch (Exception exception) {
Log.Error(exception, "Could not disable plugin.");
this.errorModalDrawing = true;
@ -180,7 +178,7 @@ namespace Dalamud.Plugin
{
this.installStatus = PluginInstallStatus.InProgress;
Task.Run(() => this.repository.UpdatePlugins()).ContinueWith(t => {
Task.Run(() => this.dalamud.PluginRepository.UpdatePlugins()).ContinueWith(t => {
this.installStatus =
t.Result.Success ? PluginInstallStatus.Success : PluginInstallStatus.Fail;
this.installStatus =

View file

@ -14,9 +14,9 @@ namespace Dalamud.Plugin
{
internal class PluginRepository
{
private const string PluginRepoBaseUrl = "https://goatcorp.github.io/DalamudPlugins/";
private const string PluginRepoBaseUrl = "https://raw.githubusercontent.com/goatcorp/DalamudPlugins/";
private PluginManager manager;
private readonly Dalamud dalamud;
private string pluginDirectory;
public ReadOnlyCollection<PluginDefinition> PluginMaster;
@ -29,31 +29,32 @@ namespace Dalamud.Plugin
public InitializationState State { get; private set; }
public PluginRepository(PluginManager manager, string pluginDirectory, string gameVersion)
public PluginRepository(Dalamud dalamud, string pluginDirectory, string gameVersion)
{
this.manager = manager;
this.dalamud = dalamud;
this.pluginDirectory = pluginDirectory;
State = InitializationState.InProgress;
Task.Run(CachePluginMaster).ContinueWith(t => {
Task.Run(ReloadPluginMaster).ContinueWith(t => {
if (t.IsFaulted)
State = InitializationState.Fail;
});
}
private void CachePluginMaster()
public void ReloadPluginMaster()
{
try
{
using var client = new WebClient();
var data = client.DownloadString(PluginRepoBaseUrl + "pluginmaster.json");
var data = client.DownloadString(PluginRepoBaseUrl + (this.dalamud.Configuration.DoPluginTest ? "testing/" : "master/") + "pluginmaster.json");
this.PluginMaster = JsonConvert.DeserializeObject<ReadOnlyCollection<PluginDefinition>>(data);
State = InitializationState.Success;
}
catch {
catch(Exception ex) {
Log.Error(ex, "Could not download PluginMaster");
State = InitializationState.Fail;
}
}
@ -71,7 +72,7 @@ namespace Dalamud.Plugin
if (disabledFile.Exists)
disabledFile.Delete();
return this.manager.LoadPluginFromAssembly(dllFile, false);
return this.dalamud.PluginManager.LoadPluginFromAssembly(dllFile, false);
}
if (dllFile.Exists && !enableAfterInstall) {
@ -100,7 +101,7 @@ namespace Dalamud.Plugin
return true;
}
return this.manager.LoadPluginFromAssembly(dllFile, false);
return this.dalamud.PluginManager.LoadPluginFromAssembly(dllFile, false);
}
catch (Exception e)
{
@ -165,7 +166,7 @@ namespace Dalamud.Plugin
if (!dryRun)
{
var wasEnabled =
this.manager.Plugins.Where(x => x.Definition != null).Any(
this.dalamud.PluginManager.Plugins.Where(x => x.Definition != null).Any(
x => x.Definition.InternalName == info.InternalName); ;
Log.Verbose("wasEnabled: {0}", wasEnabled);
@ -173,7 +174,7 @@ namespace Dalamud.Plugin
// Try to disable plugin if it is loaded
try
{
this.manager.DisablePlugin(info);
this.dalamud.PluginManager.DisablePlugin(info);
}
catch (Exception ex)
{