GetMGSVersion() статический приватный Метод

static private GetMGSVersion ( ) : System.Version
Результат System.Version
Пример #1
0
        public bool IsUpToDate(Version ModVersion) //shouldn't be in settingsmanager
        {
            bool isUpToDate    = ModManager.GetMGSVersion() == ModVersion;
            bool isSpecialCase = ModVersion == new Version(0, 0, 0, 0) || ModVersion == new Version(1, 0, 14, 0) || ModVersion == new Version(1, 0, 15, 1); // 1.0.14.0 and 1.0.15.1 mods are still up to date

            return(isUpToDate || isSpecialCase);
        }
Пример #2
0
        public static bool isPresetUpToDate(Settings presetSettings)
        {
            var presetVersion = presetSettings.MGSVersion.AsVersion();
            var MGSVersion    = ModManager.GetMGSVersion();

            return(presetVersion == MGSVersion);
        }
Пример #3
0
        public bool IsUpToDate(Version ModVersion) //shouldn't be in settingsmanager
        {
            bool isUpToDate    = ModManager.GetMGSVersion() == ModVersion;
            bool isSpecialCase = ModVersion == new Version(0, 0, 0, 0) || ModVersion == new Version(1, 0, 15, 2); // GAMEVERSION 1.0.15.2 vs .3 was just an exe change, so allow .2

            return(isUpToDate || isSpecialCase);
        }
