コード例 #1
0
        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])
                {
                    if (modpack.Value.Contains(entry.Key))
                    {
                        Backups.restoreBak(expandPath(entry.Key));
                    }
                    else
                    {
                        Backups.deleteBak(expandPath(entry.Key));
                    }
                }

                Config.rmPatched(modpack.Key);
            }
            Config.MCC_version = Config.getCurrentBuild();
            Config.saveCfg();
            Backups.saveBackups();

            return(true);
        }
コード例 #2
0
        private void Form1_Load(object sender, EventArgs e)
        {
            Program.MasterForm.Size = new System.Drawing.Size(577, 455);
            version_lbl.Text        = Config.version;
            int r = Config.LoadCfg();

            if (r == 3)     // Config error, user refused to regenerate config
            {
                Utility.ShowMsg("MCC Mod Manager cannot load because there are problems with the configuration file.", "Error");
                Environment.Exit(1);
            }
            Backups.LoadBackups();

            if (r == 2)     // User refused to stabilize the game
            {
                patchButton.Enabled        = false;
                delModpack.Enabled         = false;
                restoreSelectedBtn.Enabled = false;
                restoreAllBaksBtn.Enabled  = false;
                delSelectedBak.Enabled     = false;
                delAllBaksBtn.Enabled      = false;
                manualOverride.Enabled     = false;

                megaCaution.Visible = true;
                tt.SetToolTip(megaCaution, "MCC Mod Manager has detected an update and needs to stabilize the game. Please restart the app.");
            }
            else if (r == 1)        // User allowed the manager to stabilize the game
            {
                Modpacks.StabilizeGame();
                Backups.LoadBackups();
            }
            MyMods.LoadModpacks();
            LoadEventHandlers();
            PBar_init();
        }
コード例 #3
0
        private static int unpatchModpack(string modpackname)
        {
            try {
                modpackCfg modpackConfig = getModpackConfig(modpackname);
                using (ZipArchive archive = ZipFile.OpenRead(Config.modpack_dir + @"\" + modpackname + ".zip")) {
                    if (modpackConfig == null)
                    {
                        form1.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(expandPath(entry.dest)))
                            {
                                // repatch restored mod files
                                foreach (modpackEntry e in restored)
                                {
                                    int r = patchFile(archive, e);
                                    if (r == 2 || r == 3)
                                    {
                                        form1.showMsg("Critical error encountered while unpatching '" + modpackname + "'." +
                                                      "\r\nYou may need to verify your game files on steam or reinstall.", "Error");
                                    }
                                }
                                return(2);
                            }
                        }
                        else if (entry.type == "create")
                        {
                            if (!IO.DeleteFile(expandPath(entry.dest)))
                            {
                                form1.showMsg("Could not delete the file '" + expandPath(entry.dest) + "'. This may affect your game. " +
                                              "if you encounter issue please delete this file manually.", "Warning");
                            }
                        }
                        else
                        {
                            form1.showMsg("Unknown modfile type in modpack config.\r\nCould not install the '" + modpackname + "' modpack.", "Error");
                        }
                        restored.Add(entry);
                    }
                }
            } catch (FileNotFoundException) {
                form1.showMsg("Could not unpatch '" + modpackname + "'. Could not find the modpack file to read the config from.", "Error");
                return(2);
            } catch (InvalidDataException) {
                form1.showMsg("Could not unpatch '" + modpackname + "'. The modpack file appears corrupted and the config cannot be read.", "Error");
                return(2);
            }

            return(0);
        }
コード例 #4
0
ファイル: Config.cs プロジェクト: mythis890/MCC_Mod_Manager
 public static void doResetApp()
 {
     patched     = new Dictionary <string, Dictionary <string, string> >();
     MCC_version = getCurrentBuild();
     saveCfg();
     Modpacks.loadModpacks();
     if (!Backups.deleteAll(true))
     {
         form1.showMsg("There was an issue deleting at least one backup. Please delete these in the Backups tab to avoid restoring an old " +
                       "version of the file in the future.", "Error");
     }
     Backups.loadBackups();
 }
