LogLine() public static method

public static LogLine ( string Text, LogLevel LogLevel = LogLevel.All ) : void
Text string
LogLevel LogLevel
return void
Esempio n. 1
0
        }//UninstallMod batch

        private static void UninstallMods(List <ModEntry> uninstallMods, ref List <string> zeroFiles, ref List <string> oneFilesList)
        {
            Debug.LogLine(String.Format("[Uninstall] Bulk uninstall started"), Debug.LogLevel.Basic);
            List <string>      fullRemoveQarPaths;      // for qar files that can be removed altogether
            List <ModQarEntry> partialEditQarEntries;   // for qar files that need to be rebuilt using base archives
            List <ModFpkEntry> partialRemoveFpkEntries; // of the qar files that need to be rebuilt, these are the fpk files that will be removed from them

            Debug.LogLine("[Uninstall] Building fpk removal lists", Debug.LogLevel.Basic);
            GetFpkRemovalLists(uninstallMods, out fullRemoveQarPaths, out partialEditQarEntries, out partialRemoveFpkEntries);

            Debug.LogLine("[Uninstall] Unmerging any fpk entries", Debug.LogLevel.Basic);
            UnmergePackFiles(partialEditQarEntries, partialRemoveFpkEntries);

            Debug.LogLine("[Uninstall] Removing any unmodified fpk entries", Debug.LogLevel.Basic);
            RemoveDemoddedQars(ref zeroFiles, fullRemoveQarPaths);

            GameData gameData = SBBuildManager.GetGameData();

            foreach (ModEntry uninstallMod in uninstallMods)
            {
                SBBuildManager.RemoveMod(uninstallMod);

                Debug.LogLine(string.Format("[Uninstall] Removing any game dir file entries for {0}", uninstallMod.Name), Debug.LogLevel.Basic);
                UninstallGameDirEntries(uninstallMod, ref gameData);

                Debug.LogLine(String.Format("[Uninstall] Removing any loose textures for {0}", uninstallMod.Name), Debug.LogLevel.Basic);
                UninstallLooseFtexs(uninstallMod, ref oneFilesList, ref gameData);
            }
            SBBuildManager.SetGameData(gameData);
        }
Esempio n. 2
0
 //Cull any invalid entries that might have slipped in via older versions of snakebite
 public static void ValidateGameData(ref GameData gameData, ref List<string> zeroFiles)
 {
     Debug.LogLine("[ValidateGameData] Validating gameData files", Debug.LogLevel.Basic);
     Debug.LogLine("[ValidateGameData] Validating qar entries", Debug.LogLevel.Basic);
     for (int i = gameData.GameQarEntries.Count-1; i >= 0; i--)
     {
         ModQarEntry qarEntry = gameData.GameQarEntries[i];
         if (!GzsLib.IsExtensionValidForArchive(qarEntry.FilePath, ".dat"))
         {
             Debug.LogLine($"[ValidateGameData] Found invalid file entry {qarEntry.FilePath} for archive {qarEntry.SourceName}", Debug.LogLevel.Basic);
             gameData.GameQarEntries.RemoveAt(i);
             zeroFiles.Remove(qarEntry.FilePath);//DEBUGNOW VERIFY
         }
     }
     Debug.LogLine("[ValidateGameData] Validating fpk entries", Debug.LogLevel.Basic);
     for (int i = gameData.GameFpkEntries.Count-1; i >= 0; i--)
     {
         ModFpkEntry fpkEntry = gameData.GameFpkEntries[i];
         if (!GzsLib.IsExtensionValidForArchive(fpkEntry.FilePath, fpkEntry.FpkFile))
         {
             Debug.LogLine($"[ValidateGameData] Found invalid file entry {fpkEntry.FilePath} for archive {fpkEntry.FpkFile}", Debug.LogLevel.Basic);
             gameData.GameFpkEntries.RemoveAt(i);
         }
     }
 }