Пример #4
0
 private void labelVersionWarning_Click(object sender, EventArgs e)
 {
     if (listInstalledMods.SelectedIndex >= 0)
     {
         var      mods              = manager.GetInstalledMods();
         ModEntry selectedMod       = mods[listInstalledMods.SelectedIndex];
         var      currentMGSVersion = ModManager.GetMGSVersion();
         var      modMGSVersion     = selectedMod.MGSVersion.AsVersion();
         if (currentMGSVersion != modMGSVersion && modMGSVersion != new Version(0, 0, 0, 0))
         {
             if (currentMGSVersion > modMGSVersion && modMGSVersion > new Version(0, 0, 0, 0))
             {
                 MessageBox.Show(String.Format("{0} appears to be for MGSV Version {1}.\n\nIt is recommended that you check for an updated version.", selectedMod.Name, modMGSVersion), "Game version mismatch", MessageBoxButtons.OK, MessageBoxIcon.Warning);
             }
             if (currentMGSVersion < modMGSVersion)
             {
                 MessageBox.Show(String.Format("{0} is intended for MGSV version {1}, but your installation is version {2}.\n\nThis mod may not be compatible with MGSV version {2}", selectedMod.Name, modMGSVersion, currentMGSVersion), "Update recommended", MessageBoxButtons.OK, MessageBoxIcon.Warning);
             }
         }
         else
         {
             MessageBox.Show(String.Format("This mod is up to date with the current MGSV version {0}", currentMGSVersion), "Mod is up to date", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
     }
 }
Пример #5
0
        public static void FilterModValidity(List <string> ModFiles)// checks if mods are too old for snakebite, or if snakebite is too old for mods, and whether mods were for an older version of the game.
        {
            // remove from the list if the mod is too old for snakebite or snakebite is too old for mod. ask user for input if the mod is for an older version of the game.
            // return a list of mods that Snakebite/user has OK'd

            ModEntry metaData;

            for (int i = ModFiles.Count() - 1; i >= 0; i--)
            {
                // check if mod contains metadata.xml
                metaData = Tools.ReadMetaData(ModFiles[i]);
                if (metaData == null)
                {
                    MessageBox.Show(String.Format("{0} does not contain a metadata.xml and cannot be installed.", ModFiles[i]));
                    ModFiles.RemoveAt(i);
                    continue;
                }

                // check version conflicts
                var SBVersion  = ModManager.GetSBVersion();
                var MGSVersion = ModManager.GetMGSVersion();

                Version modSBVersion  = new Version();
                Version modMGSVersion = new Version();
                try
                {
                    modSBVersion  = metaData.SBVersion.AsVersion();
                    modMGSVersion = metaData.MGSVersion.AsVersion();
                }
                catch
                {
                    MessageBox.Show(String.Format("The selected version of {0} was created with an older version of SnakeBite and is no longer compatible, please download the latest version and try again.", metaData.Name), "Mod update required", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    ModFiles.RemoveAt(i);
                    continue;
                }

                // Check if mod requires SB update
                if (modSBVersion > SBVersion)
                {
                    if (DialogResult.Yes != MessageBox.Show($"'{metaData.Name}' was created with SnakeBite {metaData.SBVersion.AsString()} and may not be compatible with {SBVersion}.\n\nContinue?", "Update required", MessageBoxButtons.YesNo, MessageBoxIcon.Warning))
                    {
                        ModFiles.RemoveAt(i);
                    }
                    continue;
                }

                if (modSBVersion < new Version(0, 8, 0, 0)) // 0.8.0.0
                {
                    MessageBox.Show(String.Format("The selected version of {0} was created with an older version of SnakeBite and is no longer compatible, please download the latest version and try again.", metaData.Name), "Mod update required", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    ModFiles.RemoveAt(i);
                    continue;
                }
            }
        }
Пример #6
0
 public void SaveTo(string directory, string filename)
 {
     // Write settings to XML
     Directory.CreateDirectory(directory);
     using (FileStream s = new FileStream(Path.Combine(directory, filename), FileMode.Create))
     {
         XmlSerializer x = new XmlSerializer(typeof(Settings), new[] { typeof(Settings) });
         foreach (ModEntry mod in ModEntries)
         {
             mod.Description = mod.Description.Replace("\r\n", "\n");
         }
         SbVersion.Version  = ModManager.GetSBVersion().ToString();
         MGSVersion.Version = ModManager.GetMGSVersion().ToString();
         x.Serialize(s, this);
     }
 }
Пример #7
0
 private void listInstalledMods_SelectedIndexChanged(object sender, EventArgs e)// Populate mod details pane
 {
     if (listInstalledMods.SelectedIndex >= 0)
     {
         var      mods        = manager.GetInstalledMods();
         ModEntry selectedMod = mods[listInstalledMods.SelectedIndex];
         labelModName.Text    = selectedMod.Name;
         labelModAuthor.Text  = "By " + selectedMod.Author;
         labelModWebsite.Text = selectedMod.Version;
         textDescription.Text = selectedMod.Description;
         if (ModManager.GetMGSVersion() != selectedMod.MGSVersion.AsVersion() && selectedMod.MGSVersion.AsVersion() != new Version(0, 0, 0, 0))
         {
             labelVersionWarning.ForeColor = Color.Yellow; labelVersionWarning.BackColor = Color.Chocolate; labelVersionWarning.Text = "!";
         }
         else
         {
             labelVersionWarning.ForeColor = Color.MediumSeaGreen; labelVersionWarning.BackColor = Color.Gainsboro; labelVersionWarning.Text = "✔";
         }
     }
 }
Пример #8
0
        public static void FilterModValidity(List <string> ModFiles)// checks if mods are too old for snakebite, or if snakebite is too old for mods, and whether mods were for an older version of the game.
        {
            // remove from the list if the mod is too old for snakebite or snakebite is too old for mod. ask user for input if the mod is for an older version of the game.
            // return a list of mods that Snakebite/user has OK'd

            ModEntry metaData;

            for (int i = ModFiles.Count() - 1; i >= 0; i--)
            {
                // check if mod contains metadata.xml
                metaData = Tools.ReadMetaData(ModFiles[i]);
                if (metaData == null)
                {
                    MessageBox.Show(String.Format("{0} does not contain a metadata.xml and cannot be installed.", ModFiles[i]));
                    ModFiles.RemoveAt(i);
                    continue;
                }

                // check version conflicts
                var SBVersion  = ModManager.GetSBVersion();
                var MGSVersion = ModManager.GetMGSVersion();

                Version modSBVersion  = new Version();
                Version modMGSVersion = new Version();
                try
                {
                    modSBVersion  = metaData.SBVersion.AsVersion();
                    modMGSVersion = metaData.MGSVersion.AsVersion();
                }
                catch
                {
                    MessageBox.Show(String.Format("The selected version of {0} was created with an older version of SnakeBite and is no longer compatible, please download the latest version and try again.", metaData.Name), "Mod update required", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    ModFiles.RemoveAt(i);
                    continue;
                }

                // Check if mod requires SB update
                if (modSBVersion > SBVersion)
                {
                    MessageBox.Show(String.Format("{0} requires SnakeBite version {1} or newer. Please follow the link on the Settings page to get the latest version.", metaData.Name, metaData.SBVersion), "Update required", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    ModFiles.RemoveAt(i);
                    continue;
                }

                if (modSBVersion < new Version(0, 8, 0, 0)) // 0.8.0.0
                {
                    MessageBox.Show(String.Format("The selected version of {0} was created with an older version of SnakeBite and is no longer compatible, please download the latest version and try again.", metaData.Name), "Mod update required", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    ModFiles.RemoveAt(i);
                    continue;
                }

                // Check MGS version compatibility

                /* if (MGSVersion != modMGSVersion && modMGSVersion != new Version(0, 0, 0, 0))
                 * {
                 *   if (MGSVersion > modMGSVersion && modMGSVersion > new Version(0, 0, 0, 0))
                 *   {
                 *       var contInstall = MessageBox.Show(String.Format("{0} appears to be for an older version of MGSV. It is recommended that you at least check for an updated version before installing.\n\nWould you still like to install this mod?", metaData.Name), "Game version mismatch", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                 *       if (contInstall == DialogResult.No)
                 *       {
                 *           ModFiles.RemoveAt(i);
                 *           continue;
                 *       }
                 *   }
                 *   if (MGSVersion < modMGSVersion)
                 *   {
                 *       MessageBox.Show(String.Format("{0} requires MGSV version {1}, but your installation is version {2}. Please update MGSV and try again.", metaData.Name, modMGSVersion, MGSVersion), "Update required", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 *       ModFiles.RemoveAt(i);
                 *      continue;
                 *   }
                 * }
                 */
            }
        }
Пример #9
0
        public static bool CheckConflicts(string ModFile)
        { //Morbid: Conflict check has been reworked as of 0.9.0. CheckConflicts is now split into PreinstallManager.FilterModValidity and PreinstallManager.FilterModConflicts.
          //        CheckConflicts is only used for command-line installation.
            ModEntry metaData = Tools.ReadMetaData(ModFile);

            if (metaData == null)
            {
                return(false);
            }
            // check version conflicts
            var SBVersion  = ModManager.GetSBVersion();
            var MGSVersion = ModManager.GetMGSVersion();

            Version modSBVersion  = new Version();
            Version modMGSVersion = new Version();

            try
            {
                modSBVersion  = metaData.SBVersion.AsVersion();
                modMGSVersion = metaData.MGSVersion.AsVersion();
            }
            catch
            {
                MessageBox.Show(String.Format("The selected version of {0} was created with an older version of SnakeBite and is no longer compatible, please download the latest version and try again.", metaData.Name), "Mod update required", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }


            // Check if mod requires SB update
            if (modSBVersion > SBVersion)
            {
                MessageBox.Show(String.Format("{0} requires SnakeBite version {1} or newer. Please follow the link on the Settings page to get the latest version.", metaData.Name, metaData.SBVersion), "Update required", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            if (modSBVersion < new Version(0, 8, 0, 0)) // 0.8.0.0
            {
                MessageBox.Show(String.Format("The selected version of {0} was created with an older version of SnakeBite and is no longer compatible, please download the latest version and try again.", metaData.Name), "Mod update required", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            // Check MGS version compatibility
            if (MGSVersion != modMGSVersion && modMGSVersion != new Version(0, 0, 0, 0))
            {
                if (MGSVersion > modMGSVersion && modMGSVersion > new Version(0, 0, 0, 0))
                {
                    var contInstall = MessageBox.Show(String.Format("{0} appears to be for an older version of MGSV. It is recommended that you at least check for an updated version before installing.\n\nContinue installation?", metaData.Name), "Game version mismatch", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                    if (contInstall == DialogResult.No)
                    {
                        return(false);
                    }
                }
                if (MGSVersion < modMGSVersion)
                {
                    MessageBox.Show(String.Format("{0} requires MGSV version {1}, but your installation is version {2}. Please update MGSV and try again.", metaData.Name, modMGSVersion, MGSVersion), "Update required", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(false);
                }
            }
            //end of validity checks


            Debug.LogLine(String.Format("[Mod] Checking conflicts for {0}", metaData.Name));
            int confCounter = 0;
            // search installed mods for conflicts
            SettingsManager manager         = new SettingsManager(GameDir);
            var             mods            = manager.GetInstalledMods();
            List <string>   conflictingMods = new List <string>();
            int             confIndex       = -1;

            foreach (ModEntry mod in mods)                                  // iterate through installed mods
            {
                foreach (ModFileEntry fileEntry in metaData.ModFileEntries) // iterate external files from new mod
                {
                    ModFileEntry conflicts = mod.ModFileEntries.FirstOrDefault(entry => Tools.CompareHashes(entry.FilePath, fileEntry.FilePath));
                    if (conflicts != null)
                    {
                        if (confIndex == -1)
                        {
                            confIndex = mods.IndexOf(mod);
                        }
                        if (!conflictingMods.Contains(mod.Name))
                        {
                            conflictingMods.Add(mod.Name);
                        }
                        Debug.LogLine(String.Format("[{0}] Conflict in 00.dat: {1}", mod.Name, conflicts.FilePath));
                        confCounter++;
                    }
                }

                foreach (ModQarEntry qarEntry in metaData.ModQarEntries) // iterate qar files from new mod
                {
                    if (qarEntry.FilePath.Contains(".fpk"))
                    {
                        continue;
                    }
                    ModQarEntry conflicts = mod.ModQarEntries.FirstOrDefault(entry => Tools.CompareHashes(entry.FilePath, qarEntry.FilePath));
                    if (conflicts != null)
                    {
                        if (confIndex == -1)
                        {
                            confIndex = mods.IndexOf(mod);
                        }
                        if (!conflictingMods.Contains(mod.Name))
                        {
                            conflictingMods.Add(mod.Name);
                        }
                        Debug.LogLine(String.Format("[{0}] Conflict in 00.dat: {1}", mod.Name, conflicts.FilePath));
                        confCounter++;
                    }
                }

                foreach (ModFpkEntry fpkEntry in metaData.ModFpkEntries) // iterate fpk files from new mod
                {
                    ModFpkEntry conflicts = mod.ModFpkEntries.FirstOrDefault(entry => Tools.CompareHashes(entry.FpkFile, fpkEntry.FpkFile) &&
                                                                             Tools.CompareHashes(entry.FilePath, fpkEntry.FilePath));
                    if (conflicts != null)
                    {
                        if (confIndex == -1)
                        {
                            confIndex = mods.IndexOf(mod);
                        }
                        if (!conflictingMods.Contains(mod.Name))
                        {
                            conflictingMods.Add(mod.Name);
                        }
                        Debug.LogLine(String.Format("[{0}] Conflict in {2}: {1}", mod.Name, conflicts.FilePath, Path.GetFileName(conflicts.FpkFile)));
                        confCounter++;
                    }
                }
            }

            // if the mod conflicts, display message

            if (conflictingMods.Count > 0)
            {
                Debug.LogLine(String.Format("[Mod] Found {0} conflicts", confCounter));
                string msgboxtext = "The selected mod conflicts with these mods:\n";
                foreach (string Conflict in conflictingMods)
                {
                    msgboxtext += Conflict + "\n";
                }
                msgboxtext += "\nMore information regarding the conflicts has been output to the logfile.";
                MessageBox.Show(msgboxtext, "Installation Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            Debug.LogLine("[Mod] No conflicts found");

            bool sysConflict = false;
            // check for system file conflicts
            var gameData = manager.GetGameData();

            foreach (ModQarEntry gameQarFile in gameData.GameQarEntries.FindAll(entry => entry.SourceType == FileSource.System))
            {
                if (metaData.ModQarEntries.Count(entry => Tools.ToQarPath(entry.FilePath) == Tools.ToQarPath(gameQarFile.FilePath)) > 0)
                {
                    sysConflict = true;
                }
            }

            foreach (ModFpkEntry gameFpkFile in gameData.GameFpkEntries.FindAll(entry => entry.SourceType == FileSource.System))
            {
                if (metaData.ModFpkEntries.Count(entry => entry.FilePath == gameFpkFile.FilePath && entry.FpkFile == gameFpkFile.FpkFile) > 0)
                {
                    sysConflict = true;
                }
            }
            if (sysConflict)
            {
                //tex TODO: figure out what it's actually checking and how this can be corrupted
                string msgboxtext = "The selected mod conflicts with existing MGSV system files,\n";
                msgboxtext += "or the snakebite.xml base entries has become corrupt.\n";
                msgboxtext += "Please use the Restore Original Game Files option in Snakebite settings and re-run snakebite\n";
                MessageBox.Show(msgboxtext, "SnakeBite", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            return(true);
        }
Пример #10
0
        private static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            SettingsManager.DisableConflictCheck = false;
            if (Properties.Settings.Default.LastSBVersion == null || new Version(Properties.Settings.Default.LastSBVersion) < ModManager.GetSBVersion())
            {
                Properties.Settings.Default.Upgrade();
            }

            Properties.Settings.Default.LastSBVersion = ModManager.GetSBVersion().ToString();
            Properties.Settings.Default.Save();

            Debug.Clear();

            Debug.LogLine(String.Format(
                              "SnakeBite {0}\n" +
                              "{1}\n" +
                              "-------------------------",
                              ModManager.GetSBVersion(),
                              Environment.OSVersion.VersionString));

            // Delete old settings file
            if (File.Exists(ModManager.GameDir + "\\sbmods.xml"))
            {
                Debug.LogLine("Settings v0.7 or less detected, removing");
                File.Delete(ModManager.GameDir + "\\sbmods.xml");
                MessageBox.Show("Due to fundamental changes from version 0.8 onwards, your settings have been reset. Please re-verify or restore the game files and run the setup wizard before continuing.", "Version Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            bool showSetupWizard = false;

            if (!SettingsManager.SettingsExist() || !SettingsManager.ValidInstallPath)
            {
                showSetupWizard = true;
            }

            // Show wizard on first run, if folder is invalid or settings out of date
            while (showSetupWizard)
            {
                // show setup wizard
                Debug.LogLine("Showing setup wizard");
                SetupWizard.SetupWizard setupWizard = new SetupWizard.SetupWizard();
                var wizResult = setupWizard.ShowDialog();
                if (wizResult == DialogResult.Cancel)
                {
                    return;
                }
                if (wizResult == DialogResult.OK)
                {
                    showSetupWizard = false;
                }
            }



            string InitLog = String.Format(
                "MGS Install Folder: {0}\n" +
                "MGS Version: {1}\n" +
                "-------------------------",
                Properties.Settings.Default.InstallPath,
                ModManager.GetMGSVersion());

            Debug.LogLine(InitLog, Debug.LogLevel.Basic);



            // Process Command Line args
            // TODO: test all command line args

            // Uninstall SnakeBite
            if (args.Length == 1)
            {
                if (args[0] == "-completeuninstall")
                {
                    Debug.LogLine("Complete uninstall");
                    // Restore backup and remove settings
                    SettingsManager.DeleteSettings();
                    BackupManager.RestoreOriginals();
                    return;
                }
            }

            // Parse command line arguments
            bool   doCmdLine       = false;     // Process command line args?
            bool   closeApp        = false;     // Close app after?
            bool   install         = false;     // Install = true, uninstall = false
            bool   ignoreConflicts = false;     // Bypass conflict check
            bool   resetDatHash    = false;     // Rehash dat file
            string installFile     = String.Empty;

            if (args.Length > 0)
            {
                foreach (string arg in args)
                {
                    switch (arg.ToLower())
                    {
                    case "-i":
                        install = true;
                        break;

                    case "-u":
                        install = false;

                        break;

                    case "-c":
                        ignoreConflicts = true;
                        break;

                    case "-d":
                        resetDatHash = true;
                        break;

                    case "-x":
                        closeApp = true;
                        break;

                    default:
                        installFile = arg;
                        doCmdLine   = true;
                        break;
                    }
                }
            }

            // Update dat hash in settings
            if (resetDatHash)
            {
                Debug.LogLine("Resetting dat hash");
                SettingsManager.UpdateDatHash();
            }

            var checkDat = SettingsManager.ValidateDatHash();

            if (!checkDat)
            {
                MessageBox.Show("Game archive has been modified. The setup wizard will now run.", "Game data hash mismatch", MessageBoxButtons.OK, MessageBoxIcon.Error);
                SetupWizard.SetupWizard setupWizard = new SetupWizard.SetupWizard();
                setupWizard.ShowDialog();
            }

            if (doCmdLine)
            {
                Debug.LogLine("Doing cmd line args");
                formMods ModForm = new formMods();
                ModForm.Show();
                ModForm.Hide();
                if (install)
                {
                    // install
                    ModForm.ProcessInstallMod(installFile, ignoreConflicts); // install mod
                }
                else
                {
                    // uninstall
                    var      mods = SettingsManager.GetInstalledMods();
                    ModEntry mod  = mods.FirstOrDefault(entry => entry.Name == installFile); // select mod

                    if (mod != null)
                    {
                        ModForm.ProcessUninstallMod(mod); // uninstall mod
                    }
                }
                ModForm.Dispose();

                if (closeApp)
                {
                    return;
                }
            }

            //Application.Run(new formMain());
            Application.Run(new formLauncher());
        }
Пример #11
0
        private static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            ICSharpCode.SharpZipLib.Zip.ZipConstants.DefaultCodePage = 437;
            SettingsManager manager            = new SettingsManager(GamePaths.SnakeBiteSettings);
            bool            updateQarFilenames = false;

            if (Properties.Settings.Default.LastSBVersion == null || new Version(Properties.Settings.Default.LastSBVersion) < ModManager.GetSBVersion())
            {
                if (Properties.Settings.Default.LastSBVersion != null)
                {
                    updateQarFilenames = true;
                }
                Properties.Settings.Default.Upgrade();
            }

            Properties.Settings.Default.LastSBVersion = ModManager.GetSBVersion().ToString();
            Properties.Settings.Default.Save();

            Debug.Clear();

            Debug.LogLine(String.Format(
                              "SnakeBite {0}\n" +
                              "{1}\n" +
                              "-------------------------",
                              ModManager.GetSBVersion(),
                              Environment.OSVersion.VersionString));

            // Delete old settings file
            if (File.Exists(GamePaths.GameDir + "\\sbmods.xml"))
            {
                Debug.LogLine("Settings v0.7 or less detected, removing");
                File.Delete(GamePaths.GameDir + "\\sbmods.xml");
                MessageBox.Show("Due to fundamental changes from version 0.8 onwards, your settings have been reset. Please re-verify or restore the game files and run the setup wizard before continuing.", "Version Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            bool showSetupWizard = true;

            if (manager.SettingsExist() && manager.ValidInstallPath)
            {
                showSetupWizard = false;
            }

            // Show wizard on first run, if folder is invalid or settings out of date
            while (showSetupWizard)
            {
                // show setup wizard
                Debug.LogLine("[Setup] Starting Setup Wizard");
                try
                {
                    SetupWizard.SetupWizard setupWizard = new SetupWizard.SetupWizard();
                    var wizResult = setupWizard.ShowDialog();
                    if (wizResult == DialogResult.Cancel)
                    {
                        return;
                    }
                    if (wizResult == DialogResult.OK)
                    {
                        showSetupWizard = false;
                    }
                }
                catch (Exception e)
                {
                    Debug.LogLine("[Setup] Setup Wizard error: " + e.ToString());
                }
            }
            manager = new SettingsManager(GamePaths.SnakeBiteSettings);


            string InitLog = String.Format(
                "MGS Install Folder: {0}\n" +
                "MGS Version: {1}\n" +
                "-------------------------",
                Properties.Settings.Default.InstallPath,
                ModManager.GetMGSVersion());

            Debug.LogLine(InitLog, Debug.LogLevel.Basic);

            // Process Command Line args
            // Uninstall SnakeBite
            if (args.Length == 1)
            {
                if (args[0] == "-completeuninstall")
                {
                    Debug.LogLine("Complete uninstall");
                    // Restore backup and remove settings
                    manager.DeleteSettings();
                    BackupManager.RestoreOriginals();
                    return;
                }
            }

            // Parse command line arguments
            bool   doCmdLine          = false;  // Process command line args?
            bool   closeApp           = false;  // Close app after?
            bool   install            = false;  // Install = true, uninstall = false
            bool   resetDatHash       = false;  // Rehash dat file
            bool   skipConflictChecks = false;
            bool   skipCleanup        = false;  // Skip CleanupDatabase
            string installFile        = String.Empty;

            if (args.Length > 0)
            {
                foreach (string arg in args)
                {
                    switch (arg.ToLower())
                    {
                    case "-i":
                        install = true;
                        break;

                    case "-u":
                        install = false;
                        break;

                    case "-d":
                        resetDatHash = true;
                        break;

                    case "-x":
                        closeApp = true;
                        break;

                    case "-s":
                        skipCleanup = true;
                        break;

                    case "-c":
                        skipConflictChecks = true;
                        break;

                    default:
                        installFile = arg;
                        doCmdLine   = true;
                        break;
                    }
                }
            }
            // Update dat hash in settings
            if (resetDatHash)
            {
                Debug.LogLine("Resetting dat hash");
                manager.UpdateDatHash();
            }
            if (ModManager.GetMGSVersion() > SettingsManager.IntendedGameVersion)
            {
                var contSB = MessageBox.Show("Due to a recent game update, this version of SnakeBite is outdated, and some features will not function properly.\n\nIt is highly recommended that you do not continue, and update to the latest version of Snakebite when it becomes available.\n\nWould you still like to continue? ", "Game Version Update", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                if (contSB == DialogResult.No)
                {
                    return;
                }
            }
            if (!File.Exists(GamePaths.ZeroPath) || !File.Exists(GamePaths.OnePath))
            {
                MessageBox.Show(string.Format("Critical Error: SnakeBite could not locate critical game data! \n\n({0})\nand/or\n({1}).\n\nRestore your game files with backups, MGSVPreset files, or revalidating through Steam!", GamePaths.ZeroPath, GamePaths.OnePath), "Archive(s) Not Found", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                try
                {
                    bool checkDat = false;

                    if (updateQarFilenames)
                    {
                        manager.updateQarFileNames();
                    }

                    checkDat = manager.ValidateDatHash();

                    if (!checkDat || manager.IsVanilla0001DatHash())
                    {
                        if (manager.IsVanilla0001DatHash() || manager.IsVanilla0001Size())
                        {
                            MessageBox.Show("Fresh 00.dat/01.dat detected. The setup wizard will now run.", "Game data hash mismatch", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        else
                        {
                            MessageBox.Show("Game archive has been modified. The setup wizard will now run.", "Game data hash mismatch", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }

                        SetupWizard.SetupWizard setupWizard = new SetupWizard.SetupWizard();
                        setupWizard.ShowDialog();
                    }
                    else if (!BackupManager.c7t7Exist()) // chunk7 and/or texture7 are missing, despite the dathash validating.
                    {
                        MessageBox.Show("To continue, SnakeBite must build a_chunk7.dat and a_texture7.dat from your current archives. The setup wizard will now run.", "Setup required", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        SetupWizard.SetupWizard setupWizard = new SetupWizard.SetupWizard();
                        setupWizard.ShowDialog();
                    }
                }
                catch (InvalidOperationException e)
                {
                    if (File.Exists(GamePaths.OnePath) && File.Exists(GamePaths.ZeroPath))
                    {
                        if (manager.IsVanilla0001Size())
                        {
                            File.Delete(GamePaths.SnakeBiteSettings);
                            SetupWizard.SetupWizard setupWizard = new SetupWizard.SetupWizard();
                            setupWizard.ShowDialog();
                        }
                    }
                    MessageBox.Show(string.Format("Critical Error: SnakeBite could not read settings data! \n\n({0})\n\nRestore your game files with backups, MGSVPreset files, or revalidating through Steam!", GamePaths.SnakeBiteSettings), "Failed To Read Settings", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Debug.LogLine("Error: ValidateDatHash failed: " + e);
                }
            }

            if (doCmdLine)
            {
                Debug.LogLine("Doing cmd line args");
                formMods ModForm = new formMods();
                ModForm.Show();
                ModForm.Hide();
                if (install)
                {
                    ModForm.ProcessInstallMod(installFile, skipConflictChecks, skipCleanup); // install mod
                }
                else
                {
                    // uninstall
                    var      mods = manager.GetInstalledMods();
                    ModEntry mod  = mods.FirstOrDefault(entry => entry.Name == installFile); // select mod
                    if (mod != null)
                    {
                        ModForm.ProcessUninstallMod(mod, skipCleanup); // uninstall mod
                    }
                }
                ModForm.Dispose();

                if (closeApp)
                {
                    return;
                }
            }

            if (Properties.Settings.Default.SkipLauncher)
            {
                Application.Run(new formMods());
            }
            else
            {
                Application.Run(new formLauncher());
            }
        }
Пример #12
0
        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);
            }
        }
Пример #13
0
        public static bool CheckConflicts(string ModFile, bool ignoreConflicts = false)
        {
            var metaData = Tools.ReadMetaData(ModFile);

            if (metaData == null)
            {
                return(false);
            }

            if (!SettingsManager.DisableConflictCheck && !ignoreConflicts)
            {
                // check version conflicts
                var SBVersion  = ModManager.GetSBVersion();
                var MGSVersion = ModManager.GetMGSVersion();

                Version modSBVersion  = new Version();
                Version modMGSVersion = new Version();
                try
                {
                    modSBVersion  = metaData.SBVersion.AsVersion();
                    modMGSVersion = metaData.MGSVersion.AsVersion();
                }
                catch
                {
                    MessageBox.Show(String.Format("The selected version of {0} was created with an older version of SnakeBite and is no longer compatible, please download the latest version and try again.", metaData.Name), "Mod update required", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(false);
                }


                // Check if mod requires SB update
                if (modSBVersion > SBVersion)
                {
                    MessageBox.Show(String.Format("{0} requires a newer version of SnakeBite. Please follow the link on the Settings page to get the latest version.", metaData.Name), "Update required", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(false);
                }

                if (modSBVersion < new Version(0, 8, 0, 0)) // 0.8.0.0
                {
                    MessageBox.Show(String.Format("The selected version of {0} was created with an older version of SnakeBite and is no longer compatible, please download the latest version and try again.", metaData.Name), "Mod update required", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(false);
                }

                // Check MGS version compatibility
                if (MGSVersion != modMGSVersion && modMGSVersion != new Version(0, 0, 0, 0))
                {
                    if (MGSVersion > modMGSVersion && modMGSVersion > new Version(0, 0, 0, 0))
                    {
                        var contInstall = MessageBox.Show(String.Format("{0} appears to be for an older version of MGSV. It is recommended that you at least check for an updated version before installing.\n\nContinue installation?", metaData.Name, modMGSVersion, MGSVersion), "Game version mismatch", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                        if (contInstall == DialogResult.No)
                        {
                            return(false);
                        }
                    }
                    if (MGSVersion < modMGSVersion)
                    {
                        MessageBox.Show(String.Format("{0} requires MGSV version {1}, but your installation is version {2}. Please update MGSV and try again.", metaData.Name, modMGSVersion, MGSVersion), "Update required", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return(false);
                    }
                }

                Debug.LogLine(String.Format("[Mod] Checking conflicts for {0}", metaData.Name));
                int confCounter = 0;
                // search installed mods for conflicts
                var           mods            = SettingsManager.GetInstalledMods();
                List <string> conflictingMods = new List <string>();
                int           confIndex       = -1;
                foreach (ModEntry mod in mods)                               // iterate through installed mods
                {
                    foreach (ModQarEntry qarEntry in metaData.ModQarEntries) // iterate qar files from new mod
                    {
                        if (qarEntry.FilePath.Contains(".fpk"))
                        {
                            continue;
                        }
                        ModQarEntry conflicts = mod.ModQarEntries.FirstOrDefault(entry => Tools.CompareHashes(entry.FilePath, qarEntry.FilePath));
                        if (conflicts != null)
                        {
                            if (confIndex == -1)
                            {
                                confIndex = mods.IndexOf(mod);
                            }
                            if (!conflictingMods.Contains(mod.Name))
                            {
                                conflictingMods.Add(mod.Name);
                            }
                            Debug.LogLine(String.Format("[{0}] Conflict in 00.dat: {1}", mod.Name, conflicts.FilePath));
                            confCounter++;
                        }
                    }

                    foreach (ModFpkEntry fpkEntry in metaData.ModFpkEntries) // iterate fpk files from new mod
                    {
                        ModFpkEntry conflicts = mod.ModFpkEntries.FirstOrDefault(entry => Tools.CompareHashes(entry.FpkFile, fpkEntry.FpkFile) &&
                                                                                 Tools.CompareHashes(entry.FilePath, fpkEntry.FilePath));
                        if (conflicts != null)
                        {
                            if (confIndex == -1)
                            {
                                confIndex = mods.IndexOf(mod);
                            }
                            if (!conflictingMods.Contains(mod.Name))
                            {
                                conflictingMods.Add(mod.Name);
                            }
                            Debug.LogLine(String.Format("[{0}] Conflict in {2}: {1}", mod.Name, conflicts.FilePath, Path.GetFileName(conflicts.FpkFile)));
                            confCounter++;
                        }
                    }
                }

                // if the mod conflicts, display message

                if (conflictingMods.Count > 0)
                {
                    Debug.LogLine(String.Format("[Mod] Found {0} conflicts", confCounter));
                    string msgboxtext = "The selected mod conflicts with these mods:\n";
                    foreach (string Conflict in conflictingMods)
                    {
                        msgboxtext += Conflict + "\n";
                    }
                    msgboxtext += "\nMore information regarding the conflicts has been output to the logfile. Double click the version number shown in the Launcher to view the current logfile.";
                    MessageBox.Show(msgboxtext, "Installation Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(false);
                }

                Debug.LogLine("[Mod] No conflicts found");

                bool sysConflict = false;
                // check for system file conflicts
                var gameData = SettingsManager.GetGameData();
                foreach (ModQarEntry gameQarFile in gameData.GameQarEntries.FindAll(entry => entry.SourceType == FileSource.System))
                {
                    if (metaData.ModQarEntries.Count(entry => Tools.ToQarPath(entry.FilePath) == Tools.ToQarPath(gameQarFile.FilePath)) > 0)
                    {
                        sysConflict = true;
                    }
                }

                foreach (ModFpkEntry gameFpkFile in gameData.GameFpkEntries.FindAll(entry => entry.SourceType == FileSource.System))
                {
                    if (metaData.ModFpkEntries.Count(entry => entry.FilePath == gameFpkFile.FilePath && entry.FpkFile == gameFpkFile.FpkFile) > 0)
                    {
                        sysConflict = true;
                    }
                }
                if (sysConflict)
                {
                    MessageBox.Show("The selected mod conflicts with existing MGSV system files.", "SnakeBite", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(false);
                }

                DialogResult confirmInstall = MessageBox.Show(String.Format("You are about to install {0}, continue?", metaData.Name), "SnakeBite", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (confirmInstall == DialogResult.No)
                {
                    return(false);
                }
            }
            return(true);
        }