Пример #1
0
        /// <summary>
        /// Creates a .MGSVPreset file for the mods that are currently installed
        /// </summary>
        public static bool SavePreset(string presetFilePath)
        {
            bool success = false;

            Directory.CreateDirectory("_build\\master\\0");
            SettingsManager manager    = new SettingsManager(SnakeBiteSettings);
            string          presetName = Path.GetFileName(presetFilePath);

            Debug.LogLine($"[SavePreset] Saving {presetName}...", Debug.LogLevel.Basic);
            try
            {
                foreach (string gameFile in manager.GetModExternalFiles())
                {
                    string sourcePath = Path.Combine(GameDir, Tools.ToWinPath(gameFile));

                    string DestDir  = "_build\\" + Path.GetDirectoryName(gameFile);
                    string fileName = Path.GetFileName(gameFile);

                    Directory.CreateDirectory(DestDir);
                    if (File.Exists(sourcePath))
                    {
                        Debug.LogLine(string.Format("[SavePreset] Copying to build directory: {0}", gameFile), Debug.LogLevel.Basic);  File.Copy(sourcePath, Path.Combine(DestDir, fileName), true);
                    }
                    else
                    {
                        Debug.LogLine(string.Format("[SavePreset] File not found: {0}", sourcePath), Debug.LogLevel.Basic);
                    }
                }
                Debug.LogLine("[SavePreset] Copying to build directory: 00.dat", Debug.LogLevel.Basic);
                File.Copy(ZeroPath, "_build\\master\\0\\00.dat", true);

                Debug.LogLine("[SavePreset] Copying to build directory: 01.dat", Debug.LogLevel.Basic);
                File.Copy(OnePath, "_build\\master\\0\\01.dat", true);

                Debug.LogLine("[SavePreset] Copying to build directory: snakebite.xml", Debug.LogLevel.Basic);
                File.Copy(SnakeBiteSettings, "_build\\snakebite.xml", true);

                if (presetFilePath == SavePresetPath + build_ext)
                {
                    Debug.LogLine($"Note: '{Path.GetFileNameWithoutExtension(presetName)}' can be disabled in the Settings menu to save time during installation and uninstallation.", Debug.LogLevel.Basic);
                }

                FastZip zipper = new FastZip();
                Debug.LogLine(string.Format("[SavePreset] Writing {0}...", presetName), Debug.LogLevel.Basic);
                zipper.CreateZip(presetFilePath, "_build", true, "(.*?)");
                Debug.LogLine("[SavePreset] Write Complete", Debug.LogLevel.Basic);
                success = true;
            }
            catch (Exception e)
            {
                MessageBox.Show("An error has occurred and the preset was not saved.\nException: " + e);
            }
            finally
            {
                ModManager.CleanupFolders();
            }

            return(success);
        }
Пример #2
0
        public static void RestoreBackupGameDir(SettingsManager SBBuildSettings)
        {
            Debug.LogLine("[SB_Build] Promoting SB_Build Game Directory", Debug.LogLevel.Basic);
            if (!Directory.Exists(GameDirBackup_Build))
            {
                Debug.LogLine($"[SB_Build] Directory not found: {GameDirBackup_Build}", Debug.LogLevel.Basic);
                return;
            }

            List<string> fileEntryDirs = new List<string>();
            foreach (string externalBuildFiles in SBBuildSettings.GetModExternalFiles())
            {
                string fileModPath = Tools.ToWinPath(externalBuildFiles);
                string sourceFullPath = Path.Combine(GameDir, fileModPath);

                string sourceDir = Path.GetDirectoryName(sourceFullPath);
                if (!fileEntryDirs.Contains(sourceDir)) fileEntryDirs.Add(sourceDir);

                if (File.Exists(sourceFullPath)) File.Delete(sourceFullPath); // deletes all of the new snakebite.xml's managed files
                else Debug.LogLine(string.Format("[SB_Build] File not found: {0}", sourceFullPath), Debug.LogLevel.Basic);
            }

            Tools.DirectoryCopy(GameDirBackup_Build, GameDir, true); // moves all gamedir_backup_build files over

            foreach (string fileEntryDir in fileEntryDirs) //all the directories that have had files deleted within them
            {
                if (Directory.Exists(fileEntryDir) && Directory.GetFiles(fileEntryDir).Length == 0) // if the directory has not yet been deleted and there are no more files inside the directory
                {
                    Debug.LogLine(String.Format("[SB_Build] deleting empty folder: {0}", fileEntryDir), Debug.LogLevel.All);
                    try
                    {
                        Directory.Delete(fileEntryDir);
                    }
                    catch
                    {
                        Console.WriteLine("[Uninstall] Could not delete: " + fileEntryDir);
                    }
                }
            }
        }