Esempio n. 3
0
        public static bool MoveDatFiles() // moves all vanilla 00.dat files, excluding foxpatch.dat, to 01.dat
        {
            SettingsManager manager = new SettingsManager(SnakeBiteSettings);
            Debug.LogLine("[DatMerge] Beginning to move files to new archives");
            try
            {
                if (manager.IsVanilla0001DatHash() || manager.IsVanilla0001Size() )
                {   // first time setup or files have been revalidated
                    MoveDatFilesClean(manager);
                }
                else
                {   // the "uncertainty" case.
                    MoveDatFilesDirty(manager);
                }

                Debug.LogLine(String.Format("[DatMerge] Archive merging finished"), Debug.LogLevel.Debug);
                CleanupFolders();

                return Checkc7t7Setup();
            }
            catch (Exception e)
            {
                MessageBox.Show(string.Format("An error has occured while moving files into new archives: {0}", e), "Exception Occurred", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Debug.LogLine(string.Format("[DatMerge] Exception Occurred: {0}", e), Debug.LogLevel.Basic);
                Debug.LogLine("[DatMerge] SnakeBite could not move the 00.dat or 01.dat contents to new archives.", Debug.LogLevel.Basic);

                return false;
            }
        }
Esempio n. 4
0
        public static void getAllConflicts(List <PreinstallEntry> allMods) // checks each mod against one another for conflicts, and adds conflicting mods to a list.
        {
            List <PreinstallEntry> ModsChecked = new List <PreinstallEntry>();

            foreach (PreinstallEntry modA in allMods) // modA, modB, modC...
            {
                Debug.LogLine(String.Format("[PreinstallCheck] Checking for conflicts: {0}", modA.modInfo.Name), Debug.LogLevel.Basic);
                bool Skip = true;
                foreach (PreinstallEntry modB in allMods) // [modA -> modA], [modA -> modB], [modA -> modC]
                {
                    if (modA.Equals(modB))
                    {
                        Skip = false; continue;
                    }                                                  // skip reflexive compare (i.e. [modA -> modA])
                    if (Skip)
                    {
                        continue;
                    }                                            // skip previous compares (i.e. [modB -> modA], [modC -> modB], [modC -> modA])

                    if (hasConflict(modA.modInfo, modB.modInfo)) // [modA -> modB], [modA -> modC], [modB -> modC]
                    {
                        modA.ModConflicts.Add(modB.modInfo.Name);
                        modB.ModConflicts.Add(modA.modInfo.Name);
                    }
                }
            }
        }
Esempio n. 5
0
 private void buttonLaunchGame_Click(object sender, EventArgs e)
 {
     {
         SettingsManager manager = new SettingsManager(GamePaths.SnakeBiteSettings);
         if (manager.ValidInstallPath)
         {
             Debug.LogLine("Launching game...", Debug.LogLevel.Basic);
             try
             {
                 Process.Start(GamePaths.GameDir + "\\mgsvtpp.exe");
                 if (Properties.Settings.Default.CloseSnakeBiteOnLaunch)
                 {
                     Application.Exit();
                 }
             }
             catch
             {
                 Debug.LogLine("Failed to run mgsvtpp.exe", Debug.LogLevel.Basic);
             }
         }
         else
         {
             MessageBox.Show("Unable to locate mgsvtpp.exe. Please check the MGSV install path and try again.", "Error launching MGSV", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }
Esempio n. 6
0
        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);
        }
Esempio n. 7
0
        /// <summary>
        /// Merges the new mod files with the existing modded files and vanilla game files.
        /// The resulting file structure is the new _working0 folder to pack as 00.dat
        /// </summary>
        private static void InstallMods(List <string> modFilePaths, SettingsManager manager, List <string> pullFromVanillas, List <string> pullFromMods, ref HashSet <string> zeroFiles, ref List <string> oneFilesList, Dictionary <string, bool> pathUpdatesExist)
        {
            //Assumption: modded packs have already been extracted to _working0 directory - qarEntryEditList
            //Assumption: vanilla packs have already been extracted to _gameFpk directory (during AddToSettings) - fpkEntryRetrievalList
            //theoretically there should be no qar overlap between the _gamefpk(vanilla) and _working0(modded) files
            FastZip  unzipper = new FastZip();
            GameData gameData = manager.GetGameData();

            foreach (string modFilePath in modFilePaths)
            {
                Debug.LogLine($"[Install] Installation started: {Path.GetFileName(modFilePath)}", Debug.LogLevel.Basic);

                Debug.LogLine($"[Install] Unzipping mod .mgsv ({Tools.GetFileSizeKB(modFilePath)} KB)", Debug.LogLevel.Basic);
                unzipper.ExtractZip(modFilePath, "_extr", "(.*?)");

                Debug.LogLine("[Install] Load mod metadata", Debug.LogLevel.Basic);
                ModEntry extractedModEntry = new ModEntry("_extr\\metadata.xml");
                if (pathUpdatesExist[extractedModEntry.Name])
                {
                    Debug.LogLine(string.Format("[Install] Checking for Qar path updates: {0}", extractedModEntry.Name), Debug.LogLevel.Basic);
                    foreach (ModQarEntry modQar in extractedModEntry.ModQarEntries.Where(entry => !entry.FilePath.StartsWith("/Assets/")))
                    {
                        string unhashedName = HashingExtended.UpdateName(modQar.FilePath);
                        if (unhashedName != null)
                        {
                            Debug.LogLine(string.Format("[Install] Update successful: {0} -> {1}", modQar.FilePath, unhashedName), Debug.LogLevel.Basic);

                            string workingOldPath = Path.Combine("_extr", Tools.ToWinPath(modQar.FilePath));
                            string workingNewPath = Path.Combine("_extr", Tools.ToWinPath(unhashedName));
                            if (!Directory.Exists(Path.GetDirectoryName(workingNewPath)))
                            {
                                Directory.CreateDirectory(Path.GetDirectoryName(workingNewPath));
                            }
                            if (!File.Exists(workingNewPath))
                            {
                                File.Move(workingOldPath, workingNewPath);
                            }

                            modQar.FilePath = unhashedName;
                        }
                    }
                }

                GzsLib.LoadModDictionary(extractedModEntry);
                ValidateModEntries(ref extractedModEntry);

                Debug.LogLine("[Install] Check mod FPKs against game .dat fpks", Debug.LogLevel.Basic);
                zeroFiles.UnionWith(MergePacks(extractedModEntry, pullFromVanillas, pullFromMods));
                //foreach (string zeroFile in zeroFiles) Debug.LogLine(string.Format("Contained in zeroFiles: {0}", zeroFile));

                Debug.LogLine("[Install] Copying loose textures to 01.", Debug.LogLevel.Basic);
                InstallLooseFtexs(extractedModEntry, ref oneFilesList);

                Debug.LogLine("[Install] Copying game dir files", Debug.LogLevel.Basic);
                InstallGameDirFiles(extractedModEntry, ref gameData);
            }

            manager.SetGameData(gameData);
        }
Esempio n. 8
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);
        }
