Exemplo n.º 1
0
        public static void RestoreAllBaksBtn_Click(object sender, EventArgs e)
        {
            EnsureBackupFolderExists();
            List <string> bakList = new List <string>();

            foreach (KeyValuePair <string, string> b in _baks)
            {
                bakList.Add(b.Key);
            }

            Dictionary <string, List <string> > x = checkForPartialRestores(bakList);

            if (x["partials"].Any())
            {
                DialogResult ans = Utility.ShowMsg("Restoring the selected backups will partially unpatch at least one modpack. All files within a modpack " +
                                                   "are intended to be patched and unpatched together. This may cause issues with your game.\r\nContinue?", "Question");
                if (ans == DialogResult.No)
                {
                    return;
                }
            }
            int r = RestoreBaks(bakList);

            MyMods.setModpacksDisabled(x["disable"]);
            MyMods.setModpacksPartial(x["partials"]);

            if (r == 0)
            {
                Utility.ShowMsg("Files have been restored.", "Info");
            }
            else if (r == 1 || r == 2)
            {
                Utility.ShowMsg("At least one file restore failed. Your game may be in an unstable state.", "Warning");
            }
        }
Exemplo n.º 2
0
        public static void RestoreSelectedBtn_Click(object sender, EventArgs e)
        {
            IEnumerable <Panel> bakList     = Program.MasterForm.bakListPanel.Controls.OfType <Panel>();
            List <string>       backupPaths = new List <string>();

            foreach (Panel p in bakList)
            {
                CheckBox chb = (CheckBox)p.GetChildAtPoint(Config.BackupsChbPoint);
                if (chb.Checked)
                {
                    if (Program.MasterForm.fullBakPath_chb.Checked)
                    {
                        backupPaths.Add(chb.Text.Replace(Config.dirtyPadding, ""));
                    }
                    else
                    {
                        backupPaths.Add(GetBakKey(chb.Text.Replace(Config.dirtyPadding, "")));
                    }
                    chb.Checked = false;
                }
            }

            if (!backupPaths.Any())
            {
                Utility.ShowMsg("No items selected from the list.", "Error");
                return;
            }
            Dictionary <string, List <string> > x = checkForPartialRestores(backupPaths);

            if (x["partials"].Any())
            {
                DialogResult ans = Utility.ShowMsg("Restoring the selected backups will partially unpatch at least one modpack. All files within a modpack " +
                                                   "are intended to be patched and unpatched together. This may cause issues with your game.\r\nContinue?", "Question");
                if (ans == DialogResult.No)
                {
                    return;
                }
            }
            int r = RestoreBaks(backupPaths);

            MyMods.setModpacksDisabled(x["disable"]);
            MyMods.setModpacksPartial(x["partials"]);

            if (r == 0)
            {
                Utility.ShowMsg("Selected files have been restored.", "Info");
            }
            else if (r == 1 || r == 2)
            {
                Utility.ShowMsg("At least one file restore failed. Your game may be in an unstable state.", "Warning");
            }
        }
