public static void DownloadModFile(string SourceUrl, string DestFile) { Debug.LogLine(String.Format("[Web] Downloading {0}", SourceUrl)); WebClient modWebClient = new WebClient(); modWebClient.Headers.Add("User-Agent", string.Format("SnakeBite/{0}", ModManager.GetSBVersion())); modWebClient.DownloadFile(new Uri(SourceUrl), DestFile); }
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; } } }
public void Save() { // Write settings to XML using (FileStream s = new FileStream(Path.Combine(ModManager.GameDir, "snakebite.xml"), 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(); x.Serialize(s, this); } }
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); } }
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; * } * } */ } }
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); }
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()); }
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()); } }
private void formLauncher_Load(object sender, EventArgs e) { textInfo = cultureInfo.TextInfo; // Check for updates Debug.LogLine("[Update] Checking for updates"); UpdateFile updater = new UpdateFile(); bool updateSuccess = updater.ReadXmlFromInterweb("http://www.xobanimot.com/snakebite/update/update.xml"); if (updateSuccess) { if (updater.SnakeBite.Version.AsVersion() > ModManager.GetSBVersion()) { Debug.LogLine(String.Format("Update found! Version {0} is available", updater.SnakeBite.Version.AsVersion())); labelUpdate.Text = String.Format("SnakeBite version {0} now available!", updater.SnakeBite.Version.AsString()); labelUpdate.Show(); } else { Debug.LogLine("No update found"); } } // Retrieve and display version info var MGSVersionInfo = FileVersionInfo.GetVersionInfo(Properties.Settings.Default.InstallPath + "\\mgsvtpp.exe"); string SBVersion = Application.ProductVersion; string MGSVersion = MGSVersionInfo.ProductVersion; // Update version text string VersionText = String.Format("MGSV {0} / SB {1}", MGSVersion, SBVersion); labelVersion.Text = VersionText; UpdateVersionLabel(); UpdateModToggle(); SetupTheme(); // Fade in form Opacity = 0; int duration = 100;//in milliseconds int steps = 30; Timer timer = new Timer(); timer.Interval = duration / steps; int currentStep = 0; timer.Tick += (arg1, arg2) => { Opacity = ((double)currentStep) / steps; currentStep++; if (Opacity == 1) { timer.Stop(); timer.Dispose(); } }; timer.Start(); }
public static List <WebMod> GetOnlineMods() { Debug.LogLine("[Web] Fetching online mod list"); WebClient modListClient = new WebClient(); modListClient.Headers.Add("User-Agent", string.Format("{0}/SnakeBite-{1}", Environment.OSVersion.VersionString, ModManager.GetSBVersion())); List <WebMod> WebMods; try { string webModData = modListClient.DownloadString(new Uri(MODLIST_URL)); XmlSerializer x = new XmlSerializer(typeof(List <WebMod>)); StringReader s = new StringReader(webModData); XmlReader r = XmlReader.Create(s); WebMods = (List <WebMod>)x.Deserialize(r); foreach (WebMod mod in WebMods) { mod.Description = mod.Description.Replace("\n", "\r\n"); } Debug.LogLine("[Web] Download successful"); } catch { Debug.LogLine("[Web] Download failed", Debug.LogLevel.Debug); WebMods = new List <WebMod>(); } return(WebMods); }
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); }