示例#1
0
        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));
                    });
                }
            }
        }
        public async Task <bool> DownloadMod(BaseMod mod)
        {
            if (downloadingMods.Exists(x => x.ModId == mod.ModId))
            {
                Log.Information("User tried to download an already downloading mod.");
                return(false);
            }
            ;

            Log.Information($"User started a download for new mod {mod.ModId}");

            downloadingMods.Add(mod);
            needsUpdate = true;

            bool ok = await downloader.DownloadMods(new List <BaseMod> {
                mod
            });

            // Just to make sure...
            downloadingMods.RemoveAll(x => x.ModId == mod.ModId);
            needsUpdate = true;

            if (!ok)
            {
                MessageBox.Show($"An error occurred while downloading workshop mod {mod.ModId}; Check the log file.", "Uh oh", MessageBoxButtons.OK, MessageBoxIcon.Error);

                return(false);
            }

            Log.Information($"User downloaded new mod {mod.ModId}; Moving it into Mods folder.");

            // TODO: Maybe some kind of setting for file verification? The only thing steam tells us about mod files is the size but we could use that.

            //string folder = Path.Combine(downloadPath, mod.ModId);

            //var info = new DirectoryInfo(folder);

            //Log.Information("Mod size {0}", mod.Details.file_size);

            //info.

            updater.UpdateMod(mod, downloadPath, true);

            return(true);
        }
示例#3
0
        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);
            });
        }
示例#4
0
 public static void UpdateObject(BaseMod obj)
 {
     _instance.listObjectsParsed.UpdateObject(obj);
 }
示例#5
0
 public static void AddRow(BaseMod mod)
 {
     _instance.listObjectsParsed.AddObject(mod);
 }
示例#6
0
        public bool UpdateMod(BaseMod mod, string downloadPath, bool forceNoBackup = false)
        {
            var    details        = mod.Details;
            string downloadFolder = Path.Combine(downloadPath, details.publishedfileid);

            string modPath   = Path.Combine(ModsPath, mod.Folder);
            string oldFolder = Path.Combine(modPath, "update_backup");

            Log.Information($"Moving downloaded mod files for {Path.GetFileName(downloadFolder)} ({mod.ModId}) into mod folder \"{Path.GetFileName(modPath)}\"");

            if (!Directory.Exists(downloadFolder))
            {
                Log.Error($"Couldn't find downloaded folder for {details.title} ({details.publishedfileid}). Skipping update.");
                return(false);
            }

            if (!File.Exists(Path.Combine(downloadFolder, "About", "About.xml")))
            {
                Log.Error($"Couldn't update mod {details.title} ({details.publishedfileid}). About.xml is missing from downloaded files.");
                return(false);
            }

            // Throw an error if only About.xml exists in the download folder AND the amount of files in the original mod folder is larger than 1
            // edit: Huh? Why did I do this again?
            if (Utils.CountShit(downloadFolder) <= 1 && Utils.CountShit(mod.ModPath) > 1)
            {
                Log.Error($"Couldn't update mod {details.title} ({details.publishedfileid}). No files exist other than About.xml???");
                return(false);
            }

            if (Settings.ShouldBackupMods && !forceNoBackup)
            {
                if (!Directory.Exists(oldFolder))
                {
                    Directory.CreateDirectory(oldFolder);
                }
                else
                {
                    Directory.Delete(oldFolder, true);
                    Directory.CreateDirectory(oldFolder);
                }

                Utils.MoveShit(modPath, oldFolder, "update_backup");
            }
            else
            {
                Directory.CreateDirectory(modPath);
                Utils.DeleteShit(modPath);
            }

            Utils.MoveShit(downloadFolder, modPath, "update_backup");
            Directory.Delete(downloadFolder, true);

            if (Directory.Exists(Path.Combine(modPath, "About")))
            {
                string path = Path.Combine(modPath, "About", ".lastupdated");
                File.WriteAllText(path, DateTimeOffset.Now.ToUnixTimeSeconds().ToString());
                File.SetAttributes(path, FileAttributes.Hidden);
            }

            return(true);
        }