/// <summary> /// Checks if Addon file exists /// </summary> public static bool AddonExists(AddonsObject addon, bool isIToS) { string addonFile = string.Format(addonFileName, addon.file, addon.unicode, addon.fileVersion, addon.extension); return(JsonManager.FileExists(MainWindow.settings.TosDataFolder + addonFile)); }
/// <summary> /// Checks if file exists on the requested uri /// </summary> public static bool AddonFileExists(AddonDisplayObject obj) { bool exists = true; AddonsObject addon = obj.currentDisplay.addon; string useSource = string.Format(addonDownloadUrl, obj.currentDisplay.repo, addon.releaseTag, addon.file, addon.fileVersion, addon.extension); Debug.WriteLine("Checking if file exists at: " + useSource); try { using (WebClient testClient = new WebClient()) { testClient.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore); ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; Stream stream = testClient.OpenRead(useSource); stream.Dispose(); } } catch (Exception ex) { Debug.WriteLine(ex.Message); exists = false; } return(exists); }
/// <summary> /// Deletes Addon /// </summary> public static void DeleteAddon(AddonObject addonObj, bool deleteFolder = true) { AddonsObject addon = addonObj.addon; JsonManager.RemoveFile(MainWindow.settings.TosDataFolder, string.Format(addonFileName, addon.file, addon.unicode, addon.fileVersion, addon.extension)); if (deleteFolder) { RemoveAddonFolder(addonObj.addon); } addonObj.isInstalled = false; }
/// <summary> /// Processes Download Queue /// </summary> private static void ProcessQueue() { if (webClient != null && webClient.IsBusy) { return; } if (DownloadQueue.Count <= 0) { return; } ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072; webClient = new NoKeepAliveWebClient(); webClient.CancelAsync(); webClient.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore); AddonsObject addon = DownloadQueue.First().addon.currentDisplay.addon; string useSource = string.Format(addonDownloadUrl, DownloadQueue.First().addon.currentDisplay.repo, addon.releaseTag, addon.file, addon.fileVersion, addon.extension); Debug.WriteLine("Downloading from " + useSource); string fileName = string.Format(addonFileName, addon.file, addon.unicode, addon.fileVersion, addon.extension); Debug.WriteLine(fileName); webClient.Headers.Add("Accept: text/html, application/xhtml+xml, */*"); webClient.Headers.Add("User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)"); webClient.DownloadDataCompleted += Manager_DownloadComplete; webClient.DownloadProgressChanged += DownloadQueue.First().ProgressCallback; webClient.DownloadDataAsync(new Uri(useSource)); if (!DownloadQueue.First().addon.currentDisplay.isDownloading) { DownloadQueue.First().addon.currentDisplay.isDownloading = true; DownloadQueue.First().addon.tabManager.PopulateAddon(DownloadQueue.First().addon, 0, 0); } }
/// <summary> /// Continues Queue on download complete /// </summary> private static void Manager_DownloadComplete(object sender, DownloadDataCompletedEventArgs e) { try { //Debug.WriteLine("DownloadComplete"); if (e.Error != null) { //there's been an error downloading the addon for whatever reason Debug.WriteLine(e.Error.Message); } else { AddonsObject addon = DownloadQueue.First().addon.currentDisplay.addon; string filePath = string.Format(addonFileName, addon.file, addon.unicode, addon.fileVersion, addon.extension); Debug.WriteLine("Writing to path: " + MainWindow.settings.TosDataFolder + filePath); File.WriteAllBytes(MainWindow.settings.TosDataFolder + filePath, e.Result); DownloadDependencies(DownloadQueue.First().addon.currentDisplay.dependencies); DownloadQueue.First().addon.currentDisplay.IsQueued = false; DownloadQueue.First().addon.currentDisplay.isInstalled = true; DownloadQueue.First().addon.currentDisplay.isDownloading = false; DownloadQueue.First().addon.tabManager.RemoveFromList(DownloadQueue.First().addon); DownloadQueue.First().addon.tabManager.AddToInstalledAddons(DownloadQueue.First().addon); CreateAddonFolder(DownloadQueue.First().addon.currentDisplay.addon); } isDownloadInProgress = false; DownloadQueue.Remove(DownloadQueue.First()); ProcessQueue(); } catch (Exception ex) { Debug.WriteLine(ex.Message); } }
/// <summary> /// Removes Addon folder /// </summary> private static void RemoveAddonFolder(AddonsObject addon) { JsonManager.DeleteFolder(MainWindow.settings.TosAddonFolder + @"\" + addon.file); }