Esempio n. 9
0
        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);
        }
Esempio n. 10
0
        /// <summary>
        /// command-line install.
        /// </summary>
        internal void ProcessInstallMod(List <string> installPaths, bool skipConflictChecks, bool skipCleanup)
        {
            List <string> InstallFileList = new List <string>();

            foreach (string installModPath in installPaths)
            {
                if (File.Exists(installModPath) && installModPath.Contains(".mgsv"))
                {
                    InstallFileList.Add(installModPath);
                }
                else
                {
                    if (Directory.Exists(installModPath))
                    {
                        var folderFiles = Directory.GetFiles(installModPath, "*.mgsv");
                        foreach (string mgsv in folderFiles)
                        {
                            InstallFileList.Add(mgsv);
                        }
                        if (InstallFileList.Count == 0)
                        {
                            Debug.LogLine($"[Install] Could not find any .mgsv files in {installModPath}.", Debug.LogLevel.Basic);
                        }
                        InstallFileList.Sort();
                    }
                    else
                    {
                        Debug.LogLine($"[Install] Could not find file or directory {installModPath}.", Debug.LogLevel.Basic);
                    }
                }
            }
            if (InstallFileList.Count == 0)
            {
                Debug.LogLine($"[Install] Could not find any .mgsv files in installPaths.", Debug.LogLevel.Basic);
                return;
            }
            if (!skipConflictChecks)
            {
                foreach (string modPath in InstallFileList)
                {
                    if (!PreinstallManager.CheckConflicts(modPath))
                    {
                        return;
                    }
                }
            }
            string displayPath = InstallFileList[0];

            if (InstallFileList.Count > 1)
            {
                displayPath = $"{displayPath} and {InstallFileList.Count} mods";
            }
            ProgressWindow.Show("Installing Mod", $"Installing {displayPath}...",
                                new Action((MethodInvoker) delegate { InstallManager.InstallMods(InstallFileList, skipCleanup); }
                                           ), log);
            this.Invoke((MethodInvoker) delegate { RefreshInstalledMods(); });
        }
Esempio n. 11
0
 public static void ClearBuildFiles(params string[] paths)
 {
     Debug.LogLine("[SB_Build] Deleting SB_Build files", Debug.LogLevel.Basic);
     foreach (string path in paths)
     {
         if (File.Exists(path + build_ext))
             File.Delete(path + build_ext);
     }
 }