コード例 #5
0
ファイル: Form1.cs プロジェクト: mythis890/MCC_Mod_Manager
 private void fullBakPath_chb_CheckedChanged(object sender, EventArgs e)
 {
     Config.fullBakPath = fullBakPath_chb.Checked;
     if (Config.fullBakPath)     // swapping from filename to full path
     {
         foreach (CheckBox chb in bakListPanel.Controls.OfType <CheckBox>())
         {
             chb.Text = Config.dirtyPadding + Backups.getBakKey(chb.Text.Replace(Config.dirtyPadding, ""));
         }
     }
     else        // swapping from full path to filename
     {
         foreach (CheckBox chb in bakListPanel.Controls.OfType <CheckBox>())
         {
             chb.Text = Config.dirtyPadding + Backups._baks[chb.Text.Replace(Config.dirtyPadding, "")];
         }
     }
 }
コード例 #6
0
ファイル: Form1.cs プロジェクト: mythis890/MCC_Mod_Manager
        private void Form1_Load(object sender, EventArgs e)
        {
            version_lbl.Text = Config.version;
            Config.form1     = this;
            int r = Config.loadCfg();

            if (r == 3)
            {
                showMsg("MCC Mod Manager cannot load because there are problems with the configuration file.", "Error");
                Environment.Exit(1);
            }
            Backups.form1 = this;
            Backups.loadBackups();

            if (r == 2)
            {
                patchButton.Enabled        = false;
                delModpack.Enabled         = false;
                restoreSelectedBtn.Enabled = false;
                restoreAllBaksBtn.Enabled  = false;
                delSelectedBak.Enabled     = false;
                delAllBaksBtn.Enabled      = false;
                manualOverride.Enabled     = false;

                megaCaution.Visible = true;
                tt.SetToolTip(megaCaution, "MCC Mod Manager has detected an update and needs to stabilize the game. Please restart the app.");
            }
            else if (r == 1)
            {
                Modpacks.stabilizeGame();
                Backups.loadBackups();
            }

            Modpacks.form1 = this;
            Modpacks.loadModpacks();
            AssemblyPatching.form1 = this;
            IO.form1 = this;
            pBar_init();
            tt.SetToolTip(addRowButton, "Select mod file(s) to add");
        }
コード例 #7
0
        private static int unpatchModpacks(List <CheckBox> toUnpatch)
        {
            bool packErr = false;

            form1.pBar_show(toUnpatch.Count());
            foreach (CheckBox chb in toUnpatch)
            {
                form1.pBar_update();
                string modpackname = chb.Text.Replace(Config.dirtyPadding, "");
                int    ret         = unpatchModpack(modpackname);
                if (ret == 2)
                {
                    packErr     = true;
                    chb.Checked = true;
                }
                else        // modpack was unpatched
                {
                    Config.rmPatched(modpackname);
                    ((PictureBox)chb.Parent.GetChildAtPoint(new Point(chb.Location.X - 45, chb.Location.Y))).Image = Properties.Resources.redDot_15px;
                }
            }

            if (Config.deleteOldBaks)   // update backup pane because backups will have been deleted
            {
                Backups.saveBackups();
                Backups.updateBackupList();
            }

            form1.pBar_hide();
            if (packErr)   // fail / partial success - At least one modpack was not patched
            {
                return(2);
            }
            else        // success, no errors
            {
                return(0);
            }
        }
コード例 #8
0
ファイル: Form1.cs プロジェクト: mythis890/MCC_Mod_Manager
 private void delAllBaksBtn_Click(object sender, EventArgs e)
 {
     Backups.deleteAll(false);
 }
コード例 #9
0
ファイル: Form1.cs プロジェクト: mythis890/MCC_Mod_Manager
 private void delSelectedBak_Click(object sender, EventArgs e)
 {
     Backups.deleteSelected(bakListPanel.Controls.OfType <CheckBox>());
 }
コード例 #10
0
ファイル: Form1.cs プロジェクト: mythis890/MCC_Mod_Manager
 private void restoreAllBaksBtn_Click(object sender, EventArgs e)
 {
     Backups.restoreAll();
 }
コード例 #11
0
ファイル: Form1.cs プロジェクト: mythis890/MCC_Mod_Manager
 private void restoreSelectedBtn_Click(object sender, EventArgs e)
 {
     Backups.restoreSelected(bakListPanel.Controls.OfType <CheckBox>());
 }
コード例 #12
0
ファイル: Form1.cs プロジェクト: mythis890/MCC_Mod_Manager
 private void makeBakBtn_Click(object sender, EventArgs e)
 {
     Backups.newBackup();
 }
