public bool InstallPlugin(PluginDefinition definition, bool enableAfterInstall = true) { try { var outputDir = new DirectoryInfo(Path.Combine(this.pluginDirectory, definition.InternalName, definition.AssemblyVersion)); var dllFile = new FileInfo(Path.Combine(outputDir.FullName, $"{definition.InternalName}.dll")); var disabledFile = new FileInfo(Path.Combine(outputDir.FullName, ".disabled")); var wasDisabled = disabledFile.Exists; if (dllFile.Exists && enableAfterInstall) { if (disabledFile.Exists) { disabledFile.Delete(); } return(this.manager.LoadPluginFromAssembly(dllFile, false)); } if (dllFile.Exists && !enableAfterInstall) { return(true); } try { if (outputDir.Exists) { outputDir.Delete(true); } outputDir.Create(); } catch { // ignored, since the plugin may be loaded already } var path = Path.GetTempFileName(); Log.Information("Downloading plugin to {0}", path); using var client = new WebClient(); client.DownloadFile(PluginRepoBaseUrl + $"/plugins/{definition.InternalName}/latest.zip", path); Log.Information("Extracting to {0}", outputDir); ZipFile.ExtractToDirectory(path, outputDir.FullName); if (wasDisabled || !enableAfterInstall) { disabledFile.Create(); return(true); } return(this.manager.LoadPluginFromAssembly(dllFile, false)); } catch (Exception e) { Log.Error(e, "Plugin download failed hard."); return(false); } }
private void InstallPlugin(PluginDefinition definition) { try { var outputDir = new DirectoryInfo(Path.Combine(this.pluginDirectory, definition.InternalName, definition.AssemblyVersion)); var dllFile = new FileInfo(Path.Combine(outputDir.FullName, $"{definition.InternalName}.dll")); var disabledFile = new FileInfo(Path.Combine(outputDir.FullName, ".disabled")); if (dllFile.Exists) { if (disabledFile.Exists) { disabledFile.Delete(); } this.installStatus = this.manager.LoadPluginFromAssembly(dllFile, false) ? PluginInstallStatus.Success : PluginInstallStatus.Fail; return; } if (outputDir.Exists) { outputDir.Delete(true); } outputDir.Create(); var path = Path.GetTempFileName(); Log.Information("Downloading plugin to {0}", path); using var client = new WebClient(); client.DownloadFile(PluginRepoBaseUrl + $"/plugins/{definition.InternalName}/latest.zip", path); Log.Information("Extracting to {0}", outputDir); ZipFile.ExtractToDirectory(path, outputDir.FullName); this.installStatus = this.manager.LoadPluginFromAssembly(dllFile, false) ? PluginInstallStatus.Success : PluginInstallStatus.Fail; } catch (Exception e) { Log.Error(e, "Plugin download failed hard."); this.installStatus = PluginInstallStatus.Fail; } }
public bool InstallPlugin(PluginDefinition definition, bool enableAfterInstall = true, bool isUpdate = false, bool fromTesting = false) { try { using var client = new WebClient(); var outputDir = new DirectoryInfo(Path.Combine(this.pluginDirectory, definition.InternalName, fromTesting ? definition.TestingAssemblyVersion : definition.AssemblyVersion)); var dllFile = new FileInfo(Path.Combine(outputDir.FullName, $"{definition.InternalName}.dll")); var disabledFile = new FileInfo(Path.Combine(outputDir.FullName, ".disabled")); var testingFile = new FileInfo(Path.Combine(outputDir.FullName, ".testing")); var wasDisabled = disabledFile.Exists; if (dllFile.Exists && enableAfterInstall) { if (disabledFile.Exists) { disabledFile.Delete(); } return(this.dalamud.PluginManager.LoadPluginFromAssembly(dllFile, false, PluginLoadReason.Installer)); } if (dllFile.Exists && !enableAfterInstall) { return(true); } try { if (outputDir.Exists) { outputDir.Delete(true); } outputDir.Create(); } catch { // ignored, since the plugin may be loaded already } var path = Path.GetTempFileName(); var doTestingDownload = false; if ((Version.TryParse(definition.TestingAssemblyVersion, out var testingAssemblyVer) || definition.IsTestingExclusive) && fromTesting) { doTestingDownload = testingAssemblyVer > Version.Parse(definition.AssemblyVersion) || definition.IsTestingExclusive; } var url = definition.DownloadLinkInstall; if (doTestingDownload) { url = definition.DownloadLinkTesting; } else if (isUpdate) { url = definition.DownloadLinkUpdate; } Log.Information("Downloading plugin to {0} from {1} doTestingDownload:{2} isTestingExclusive:{3}", path, url, doTestingDownload, definition.IsTestingExclusive); client.DownloadFile(url, path); Log.Information("Extracting to {0}", outputDir); ZipFile.ExtractToDirectory(path, outputDir.FullName); if (wasDisabled || !enableAfterInstall) { disabledFile.Create().Close(); return(true); } if (doTestingDownload) { testingFile.Create().Close(); } else { if (testingFile.Exists) { testingFile.Delete(); } } return(this.dalamud.PluginManager.LoadPluginFromAssembly(dllFile, false, PluginLoadReason.Installer)); } catch (Exception e) { Log.Error(e, "Plugin download failed hard."); return(false); } }