Esempio n. 12
0
 public static void PromoteBuildFiles(params string[] paths)
 {
     // Promote SB builds
     Debug.LogLine("[SB_Build] Promoting SB_Build files", Debug.LogLevel.Basic);
     foreach (string path in paths)
     {
         GzsLib.PromoteQarArchive(path + build_ext, path);
     }
     
     new SettingsManager(SnakeBiteSettings).UpdateDatHash();
 }
Esempio n. 13
0
 private void labelVersion_DoubleClick(object sender, EventArgs e)
 {
     try
     {
         Process.Start(GamePaths.SBInstallDir);
     }
     catch
     {
         Debug.LogLine(String.Format("Failed to open SnakeBite Installation Directory"), Debug.LogLevel.Basic);
     }
 }
Esempio n. 14
0
        internal bool ValidateDatHash()
        {
            string datHash = Tools.GetMd5Hash(ModManager.ZeroPath) + Tools.GetMd5Hash(ModManager.OnePath);
            string hashOld = this.GetGameData().DatHash;

            if (datHash != hashOld)
            {
                Debug.LogLine(String.Format("[ValidateDatHash] 00/01 dat hash mismatch:\n{0} (Found Hash) != {1} (Expected Hash)", datHash, hashOld), Debug.LogLevel.All);
                return(false);
            }
            return(true);
        }
Esempio n. 15
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;
            }
        }