コード例 #13
0
ファイル: Form1.cs プロジェクト: mythis890/MCC_Mod_Manager
 private void refreshButton_Click(object sender, EventArgs e)
 {
     Config.loadCfg();
     Backups.loadBackups();
     Modpacks.loadModpacks();
 }
コード例 #14
0
        private static int patchModpack(string modpackname)
        {
            string retStr = willOverwriteOtherMod(modpackname);

            if (!String.IsNullOrEmpty(retStr))
            {
                form1.showMsg("Installing '" + modpackname + "' would overwrite files for '" + retStr + "'. Modpack will be skipped.", "Error");
                return(2);
            }

            bool baksMade = false;

            try {
                modpackCfg modpackConfig = getModpackConfig(modpackname);
                using (ZipArchive archive = ZipFile.OpenRead(Config.modpack_dir + @"\" + modpackname + ".zip")) {
                    if (modpackConfig == null)
                    {
                        form1.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. If the game is running, exit it and try again.";
                            }
                            else if (r == 3)
                            {
                                errMsg = "This modpack appears to be missing files.";
                            }
                            else        // r == 4
                            {
                                errMsg = "Unknown modfile type in modpack config.";
                            }
                            form1.showMsg(errMsg + "\r\nCould not install the '" + modpackname + "' modpack.", "Error");

                            if (Backups.restoreBaks(patched) != 0)
                            {
                                form1.showMsg("At least one file restore failed. Your game is likely in an unstable state.", "Warning");
                            }
                            return(2);
                        }
                        else if (r == 1)
                        {
                            baksMade = true;
                        }

                        patched.Add(expandPath(entry.dest));
                    }
                }
            } catch (FileNotFoundException) {
                form1.showMsg("Could not find the '" + modpackname + "' modpack.", "Error");
                return(2);
            } catch (InvalidDataException) {
                form1.showMsg("The modpack '" + modpackname + "' appears corrupted." +
                              "\r\nThis modpack cannot be installed.", "Error");
                return(2);
            }

            if (baksMade)
            {
                return(1);
            }
            else
            {
                return(0);
            }
        }
コード例 #15
0
        private static int patchFile(ZipArchive archive, modpackEntry entry)
        {
            string          destination = expandPath(entry.dest);
            bool            baksMade    = false;
            ZipArchiveEntry modFile     = archive.GetEntry(entry.src);

            if (modFile == null)
            {
                return(3);
            }
            if (String.IsNullOrEmpty(entry.type) || entry.type == "replace")    // assume replace type entry
            {
                if (File.Exists(destination))
                {
                    if (Backups.createBackup(destination, false) == 0)
                    {
                        baksMade = true;
                    }
                    if (!IO.DeleteFile(destination))
                    {
                        return(2);
                    }
                }
                try {
                    modFile.ExtractToFile(destination);
                } catch (IOException) {
                    return(2);
                }

                if (baksMade)
                {
                    return(1);
                }
                else
                {
                    return(0);
                }
            }
            else if (entry.type == "patch")
            {
                if (File.Exists(destination))
                {
                    if (Backups.createBackup(destination, false) == 0)
                    {
                        baksMade = true;
                    }
                    if (!IO.DeleteFile(destination))
                    {
                        return(2);
                    }
                }

                string unmoddedPath = expandPath(entry.orig);
                if (!IO.getUnmodifiedHash(entry.orig).Equals(getMD5(unmoddedPath), StringComparison.OrdinalIgnoreCase))
                {
                    unmoddedPath = Config.backup_dir + @"\" + Backups._baks[unmoddedPath];  // use backup version
                }

                if (!AssemblyPatching.applyPatch(modFile, Path.GetFileName(entry.src), unmoddedPath, destination))
                {
                    return(5);   // no extra error message
                }

                if (baksMade)
                {
                    return(1);
                }
                else
                {
                    return(0);
                }
            }
            else if (entry.type == "create")
            {
                if (File.Exists(destination))
                {
                    if (!IO.DeleteFile(destination))
                    {
                        return(2);
                    }
                }
                try {
                    modFile.ExtractToFile(destination);
                } catch (IOException) {
                    return(2);
                }

                return(0);
            }
            else
            {
                return(4);
            }
        }