public void Read(UserProfile profile, out BindableCollection <Addon> addons, out BindableCollection <LaunchParameter> parameters, out LaunchSettings launchSettings) { Logger.LogDebug("ProfileService", "Reading profile from disk"); try { ProfileFile profileFile = new ProfileFile { Profile = profile }; var settings = new JsonSerializerSettings { Converters = { new JsonLaunchParameterConverter() } }; JsonConvert.PopulateObject(_fileAccessor.ReadAllText(Path.Combine(ApplicationConfig.ConfigPath, ApplicationConfig.ProfilesFolder, string.Format(ApplicationConfig.ProfileNameFormat, profile.Id))), profileFile, settings); addons = profileFile.Addons; parameters = profileFile.Parameters; launchSettings = profileFile.LaunchSettings; } catch (Exception e) { Logger.LogException("ProfileService", "Error reading profile", e); addons = new BindableCollection <Addon>(); parameters = new BindableCollection <LaunchParameter>(); launchSettings = new LaunchSettings(); } }
private void ReadProcessedImage(IFormFile picture, string outputPath, ProfileFile avatar) { using (var reader = new BinaryReader(System.IO.File.OpenRead(outputPath))) { avatar.Content = reader.ReadBytes((int)picture.Length); } }
/// Profileを読み込む private bool OpenProfileInternal(string path) { // Profile var profileFile = new ProfileFile(this.Profile); var result = profileFile.ReadFile(path); if (!result) { return(false); } // バックアップパラメータの復元 if (this.Options.RestoreMissingWindowWhenOpeningProfile) { this.Profile.RestoreBackupParameters(); } // Options this.Options.AddRecentProfile(path); // RuntimeOptions this.RuntimeOptions.ProfilePath = path; this.RuntimeOptions.ProfileName = Path.GetFileNameWithoutExtension(path); this.RuntimeOptions.LastSavedTimestamp = this.Profile.Timestamp; this.RuntimeOptions.LastAppliedTimestamp = RuntimeOptions.InvalidTimestamp; this.Profile.RaiseChanged(); return(true); }
public void Write(UserProfile profile, BindableCollection <Addon> addons, BindableCollection <LaunchParameter> parameters, LaunchSettings launchSettings) { Logger.LogDebug("ProfileService", "Writing profile to disk"); try { ProfileFile profileFile = new ProfileFile { Profile = profile, Addons = addons ?? new BindableCollection <Addon>(), Parameters = parameters ?? new BindableCollection <LaunchParameter>(), LaunchSettings = launchSettings ?? new LaunchSettings() }; if (!_fileAccessor.DirectoryExists(Path.Combine(ApplicationConfig.ConfigPath, ApplicationConfig.ProfilesFolder))) { _fileAccessor.CreateDirectory(Path.Combine(ApplicationConfig.ConfigPath, ApplicationConfig.ProfilesFolder)); } _fileAccessor.WriteAllText(Path.Combine(ApplicationConfig.ConfigPath, ApplicationConfig.ProfilesFolder, string.Format(ApplicationConfig.ProfileNameFormat, profile.Id)), JsonConvert.SerializeObject(profileFile, ApplicationConfig.JsonFormatting)); } catch (Exception e) { Logger.LogException("ProfileService", "Error writing profile", e); } }
private void wizardPageSave_Commit(object sender, WizardPageConfirmEventArgs e) { try { var profileFile = new ProfileFile { EngineScriptName = _selectedEngineScript.Name, Name = textBoxName.Text }; _luaManager.SaveSettings(profileFile); // Save file string filePath = Path.Combine(textBoxSaveFolder.Text, textBoxName.Text); filePath = Path.ChangeExtension(filePath, "shp"); if (File.Exists(filePath)) { if (MessageBox.Show(@"The file already exists, do you want to override it?", @"Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No) { e.Cancel = true; return; } } _profileFileFullName = filePath; profileFile.FilePath = filePath; ProfileFile.Save(profileFile); } catch { e.Cancel = true; } }
private async Task ParseImageToDatabase(IFormFile picture, string outputPath, string savePath, UserProfile userProfile) { var avatar = new ProfileFile { FileName = picture.FileName, FileType = FileType.Avatar, ContentType = picture.ContentType, }; ReadProcessedImage(picture, outputPath, avatar); DeleteSavedImages(outputPath, savePath); await SetUserAvatar(userProfile, avatar); }
private async Task SetUserAvatar(UserProfile userProfile, ProfileFile avatar) { var currentUserAvatar = userProfile.ProfileFiles.FirstOrDefault(x => x.FileType == FileType.Avatar); if (currentUserAvatar != null) { userProfile.ProfileFiles.Remove(currentUserAvatar); await _ctx.SaveChangesAsync(); } userProfile.ProfileFiles.Add(avatar); _ctx.SaveChanges(); }
/// Profileの保存 private bool SaveProfileInternal(string path) { // Profile var profileFile = new ProfileFile(this.Profile); var result = profileFile.WriteFile(path); if (!result) { return(false); } // Options this.Options.AddRecentProfile(path); // RuntimeOptions this.RuntimeOptions.ProfilePath = path; this.RuntimeOptions.ProfileName = Path.GetFileNameWithoutExtension(path); this.RuntimeOptions.LastSavedTimestamp = this.Profile.Timestamp; return(true); }
public bool LoadEngineAndProfile(EngineScript engineScript, ProfileFile profileFile) { // init Engine instance if (profileFile == null) { ActiveEngine = new Engine(engineScript, null); } else { string name = Path.GetFileNameWithoutExtension(profileFile.FilePath); ActiveEngine = new Engine(engineScript, Path.Combine(profileFile.RootFolder, name)); } // Set engine variables (name, namespace) _lua["_engine_"] = ActiveEngine; _lua.NewTable("_engine_namespace_"); foreach (EngineScriptFile backupEngineFile in engineScript.Files) { if (backupEngineFile.IsToc) { continue; } if (!LoadFile(backupEngineFile)) { ActiveEngine = null; return(false); } } if (profileFile != null) { LoadSettings(profileFile.Settings); LoadSnapshots(profileFile.Snapshots); } return(true); }
public void SaveSettings(ProfileFile profileFile) { profileFile.Settings.Clear(); foreach (var setting in ActiveEngine.Settings) { if (setting is EngineSettingCheckbox engineSettingCheckbox) { profileFile.Settings.Add(new ProfileSettingBoolean { Name = engineSettingCheckbox.Name, Value = engineSettingCheckbox.Value, Kind = engineSettingCheckbox.Kind }); } if (setting is EngineSettingCombobox settingCombobox) { profileFile.Settings.Add(new ProfileSettingInteger { Name = settingCombobox.Name, Value = settingCombobox.Value, Kind = settingCombobox.Kind }); } if (setting is EngineSettingFolderBrowser settingFolder) { profileFile.Settings.Add(new ProfileSettingString { Name = settingFolder.Name, Value = settingFolder.Value, Kind = settingFolder.Kind }); } if (setting is EngineSettingTextbox settingTextbox) { profileFile.Settings.Add(new ProfileSettingString { Name = settingTextbox.Name, Value = settingTextbox.Value, Kind = settingTextbox.Kind }); } } }
static void Main(string[] args) { /* * MissionModelsFile missionModels = new MissionModelsFile(); * Stream input = File.OpenRead("entities.mdl"); * missionModels.Read(input); * input.Close(); */ /* * MissionEntitiesFile missionEntities = new MissionEntitiesFile(); * Stream input = File.OpenRead("mission.gbe"); * missionEntities.Read(input); * input.Close(); */ ProfileFile profile = new ProfileFile(); Stream input = File.OpenRead("David"); profile.Read(input); input.Close(); for (int i = 0; i < profile.Missions.Length; i++) { profile.Missions[i].ActiveInCampaign = i == 0 ? 1 : 0; profile.Missions[i].Invisible = 0; profile.Missions[i].UnlockMode = 2; } for (int i = 0; i < profile.Planes.Length; i++) { profile.Planes[i].UnlockMode = 2; PlaneInformation details = Gibbed.Firehawk.GameInformation.Planes[i]; if (details.Name == "RAFALEM" || details.Name == "MIG142" || details.Name == "MIRAGE4000" || details.Name == "RF15" || details.Name == "F18HARV" || details.Name == "MIG31" || details.Name == "FB22" || details.Name == "SAAB37" || details.Name == "MIG23" || details.Name == "SAAB35" || details.Name == "SR71" || details.Name == "A12" || details.Name == "MIRAGE2000N" || details.Name == "F111F" || details.Name == "F4E" || details.Name == "SU39") { profile.Planes[i].SpecialUnlockMode = 1; } if (Gibbed.Firehawk.GameInformation.Planes[i].HasSkin) { profile.Planes[i].UnlockSkin = 1; } for (int j = 0; j < profile.Planes[i].SPPacks.Length; j++) { profile.Planes[i].SPPacks[j] = 2; } for (int j = 0; j < profile.Planes[i].MPPacks.Length; j++) { profile.Planes[i].MPPacks[j] = 2; } } // profile.Callsign = "Rick"; Stream output = File.Open("David.new", FileMode.Create, FileAccess.ReadWrite); output.Seek(0, SeekOrigin.Begin); profile.Write(output); // Compute CRC of profile data output.Seek(4, SeekOrigin.Begin); uint allOnes = output.ReadU32BE(); allOnes = ~allOnes; ProfileCRC32 crc = new ProfileCRC32(); crc.CRC = allOnes; byte[] hash = crc.ComputeHash(output); output.Seek(0, SeekOrigin.Begin); output.Write(hash, 0, hash.Length); output.Close(); }
private void Collect() { while (_pool.HasUsers || _bench.HasUsers) { if (_benchPriority && _bench.TotalUsers == 0) { _benchPriority = false; } // Take User var user = (_benchPriority && _bench.HasUsers) || (!_pool.HasUsers && _bench.HasUsers) ? _bench.TakeUser() : _pool.TakeUser(); // Request Data if (!user.HasProfile) { if (_options.IgnoreUserProfile) { // Default Value user.UserProfile = "{}"; } else { var resource = _resources.GetResource(RequestType.User); if (resource != null) { var response = resource.GetUser(user.ID); user.UserProfile = response; } } } if (!user.HasFriends) { if (_options.IgnoreFriends) { // Default Value user.Friends = new long[0]; } else { var resource = _resources.GetResource(RequestType.Friends); if (resource != null) { var response = resource.GetFriends(user.ID); if (response != null) { user.Friends = response.ToArray(); } } } } if (!user.HasFollowers) { if (_options.IgnoreFollowers) { // Default Value user.Followers = new long[0]; } else { var resource = _resources.GetResource(RequestType.Followers); if (resource != null) { var response = resource.GetFollowers(user.ID); if (response != null) { user.Followers = response.ToArray(); } } } } if (!user.HasTimeline) { if (_options.IgnoreTimeline) { // Default Value user.Timeline = "[]"; } else { checkpoint: var resource = _resources.GetResource(RequestType.Timeline); if (resource != null) { var response = resource.GetUserTimeline(user.ID, 200, 0, user.MaxID, _options.IncludeRetweets); if (!string.IsNullOrEmpty(response.Content)) { if (response.Tweets > 0) { user.Timeline += response.Content + ProfileFile.UNIT_SEPARATOR; user.Tweets += response.Tweets; if (response.Tweets > 50 && user.Tweets < _options.MaxTweetsByTimeline) { user.MaxID = response.MinID; goto checkpoint; } user.MaxID = 0; } else { user.Timeline += response.Content + ProfileFile.UNIT_SEPARATOR; user.Tweets += response.Tweets; } } } } } if (user.IsComplete) { // Add users to Pool if (_options.AllowDiscovery) { this.AddToPool(user.Friends, user.Level + 1); this.AddToPool(user.Followers, user.Level + 1); } // Save Data var file = new ProfileFile(user, _options.OutputDirectory); file.SaveProfile(); _pool.SetCompleted(user.ID); _collectedProfiles++; } else { if (user.Source == SourceType.Bench && user.Cycle < _benchLimit) { user.Cycle++; // Enqueue until next window _bench.AddUser(user); } else if (user.Source == SourceType.Bench && user.Cycle == _benchLimit) { // Set Default Values if (!user.HasProfile) { user.UserProfile = "{}"; } if (!user.HasFriends) { user.Friends = new long[0]; } if (!user.HasFollowers) { user.Followers = new long[0]; } if (!user.HasTimeline) { user.Timeline = "[]"; } // Save Data var partialDirectory = Path.Combine(_options.OutputDirectory, "part"); if (!Directory.Exists(partialDirectory)) { Directory.CreateDirectory(partialDirectory); } var file = new ProfileFile(user, partialDirectory); file.SaveProfile(); _pool.SetCompleted(user.ID); _collectedProfiles++; } else { // Enqueue until next window _bench.AddUser(user); } if (_pool.HasUsers && user.Source == SourceType.Bench) { _benchPriority = false; } } this.OnProgress(new MessageEventArgs(MessageType.Progress, MessagePriority.Medium, "Users: {0} / Pool: {1} / Bench: {2} / RC: {3}--", _collectedProfiles, _pool.TotalUsers, _bench.TotalUsers, _resources.Footprint )); _resources.RestartFootprint(); _resources.CheckAvailability(); } }
protected void CreateProfile(DataSet dataSet) { string path = Path.Combine(TestContext.CurrentContext.TestDirectory, @"Scripts", dataSet.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"); Assert.AreEqual(dataSet.Name, engineScript.Name); Assert.AreEqual(dataSet.Title, engineScript.Title); Assert.AreEqual(dataSet.Author, engineScript.Author); Assert.AreEqual(dataSet.FileCount, engineScript.Files.Count); Assert.IsTrue(engineScript.IsValid()); Assert.IsFalse(engineScript.IsAltered(true)); Assert.IsTrue(engineScript.Official); LuaManager luaManager = new LuaManager(); bool loadEngine = luaManager.LoadEngine(engineScript); Assert.IsTrue(loadEngine); if (!Directory.Exists(dataSet.SourceFolder)) { Directory.CreateDirectory(dataSet.SourceFolder); } foreach (var setting in luaManager.ActiveEngine.Settings.Where(s => s.Kind == EngineSettingKind.Setup).OrderBy(s => - s.Index)) { Assert.IsTrue(dataSet.Settings.ContainsKey(setting.Name)); if (setting is EngineSettingCombobox settingCombobox) { settingCombobox.Value = (int)dataSet.Settings[setting.Name]; } if (setting is EngineSettingFolderBrowser settingFolder) { Assert.IsTrue(settingFolder.CanAutoDetect == dataSet.CanAutoDetect); if (dataSet.CanAutoDetect) { Assert.IsNotNull(settingFolder.OnAutoDetect); Assert.DoesNotThrow(() => { string s = settingFolder.OnAutoDetect?.Call().FirstOrDefault() as string; Assert.IsNotNull(s); }); } settingFolder.Value = (string)dataSet.Settings[setting.Name]; } } Assert.IsNotNull(luaManager.ActiveEngine.OnSetupValidate); Assert.DoesNotThrow(() => { bool?b = luaManager.ActiveEngine.OnSetupValidate.Call().First() as bool?; Assert.IsNotNull(b); Assert.IsTrue(b.Value); }); if (luaManager.ActiveEngine.OnSetupSuggestProfileName != null) { Assert.DoesNotThrow(() => { string s = luaManager.ActiveEngine.OnSetupSuggestProfileName.Call().First() as string; Assert.IsFalse(string.IsNullOrEmpty(s)); Assert.IsTrue(HgUtility.IsValidFileName(s)); Assert.AreEqual(dataSet.SuggestProfileName, s); }); } if (luaManager.ActiveEngine.ReadMe != null) { Assert.DoesNotThrow(() => { string s = luaManager.ActiveEngine.ReadMe.Call().First() as string; Assert.IsFalse(string.IsNullOrEmpty(s)); }); } var profileFile = new ProfileFile { EngineScriptName = engineScript.Name, Name = dataSet.ProfileName }; luaManager.SaveSnapshots(profileFile); luaManager.SaveSettings(profileFile); string filePath = Path.Combine(dataSet.SourceFolder, dataSet.ProfileName + "_Create.shp"); profileFile.FilePath = filePath; ProfileFile.Save(profileFile); Assert.DoesNotThrow(() => { profileFile.Release(); }); string expected = File.ReadAllText(Path.Combine(dataSet.DataRoot, "Original", dataSet.ProfileName + "_Create.shp")); expected = expected.Replace(@"%SOURCEFOLDER%", dataSet.SourceFolder.Replace(@"\", @"\\")); string produced = File.ReadAllText(filePath); Assert.AreEqual(expected, produced); luaManager.Release(); Directory.Delete(dataSet.SourceFolder, true); }
public void SaveSnapshots(ProfileFile profileFile) { profileFile.Snapshots.Clear(); profileFile.Snapshots.AddRange(ActiveEngine.Snapshots); }
protected void OpenProfile(DataSet dataSet) { string path = Path.Combine(TestContext.CurrentContext.TestDirectory, @"Scripts", dataSet.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"); Assert.AreEqual(dataSet.Name, engineScript.Name); Assert.AreEqual(dataSet.Title, engineScript.Title); Assert.AreEqual(dataSet.Author, engineScript.Author); Assert.AreEqual(dataSet.FileCount, engineScript.Files.Count); Assert.IsTrue(engineScript.IsValid()); Assert.IsFalse(engineScript.IsAltered(true)); Assert.IsTrue(engineScript.Official); if (!Directory.Exists(dataSet.SourceFolder)) { Directory.CreateDirectory(dataSet.SourceFolder); } string profilePathOrigin = Path.Combine(dataSet.DataRoot, @"Original", dataSet.ProfileName + "_Open.shp"); string profilePathSimulation = Path.Combine(dataSet.SourceFolder, dataSet.ProfileName + "_Open.shp"); File.Copy(profilePathOrigin, profilePathSimulation); string content = File.ReadAllText(profilePathSimulation); content = content.Replace(@"%SOURCEFOLDER%", dataSet.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++; }; if (luaManager.ActiveEngine.OnInitialized != null) { Assert.DoesNotThrow(() => { luaManager.ActiveEngine.OnInitialized.Call(); }); } if (luaManager.ActiveEngine.OnLoaded != null) { Assert.DoesNotThrow(() => { luaManager.ActiveEngine.OnLoaded.Call(); }); } Assert.AreEqual(1, catCount); Assert.AreEqual(1, snapCount); // End of open luaManager.SaveSettings(profileFile); luaManager.SaveSnapshots(profileFile); ProfileFile.Save(profileFile); Assert.DoesNotThrow(() => { profileFile.Release(); }); string expected = File.ReadAllText(profilePathOrigin); expected = expected.Replace(@"%SOURCEFOLDER%", dataSet.SourceFolder.Replace(@"\", @"\\")); string produced = File.ReadAllText(profilePathSimulation); Assert.AreEqual(expected, produced); luaManager.Release(); Directory.Delete(dataSet.SourceFolder, true); }
public void CheckBackupRestore(DataSetSatisfactory dataSetSatisfactory) { string path = Path.Combine(TestContext.CurrentContext.TestDirectory, @"Scripts", dataSetSatisfactory.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(dataSetSatisfactory.SourceFolder)) { Directory.CreateDirectory(dataSetSatisfactory.SourceFolder); } string profilePathOrigin = Path.Combine(dataSetSatisfactory.DataRoot, @"Original", dataSetSatisfactory.ProfileName + "_Open.shp"); string profilePathSimulation = Path.Combine(dataSetSatisfactory.SourceFolder, dataSetSatisfactory.ProfileName + "_Open.shp"); File.Copy(profilePathOrigin, profilePathSimulation); string content = File.ReadAllText(profilePathSimulation); content = content.Replace(@"%SOURCEFOLDER%", dataSetSatisfactory.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("IncludeAutosave"); if (setting is EngineSettingCheckbox s) { s.Value = true; } // End of open Directory.CreateDirectory(dataSetSatisfactory.SourceFolder); Thread.Sleep(100); string fileSource = Path.Combine(dataSetSatisfactory.DataRoot, @"Original"); string fileDest = dataSetSatisfactory.SourceFolder; foreach (var files in dataSetSatisfactory.Watchers.OrderBy(x => x.Key)) { foreach (var file in files.Value.Files) { File.Copy( Path.Combine(fileSource, file), Path.Combine(fileDest, file)); } Thread.Sleep(100); Assert.DoesNotThrow(() => { luaManager.ActiveEngine.ActionSnapshotBackup(ActionSource.HotKey, files.Value.SnapshotAutosave != ""); }); 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.SnapshotBuildVersion, snapshot.CustomValueByKey("BuildVersion").ToString()); Assert.AreEqual(files.Value.SnapshotSaveVersion, snapshot.CustomValueByKey("SaveVersion").ToString()); Assert.AreEqual(files.Value.SnapshotSessionName, snapshot.CustomValueByKey("SessionName").ToString()); Assert.AreEqual(files.Value.SnapshotPlayedTime, snapshot.CustomValueByKey("PlayedTime").ToString()); Assert.AreEqual(files.Value.SnapshotAutosave, snapshot.CustomValueByKey("Autosave").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(dataSetSatisfactory.SourceFolder, true); }
public void CheckWatcher(DataSetSatisfactory dataSetSatisfactory) { string path = Path.Combine(TestContext.CurrentContext.TestDirectory, @"Scripts", dataSetSatisfactory.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(dataSetSatisfactory.SourceFolder)) { Directory.CreateDirectory(dataSetSatisfactory.SourceFolder); } string profilePathOrigin = Path.Combine(dataSetSatisfactory.DataRoot, @"Original", dataSetSatisfactory.ProfileName + "_Open.shp"); string profilePathSimulation = Path.Combine(dataSetSatisfactory.SourceFolder, dataSetSatisfactory.ProfileName + "_Open.shp"); File.Copy(profilePathOrigin, profilePathSimulation); string content = File.ReadAllText(profilePathSimulation); content = content.Replace(@"%SOURCEFOLDER%", dataSetSatisfactory.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("IncludeAutosave"); 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); Thread.Sleep(100); watcherManager.SetAutoBackup(true); Assert.AreEqual(AutoBackupStatus.Enabled, watcherManager.AutoBackupStatus); string fileSource = Path.Combine(dataSetSatisfactory.DataRoot, @"Original"); string fileDest = dataSetSatisfactory.SourceFolder; foreach (var files in dataSetSatisfactory.Watchers.OrderBy(x => x.Key)) { backupCount = 0; foreach (var file in files.Value.Files) { // this engine requires file changes //using (var fileStream = File.Create(Path.Combine(fileDest, file))) //{ } //Thread.Sleep(100); using (var fileStream = File.OpenWrite(Path.Combine(fileDest, file))) { var bytes = File.ReadAllBytes(Path.Combine(fileSource, file)); fileStream.Write(bytes, 0, bytes.Length); } Thread.Sleep(100); } Thread.Sleep(500); Assert.GreaterOrEqual(backupCount, 1); 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.SnapshotBuildVersion, snapshot.CustomValueByKey("BuildVersion").ToString()); Assert.AreEqual(files.Value.SnapshotSaveVersion, snapshot.CustomValueByKey("SaveVersion").ToString()); Assert.AreEqual(files.Value.SnapshotSessionName, snapshot.CustomValueByKey("SessionName").ToString()); Assert.AreEqual(files.Value.SnapshotPlayedTime, snapshot.CustomValueByKey("PlayedTime").ToString()); Assert.AreEqual(files.Value.SnapshotAutosave, snapshot.CustomValueByKey("Autosave").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(dataSetSatisfactory.SourceFolder, true); }
/// Profileの保存 private bool SaveProfileInternal(string path) { // Profile var profileFile = new ProfileFile(this.Profile); var result = profileFile.WriteFile(path); if (!result) return false; // Options this.Options.AddRecentProfile(path); // RuntimeOptions this.RuntimeOptions.ProfilePath = path; this.RuntimeOptions.ProfileName = Path.GetFileNameWithoutExtension(path); this.RuntimeOptions.LastSavedTimestamp = this.Profile.Timestamp; return true; }
/// Profileを読み込む private bool OpenProfileInternal(string path) { // Profile var profileFile = new ProfileFile(this.Profile); var result = profileFile.ReadFile(path); if (!result) return false; // バックアップパラメータの復元 if (this.Options.RestoreMissingWindowWhenOpeningProfile) { this.Profile.RestoreBackupParameters(); } // Options this.Options.AddRecentProfile(path); // RuntimeOptions this.RuntimeOptions.ProfilePath = path; this.RuntimeOptions.ProfileName = Path.GetFileNameWithoutExtension(path); this.RuntimeOptions.LastSavedTimestamp = this.Profile.Timestamp; this.RuntimeOptions.LastAppliedTimestamp = RuntimeOptions.InvalidTimestamp; this.Profile.RaiseChanged(); return true; }