//https://raw.githubusercontent.com/repo/master/README.md //https://raw.githubusercontent.com/repo/master/addonName/README.md public static string GetReadme(AddonObject addon) { string url = string.Format(readmeDownloadUrlFirst, addon.repo, addon.addon.name.ToLower()); Debug.WriteLine("Trying to get README from: " + url); try { using (WebClient testClient = new WebClient()) { testClient.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore); ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; testClient.Encoding = Encoding.UTF8; string readme = testClient.DownloadString(url); if (readme[0] == '4' && readme[1] == '0' && readme[2] == '4') { return(SecondReadme(addon)); } return(readme); } } catch (Exception) { return(SecondReadme(addon)); } }
public void StartDownload() { if (DownloadManager.AddonFileExists(this)) { AddonObject obj = GetOtherInstalled(); if (obj != null) { if (Settings.isTosRunning()) { Settings.CauseError("Please close ToS before downloading a different version.", "Close ToS", Settings.CloseTos); return; } //Removes current installed addon DownloadManager.DeleteAddon(obj, false); } //Set the progress to 0 addonControl.DynamicNotificationBG.Width = 0; //Update the display currentDisplay.IsQueued = true; tabManager.PopulateAddon(this, 0, 0); DownloadManager.Queue(this, UpdateDownloadProgress); } else { Debug.WriteLine("File couldn't be found on github."); Settings.CauseError("File could not be found. Please contact the Author."); } }
/// <summary> /// Checks if file exists on the requested uri /// </summary> public static bool AddonFileExists(AddonObject obj) { AddonDisplayObject disp = new AddonDisplayObject { currentDisplay = obj }; return(AddonFileExists(disp)); }
public static bool IsBrokenAddon(AddonObject obj) { return((from brk in brokenAddons let semver = SemVersion.Parse(brk.version) where obj.addon.file == brk.file && string.Equals(obj.repo.Split('/')[0], brk.author, StringComparison.CurrentCultureIgnoreCase) && obj.semversion.CompareTo(semver) == 0 select brk).Any()); }
public static bool IsOutdatedAddon(AddonObject obj) { if (!string.IsNullOrEmpty(obj.addon.tosversion)) { return(int.Parse(ToSVersion) > int.Parse(obj.addon.tosversion)); } return(false); }
public void OverrideCurrentDisplay(AddonObject display) { if (!addons.Contains(currentDisplay)) { addons.Add(currentDisplay); } currentDisplay = display; addons.Add(display); }
private void CopyAddonDescriptor(AddonObject a) { installedAddons[a.addon.file].currentDisplay.addon.name = a.addon.name; installedAddons[a.addon.file].currentDisplay.addon.tags = a.addon.tags; installedAddons[a.addon.file].currentDisplay.dependencies = a.dependencies; installedAddons[a.addon.file].currentDisplay.addon.description = a.addon.description; installedAddons[a.addon.file].currentDisplay.addon.releaseTag = a.addon.releaseTag; installedAddons[a.addon.file].currentDisplay.repo = a.repo; installedAddons[a.addon.file].currentDisplay.date = a.date; installedAddons[a.addon.file].currentDisplay.readdate = a.readdate; }
/// <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> /// Returns List of all installed Addons /// </summary> public static List <AddonObject> GetInstalledAddons() { var installedAddons = new List <AddonObject>(); if (!Directory.Exists(MainWindow.settings.TosDataFolder)) { return(installedAddons); } var dirFiles = Directory.GetFiles(MainWindow.settings.TosDataFolder, "*.ipf"); Regex rx = new Regex(@"_(.*)-(.*)-(v\d+.\d+.\d+.*).ipf", RegexOptions.Compiled | RegexOptions.IgnoreCase); foreach (string file in dirFiles) { string fileName = Path.GetFileName(file); //Debug.WriteLine("Trying: " + fileName); MatchCollection matches = rx.Matches(fileName); if (matches.Count > 0) { GroupCollection group = matches[0].Groups; string addonFile = group[1].Value; string addonUnicode = group[2].Value; string addonVersion = group[3].Value; //Debug.WriteLine("found itos "+isitos); AddonObject addonObj = new AddonObject { isInstalled = true, addon = new AddonsObject { extension = "ipf", file = addonFile, fileVersion = addonVersion, unicode = addonUnicode } }; installedAddons.Add(addonObj); //Debug.WriteLine("Found Addon: " + addonFile); } } return(installedAddons); }
public bool IsSameAs(AddonObject other) { if (semversion == null) { InitSemver(); } if (other.semversion == null) { other.InitSemver(); } if (semversion.CompareTo(other.semversion) != 0) { return(false); } return(true); }
public bool IsNewerThan(AddonObject other) { if (semversion == null) { InitSemver(); } if (other.semversion == null) { other.InitSemver(); } if (semversion.CompareTo(other.semversion) < 1) { return(false); } return(true); }
private static string SecondReadme(AddonObject addon) { string url = string.Format(readmeDownloadUrl, addon.repo); Debug.WriteLine("Trying to get README from: " + url); try { using (WebClient testClient = new WebClient()) { testClient.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore); ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; testClient.Encoding = Encoding.UTF8; return(testClient.DownloadString(url)); } } catch (Exception) { return("ERROR"); } }
public void StartUpdate() { if (!currentDisplay.hasUpdate) { return; } AddonObject newObj = GetNewest(); //The file can't be downloaded if (!DownloadManager.AddonFileExists(newObj)) { Settings.CauseError("File could not be found. Please contact the Author."); return; } //Make sure it isn't the exact same version if (newObj == currentDisplay) { Settings.CauseError("Cannot update to the same version."); return; } //Remove the current installed file Remove(true); //Set the display to the newest version currentDisplay = newObj; //Set the progress to 0 addonControl.DynamicNotificationBG.Width = 0; //Update the display tabManager.PopulateAddon(this, 0, 0); //Download the newest version DownloadManager.Queue(this, UpdateDownloadProgress); }
private AddonObject GetNewest() { //List<AddonObject> _versionList = new List<AddonObject>(this.addons); AddonObject newest = null; foreach (AddonObject obj in addons) { if (newest == null) { newest = obj; continue; } if (obj > newest) { newest = obj; } } Debug.WriteLine("Newest: " + newest.addon.fileVersion); return(newest); }
public void Remove(bool isUpdate = false) { if (Settings.isTosRunning()) { Settings.CauseError("Please close ToS before " + (isUpdate ? "updating" : "removing") + " addons.", "Close ToS", Settings.CloseTos); return; } if (!isUpdate) { AddonObject installedObj = GetOtherInstalled(); //Remove it from the list if there isn't another installed one if (installedObj == null) { InstalledAddons.RemoveAddon(this); DownloadManager.DeleteAddon(this); } else //Remove it and update the display to the installed one { DownloadManager.DeleteAddon(this, false); //Set it to uninstalled currentDisplay.isInstalled = false; //Update the display currentDisplay = installedObj; tabManager.PopulateAddon(this, 0, 0); } } else { currentDisplay.isInstalled = false; currentDisplay.hasUpdate = false; DownloadManager.DeleteAddon(this, false); } }
//Fetch version public static DateTimeOffset GetAddonDate(AddonObject addon) { string url = string.Format(dateDownloadUrl, addon.repo, addon.addon.releaseTag); if (_usedReleases == null) { _usedReleases = new Dictionary <string, DateTimeOffset>(); } if (_usedReleases.ContainsKey(url)) { return(_usedReleases[url]); } try { using (WebClient testClient = new WebClient()) { testClient.CachePolicy = new RequestCachePolicy(RequestCacheLevel.CacheIfAvailable); ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; testClient.Encoding = Encoding.UTF8; Atom10FeedFormatter formatter = new Atom10FeedFormatter(); using (XmlReader reader = XmlReader.Create(new StringReader(testClient.DownloadString(url)))) { formatter.ReadFrom(reader); } foreach (SyndicationItem item in formatter.Feed.Items) { //long t = long.Parse(item.LastUpdatedTime.ToString("yyyyMMddhhmmss")); if (_usedReleases == null) { _usedReleases = new Dictionary <string, DateTimeOffset>(); } _usedReleases.Add(url, item.LastUpdatedTime); return(item.LastUpdatedTime); } } } catch (WebException e) { Debug.WriteLine(((HttpWebResponse)e.Response).StatusCode); if ((int)((HttpWebResponse)e.Response).StatusCode == 429) { return(Task.Delay(5000).ContinueWith(t => GetAddonDate(addon)).Result); } return(new DateTimeOffset()); } catch (Exception) { //Anything else we ignore } return(new DateTimeOffset()); }
public void AddAddon(AddonObject display) { addons.Add(display); }
public bool CheckInstalled(AddonObject addon, string repo) { if (installedAddons.ContainsKey(addon.addon.file)) { //Is the same version&name already in here? if (installedAddons[addon.addon.file].currentDisplay.addon.name == addon.addon.name && installedAddons[addon.addon.file].currentDisplay == addon) { //Fixes some issue where a known addon is unknown installedAddons[addon.addon.file].currentDisplay.isUnknown = false; CopyAddonDescriptor(addon); return(true); } foreach (AddonObject obj in installedAddons[addon.addon.file].addons) { if (obj.addon.name == addon.addon.name && obj == addon) { return(true); } } if (installedAddons[addon.addon.file].currentDisplay.isUnknown) { if (addon == installedAddons[addon.addon.file].currentDisplay) { CopyAddonDescriptor(addon); installedAddons[addon.addon.file].currentDisplay.isUnknown = false; } else { installedAddons[addon.addon.file].AddAddon(addon); } } else { if (addon > installedAddons[addon.addon.file].currentDisplay) { addon.isNewest = true; installedAddons[addon.addon.file].AddAddon(addon); installedAddons[addon.addon.file].currentDisplay.hasUpdate = true; installedAddons[addon.addon.file].currentDisplay.isNewest = false; } else { if (addon == installedAddons[addon.addon.file].currentDisplay) { CopyAddonDescriptor(addon); installedAddons[addon.addon.file].currentDisplay.isUnknown = false; } installedAddons[addon.addon.file].AddAddon(addon); } } if (installedAddons[addon.addon.file].currentDisplay.addon.name == installedAddons[addon.addon.file].currentDisplay.addon.file) { CopyAddonDescriptor(addon); if (addon > installedAddons[addon.addon.file].currentDisplay) { addon.isNewest = true; installedAddons[addon.addon.file].currentDisplay.hasUpdate = true; installedAddons[addon.addon.file].currentDisplay.isNewest = false; } } //Populate(); return(true); } return(false); }