internal static void UpdateDatHash() { // updates dat file hash string datHash = Tools.HashFile(GameArchivePath); Settings oSet = new Settings(); oSet.LoadSettings(); oSet.GameData.DatHash = datHash; oSet.SaveSettings(); }
// gets information about the existing 01.dat archive internal static GameData RebuildGameData(bool copyBackup = false) { if (Directory.Exists(GameArchiveDir)) Directory.Delete(GameArchiveDir, true); ExtractGameArchive(); if (!Directory.Exists(GameArchiveDir)) return null; GameData buildData = new GameData(); // Extract game archive and load data QarFile gameQarXml = new QarFile(); gameQarXml.LoadFromFile(GameArchiveXmlPath); // Load currently installed mods Settings oSet = new Settings(); oSet.LoadSettings(); foreach (QarEntry gameQarEntry in gameQarXml.QarEntries) { buildData.GameQarEntries.Add(new ModQarEntry() { FilePath = gameQarEntry.FilePath, Compressed = gameQarEntry.Compressed, Hash = gameQarEntry.Hash }); } buildData.GameFpkEntries = BuildFpkList(GameArchiveDir); // recurse through all installed mods foreach (ModEntry mod in oSet.ModEntries) { // check all files in mod against qar archive foreach (ModFpkEntry modFpkFile in mod.ModFpkEntries) { buildData.GameFpkEntries.RemoveAll(entry => entry.FilePath == modFpkFile.FilePath && entry.FpkFile == modFpkFile.FpkFile); } foreach (ModQarEntry modQarFile in mod.ModQarEntries) { buildData.GameQarEntries.RemoveAll(entry => entry.FilePath == modQarFile.FilePath); } } if(copyBackup) { foreach (ModFpkEntry fpkEntry in buildData.GameFpkEntries) { string fpkDir = Tools.ToWinPath(fpkEntry.FpkFile.Replace(".", "_")); backupMan.AddFile(GameArchiveDir + fpkDir + Tools.ToWinPath(fpkEntry.FilePath), fpkEntry.FilePath, fpkEntry.FpkFile); } foreach (ModQarEntry qarEntry in buildData.GameQarEntries) { backupMan.AddFile(GameArchiveDir + Tools.ToWinPath(qarEntry.FilePath), Tools.ToQarPath(qarEntry.FilePath)); } backupMan.Save(); } DeleteGameArchive(); return buildData; }
internal static List<ModEntry> GetInstalledMods() { Settings settingsXml = new Settings(); settingsXml.LoadSettings(); return settingsXml.ModEntries; }
internal static void CleanupModSettings() { // Load current settings Settings oSet = new Settings(); oSet.LoadSettings(); // Unpack game archive ExtractGameArchive(); // Load archive data QarFile gameQar = new QarFile(); gameQar.LoadFromFile(GameArchiveXmlPath); // recurse through all installed mods foreach (ModEntry mod in oSet.ModEntries) { List<string> remQar = new List<string>(); // list of files to remove foreach (ModQarEntry modQarFile in mod.ModQarEntries) // check all mod files { if (!File.Exists(GameArchiveDir + Tools.ToWinPath(modQarFile.FilePath))) { // if the file doesn't exist, it will be removed remQar.Add(modQarFile.FilePath); } } foreach (string remFile in remQar) { mod.ModQarEntries.RemoveAll(entry => entry.FilePath == remFile); // remove files from db mod.ModFpkEntries.RemoveAll(entry => entry.FpkFile == remFile); // fpks from db } } // remove empty mods oSet.ModEntries.RemoveAll(entry => entry.ModQarEntries.Count == 0 && entry.ModFpkEntries.Count == 0); oSet.SaveSettings(); DeleteGameArchive(); }
// validates 01.dat MD5 against previous hash internal static bool CheckDatHash() { string datHash = Tools.HashFile(GameArchivePath); Settings oSet = new Settings(); oSet.LoadSettings(); string hashOld = oSet.GameData.DatHash; if (datHash != hashOld) return false; return true; }
// gets information about the existing 01.dat archive internal static GameData RebuildGameData() { if (Directory.Exists(GameArchiveDir)) Directory.Delete(GameArchiveDir, true); ExtractGameArchive(); if (!Directory.Exists(GameArchiveDir)) return null; GameData buildData = new GameData(); // Extract game archive and load data QarFile gameQarXml = new QarFile(); gameQarXml.LoadFromFile(GameArchiveXmlPath); // Load currently installed mods Settings oSet = new Settings(); oSet.LoadSettings(); foreach (QarEntry gameQarEntry in gameQarXml.QarEntries) { buildData.GameQarEntries.Add(new ModQarEntry() { FilePath = gameQarEntry.FilePath, Compressed = gameQarEntry.Compressed, Hash = gameQarEntry.Hash }); } buildData.GameFpkEntries = BuildFpkList(GameArchiveDir); // recurse through all installed mods foreach (ModEntry mod in oSet.ModEntries) { // check all files in mod against qar archive foreach (ModFpkEntry modFpkFile in mod.ModFpkEntries) { buildData.GameFpkEntries.RemoveAll(entry => entry.FilePath == modFpkFile.FilePath && entry.FpkFile == modFpkFile.FpkFile); } foreach (ModQarEntry modQarFile in mod.ModQarEntries) { buildData.GameQarEntries.RemoveAll(entry => entry.FilePath == modQarFile.FilePath); } } Directory.Delete(GameArchiveDir, true); File.Delete(GameArchiveXmlPath); return buildData; }