public static bool LoadModpacks() { Modpacks.EnsureModpackFolderExists(); Program.MasterForm.modListPanel.Controls.Clear(); string[] fileEntries = Directory.GetFiles(Config.Modpack_dir); foreach (string file in fileEntries) { string modpackName = Path.GetFileName(file).Replace(".zip", ""); ModpackCfg modpackConfig = Modpacks.GetModpackConfig(modpackName); if (modpackConfig != null) { ModListPanel_add(modpackName, modpackConfig.MCC_version); } } return(true); }
private static List <string> FilterNeededBackups(List <string> paths) { List <string> requiredBaks = new List <string>(); foreach (string enabledModpack in Config.GetEnabledModpacks()) { ModpackCfg modpackConfig = Modpacks.GetModpackConfig(enabledModpack); foreach (ModpackEntry entry in modpackConfig.entries) { foreach (string path in paths) { if (path == Utility.ExpandPath(entry.dest)) { requiredBaks.Add(path); } } } } return(requiredBaks); }
public static bool AddPatched(string modpackName) { Dictionary <string, string> modfiles = new Dictionary <string, string>(); ModpackCfg mCfg = Modpacks.GetModpackConfig(modpackName); using (ZipArchive archive = ZipFile.OpenRead(Config.Modpack_dir + @"\" + modpackName + ".zip")) { if (mCfg == null) { Utility.ShowMsg("Cannot set state to enabled. The file '" + modpackName + ".zip' is either not a compatible modpack or the config is corrupted.", "Error"); return(false); } List <string> patched = new List <string>(); // track patched files in case of failure mid patch foreach (ModpackEntry entry in mCfg.entries) { modfiles[entry.dest] = Modpacks.GetMD5(Utility.ExpandPath(entry.dest)); } } Patched[modpackName] = new patchedEntry(); Patched[modpackName].files = modfiles; return(true); }
private static string WillOverwriteOtherMod(string modpack) { ModpackCfg primaryConfig = Modpacks.GetModpackConfig(modpack); foreach (string enabledModpack in Config.GetEnabledModpacks()) { ModpackCfg modpackConfig = Modpacks.GetModpackConfig(enabledModpack); // Deliberately not checking for null so program throws a stack trace // This should never happen, but if it does I want the user to let me know about it foreach (ModpackEntry entry in modpackConfig.entries) { foreach (ModpackEntry primary in primaryConfig.entries) { if (entry.dest == primary.dest) { return(enabledModpack); } } } } return(null); }
public static int LoadCfg() { bool stabilize = false; bool needsStabilize = false; if (!File.Exists(_cfgLocation)) { CreateDefaultCfg(); } else { int r = ReadCfg(); if (r == 1) { DialogResult ans = Utility.ShowMsg("Your configuration has formatting errors, would you like to overwrite it with a default config?", "Question"); if (ans == DialogResult.No) { return(3); } CreateDefaultCfg(); } else if (r == 2) { DialogResult ans = Utility.ShowMsg("Your config file is using an old format, would you like to overwrite it with a default config?", "Question"); if (ans == DialogResult.No) { return(3); } CreateDefaultCfg(); } else { // check if game was updated if (MCC_version != GetCurrentBuild()) { DialogResult ans = Utility.ShowMsg("It appears that MCC has been updated. MCC Mod Manager needs to stabilize the game by uninstalling certain modpacks." + "\r\nWould you like to do this now? Selecting 'No' will disable features.", "Question"); if (ans == DialogResult.Yes) { stabilize = true; } else { needsStabilize = true; } } } } bool msg = false; List <string> tmp = new List <string>(); foreach (KeyValuePair <string, patchedEntry> modpack in Patched) { if (!Modpacks.VerifyExists(modpack.Key)) { if (!msg) { msg = true; Utility.ShowMsg("The '" + modpack.Key + "' modpack is missing from the modpacks folder. If this modpack is actually installed, " + "MCC Mod Manager won't be able to uninstall it. You should restore from backups or verify the game files through Steam." + "\r\nThis warning will only show once.", "Warning"); } tmp.Add(modpack.Key); } } foreach (string modpack in tmp) { RmPatched(modpack); } SaveCfg(); // Update config tab Program.MasterForm.cfgTextBox1.Text = MCC_home; Program.MasterForm.cfgTextBox2.Text = Backup_dir; Program.MasterForm.cfgTextBox3.Text = Modpack_dir; Program.MasterForm.delOldBaks_chb.Checked = DeleteOldBaks; if (stabilize) { return(1); } else if (needsStabilize) { return(2); } else { return(0); } }
public static int UnpatchModpack(string modpackname) { try { ModpackCfg modpackConfig = Modpacks.GetModpackConfig(modpackname); using (ZipArchive archive = ZipFile.OpenRead(Config.Modpack_dir + @"\" + modpackname + ".zip")) { if (modpackConfig == null) { Utility.ShowMsg("Could not unpatch '" + modpackname + "' because the modpack's configuration is corrupted or missing." + "\r\nPlease restore from backups using the Backups tab or verify integrity of game files on Steam.", "Error"); return(2); } List <ModpackEntry> restored = new List <ModpackEntry>(); // track restored files in case of failure mid unpatch foreach (ModpackEntry entry in modpackConfig.entries) { if (String.IsNullOrEmpty(entry.type) || entry.type == "replace" || entry.type == "patch") // assume replace type entry if null { if (!Backups.RestoreBak(Utility.ExpandPath(entry.dest))) { // repatch restored mod files bool err = false; foreach (ModpackEntry e in restored) { int r = PatchFile(archive, e); if (r == 2 || r == 3) { err = true; } } if (err) { Utility.ShowMsg("Critical error encountered while unpatching '" + modpackname + "'." + "\r\nYou may need to verify your game files on steam or reinstall.", "Error"); } return(3); } } else if (entry.type == "create") { if (!Utility.DeleteFile(Utility.ExpandPath(entry.dest))) { Utility.ShowMsg("Could not delete the file '" + Utility.ExpandPath(entry.dest) + "'. This may affect your game. " + "if you encounter issues please delete this file manually.", "Warning"); } } else { Utility.ShowMsg("Unknown modfile type in modpack config.\r\nCould not install the '" + modpackname + "' modpack.", "Error"); } restored.Add(entry); } } } catch (FileNotFoundException) { Utility.ShowMsg("Could not unpatch '" + modpackname + "'. Could not find the modpack file to read the config from.", "Error"); return(2); // Unpatch failed due to error } catch (InvalidDataException) { Utility.ShowMsg("Could not unpatch '" + modpackname + "'. The modpack file appears corrupted and the config cannot be read.", "Error"); return(2); // Unpatch failed due to error } return(0); }
private static int PatchModpack(string modpackname) { string retStr = WillOverwriteOtherMod(modpackname); if (!String.IsNullOrEmpty(retStr)) { Utility.ShowMsg("Installing '" + modpackname + "' would overwrite files for '" + retStr + "'. Modpack will be skipped.", "Error"); return(2); } bool baksMade = false; try { ModpackCfg modpackConfig = Modpacks.GetModpackConfig(modpackname); using (ZipArchive archive = ZipFile.OpenRead(Config.Modpack_dir + @"\" + modpackname + ".zip")) { if (modpackConfig == null) { Utility.ShowMsg("The file '" + modpackname + ".zip' is either not a compatible modpack or the config is corrupted." + "\r\nTry using the 'Create Modpack' Tab to convert this mod into a compatible modpack.", "Error"); return(2); } List <string> patched = new List <string>(); // track patched files in case of failure mid patch foreach (ModpackEntry entry in modpackConfig.entries) { int r = PatchFile(archive, entry); if (r != 0 && r != 1) { string errMsg = ""; if (r == 2) { errMsg = "File Access Exception.\n" + "If you're using the Microsoft Store version of the game, please run this tool as an administrator.\n" + "If the game is running, exit it and try again.\r\n"; } else if (r == 3) { errMsg = "This modpack appears to be missing files.\r\n"; } else if (r == 4) { errMsg = "Unknown modfile type in modpack config.\r\n"; } Utility.ShowMsg(errMsg + "Could not install the '" + modpackname + "' modpack.", "Error"); if (Backups.RestoreBaks(patched) != 0) { Utility.ShowMsg("At least one file restore failed. Your game is likely in an unstable state.", "Warning"); return(3); } return(2); } else if (r == 1) { baksMade = true; } patched.Add(Utility.ExpandPath(entry.dest)); } } } catch (FileNotFoundException) { Utility.ShowMsg("Could not find the '" + modpackname + "' modpack.", "Error"); return(2); } catch (InvalidDataException) { Utility.ShowMsg("The modpack '" + modpackname + "' appears corrupted." + "\r\nThis modpack cannot be installed.", "Error"); return(2); } if (baksMade) { return(1); } else { return(0); } }