public async Task <FileInfo> DownloadPluginAsync(InstalledPlugin plugin, string targetPath) { if (!IsAPIAvailable()) { ErrorLogger.Append(new WebException("api.Fork.gg is not online or operational")); return(null); } try { string pluginUrl = WebUtility.UrlEncode(plugin.Plugin.file.url); WebClient webClient = new WebClient(); webClient.Headers.Add("user-agent", ApplicationManager.UserAgent); await webClient.DownloadFileTaskAsync(new Uri(apiBaseURL + "plugins/download?url=" + pluginUrl), targetPath); FileInfo pluginFile = new FileInfo(targetPath); if (pluginFile.Exists) { return(pluginFile); } } catch (Exception e) { ErrorLogger.Append(e); } return(null); }
public PluginInstalledEvent ( InstalledPlugin plugin ) : base(plugin) { }
private bool DeletePlugin(InstalledPlugin plugin, PluginViewModel viewModel) { try { string folder = plugin.IsEnabled ? "plugins" : "plugins_disabled"; FileInfo jarFile = new FileInfo(Path.Combine(App.ServerPath, viewModel.EntityViewModel.Name, folder, StringUtils.PluginNameToJarName(plugin.Name) + ".jar")); if (!jarFile.Exists) { ErrorLogger.Append(new ArgumentException( ".jar for plugin " + plugin.Name + " was not found. Removing it from the list...")); } else { jarFile.Delete(); } Application.Current.Dispatcher?.Invoke(() => viewModel.InstalledPlugins.Remove(plugin)); //Check if plugin is in loaded list currently (in that case change it to downlaodable) viewModel.CheckForDeletedPlugin(plugin.Plugin); Console.WriteLine("Deleted Plugin " + plugin.Name); return(true); } catch (Exception e) { ErrorLogger.Append(e); Console.WriteLine("Error while deleting Plugin " + plugin.Name); return(false); } }
private async Task <bool> DownloadPlugin(InstalledPlugin plugin, EntityViewModel viewModel) { if (plugin.IsDownloaded) { return(true); } if (!plugin.IsSpigetPlugin || plugin.Plugin.file.type.Equals("external")) { return(false); } APIController apiController = new APIController(); try { var result = await apiController.DownloadPluginAsync(plugin, Path.Combine(App.ServerPath, viewModel.Entity.Name, "plugins", StringUtils.PluginNameToJarName(plugin.Name) + ".jar")); if (result == null) { return(false); } } catch (Exception e) { ErrorLogger.Append(e); return(false); } plugin.IsDownloaded = true; return(true); }
private bool InstallPlugin(Plugin plugin, PluginViewModel pluginViewModel) { foreach (InstalledPlugin iPlugin in pluginViewModel.InstalledPlugins) { if (iPlugin.Plugin == null) { continue; } if (iPlugin.Plugin.id == plugin.id) { Console.WriteLine("Error installing plugin: Plugin " + plugin.name + " is already installed."); return(false); } } PluginWebRequester webRequester = new PluginWebRequester(); InstalledPlugin installedPlugin = new InstalledPlugin { Name = StringUtils.BeautifyPluginName(plugin.name), IsSpigetPlugin = true, SpigetId = plugin.id, InstalledVersion = webRequester.RequestLatestVersion(plugin.id) }; Application.Current.Dispatcher?.Invoke(() => pluginViewModel.InstalledPlugins.Add(installedPlugin)); installedPlugin.AfterInit(new StreamingContext()); //TODO attach something to update event Console.WriteLine("Installed Plugin " + installedPlugin.Name); return(DownloadPlugin(installedPlugin, pluginViewModel.EntityViewModel).Result); }
private async Task <bool> DownloadPlugin(InstalledPlugin plugin, EntityViewModel viewModel) { if (plugin.IsDownloaded) { return(true); } if (!plugin.IsSpigetPlugin || plugin.Plugin.file.type.Equals("external")) { return(false); } APIController apiController = new APIController(); var result = await apiController.DownloadPluginAsync(plugin, Path.Combine(App.ServerPath, viewModel.Entity.Name, "plugins", StringUtils.PluginNameToJarName(plugin.Name) + ".jar")); /*HttpClient httpClient = new HttpClient(new HttpClientHandler{AllowAutoRedirect = true}); * Uri uri = new Uri(new PluginWebRequester().BuildDownloadURL(plugin)); * HttpResponseMessage response = await httpClient.GetAsync(uri); * await using (var fileStream = new FileStream(Path.Combine(App.ServerPath, viewModel.Entity.Name, "plugins", StringUtils.PluginNameToJarName(plugin.Name)+ ".jar"), FileMode.Create)) * { * await response.Content.CopyToAsync(fileStream); * }*/ plugin.IsDownloaded = true; return(true); }
public async Task <bool> EnablePluginAsync(InstalledPlugin plugin, PluginViewModel pluginViewModel) { Task <bool> t = new Task <bool>(() => EnablePlugin(plugin, pluginViewModel)); t.Start(); bool r = await t; return(r); }
public string BuildDownloadURL(InstalledPlugin plugin) { if (plugin.Plugin.file.type.Equals("external")) { throw new ArgumentException("Download links for external plugins can not be built"); } string url = baseURL + "resources/" + plugin.SpigetId + "/download"; return(url); }
private bool EnablePlugin(InstalledPlugin plugin, PluginViewModel viewModel) { try { if (plugin.IsEnabled) { return(true); } FileInfo jarFile = new FileInfo(Path.Combine(App.ServerPath, viewModel.EntityViewModel.Name, "plugins_disabled", StringUtils.PluginNameToJarName(plugin.Name) + ".jar")); if (!jarFile.Exists) { ErrorLogger.Append(new ArgumentException( ".jar for plugin " + plugin.Name + " was not found. Can't enable it. Removing it from the list...")); Application.Current.Dispatcher?.Invoke(() => viewModel.InstalledPlugins.Remove(plugin)); } else { DirectoryInfo directoryInfo = new DirectoryInfo(Path.Combine(App.ServerPath, viewModel.EntityViewModel.Name, "plugins")); if (!directoryInfo.Exists) { directoryInfo.Create(); } jarFile.MoveTo(Path.Combine(directoryInfo.FullName, jarFile.Name), true); } Console.WriteLine("Enabled Plugin " + plugin.Name); viewModel.EnablePlugin(plugin); return(true); } catch (Exception e) { ErrorLogger.Append(e); Console.WriteLine("Error while enabling Plugin " + plugin.Name); return(false); } }
public async Task <bool> DownloadPluginAsync(InstalledPlugin plugin, EntityViewModel viewModel) { return(await DownloadPlugin(plugin, viewModel)); }
public void EnablePlugin(InstalledPlugin installedPlugin) { installedPlugin.IsEnabled = true; RaisePropertyChanged(this, new PropertyChangedEventArgs(nameof(installedPlugin.IsEnabled))); InstalledPluginSerializer.Instance.StoreInstalledPlugins(InstalledPlugins.ToList(), EntityViewModel); }