} // end downloadAndSaveAddon internal bool deleteInstalledAddon(bool purgeDirectory) { try { if (purgeDirectory) { string localAddonDataDir = addonData.File; addonInstallerOverride addonOverride = addonInstallerOverrides.FirstOrDefault(x => x.filename == addonData.File && x.fileVersion == addonData.FileVersion && x.whichRepo == addonData.whichRepo); if (addonOverride != null) { if (!string.IsNullOrEmpty(addonOverride.addonDirectoryOverride)) { localAddonDataDir = addonOverride.addonDirectoryOverride; } } if (System.IO.Directory.Exists($"{rootDir}/addons/{localAddonDataDir}")) { System.IO.Directory.Delete($"{rootDir}/addons/{localAddonDataDir}", true); } } string fullAddonFile = $"_{addonData.File}-{addonData.Unicode}-{addonData.FileVersion}.{addonData.Extension}"; if (System.IO.File.Exists($"{rootDir}/data/{fullAddonFile}")) { System.IO.File.Delete($"{rootDir}/data/{fullAddonFile}"); } return(true); } catch (Exception ex) { Common.showError("Delete Installed Addon Button Error", ex); return(false); } } // end deleteInstalledAddon
internal async Task <bool> downloadAndSaveAddon(IProgress <taskProgressMsg> progressMessages, HttpClient webConnector) { try { // Download file, save it, create addon directory. progressMessages.Report(new taskProgressMsg { currentMsg = "Connecting to Repo..." }); HttpResponseMessage webConnectorRespoonse = await webConnector.GetAsync($"https://github.com/{addonData.authorRepo}/releases/download/{addonData.ReleaseTag}/{addonData.File}-{addonData.FileVersion}.{addonData.Extension}"); System.IO.FileStream fs = new System.IO.FileStream($"{rootDir}/data/_{addonData.File}-{addonData.Unicode}-{addonData.FileVersion}.{addonData.Extension}", System.IO.FileMode.Create); progressMessages.Report(new taskProgressMsg { currentMsg = "Saving addon..." }); await webConnectorRespoonse.Content.CopyToAsync(fs); fs.Close(); fs.Dispose(); webConnectorRespoonse.Dispose(); progressMessages.Report(new taskProgressMsg { currentMsg = "Addon saved..." }); string localAddonDataDir = addonData.File; addonInstallerOverride addonOverride = addonInstallerOverrides.FirstOrDefault(x => x.filename == addonData.File && x.fileVersion == addonData.FileVersion && x.whichRepo == addonData.whichRepo); if (addonOverride != null) { if (!string.IsNullOrEmpty(addonOverride.addonDirectoryOverride)) { localAddonDataDir = addonOverride.addonDirectoryOverride; } // Currently, only have a directory override } if (!System.IO.Directory.Exists($"{rootDir}/addons/{localAddonDataDir}")) { System.IO.Directory.CreateDirectory($"{rootDir}/addons/{localAddonDataDir}"); } return(true); } catch (Exception ex) { progressMessages.Report(new taskProgressMsg { currentMsg = "Download and Save Addon Error", exceptionContent = ex, showAsPopup = true }); return(false); } } // end downloadAndSaveAddon