public void CheckWatcher(DataSetDoom dataSetDoom) { string path = Path.Combine(TestContext.CurrentContext.TestDirectory, @"Scripts", dataSetDoom.Name); DirectoryInfo directoryInfo = new DirectoryInfo(path); Assert.IsNotNull(directoryInfo, "Scripts directory is null"); Assert.IsTrue(directoryInfo.Exists, "Scripts directory does not exist"); EngineScript engineScript = EngineScriptManager.LoadEngineScript(directoryInfo); Assert.IsNotNull(engineScript, "EngineScript not loaded properly"); if (!Directory.Exists(dataSetDoom.SourceFolder)) { Directory.CreateDirectory(dataSetDoom.SourceFolder); } string profilePathOrigin = Path.Combine(dataSetDoom.DataRoot, @"Original", dataSetDoom.ProfileName + "_Open.shp"); string profilePathSimulation = Path.Combine(dataSetDoom.SourceFolder, dataSetDoom.ProfileName + "_Open.shp"); File.Copy(profilePathOrigin, profilePathSimulation); string content = File.ReadAllText(profilePathSimulation); content = content.Replace(@"%SOURCEFOLDER%", dataSetDoom.SourceFolder.Replace(@"\", @"\\")); File.WriteAllText(profilePathSimulation, content); ProfileFile profileFile = ProfileFile.Load(profilePathSimulation); Assert.IsNotNull(profileFile); LuaManager luaManager = new LuaManager(); Assert.IsNotNull(luaManager); bool loadEngine = luaManager.LoadEngineAndProfile(engineScript, profileFile); Assert.IsTrue(loadEngine); if (luaManager.ActiveEngine.OnOpened != null) { Assert.DoesNotThrow(() => { luaManager.ActiveEngine.OnOpened.Call(); }); } int catCount = 0; luaManager.ActiveEngine.OnCategoriesChanges += () => { catCount++; }; int snapCount = 0; luaManager.ActiveEngine.OnSnapshotsChanges += () => { snapCount++; }; int backupCount = 0; luaManager.ActiveEngine.OnAutoBackupOccurred += success => { if (success) { backupCount++; } }; if (luaManager.ActiveEngine.OnInitialized != null) { Assert.DoesNotThrow(() => { luaManager.ActiveEngine.OnInitialized.Call(); }); } Assert.IsNotNull(luaManager.ActiveEngine.Watcher); var setting = luaManager.ActiveEngine.SettingByName("IncludeDeath"); if (setting is EngineSettingCheckbox s) { s.Value = true; } WatcherManager watcherManager = new WatcherManager(luaManager.ActiveEngine.Watcher) { IsProcessRunning = () => true }; // int backupStatus = 0; watcherManager.AutoBackupStatusChanged += () => { // backupStatus++; }; if (luaManager.ActiveEngine.OnLoaded != null) { Assert.DoesNotThrow(() => { luaManager.ActiveEngine.OnLoaded.Call(); }); } Assert.AreEqual(1, catCount); Assert.AreEqual(1, snapCount); // End of open Assert.AreEqual(AutoBackupStatus.Disabled, watcherManager.AutoBackupStatus); watcherManager.SetAutoBackup(true); Assert.AreEqual(AutoBackupStatus.Waiting, watcherManager.AutoBackupStatus); Directory.CreateDirectory(Path.Combine(dataSetDoom.SourceFolder, @"GAME-AUTOSAVE0")); Thread.Sleep(100); Assert.AreEqual(AutoBackupStatus.Enabled, watcherManager.AutoBackupStatus); string fileSource = Path.Combine(dataSetDoom.DataRoot, @"Original", @"GAME-AUTOSAVE0"); string fileDest = Path.Combine(dataSetDoom.SourceFolder, @"GAME-AUTOSAVE0"); foreach (var files in dataSetDoom.Watchers.OrderBy(x => x.Key)) { backupCount = 0; foreach (var file in files.Value.Files) { File.Copy( Path.Combine(fileSource, file), Path.Combine(fileDest, file + ".temp")); } foreach (var file in files.Value.Files) { File.Move( Path.Combine(fileDest, file + ".temp"), Path.Combine(fileDest, file)); Thread.Sleep(100); } Thread.Sleep(500); Assert.AreEqual(1, backupCount); Assert.AreEqual(1, luaManager.ActiveEngine.Snapshots.Count); EngineSnapshot snapshot = luaManager.ActiveEngine.Snapshots.First(); Assert.AreSame(snapshot, luaManager.ActiveEngine.LastSnapshot); Assert.AreEqual(files.Value.SnapshotSaveAt, RoundSavedAt(snapshot.SavedAt)); Assert.AreEqual(files.Value.SnapshotDifficulty, snapshot.CustomValueByKey("Difficulty").ToString()); Assert.AreEqual(files.Value.SnapshotMapDesc, snapshot.CustomValueByKey("MapDesc").ToString()); Assert.AreEqual(files.Value.SnapshotMapName, snapshot.CustomValueByKey("MapName").ToString()); Assert.AreEqual(files.Value.SnapshotPlayedTime, snapshot.CustomValueByKey("PlayedTime").ToString()); Assert.AreEqual(files.Value.SnapshotDeath, snapshot.CustomValueByKey("Death").ToString()); luaManager.ActiveEngine.Snapshots.Clear(); foreach (var file in files.Value.Files) { File.Delete(Path.Combine(fileDest, file)); } Thread.Sleep(100); } watcherManager.Release(); luaManager.Release(); Directory.Delete(dataSetDoom.SourceFolder, true); }
public void CreateProfile(DataSetDoom dataSetDoom) { base.CreateProfile(dataSetDoom); }
public void OpenProfile(DataSetDoom dataSetDoom) { base.OpenProfile(dataSetDoom); }
public static IEnumerable <DataSetDoom> DataSets() { return(DataSetDoom.DataSets()); }
public void CheckBackupRestore(DataSetDoom dataSetDoom) { string path = Path.Combine(TestContext.CurrentContext.TestDirectory, @"Scripts", dataSetDoom.Name); DirectoryInfo directoryInfo = new DirectoryInfo(path); Assert.IsNotNull(directoryInfo, "Scripts directory is null"); Assert.IsTrue(directoryInfo.Exists, "Scripts directory does not exist"); EngineScript engineScript = EngineScriptManager.LoadEngineScript(directoryInfo); Assert.IsNotNull(engineScript, "EngineScript not loaded properly"); if (!Directory.Exists(dataSetDoom.SourceFolder)) { Directory.CreateDirectory(dataSetDoom.SourceFolder); } string profilePathOrigin = Path.Combine(dataSetDoom.DataRoot, @"Original", dataSetDoom.ProfileName + "_Open.shp"); string profilePathSimulation = Path.Combine(dataSetDoom.SourceFolder, dataSetDoom.ProfileName + "_Open.shp"); File.Copy(profilePathOrigin, profilePathSimulation); string content = File.ReadAllText(profilePathSimulation); content = content.Replace(@"%SOURCEFOLDER%", dataSetDoom.SourceFolder.Replace(@"\", @"\\")); File.WriteAllText(profilePathSimulation, content); ProfileFile profileFile = ProfileFile.Load(profilePathSimulation); Assert.IsNotNull(profileFile); LuaManager luaManager = new LuaManager(); Assert.IsNotNull(luaManager); bool loadEngine = luaManager.LoadEngineAndProfile(engineScript, profileFile); Assert.IsTrue(loadEngine); if (luaManager.ActiveEngine.OnOpened != null) { Assert.DoesNotThrow(() => { luaManager.ActiveEngine.OnOpened.Call(); }); } if (luaManager.ActiveEngine.OnInitialized != null) { Assert.DoesNotThrow(() => { luaManager.ActiveEngine.OnInitialized.Call(); }); } var setting = luaManager.ActiveEngine.SettingByName("IncludeDeath"); if (setting is EngineSettingCheckbox s) { s.Value = true; } // End of open Directory.CreateDirectory(Path.Combine(dataSetDoom.SourceFolder, @"GAME-AUTOSAVE0")); Thread.Sleep(100); string fileSource = Path.Combine(dataSetDoom.DataRoot, @"Original", @"GAME-AUTOSAVE0"); string fileDest = Path.Combine(dataSetDoom.SourceFolder, @"GAME-AUTOSAVE0"); foreach (var files in dataSetDoom.Watchers.OrderBy(x => x.Key)) { foreach (var file in files.Value.Files) { File.Copy( Path.Combine(fileSource, file), Path.Combine(fileDest, file + ".temp")); } foreach (var file in files.Value.Files) { File.Move( Path.Combine(fileDest, file + ".temp"), Path.Combine(fileDest, file)); } Thread.Sleep(100); Assert.DoesNotThrow(() => { luaManager.ActiveEngine.ActionSnapshotBackup(ActionSource.HotKey, files.Value.SnapshotDeath != ""); }); Assert.AreEqual(1, luaManager.ActiveEngine.Snapshots.Count); EngineSnapshot snapshot = luaManager.ActiveEngine.Snapshots.First(); Assert.AreSame(snapshot, luaManager.ActiveEngine.LastSnapshot); Assert.AreEqual(files.Value.SnapshotSaveAt, RoundSavedAt(snapshot.SavedAt)); Assert.AreEqual(files.Value.SnapshotDifficulty, snapshot.CustomValueByKey("Difficulty").ToString()); Assert.AreEqual(files.Value.SnapshotMapDesc, snapshot.CustomValueByKey("MapDesc").ToString()); Assert.AreEqual(files.Value.SnapshotMapName, snapshot.CustomValueByKey("MapName").ToString()); Assert.AreEqual(files.Value.SnapshotPlayedTime, snapshot.CustomValueByKey("PlayedTime").ToString()); Assert.AreEqual(files.Value.SnapshotDeath, snapshot.CustomValueByKey("Death").ToString()); Assert.DoesNotThrow(() => { luaManager.ActiveEngine.ActionSnapshotRestore(ActionSource.HotKey, luaManager.ActiveEngine.LastSnapshot); }); luaManager.ActiveEngine.Snapshots.Clear(); foreach (var file in files.Value.Files) { File.Delete(Path.Combine(fileDest, file)); } Thread.Sleep(100); } luaManager.Release(); Directory.Delete(dataSetDoom.SourceFolder, true); }
public static IEnumerable <DataSetDoom> DataSets() { string rand = DateTime.Now.ToString("HH-mm-ss-fff"); string data = Path.Combine(TestContext.CurrentContext.TestDirectory, "Data", "DOOM2016"); string path = Path.Combine(data, "Simulation", rand); var set = new DataSetDoom { DataRoot = data, SourceFolder = path, Name = @"DOOM2016", Title = @"DOOM 2016", Author = @"HgAlexx", FileCount = 4, Settings = new Dictionary <string, object> { { "SourceFolder", path }, { "SlotIndex", 1 } }, CanAutoDetect = true, ProfileName = "DOOM2016", SuggestProfileName = "DOOM 2016 - Slot 1", Watchers = new Dictionary <int, DataSetWatcherDoom>() }; var watcher = new DataSetWatcherDoom { SnapshotSaveAt = new DateTime(2020, 06, 19, 03, 24, 03), SnapshotDifficulty = "I'm too young to die", SnapshotMapDesc = "The UAC", SnapshotMapName = "game/sp/intro/intro", SnapshotPlayedTime = "0:02:46", SnapshotDeath = "" }; watcher.Files = new List <string> { "checkpoint.dat", "checkpoint_mapstart.dat", "game_duration.dat", "checkpoint_alt.dat", "game.details", "game.details.verify" }; set.Watchers.Add(1, watcher); watcher = new DataSetWatcherDoom { SnapshotSaveAt = new DateTime(2020, 06, 19, 03, 24, 03), SnapshotDifficulty = "I'm too young to die", SnapshotMapDesc = "The UAC", SnapshotMapName = "game/sp/intro/intro", SnapshotPlayedTime = "0:02:46", SnapshotDeath = "🕱" }; watcher.Files = new List <string> { "game_duration.dat", "checkpoint_alt.dat", "game.details", "game.details.verify" }; set.Watchers.Add(2, watcher); yield return(set); data = Path.Combine(TestContext.CurrentContext.TestDirectory, "Data", "DOOMEternal", @"Steam"); path = Path.Combine(data, "Simulation", rand, "userdata", "13371337", "782330"); set = new DataSetDoom { DataRoot = data, SourceFolder = path, Name = @"DOOMEternal", Title = @"DOOM Eternal", Author = @"HgAlexx", FileCount = 4, Settings = new Dictionary <string, object> { { "Platform", 1 }, { "SourceFolder", path }, { "SlotIndex", 1 } }, CanAutoDetect = true, ProfileName = "DOOMEternal_Steam", SuggestProfileName = "DOOM Eternal - Slot 1", Watchers = new Dictionary <int, DataSetWatcherDoom>() }; watcher = new DataSetWatcherDoom { SnapshotSaveAt = new DateTime(2020, 06, 27, 01, 16, 44, 948), SnapshotDifficulty = "Hurt me plenty", SnapshotMapDesc = "Cultist Base", SnapshotMapName = "game/sp/e1m3_cult/e1m3_cult", SnapshotPlayedTime = "1:40:32", SnapshotDeath = "🕱" }; watcher.Files = new List <string> { "game.details", }; set.Watchers.Add(1, watcher); yield return(set); data = Path.Combine(TestContext.CurrentContext.TestDirectory, "Data", "DOOMEternal", @"Bethesda"); path = Path.Combine(data, "Simulation", rand, "DOOMEternal", "base", "savegame", "d8d67efe-5bae-453a-aad5-08a71028d4dd"); set = new DataSetDoom { DataRoot = data, SourceFolder = path, Name = @"DOOMEternal", Title = @"DOOM Eternal", Author = @"HgAlexx", FileCount = 4, Settings = new Dictionary <string, object> { { "Platform", 2 }, { "SourceFolder", path }, { "SlotIndex", 1 } }, CanAutoDetect = true, ProfileName = "DOOMEternal_Bethesda", SuggestProfileName = "DOOM Eternal - Slot 1", Watchers = new Dictionary <int, DataSetWatcherDoom>() }; watcher = new DataSetWatcherDoom { SnapshotSaveAt = new DateTime(2020, 06, 27, 0, 44, 12, 444), SnapshotDifficulty = "Hurt me plenty", SnapshotMapDesc = "Cultist Base", SnapshotMapName = "game/sp/e1m3_cult/e1m3_cult", SnapshotPlayedTime = "1:40:32", SnapshotDeath = "🕱" }; watcher.Files = new List <string> { "game.details", }; set.Watchers.Add(1, watcher); yield return(set); }