Exemplo n.º 3
0
 public static void DoResetApp()
 {
     Patched     = new Dictionary <string, patchedEntry>();
     MCC_version = GetCurrentBuild();
     SaveCfg();
     MyMods.LoadModpacks();
     if (!Backups.DeleteAll(true))
     {
         Utility.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();
 }
Exemplo n.º 4
0
        public static void CreateModpackBtn_Click(object sender, EventArgs e)
        {
            string modpackName = Program.MasterForm.modpackName_txt.Text;
            IEnumerable <Panel> modFilesList = Program.MasterForm.createFilesPanel.Controls.OfType <Panel>();

            if (modFilesList.Count() == 0)
            {
                Utility.ShowMsg("Please add at least one modded file entry", "Error");
                return;
            }
            if (String.IsNullOrEmpty(modpackName))
            {
                Utility.ShowMsg("Please enter a modpack name", "Error");
                return;
            }

            List <String> chk  = new List <string>();
            ModpackCfg    mCfg = new ModpackCfg {
                MCC_version = Utility.ReadFirstLine(Config.MCC_home + @"\build_tag.txt")
            };

            foreach (Panel row in modFilesList)
            {
                string  srcText     = row.GetChildAtPoint(Config.sourceTextBoxPoint).Text;
                TextBox origTextbox = new TextBox();    // setting this to an empty value to avoid compile error on an impossible CS0165
                string  destText;
                if ((string)row.Tag == "normal")
                {
                    destText = row.GetChildAtPoint(Config.destTextBoxPoint).Text;
                }
                else
                {
                    origTextbox = (TextBox)row.GetChildAtPoint(Config.origTextBoxPoint);
                    destText    = row.GetChildAtPoint(Config.destTextBoxPointAlt).Text;
                }

                if (string.IsNullOrEmpty(srcText) || string.IsNullOrEmpty(destText) || ((string)row.Tag == "alt" && string.IsNullOrEmpty(origTextbox.Text)))
                {
                    Utility.ShowMsg("Filepaths cannot be empty.", "Error");
                    return;
                }
                if (!File.Exists(srcText))
                {
                    Utility.ShowMsg("The source file '" + srcText + "' does not exist.", "Error");
                    return;
                }
                if (!destText.StartsWith(Config.MCC_home))
                {
                    Utility.ShowMsg("Destination files must be located within the MCC install directory. " +
                                    "You may need to configure this directory if you haven't done so already.", "Error");
                    return;
                }
                if ((string)row.Tag == "alt" && origTextbox.Enabled && !origTextbox.Text.StartsWith(Config.MCC_home))
                {
                    Utility.ShowMsg("Unmodified map files must be selected at their default install location within the MCC install directory to allow the patch " +
                                    "to be correctly applied when this modpack is installed. The file you selected does not appear to lie inside the MCC install directory." +
                                    "\r\nYou may need to configure this directory if you haven't done so already.", "Error");
                    return;
                }
                string patchType;
                if (Path.GetExtension(srcText) == ".asmp")
                {
                    patchType = "patch";
                }
                else
                {
                    bool isOriginalFile;
                    try {
                        isOriginalFile = Utility.IsHaloFile(Utility.CompressPath(destText));
                    } catch (JsonReaderException) {
                        Utility.ShowMsg(@"MCC Mod Manager could not parse Formats\filetree.json", "Error");
                        return;
                    }

                    if (isOriginalFile)
                    {
                        patchType = "replace";
                    }
                    else
                    {
                        patchType = "create";
                    }
                }

                mCfg.entries.Add(new ModpackEntry {
                    src  = srcText,
                    orig = (patchType == "patch") ? Utility.CompressPath(origTextbox.Text) : null,
                    dest = Utility.CompressPath(destText),  // make modpack compatable with any MCC_home directory
                    type = patchType
                });
                chk.Add(destText);
            }

            if (chk.Distinct().Count() != chk.Count)
            {
                Utility.ShowMsg("You have multiple files trying to write to the same destination.", "Error");
                return;
            }

            EnsureModpackFolderExists();
            String modpackFilename = modpackName + ".zip";
            String zipPath         = Config.Modpack_dir + @"\" + modpackFilename;

            if (File.Exists(zipPath))
            {
                Utility.ShowMsg("A modpack with that name already exists.", "Error");
                return;
            }

            Program.MasterForm.PBar_show(mCfg.entries.Count);
            try {
                using (var archive = ZipFile.Open(zipPath, ZipArchiveMode.Create)) {
                    foreach (var entry in mCfg.entries)
                    {
                        Program.MasterForm.PBar_update();
                        String fileName = Path.GetFileName(entry.src);
                        archive.CreateEntryFromFile(entry.src, fileName); // TODO: Fix issues when two source files have same name but diff path
                        entry.src = fileName;                             // change src path to just modpack after archive creation but before json serialization
                    }
                    ZipArchiveEntry configFile = archive.CreateEntry("modpack_config.cfg");
                    string          json       = JsonConvert.SerializeObject(mCfg, Formatting.Indented);
                    using (StreamWriter writer = new StreamWriter(configFile.Open())) {
                        writer.WriteLine(json);
                    }
                    ZipArchiveEntry readmeFile = archive.CreateEntry("README.txt");
                    using (StreamWriter writer = new StreamWriter(readmeFile.Open())) {
                        if (String.IsNullOrEmpty(Program.MasterForm.readmeTxt.Text))
                        {
                            writer.WriteLine(Config._defaultReadmeText);
                        }
                        else
                        {
                            writer.WriteLine(Program.MasterForm.readmeTxt.Text);
                        }
                    }
                }
            } catch (NotSupportedException) {
                Utility.ShowMsg("The modpack name you have provided is not a valid filename on Windows.", "Error");
                return;
            }

            Utility.ShowMsg("Modpack '" + modpackFilename + "' created.", "Info");
            Program.MasterForm.PBar_hide();
            ResetCreateModpacksTab();
            MyMods.LoadModpacks();
            return;
        }