Пример #3
0
        /// <summary>
        /// overwrites existing mods with the set of mods stored in the .MGSVPreset file
        /// </summary>
        public static bool LoadPreset(string presetFilePath)
        {
            bool panicMode = (!File.Exists(ZeroPath) || !File.Exists(OnePath) || !File.Exists(SnakeBiteSettings));
            bool success   = false;

            ModManager.CleanupFolders();
            SettingsManager manager = new SettingsManager(SnakeBiteSettings);
            List <string>   existingExternalFiles = new List <string>();
            List <string>   fileEntryDirs         = new List <string>();

            try
            {
                existingExternalFiles = manager.GetModExternalFiles();
            }
            catch
            {
                panicMode = true;
            }
            try
            {
                if (!panicMode)
                {
                    Debug.LogLine("[LoadPreset] Storing backups of existing files...", Debug.LogLevel.Basic);
                    foreach (string gameFile in existingExternalFiles)
                    {
                        string gameFilePath = Path.Combine(GameDir, Tools.ToWinPath(gameFile));
                        if (File.Exists(gameFilePath)) // only stores backups of managed files
                        {
                            Debug.LogLine(string.Format("[LoadPreset] Storing backup: {0}", gameFile), Debug.LogLevel.Basic);
                            fileEntryDirs.Add(Path.GetDirectoryName(gameFilePath));
                            if (File.Exists(gameFilePath + build_ext))
                            {
                                File.Delete(gameFilePath + build_ext);
                            }
                            File.Move(gameFilePath, gameFilePath + build_ext);
                        }
                    }
                    Debug.LogLine("[LoadPreset] Storing backup: 00.dat", Debug.LogLevel.Basic);
                    File.Copy(ZeroPath, ZeroPath + build_ext, true);

                    Debug.LogLine("[LoadPreset] Storing backup: 01.dat", Debug.LogLevel.Basic);
                    File.Copy(OnePath, OnePath + build_ext, true);

                    Debug.LogLine("[LoadPreset] Storing backup: snakebite.xml", Debug.LogLevel.Basic);
                    File.Copy(SnakeBiteSettings, SnakeBiteSettings + build_ext, true);
                }
                else
                {
                    Debug.LogLine("[LoadPreset] Critical file(s) are disfunctional or not found, skipping backup procedure", Debug.LogLevel.Basic);
                }

                Debug.LogLine("[LoadPreset] Importing preset files", Debug.LogLevel.Basic);
                FastZip unzipper = new FastZip();
                unzipper.ExtractZip(presetFilePath, GameDir, "(.*?)");

                Debug.LogLine("[LoadPreset] Import Complete", Debug.LogLevel.Basic);
                success = true;
            }
            catch (Exception e)
            {
                MessageBox.Show("An error has occurred and the preset was not imported.\nException: " + e);
                if (!panicMode)
                {
                    Debug.LogLine("[LoadPreset] Restoring backup files", Debug.LogLevel.Basic);

                    File.Copy(ZeroPath + build_ext, ZeroPath, true);
                    File.Copy(OnePath + build_ext, OnePath, true);
                    File.Copy(SnakeBiteSettings + build_ext, SnakeBiteSettings, true);

                    foreach (string gameFile in existingExternalFiles)
                    {
                        string gameFilePath = Path.Combine(GameDir, Tools.ToWinPath(gameFile));
                        if (File.Exists(gameFilePath + build_ext))
                        {
                            File.Copy(gameFilePath + build_ext, gameFilePath, true);
                        }
                    }
                }
            }
            finally
            {
                if (!panicMode)
                {
                    Debug.LogLine("[LoadPreset] Removing backup files", Debug.LogLevel.Basic);
                    foreach (string gameFile in existingExternalFiles)
                    {
                        string gameFilePath = Path.Combine(GameDir, Tools.ToWinPath(gameFile));
                        if (File.Exists(gameFilePath))
                        {
                            File.Delete(gameFilePath + build_ext);
                        }
                    }

                    foreach (string fileEntryDir in fileEntryDirs)
                    {
                        if (Directory.Exists(fileEntryDir))
                        {
                            try
                            {
                                if (Directory.GetFiles(fileEntryDir).Length == 0)
                                {
                                    Debug.LogLine(String.Format("[SB_Build] deleting empty folder: {0}", fileEntryDir), Debug.LogLevel.All);
                                    Directory.Delete(fileEntryDir);
                                }
                            }

                            catch
                            {
                                Debug.LogLine("[Uninstall] Could not delete: " + fileEntryDir);
                            }
                        }
                    }
                    File.Delete(ZeroPath + build_ext);
                    File.Delete(OnePath + build_ext);
                    File.Delete(SnakeBiteSettings + build_ext);
                }
            }

            return(success);
        }