Esempio n. 16
0
        private static bool Checkc7t7Setup()
        {
            //check for good c7, t7
            int archiveState = 0;

            string chunkCheckPath = c7Path + build_ext;
            if (!File.Exists(chunkCheckPath)) chunkCheckPath = c7Path;

            string texCheckPath = t7Path + build_ext;
            if (!File.Exists(texCheckPath)) texCheckPath = t7Path;

            // check if they exist and their size
            long chunkSize = 0;
            long texSize = 0;
            if (File.Exists(chunkCheckPath) && File.Exists(texCheckPath))
            {
                chunkSize = new FileInfo(chunkCheckPath).Length;
                texSize = new FileInfo(texCheckPath).Length;
                if (chunkSize >= 345000000 && texSize >= 250000000)
                {
                    archiveState = 1; // Good State
                }
                else archiveState = 2; // Bad Size
            }
            else archiveState = 3; // Not Found
            
            switch (archiveState)
            {
                case 1:
                    Debug.LogLine("[DatMerge] chunk7 and texture7 are sufficiently large and likely valid.", Debug.LogLevel.Basic);
                    return true;

                case 2:
                    MessageBox.Show("SnakeBite has detected that the reformatted game data is smaller than expected and likely invalid." +
                        "\n\nThis will result in the game crashing on startup." +
                        "\n\n If this occurs, please use 'Restore Backup Game Files' in the SnakeBite settings or verify the integrity of your game through Steam.", "Filesize check failed", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    Debug.LogLine(string.Format("[DatMerge] {0} filesize: {1}", Path.GetFileName(chunkCheckPath), chunkSize), Debug.LogLevel.Basic);
                    Debug.LogLine(string.Format("[DatMerge] {0} filesize: {1}", Path.GetFileName(texCheckPath), texSize), Debug.LogLevel.Basic);
                    break;

                case 3:
                    MessageBox.Show("SnakeBite could not reformat the necessary game data during setup. This issue could be caused by missing game files."+
                        "\n\nThis error will result in the game crashing on startup." +
                        "\n\n If this occurs, please use 'Restore Backup Game Files' in the SnakeBite settings or verify the integrity of your game through Steam.", "Missing archive file(s)", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    Debug.LogLine("[DatMerge] chunk7 and/or texture7 were not created during the setup process.", Debug.LogLevel.Basic);
                    break;
            }

            return (MessageBox.Show("Would you still like to continue the setup process?", "Continue Setup?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes);
        }
Esempio n. 17
0
        private void menuItemOpenDir_Click(object sender, EventArgs e)
        {
            string installPath = Properties.Settings.Default.InstallPath;

            try
            {
                Process.Start(installPath);
            }
            catch
            {
                Debug.LogLine(String.Format("Failed to open game directory: {0}", installPath), Debug.LogLevel.Basic);
            }
        }
Esempio n. 18
0
        public static void CopyGameDirManagedFiles(string destinationDir)
        {
            Debug.LogLine($"[SB_Build] Copying {Path.GetDirectoryName(GameDir)} to {Path.GetDirectoryName(destinationDir)}", Debug.LogLevel.Basic);
            foreach (string externalFile in new SettingsManager(SnakeBiteSettings).GetModExternalFiles()) 
            {
                string fileModPath = Tools.ToWinPath(externalFile);
                string sourceFullPath = Path.Combine(GameDir, fileModPath);
                string destFullPath = Path.Combine(destinationDir, fileModPath);

                Directory.CreateDirectory(Path.GetDirectoryName(destFullPath));
                if (File.Exists(sourceFullPath)) { File.Copy(sourceFullPath, destFullPath, true); }
            }
        }
Esempio n. 19
0
        public void UpdateDatHash()
        {
            Settings settings = new Settings();

            settings.LoadFrom(directory, filename);

            // Hash 01.dat and update settings file
            string datHash = Tools.GetMd5Hash(ModManager.ZeroPath) + Tools.GetMd5Hash(ModManager.OnePath);

            settings.GameData.DatHash = datHash;
            Debug.LogLine(String.Format("[UpdateDatHash] Updated 00/01 dat hash to: {0}", datHash), Debug.LogLevel.All);
            settings.SaveTo(directory, filename);
        }
Esempio n. 20
0
        private static void MoveDatFilesClean(SettingsManager manager)
        {
            string sourceName = null;
            string destName = null;
            string destFolder = null;

            // lua files 00 -> 01,    texture files 01 -> texture7,   foxpatch 00 -> 00,   chunkfiles 00 -> chunk7
            Debug.LogLine("[DatMerge] First Time Setup Started", Debug.LogLevel.Debug);
            
            if (manager.SettingsExist()) manager.ClearAllMods();

            List<string> zeroFiles = GzsLib.ExtractArchive<QarFile>(ZeroPath, "_extr");
            List<string> chunk7Files = new List<string>();
            List<string> oneFiles = new List<string>();

            List<string> zeroOut = zeroFiles.ToList();

            foreach (string zeroFile in zeroFiles)
            {
                if (zeroFile == "foxpatch.dat") continue;

                sourceName = Path.Combine("_extr", Tools.ToWinPath(zeroFile));

                if (zeroFile.Contains(".lua"))
                {
                    destName = Path.Combine("_working1", Tools.ToWinPath(zeroFile)); // 00 -> 01
                    oneFiles.Add(zeroFile);
                } else
                {
                    destName = Path.Combine("_working2", Tools.ToWinPath(zeroFile)); // 00 -> chunk7
                    chunk7Files.Add(zeroFile);
                }
                zeroOut.Remove(zeroFile);

                destFolder = Path.GetDirectoryName(destName);
                if (!Directory.Exists(destFolder)) Directory.CreateDirectory(destFolder);
                if (!File.Exists(destName)) File.Move(sourceName, destName);
            }
            
            // Build a_chunk7.dat.SB_Build
            GzsLib.WriteQarArchive(c7Path + build_ext, "_working2", chunk7Files, GzsLib.chunk7Flags);

            // Build a_texture7.dat.SB_Build
            File.Copy(OnePath, t7Path + build_ext, true);

            // Build 00.dat.SB_Build
            GzsLib.WriteQarArchive(ZeroPath + build_ext, "_extr", zeroOut, GzsLib.zeroFlags);

            // Build 01.dat.SB_Build
            GzsLib.WriteQarArchive(OnePath + build_ext, "_working1", oneFiles, GzsLib.oneFlags);
        }
Esempio n. 21
0
 public static void OpenLogDirectory()
 {
     if (!Directory.Exists(logDir))
     {
         Directory.CreateDirectory(logDir);
     }
     try
     {
         Process.Start(logDir);
     }
     catch
     {
         Debug.LogLine(String.Format("Failed to open log directory: {0}", logDir), Debug.LogLevel.Basic);
     }
 }
Esempio n. 22
0
 public static void ClearSBGameDir()
 {
     Debug.LogLine("[SB_Build] Deleting old SB_Build Game Directory", Debug.LogLevel.Basic);
     try
     {
         if(Directory.Exists(GameDirSB_Build))
             Tools.DeleteDirectory(GameDirSB_Build);
         if (Directory.Exists(GameDirBackup_Build))
             Tools.DeleteDirectory(GameDirBackup_Build);
     }
     catch (IOException e)
     {
         Console.WriteLine("[Cleanup] Could not delete Game Directory Content: " + e.ToString());
     }
 }
Esempio n. 23
0
        public static void CleanupFolders() // deletes the work folders which contain extracted files from 00/01
        {
            Debug.LogLine("[Mod] Cleaning up snakebite work folders.");
            try
            {
                foreach (var folder in cleanupFolders)
                {
                    if (Directory.Exists(folder))
                    {
                        Tools.DeleteDirectory(folder);

                    }
                }
            }
            catch (Exception e){ Debug.LogLine("[Mod] Exception occurred while attempting to remove SnakeBite work folders: " + e.ToString()); }
        }
Esempio n. 24
0
        /// <summary>
        /// command-line install.
        /// </summary>
        internal void ProcessInstallMod(string installModPath, bool skipConflictChecks, bool skipCleanup)
        {
            List <string> InstallFileList = null;

            if (File.Exists(installModPath) && installModPath.Contains(".mgsv"))
            {
                InstallFileList = new List <string> {
                    installModPath
                };
            }
            else
            {
                if (Directory.Exists(installModPath))
                {
                    InstallFileList = Directory.GetFiles(installModPath, "*.mgsv").ToList();
                    if (InstallFileList.Count == 0)
                    {
                        Debug.LogLine($"[Install] Could not find any .mgsv files in {installModPath}.", Debug.LogLevel.Basic);
                        return;
                    }
                }
                else
                {
                    Debug.LogLine($"[Install] Could not find file or directory {installModPath}.", Debug.LogLevel.Basic);
                    return;
                }
            }
            if (InstallFileList == null)
            {
                return;
            }
            if (!skipConflictChecks)
            {
                foreach (string modPath in InstallFileList)
                {
                    if (!PreinstallManager.CheckConflicts(modPath))
                    {
                        return;
                    }
                }
            }
            ProgressWindow.Show("Installing Mod", $"Installing {installModPath}...",
                                new Action((MethodInvoker) delegate { InstallManager.InstallMods(InstallFileList, skipCleanup); }
                                           ), log);
            this.Invoke((MethodInvoker) delegate { RefreshInstalledMods(); });
        }
Esempio n. 25
0
        public static void GetConflicts(PreinstallEntry addedMod, List <PreinstallEntry> listedMods) // checks each mod against one another for conflicts, and adds conflicting mods to a list.
        {
            Debug.LogLine(String.Format("[PreinstallCheck] Checking for conflicts: {0}", addedMod.modInfo.Name), Debug.LogLevel.Basic);
            foreach (PreinstallEntry listedMod in listedMods)
            {
                if (addedMod.Equals(listedMod) || listedMod.ModConflicts.Contains(addedMod.modInfo.Name))
                {
                    continue;
                }

                if (hasConflict(addedMod.modInfo, listedMod.modInfo))
                {
                    addedMod.ModConflicts.Add(listedMod.modInfo.Name);
                    listedMod.ModConflicts.Add(addedMod.modInfo.Name);
                }
            }
        }
Esempio n. 26
0
 internal bool ValidateDatHash()
 {
     if (File.Exists(xmlFilePath))
     {
         string datHash = Tools.GetMd5Hash(ZeroPath) + Tools.GetMd5Hash(OnePath);
         string hashOld = GetGameData().DatHash;
         if (datHash == hashOld)
         {
             Debug.LogLine(String.Format("[ValidateDatHash] 00/01 dat hash match:\n{0} (Found Hash) == {1} (Expected Hash)", datHash, hashOld), Debug.LogLevel.All);
             return(true);
         }
         else
         {
             Debug.LogLine(String.Format("[ValidateDatHash] 00/01 dat hash mismatch:\n{0} (Found Hash) != {1} (Expected Hash)", datHash, hashOld), Debug.LogLevel.All);
             return(false);
         }
     }
     Debug.LogLine(String.Format("[ValidateDatHash] could not find snakebite.xml"), Debug.LogLevel.All);
     return(false);
 }
Esempio n. 27
0
        public static void Show(string WindowTitle, string ProgressText, Action WorkerFunction)
        {
            var progressWindow = new formProgress();

            progressWindow.StatusText.Text = ProgressText;

            //var logWindow = new formLog();
            //logWindow.Text = ProgressText;

            var progressWorker = new BackgroundWorker();

            progressWorker.DoWork += (obj, var) =>
            {
                WorkerFunction();
            };
            progressWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(
                delegate(object sender, RunWorkerCompletedEventArgs e) {
                if (e.Error != null)
                {
                    Debug.LogLine(String.Format("[Error] Exception message '{0}'", e.Error.Message));
                    //logWindow.Invoke((MethodInvoker)delegate { logWindow.Text = String.Format("Error during process :'{0}'", ProgressText); });

                    MessageBox.Show(String.Format("Exception :'{0}'\r\nCheck SnakeBites log for more info.", e.Error.Message), String.Format("Error during process :'{0}'", ProgressText), MessageBoxButtons.OK, MessageBoxIcon.Error);
                    progressWindow.Invoke((MethodInvoker) delegate { progressWindow.Close(); });
                }
                else if (e.Cancelled)
                {
                }
                else
                {
                    //logWindow.Invoke((MethodInvoker)delegate { logWindow.Close(); });
                    progressWindow.Invoke((MethodInvoker) delegate { progressWindow.Close(); });
                }
                progressWorker.Dispose();
            }
                );

            progressWorker.RunWorkerAsync();
            //logWindow.ShowDialog();
            progressWindow.ShowDialog();
        }
Esempio n. 28
0
        public static void PromoteGameDirFiles() // call this method BEFORE snakebite.xml.SB_Build is promoted, so it will reference the old snakebite.xml
        {
            Debug.LogLine("[SB_Build] Promoting SB_Build Game Directory", Debug.LogLevel.Basic);
            if (!Directory.Exists(GameDirSB_Build))
            {
                Debug.LogLine($"[SB_Build] Directory not found: {GameDirSB_Build}", Debug.LogLevel.Basic);
                return;
            }

            List<string> fileEntryDirs = new List<string>();
            foreach (string externalFile in new SettingsManager(SnakeBiteSettings).GetModExternalFiles())
            {
                string fileModPath = Tools.ToWinPath(externalFile);
                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 old snakebite.xml's managed files (unmanaged files will be overwritten later or left alone)
                else Debug.LogLine(string.Format("[SB_Build] File not found: {0}", sourceFullPath), Debug.LogLevel.Basic);
            }

            Tools.DirectoryCopy(GameDirSB_Build, GameDir, true); // moves all gamedir_sb_build files over

            foreach (string fileEntryDir in fileEntryDirs)
            {
                if (Directory.Exists(fileEntryDir) && Directory.GetFiles(fileEntryDir).Length == 0)
                {
                    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);
                    }
                }
            }
        }
Esempio n. 29
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);
                    }
                }
            }
        }
