Ejemplo n.º 1
0
        /// <summary>
        /// move vanilla 00 files to 01, moves vanilla 01 textures to texture7, cleans snakebite.xml 
        /// as DoWorkEventHandler
        /// </summary>
        public static void backgroundWorker_MergeAndCleanup(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker mergeProcessor = (BackgroundWorker)sender;
            try
            {
                GzsLib.LoadDictionaries();
                ClearBuildFiles(c7Path, t7Path, ZeroPath, OnePath, SnakeBiteSettings, SavePresetPath);
                ClearSBGameDir();
                CleanupFolders();
                
                mergeProcessor.ReportProgress(0, $"Migrating files to new archives ({Tools.GetFileSizeKB(ZeroPath, OnePath)} KB)");
                if (!MoveDatFiles()) //moves vanilla 00 files into 01, excluding foxpatch. 
                {
                    Debug.LogLine("[DatMerge] Failed to complete archive migration. Cancelling...");
                    e.Cancel = true;
                    ClearBuildFiles(c7Path, t7Path, ZeroPath, OnePath);
                    return;
                }

                mergeProcessor.ReportProgress(0, $"Modfying foxfs in chunk0.dat ({Tools.GetFileSizeKB(chunk0Path)} KB)");
                if (!ModifyFoxfs()) // adds lines to foxfs in chunk0.
                {
                    Debug.LogLine("[ModifyFoxfs] Failed to complete Foxfs modification. Cancelling...");
                    e.Cancel = true;
                    ClearBuildFiles(c7Path, t7Path, ZeroPath, OnePath, chunk0Path);
                    return;
                }

                mergeProcessor.ReportProgress(0, "Promoting new archives");
                PromoteBuildFiles(c7Path, t7Path, ZeroPath, OnePath, chunk0Path); // overwrites existing archives with modified archives

                mergeProcessor.ReportProgress(0, "Cleaning database");
                CleanupDatabase();
            }
            catch (Exception f)
            {
                MessageBox.Show(string.Format("An error has occurred while attempting to merge or clean up SnakeBite data: {0}", f), "Exception Occurred", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Debug.LogLine(string.Format("[MergeAndCleanup] Exception Occurred: {0}", f), Debug.LogLevel.Basic);
                Debug.LogLine("[MergeAndCleanup] SnakeBite has failed to merge and clean up SnakeBite data", Debug.LogLevel.Basic);
                e.Cancel = true;
                try
                {
                    ClearBuildFiles(c7Path, t7Path, ZeroPath, OnePath, chunk0Path);
                }
                catch (Exception g)
                {
                    Debug.LogLine(string.Format("[MergeAndCleanup] Exception Occurred: {0}", g), Debug.LogLevel.Basic);
                    Debug.LogLine("[MergeAndCleanup] SnakeBite has failed to remove the build files.", Debug.LogLevel.Basic);
                }
                return;
            }
        }
Ejemplo n.º 2
0
        public static bool UninstallMods(CheckedListBox.CheckedIndexCollection modIndices, bool skipCleanup = false) // Uninstalls mods based on their indices in the list
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            Debug.LogLine("[Uninstall] Start", Debug.LogLevel.Basic);

            // initial cleanup
            ModManager.ClearBuildFiles(ZeroPath, OnePath, SnakeBiteSettings, SavePresetPath);
            ModManager.ClearSBGameDir();
            ModManager.CleanupFolders();

            // backup preset build
            if (Properties.Settings.Default.AutosaveRevertPreset == true)
            {
                PresetManager.SavePreset(SavePresetPath + build_ext);
            }
            else
            {
                Debug.LogLine("[Uninstall] Skipping RevertChanges.MGSVPreset Save", Debug.LogLevel.Basic);
            }

            GzsLib.LoadDictionaries();
            File.Copy(SnakeBiteSettings, SnakeBiteSettings + build_ext, true);
            List <ModEntry> mods = SBBuildManager.GetInstalledMods();

            List <ModEntry> selectedMods = new List <ModEntry>();

            foreach (int index in modIndices)
            {
                ModEntry mod = mods[index];
                selectedMods.Add(mod);
            }

            List <string> zeroFiles  = new List <string>();
            bool          hasQarZero = ModManager.hasQarZeroFiles(selectedMods);

            if (hasQarZero)
            {
                // if necessary, extracts 00.dat and creates a list of filenames, which is pruned throughout the uninstall process and repacked at the end.
                zeroFiles = GzsLib.ExtractArchive <QarFile>(ZeroPath, "_working0");
                zeroFiles.RemoveAll(file => file.EndsWith("_unknown"));
            }

            List <string> oneFiles = null;
            bool          hasFtexs = ModManager.foundLooseFtexs(selectedMods);

            if (hasFtexs)
            {
                // if necessary, extracts 01.dat and creates a list of filenames similar to zeroFiles. only textures are pruned from the list.
                oneFiles = GzsLib.ExtractArchive <QarFile>(OnePath, "_working1");
                oneFiles.RemoveAll(file => file.EndsWith("_unknown"));
            }

            //end of qar extraction
            GameData gameData = SBBuildManager.GetGameData();

            ModManager.ValidateGameData(ref gameData, ref zeroFiles);

            Debug.LogLine("[Uninstall] Building gameFiles lists", Debug.LogLevel.Basic);
            var baseGameFiles = GzsLib.ReadBaseData();

            try
            {
                ModManager.PrepGameDirFiles();
                // begin uninstall
                UninstallMods(selectedMods, ref zeroFiles, ref oneFiles);

                if (hasQarZero)
                {
                    zeroFiles.Sort();
                    GzsLib.WriteQarArchive(ZeroPath + build_ext, "_working0", zeroFiles, GzsLib.zeroFlags);
                }

                if (hasFtexs)
                {
                    oneFiles.Sort();
                    GzsLib.WriteQarArchive(OnePath + build_ext, "_working1", oneFiles, GzsLib.oneFlags);
                }
                // end of qar rebuild

                // overwrite old mod data
                ModManager.PromoteGameDirFiles();
                ModManager.PromoteBuildFiles(ZeroPath, OnePath, SnakeBiteSettings, SavePresetPath);

                if (!skipCleanup)
                {
                    ModManager.CleanupFolders();
                    ModManager.ClearSBGameDir();
                }

                Debug.LogLine("[Uninstall] Uninstall complete", Debug.LogLevel.Basic);
                stopwatch.Stop();
                Debug.LogLine($"[Uninstall] Uninstall took {stopwatch.ElapsedMilliseconds} ms", Debug.LogLevel.Basic);
                return(true);
            }
            catch (Exception e)
            {
                Debug.LogLine("[Uninstall] Exception: " + e, Debug.LogLevel.Basic);
                stopwatch.Stop();
                Debug.LogLine($"[Uninstall] Uninstall failed at {stopwatch.ElapsedMilliseconds} ms", Debug.LogLevel.Basic);
                MessageBox.Show("An error has occurred during the uninstallation process and SnakeBite could not uninstall the selected mod(s).\nException: " + e);

                // clean up failed files
                ModManager.ClearBuildFiles(ZeroPath, OnePath, SnakeBiteSettings, SavePresetPath);
                ModManager.CleanupFolders();

                bool restoreRetry = false;
                do
                {
                    try
                    {
                        ModManager.RestoreBackupGameDir(SBBuildManager);
                    }
                    catch (Exception f)
                    {
                        Debug.LogLine("[Uninstall] Exception: " + f, Debug.LogLevel.Basic);
                        restoreRetry = DialogResult.Retry == MessageBox.Show("SnakeBite could not restore Game Directory mod files due to the following exception: {f} \nWould you like to retry?", "Exception Occurred", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
                    }
                } while (restoreRetry);

                ModManager.ClearSBGameDir();
                return(false);
            }
        }//UninstallMod batch
Ejemplo n.º 3
0
        public static bool InstallMods(List <string> ModFiles, bool skipCleanup = false)
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            Debug.LogLine("[Install] Start", Debug.LogLevel.Basic);
            ModManager.ClearBuildFiles(ZeroPath, OnePath, SnakeBiteSettings, SavePresetPath); // deletes any leftover sb_build files that might still be in the directory (ie from a mid-process shutdown)
            ModManager.ClearSBGameDir();                                                      // deletes the game directory sb_build
            ModManager.CleanupFolders();                                                      // deletes the work folders which contain extracted files from 00/01

            if (Properties.Settings.Default.AutosaveRevertPreset == true)
            {
                PresetManager.SavePreset(SavePresetPath + build_ext); // creates a backup preset file sb_build
            }
            else
            {
                Debug.LogLine("[Install] Skipping RevertChanges.MGSVPreset Save", Debug.LogLevel.Basic);
            }
            File.Copy(SnakeBiteSettings, SnakeBiteSettings + build_ext, true); // creates a settings sb_build

            GzsLib.LoadDictionaries();
            List <ModEntry> installEntryList = new List <ModEntry>();

            foreach (string modFile in ModFiles)
            {
                installEntryList.Add(Tools.ReadMetaData(modFile));
            }


            List <string> zeroFiles  = new List <string>();
            bool          hasQarZero = ModManager.hasQarZeroFiles(installEntryList);

            if (hasQarZero)
            {
                zeroFiles = GzsLib.ExtractArchive <QarFile>(ZeroPath, "_working0");
            }

            List <string> oneFiles = null;
            bool          hasFtexs = ModManager.foundLooseFtexs(installEntryList);

            if (hasFtexs)
            {
                oneFiles = GzsLib.ExtractArchive <QarFile>(OnePath, "_working1");
            }

            SettingsManager SBBuildManager = new SettingsManager(SnakeBiteSettings + build_ext);
            var             gameData       = SBBuildManager.GetGameData();

            ModManager.ValidateGameData(ref gameData, ref zeroFiles);

            var zeroFilesHashSet = new HashSet <string>(zeroFiles);

            Debug.LogLine("[Install] Building gameFiles lists", Debug.LogLevel.Basic);
            var baseGameFiles   = GzsLib.ReadBaseData();
            var allQarGameFiles = new List <Dictionary <ulong, GameFile> >();

            allQarGameFiles.AddRange(baseGameFiles);


            try
            {
                ModManager.PrepGameDirFiles();
                List <string> pullFromVanillas; List <string> pullFromMods; Dictionary <string, bool> pathUpdatesExist;

                Debug.LogLine("[Install] Writing FPK data to Settings", Debug.LogLevel.Basic);
                AddToSettingsFpk(installEntryList, SBBuildManager, allQarGameFiles, out pullFromVanillas, out pullFromMods, out pathUpdatesExist);
                InstallMods(ModFiles, SBBuildManager, pullFromVanillas, pullFromMods, ref zeroFilesHashSet, ref oneFiles, pathUpdatesExist);

                if (hasQarZero)
                {
                    zeroFiles = zeroFilesHashSet.ToList();
                    zeroFiles.Sort();
                    GzsLib.WriteQarArchive(ZeroPath + build_ext, "_working0", zeroFiles, GzsLib.zeroFlags);
                }
                if (hasFtexs)
                {
                    oneFiles.Sort();
                    GzsLib.WriteQarArchive(OnePath + build_ext, "_working1", oneFiles, GzsLib.oneFlags);
                }

                ModManager.PromoteGameDirFiles();
                ModManager.PromoteBuildFiles(ZeroPath, OnePath, SnakeBiteSettings, SavePresetPath);

                if (!skipCleanup)
                {
                    ModManager.CleanupFolders();
                    ModManager.ClearSBGameDir();
                }

                stopwatch.Stop();
                Debug.LogLine($"[Install] Installation finished in {stopwatch.ElapsedMilliseconds} ms", Debug.LogLevel.Basic);
                return(true);
            }
            catch (Exception e)
            {
                stopwatch.Stop();
                Debug.LogLine($"[Install] Installation failed at {stopwatch.ElapsedMilliseconds} ms", Debug.LogLevel.Basic);
                Debug.LogLine("[Install] Exception: " + e, Debug.LogLevel.Basic);
                MessageBox.Show("An error has occurred during the installation process and SnakeBite could not install the selected mod(s).\nException: " + e, "Mod(s) could not be installed", MessageBoxButtons.OK, MessageBoxIcon.Error);

                ModManager.ClearBuildFiles(ZeroPath, OnePath, SnakeBiteSettings, SavePresetPath);
                ModManager.CleanupFolders();

                bool restoreRetry = false;
                do
                {
                    try
                    {
                        ModManager.RestoreBackupGameDir(SBBuildManager);
                    }
                    catch (Exception f)
                    {
                        Debug.LogLine("[Uninstall] Exception: " + f, Debug.LogLevel.Basic);
                        restoreRetry = DialogResult.Retry == MessageBox.Show("SnakeBite could not restore Game Directory mod files due to the following exception: {f} \nWould you like to retry?", "Exception Occurred", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
                    }
                } while (restoreRetry);

                ModManager.ClearSBGameDir();
                return(false);
            }
        }