public static bool StabilizeGame()   // used after update is detected to uninstall half clobbered mods
        {
            Dictionary <string, List <string> > restoreMap = GetFilesToRestore();

            foreach (KeyValuePair <string, List <string> > modpack in restoreMap)
            {
                foreach (KeyValuePair <string, string> entry in Config.Patched[modpack.Key].files)
                {
                    if (modpack.Value.Contains(entry.Key))
                    {
                        Backups.RestoreBak(Utility.ExpandPath(entry.Key));
                    }
                    else
                    {
                        Backups.DeleteBak(Utility.ExpandPath(entry.Key));
                    }
                }

                Config.RmPatched(modpack.Key);
            }
            Config.MCC_version = Config.GetCurrentBuild();
            Config.SaveCfg();
            Backups.SaveBackups();

            return(true);
        }
示例#2
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);
        }