Esempio n. 30
0
        public static void AddModsToXml(params PreinstallEntry[] modsArrary)
        {
            HashingExtended.ReadDictionary();
            foreach (PreinstallEntry mod in modsArrary)
            {
                FastZip unzipper = new FastZip();
                unzipper.ExtractZip(mod.filename, "_extr", "metadata.xml");
                ModEntry metaData = new ModEntry("_extr\\metadata.xml");

                Dictionary <string, string> newNameDictionary = new Dictionary <string, string>();
                int foundUpdate = 0;

                Debug.LogLine(string.Format("[PreinstallCheck] Checking for Qar path updates: {0}", metaData.Name), Debug.LogLevel.Basic);
                foreach (ModQarEntry modQar in metaData.ModQarEntries.Where(entry => !entry.FilePath.StartsWith("/Assets/")))
                {
                    string unhashedName = HashingExtended.UpdateName(modQar.FilePath);
                    if (unhashedName != null)
                    {
                        Debug.LogLine(string.Format("[PreinstallCheck] Update successful: {0} -> {1}", modQar.FilePath, unhashedName), Debug.LogLevel.Basic);
                        newNameDictionary.Add(modQar.FilePath, unhashedName);
                        modQar.FilePath = unhashedName;
                        foundUpdate++;
                    }
                }
                if (foundUpdate > 0)
                {
                    foreach (ModFpkEntry modFpkEntry in metaData.ModFpkEntries)
                    {
                        string unHashedName;
                        if (newNameDictionary.TryGetValue(modFpkEntry.FpkFile, out unHashedName))
                        {
                            modFpkEntry.FpkFile = unHashedName;
                        }
                    }
                }

                new SettingsManager("_extr\\buildInfo.xml").AddMod(metaData);
                mod.modInfo = metaData;
            }
        }