public static bool UninstallMods(CheckedListBox.CheckedIndexCollection modIndices, bool skipCleanup = false) // Uninstalls mods based on their indices in the list { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); Debug.LogLine("[Uninstall] Start", Debug.LogLevel.Basic); // initial cleanup ModManager.ClearBuildFiles(ZeroPath, OnePath, SnakeBiteSettings, SavePresetPath); ModManager.ClearSBGameDir(); ModManager.CleanupFolders(); // backup preset build if (Properties.Settings.Default.AutosaveRevertPreset == true) { PresetManager.SavePreset(SavePresetPath + build_ext); } else { Debug.LogLine("[Uninstall] Skipping RevertChanges.MGSVPreset Save", Debug.LogLevel.Basic); } GzsLib.LoadDictionaries(); File.Copy(SnakeBiteSettings, SnakeBiteSettings + build_ext, true); List <ModEntry> mods = SBBuildManager.GetInstalledMods(); List <ModEntry> selectedMods = new List <ModEntry>(); foreach (int index in modIndices) { ModEntry mod = mods[index]; selectedMods.Add(mod); } List <string> zeroFiles = new List <string>(); bool hasQarZero = ModManager.hasQarZeroFiles(selectedMods); if (hasQarZero) { // if necessary, extracts 00.dat and creates a list of filenames, which is pruned throughout the uninstall process and repacked at the end. zeroFiles = GzsLib.ExtractArchive <QarFile>(ZeroPath, "_working0"); zeroFiles.RemoveAll(file => file.EndsWith("_unknown")); } List <string> oneFiles = null; bool hasFtexs = ModManager.foundLooseFtexs(selectedMods); if (hasFtexs) { // if necessary, extracts 01.dat and creates a list of filenames similar to zeroFiles. only textures are pruned from the list. oneFiles = GzsLib.ExtractArchive <QarFile>(OnePath, "_working1"); oneFiles.RemoveAll(file => file.EndsWith("_unknown")); } //end of qar extraction GameData gameData = SBBuildManager.GetGameData(); ModManager.ValidateGameData(ref gameData, ref zeroFiles); Debug.LogLine("[Uninstall] Building gameFiles lists", Debug.LogLevel.Basic); var baseGameFiles = GzsLib.ReadBaseData(); try { ModManager.PrepGameDirFiles(); // begin uninstall UninstallMods(selectedMods, ref zeroFiles, ref oneFiles); if (hasQarZero) { zeroFiles.Sort(); GzsLib.WriteQarArchive(ZeroPath + build_ext, "_working0", zeroFiles, GzsLib.zeroFlags); } if (hasFtexs) { oneFiles.Sort(); GzsLib.WriteQarArchive(OnePath + build_ext, "_working1", oneFiles, GzsLib.oneFlags); } // end of qar rebuild // overwrite old mod data ModManager.PromoteGameDirFiles(); ModManager.PromoteBuildFiles(ZeroPath, OnePath, SnakeBiteSettings, SavePresetPath); if (!skipCleanup) { ModManager.CleanupFolders(); ModManager.ClearSBGameDir(); } Debug.LogLine("[Uninstall] Uninstall complete", Debug.LogLevel.Basic); stopwatch.Stop(); Debug.LogLine($"[Uninstall] Uninstall took {stopwatch.ElapsedMilliseconds} ms", Debug.LogLevel.Basic); return(true); } catch (Exception e) { Debug.LogLine("[Uninstall] Exception: " + e, Debug.LogLevel.Basic); stopwatch.Stop(); Debug.LogLine($"[Uninstall] Uninstall failed at {stopwatch.ElapsedMilliseconds} ms", Debug.LogLevel.Basic); MessageBox.Show("An error has occurred during the uninstallation process and SnakeBite could not uninstall the selected mod(s).\nException: " + e); // clean up failed files ModManager.ClearBuildFiles(ZeroPath, OnePath, SnakeBiteSettings, SavePresetPath); ModManager.CleanupFolders(); bool restoreRetry = false; do { try { ModManager.RestoreBackupGameDir(SBBuildManager); } catch (Exception f) { Debug.LogLine("[Uninstall] Exception: " + f, Debug.LogLevel.Basic); restoreRetry = DialogResult.Retry == MessageBox.Show("SnakeBite could not restore Game Directory mod files due to the following exception: {f} \nWould you like to retry?", "Exception Occurred", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error); } } while (restoreRetry); ModManager.ClearSBGameDir(); return(false); } }//UninstallMod batch
private void menuItemLoadPreset_Click(object sender, EventArgs e) { OneTimePresetHelp(); /* This might be useful but I'm worried that the user might mistake the prompt and end up overwriting the preset that they wanted to load * DialogResult saveModsResult = MessageBox.Show("Would you like to save your current mods as a Preset before loading a new Preset?", "Save current mods?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); * if (saveModsResult == DialogResult.Yes) SavePreset(); * else if (saveModsResult == DialogResult.Cancel) return; */ OpenFileDialog getPresetFile = new OpenFileDialog(); getPresetFile.Filter = "MGSV Preset File|*.MGSVPreset|All Files|*.*"; getPresetFile.Multiselect = true; DialogResult getPresetResult = getPresetFile.ShowDialog(); if (getPresetResult != DialogResult.OK) { return; } string presetPath = getPresetFile.FileName; Settings presetSettings = PresetManager.ReadSnakeBiteSettings(presetPath); bool success = false; try { if (!PresetManager.isPresetUpToDate(presetSettings)) { if (MessageBox.Show(string.Format("This Preset file is intended for Game Version {0}, but your current Game Version is {1}. Loading this preset will likely cause crashes, infinite loading screens or other significant problems in-game.", presetSettings.MGSVersion.AsVersion(), ModManager.GetMGSVersion()) + "\n\nAre you sure you want to load this preset?", "Preset Version Mismatch", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) != DialogResult.Yes) { return; } } string modsToInstall = "This Preset will contain the following mods:\n"; if (presetSettings.ModEntries.Count != 0) { foreach (var mod in presetSettings.ModEntries) { modsToInstall += string.Format("\n{0}", mod.Name); } } else { modsToInstall += "\n[NONE]"; } if (MessageBox.Show(modsToInstall, "Install Preset", MessageBoxButtons.OKCancel) != DialogResult.OK) { return; } log.ClearPage(); SetVisiblePage(log); ProgressWindow.Show("Loading Preset", "Loading Preset, please wait...", new Action((MethodInvoker) delegate { success = PresetManager.LoadPreset(presetPath); }), log); } catch (Exception f) { MessageBox.Show("An error has occurred and the .MGSVPreset could not be loaded. Maybe the Preset file was packed improperly, or is being used by another program?\nException: " + f); success = false; } RefreshInstalledMods(true); if (success) { MessageBox.Show(string.Format("'{0}' Loaded", Path.GetFileName(presetPath)), "Preset Loaded", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
public static bool InstallMods(List <string> ModFiles, bool skipCleanup = false) { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); Debug.LogLine("[Install] Start", Debug.LogLevel.Basic); ModManager.ClearBuildFiles(ZeroPath, OnePath, SnakeBiteSettings, SavePresetPath); // deletes any leftover sb_build files that might still be in the directory (ie from a mid-process shutdown) ModManager.ClearSBGameDir(); // deletes the game directory sb_build ModManager.CleanupFolders(); // deletes the work folders which contain extracted files from 00/01 if (Properties.Settings.Default.AutosaveRevertPreset == true) { PresetManager.SavePreset(SavePresetPath + build_ext); // creates a backup preset file sb_build } else { Debug.LogLine("[Install] Skipping RevertChanges.MGSVPreset Save", Debug.LogLevel.Basic); } File.Copy(SnakeBiteSettings, SnakeBiteSettings + build_ext, true); // creates a settings sb_build GzsLib.LoadDictionaries(); List <ModEntry> installEntryList = new List <ModEntry>(); foreach (string modFile in ModFiles) { installEntryList.Add(Tools.ReadMetaData(modFile)); } List <string> zeroFiles = new List <string>(); bool hasQarZero = ModManager.hasQarZeroFiles(installEntryList); if (hasQarZero) { zeroFiles = GzsLib.ExtractArchive <QarFile>(ZeroPath, "_working0"); } List <string> oneFiles = null; bool hasFtexs = ModManager.foundLooseFtexs(installEntryList); if (hasFtexs) { oneFiles = GzsLib.ExtractArchive <QarFile>(OnePath, "_working1"); } SettingsManager SBBuildManager = new SettingsManager(SnakeBiteSettings + build_ext); var gameData = SBBuildManager.GetGameData(); ModManager.ValidateGameData(ref gameData, ref zeroFiles); var zeroFilesHashSet = new HashSet <string>(zeroFiles); Debug.LogLine("[Install] Building gameFiles lists", Debug.LogLevel.Basic); var baseGameFiles = GzsLib.ReadBaseData(); var allQarGameFiles = new List <Dictionary <ulong, GameFile> >(); allQarGameFiles.AddRange(baseGameFiles); try { ModManager.PrepGameDirFiles(); List <string> pullFromVanillas; List <string> pullFromMods; Dictionary <string, bool> pathUpdatesExist; Debug.LogLine("[Install] Writing FPK data to Settings", Debug.LogLevel.Basic); AddToSettingsFpk(installEntryList, SBBuildManager, allQarGameFiles, out pullFromVanillas, out pullFromMods, out pathUpdatesExist); InstallMods(ModFiles, SBBuildManager, pullFromVanillas, pullFromMods, ref zeroFilesHashSet, ref oneFiles, pathUpdatesExist); if (hasQarZero) { zeroFiles = zeroFilesHashSet.ToList(); zeroFiles.Sort(); GzsLib.WriteQarArchive(ZeroPath + build_ext, "_working0", zeroFiles, GzsLib.zeroFlags); } if (hasFtexs) { oneFiles.Sort(); GzsLib.WriteQarArchive(OnePath + build_ext, "_working1", oneFiles, GzsLib.oneFlags); } ModManager.PromoteGameDirFiles(); ModManager.PromoteBuildFiles(ZeroPath, OnePath, SnakeBiteSettings, SavePresetPath); if (!skipCleanup) { ModManager.CleanupFolders(); ModManager.ClearSBGameDir(); } stopwatch.Stop(); Debug.LogLine($"[Install] Installation finished in {stopwatch.ElapsedMilliseconds} ms", Debug.LogLevel.Basic); return(true); } catch (Exception e) { stopwatch.Stop(); Debug.LogLine($"[Install] Installation failed at {stopwatch.ElapsedMilliseconds} ms", Debug.LogLevel.Basic); Debug.LogLine("[Install] Exception: " + e, Debug.LogLevel.Basic); MessageBox.Show("An error has occurred during the installation process and SnakeBite could not install the selected mod(s).\nException: " + e, "Mod(s) could not be installed", MessageBoxButtons.OK, MessageBoxIcon.Error); ModManager.ClearBuildFiles(ZeroPath, OnePath, SnakeBiteSettings, SavePresetPath); ModManager.CleanupFolders(); bool restoreRetry = false; do { try { ModManager.RestoreBackupGameDir(SBBuildManager); } catch (Exception f) { Debug.LogLine("[Uninstall] Exception: " + f, Debug.LogLevel.Basic); restoreRetry = DialogResult.Retry == MessageBox.Show("SnakeBite could not restore Game Directory mod files due to the following exception: {f} \nWould you like to retry?", "Exception Occurred", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error); } } while (restoreRetry); ModManager.ClearSBGameDir(); return(false); } }
private void SavePreset() { SaveFileDialog savePreset = new SaveFileDialog(); savePreset.Filter = "MGSV Preset File|*.MGSVPreset"; DialogResult saveResult = savePreset.ShowDialog(); if (saveResult != DialogResult.OK) { return; } string presetPath = savePreset.FileName; log.ClearPage(); SetVisiblePage(log); bool success = false; ProgressWindow.Show("Saving Preset", "Saving Preset, please wait...", new Action((MethodInvoker) delegate { success = PresetManager.SavePreset(presetPath); }), log); if (success) { MessageBox.Show(string.Format("'{0}' Saved.", Path.GetFileName(presetPath)), "Preset Saved", MessageBoxButtons.OK, MessageBoxIcon.Information); } RefreshInstalledMods(true); }