public async Task <WorkshopFileDetails> GetWorkshopDetails() { if (Details != null) { return(Details); } string idPath = GetIdPath(); string id = ModId; if (id == null) { if (!File.Exists(idPath)) { return(null); } id = File.ReadAllText(idPath); } var details = await SteamWorkshop.GetWorkshopFileDetails(id); Details = details; if (ModId == null) { ModId = id; } return(details); }
public async Task QueryModBatch(List <BaseMod> batch, int retries = 0) { var detailList = await SteamWorkshop.GetWorkshopFileDetails(batch.ToArray()); if (detailList == null) { if (retries <= 3) { Log.Warning("Failed to query batch of {0} mods. Retry {1}...", batch.Count, retries); retries++; await QueryModBatch(batch, retries); } else { Log.Warning("Failed to query batch of {0} mods after {1} retries.", batch.Count, retries); } return; } else { if (retries > 0) { Log.Information("Got batch of {0} mods successfully after {1} retries.", batch.Count, retries); } } foreach (var details in detailList) { var mod = batch.FindAll(x => x.ModId == details.publishedfileid); mod.ForEach(x => x.Details = details); } }
private void btnManualUpdate_Click(object sender, EventArgs e) { if (currentUpdater.Updating) { MessageBox.Show("Already updating mod(s). Please wait until they're finished.", "Look it's a title!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } using (var dialog = new CommonOpenFileDialog()) { dialog.Title = "Select a mod folder"; dialog.IsFolderPicker = true; dialog.InitialDirectory = Path.Combine(textGamePath.Text, "Mods"); Log.Information("Opening folder dialog in {0}", dialog.InitialDirectory); if (dialog.ShowDialog() == CommonFileDialogResult.Ok) { string modPath = dialog.FileName; string fileIdPath = Path.Combine(modPath, "About", "PublishedFileId.txt"); if (!File.Exists(fileIdPath)) { MessageBox.Show("This is either not a mod folder or the mod does not have a PublishedFileId.txt file in About/", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } Task.Run(async() => { string fileId = File.ReadAllText(fileIdPath); var details = await SteamWorkshop.GetWorkshopFileDetails(fileId); if (details.result == 9) { MessageBox.Show($"Couldn't find file id {details.publishedfileid} on the workshop.", "Failed to update mod.", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } BaseMod obj = new BaseMod { Details = details, ModPath = modPath, }; await currentUpdater.UpdateMods(new List <BaseMod> { obj }, false); //await Downloader.DownloadWorkshopItem(obj, new Updater(Path.GetFullPath(Path.Combine(modPath, "../")))); MessageBox.Show($"Updated {details.title} ({details.publishedfileid}).", "Updated mod successfully.", MessageBoxButtons.OK, MessageBoxIcon.Information); btnReset.BeginInvoke((MethodInvoker)(() => btnReset.Enabled = true)); }); } } }
private void StartModDownload(string url) { SetDownloadButtonState(false); if (!Utils.IsValidGamePath(textGamePath.Text)) { Log.Error("User tried to download a mod but game path was invalid."); MessageBox.Show("Invalid game path; Select the folder that has your rimworld installation.\nex: C:/Games/Rimworld\n\n The program won't work if the folder you select has no Mods folder.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); SetDownloadButtonState(true); return; } string gamePath = textGamePath.Text; string modsPath = Path.Combine(gamePath, "Mods"); url = url ?? chromiumWebBrowser.Address; string id = regex.Match(url).Value; if (String.IsNullOrEmpty(id) || !url.Contains("filedetails")) { Log.Error("User tried to download a mod but no file id was found in " + url); MessageBox.Show("Couldn't find a file id for this page. Is this a workshop item/collection?", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); SetDownloadButtonState(true); return; } Task.Run(async() => { Log.Information("User wants to download stuff from {0}", url); bool isCollection = await SteamWorkshop.IsWorkshopCollection(id); if (isCollection) { List <WorkshopFileDetails> files = await SteamWorkshop.GetWorkshopFileDetailsFromCollection(id); if (files == null) { MessageBox.Show($"Request to get workshop file {id} details failed. See log for details. Try again?", "Uh oh", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (MessageBox.Show($"This is a collection. Are you sure you want to download these {files.Count} mods?\nThe total download size is ~{Utils.GetSizeTextForMods(files)}", "Warning", MessageBoxButtons.YesNo) != DialogResult.Yes) { SetDownloadButtonState(true); return; } SetDownloadButtonState(true); SetProgressBounds(1); SetProgress(0, ProgressBarStyle.Marquee); Log.Information("Querying files in collection " + id); List <BaseMod> mods = new List <BaseMod>(); foreach (WorkshopFileDetails file in files) { if (!file.IsValidResult()) { Log.Warning($"{file.publishedfileid} returned an invalid result from collection. Ignoring."); continue; } string folder = Utils.SanitizeFilename(file.title); mods.Add(new BaseMod { Details = file, ModPath = folder, ModId = file.publishedfileid }); } await downloadTabManager.DownloadMods(mods); mods.ForEach(listDownloadedObjects.UpdateObject); return; } SetDownloadButtonState(true); var details = await SteamWorkshop.GetWorkshopFileDetails(id); if (details == null) { MessageBox.Show($"Request to get workshop file {id} details failed. See log for details. Try again?", "Uh oh", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (details.result != 1) { MessageBox.Show("Invalid workshop item; Check log for details.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Log.Warning("User tried to download workshop mod but ID returned code {0}", details.result); return; } string folderName = Utils.SanitizeFilename(details.title); Log.Information($"Trying to download a new mod by the name '{details.title}' with the id '{details.publishedfileid}' into folder '{folderName}'"); string modPath = Path.Combine(modsPath, folderName); BaseMod mod = new BaseMod { Details = details, ModPath = modPath, ModId = details.publishedfileid }; await downloadTabManager.DownloadMod(mod); //await Downloader.DownloadWorkshopItem(mod, new Updater(gamePath)); listDownloadedObjects.UpdateObject(mod); }); }
public static async Task <bool> CheckForUpdates() { if (File.Exists(".ignoreupdates")) { Log.Information(".ignoreupdates file is present; Not checking for updates."); return(false); } // Does the updater need an update? Log.Information("Checking for updates..."); var client = new HttpClient(); client.DefaultRequestHeaders.Clear(); client.DefaultRequestHeaders.UserAgent.ParseAdd("RimworldModUpdater/" + Settings.Version); client.DefaultRequestHeaders.Accept.ParseAdd("text/plain"); var response = await client.GetAsync("https://gitcdn.xyz/repo/EnervationRIN/RimworldModUpdater/master/ReleaseVersion.txt"); var data = await response.Content.ReadAsByteArrayAsync(); var encoding = SteamWorkshop.GetResponseEncoding(response.Content, Encoding.UTF8); string str = encoding.GetString(data).Trim(); var localVer = GetProgramVersion(); if (Version.TryParse(str, out var ver)) { Log.Information($"Local version is {localVer.ToString()}. Remote version is {ver.ToString()}."); if (ver > localVer) { Log.Information("Update available. Creating update popup."); var result = MessageBox.Show($"There is an update available ({localVer.ToString()} => {ver.ToString()}). Do you want to open the download page?\n\nCancel to ignore updates.", "Update Available!", MessageBoxButtons.YesNoCancel); switch (result) { case DialogResult.Yes: Log.Information("Opening github releases page."); Process.Start("https://github.com/EnervationRIN/RimworldModUpdater/releases/latest"); break; case DialogResult.No: Log.Information("User declined update."); break; case DialogResult.Cancel: Log.Information("Creating .ignoreupdates file"); File.WriteAllText(".ignoreupdates", ""); break; } return(true); } else { Log.Information("No updates found."); return(false); } } Log.Warning("Couldn't parse remote version while checking for updates. Returned: '{0}'", str); return(false); }