public async void DuplicateProfile() { if (SelectedProfile == null) { return; } var newProfile = GeneralHelpers.Clone(SelectedProfile); newProfile.Name = await DialogService.ShowInputDialog("Duplicate profile", "Please enter a unique profile name"); // Verify the name while (ProfileProvider.GetAll().Contains(newProfile)) { newProfile.Name = await DialogService.ShowInputDialog("Name already in use", "Please enter a unique profile name"); // Null when the user cancelled if (string.IsNullOrEmpty(SelectedProfile.Name)) { return; } } newProfile.IsDefault = false; ProfileProvider.AddOrUpdate(newProfile); LoadProfiles(); SelectedProfile = Profiles.FirstOrDefault(p => p.Name == newProfile.Name); }
private void LuaFileChanged(object sender, FileSystemEventArgs args) { if (_luaModule == null) { DisposeLuaWatcher(); return; } if (args.ChangeType != WatcherChangeTypes.Changed) { return; } lock (_luaModule) { using (var fs = new FileStream(args.FullPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { using (var sr = new StreamReader(fs)) { _luaModule.ProfileModel.LuaScript = sr.ReadToEnd(); } } ProfileProvider.AddOrUpdate(_luaModule.ProfileModel); _luaManager.SetupLua(_luaModule.ProfileModel); } }
public override void Dispose() { // Store profile values LuaManager.ProfileModel.LuaStorage = _profileValues.TableToJson(); ProfileProvider.AddOrUpdate(LuaManager.ProfileModel); // Store global values _globalSettings.GlobalValues = _globalValues.TableToJson(); _globalSettings.Save(); }
/// <summary> /// Adds a new profile to the current game and keyboard /// </summary> public async void AddProfile() { if (_mainManager.DeviceManager.ActiveKeyboard == null) { DialogService.ShowMessageBox("Cannot add profile.", "To add a profile, please select a keyboard in the options menu first."); return; } var name = await DialogService.ShowInputDialog("Add new profile", "Please provide a profile name unique to this game and keyboard."); // Null when the user cancelled if (name == null) { return; } if (name.Length < 2) { DialogService.ShowMessageBox("Invalid profile name", "Please provide a valid profile name"); return; } var profile = new ProfileModel { Name = name, KeyboardSlug = _mainManager.DeviceManager.ActiveKeyboard.Slug, Width = _mainManager.DeviceManager.ActiveKeyboard.Width, Height = _mainManager.DeviceManager.ActiveKeyboard.Height, GameName = _gameModel.Name }; if (ProfileProvider.GetAll().Contains(profile)) { var overwrite = await DialogService.ShowQuestionMessageBox("Overwrite existing profile", "A profile with this name already exists for this game. Would you like to overwrite it?"); if (!overwrite.Value) { return; } } ProfileProvider.AddOrUpdate(profile); LoadProfiles(); SelectedProfile = profile; }
private void ProfileSaveHandler(object sender, ElapsedEventArgs e) { if (_saving || SelectedProfile == null) { return; } _saving = true; try { ProfileProvider.AddOrUpdate(SelectedProfile); } catch (Exception) { // ignored } _saving = false; }
public void SaveSelectedProfile() { if (_saving || SelectedProfile == null || _deviceManager.ChangingKeyboard) { return; } _saving = true; try { ProfileProvider.AddOrUpdate(SelectedProfile); } catch (Exception) { // ignored } _saving = false; }
public async Task <ProfileModel> AddProfile(ModuleModel moduleModel) { if (_deviceManager.ActiveKeyboard == null) { _dialogService.ShowMessageBox("Cannot add profile.", "To add a profile, please select a keyboard in the options menu first."); return(null); } var name = await GetValidProfileName("Name profile", "Please enter a unique name for your new profile"); // User cancelled if (name == null) { return(null); } var profile = new ProfileModel { Name = name, KeyboardSlug = _deviceManager.ActiveKeyboard.Slug, Width = _deviceManager.ActiveKeyboard.Width, Height = _deviceManager.ActiveKeyboard.Height, GameName = moduleModel.Name }; if (!ProfileProvider.IsProfileUnique(profile)) { var overwrite = await _dialogService.ShowQuestionMessageBox("Overwrite existing profile", "A profile with this name already exists for this game. Would you like to overwrite it?"); if (!overwrite.Value) { return(null); } } ProfileProvider.AddOrUpdate(profile); return(profile); }
/// <summary> /// Migrates old versions of profiles to new versions /// </summary> public void MigrateProfiles() { // 1.8.0.0 - Rename WindowsProfile to GeneralProfile foreach (var keyboardProvider in _deviceManager.KeyboardProviders) { var folder = ProfileProvider.ProfileFolder + "/" + keyboardProvider.Slug + "/WindowsProfile"; if (!Directory.Exists(folder)) { continue; } // Get all the profiles var profiles = ProfileProvider.ReadProfiles(keyboardProvider.Slug + "/WindowsProfile"); foreach (var profile in profiles) { // Change their GameName and save, effectively moving them to the new folder profile.GameName = "GeneralProfile"; ProfileProvider.AddOrUpdate(profile); } // Delete the old profiles Directory.Delete(folder, true); } }
public async Task <ProfileModel> DuplicateProfile(ProfileModel selectedProfile) { var newProfile = GeneralHelpers.Clone(selectedProfile); var name = await GetValidProfileName("Duplicate profile", "Please enter a unique new profile name"); // User cancelled if (name == null) { return(null); } var doRename = await MakeProfileUnique(newProfile, name, newProfile.Name); if (!doRename) { return(null); } // Make sure it's not default, in case of copying a default profile newProfile.IsDefault = false; ProfileProvider.AddOrUpdate(newProfile); return(newProfile); }
/// <summary> /// Handles refreshing the layer preview /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void PropertyChangeHandler(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == "KeyboardPreview") { return; } if (e.PropertyName == "SelectedLayer") { NotifyOfPropertyChange(() => LayerSelected); return; } if (SelectedProfile != null) { ProfileProvider.AddOrUpdate(SelectedProfile); } if (e.PropertyName != "SelectedProfile") { return; } // Update editor enabled state NotifyOfPropertyChange(() => EditorEnabled); // Update ProfileViewModel ProfileViewModel.SelectedProfile = SelectedProfile; // Update interface Layers.Clear(); if (SelectedProfile != null) { Layers.AddRange(SelectedProfile.Layers); } NotifyOfPropertyChange(() => ProfileSelected); }
public async void ImportProfile() { if (_mainManager.DeviceManager.ActiveKeyboard == null) { DialogService.ShowMessageBox("Cannot import profile.", "To import a profile, please select a keyboard in the options menu first."); return; } var dialog = new OpenFileDialog { Filter = "Artemis profile (*.json)|*.json" }; var result = dialog.ShowDialog(); if (result != DialogResult.OK) { return; } var profile = ProfileProvider.LoadProfileIfValid(dialog.FileName); if (profile == null) { DialogService.ShowErrorMessageBox("Oh noes, the profile you provided is invalid. " + "If this keeps happening, please make an issue on GitHub and provide the profile."); return; } // Verify the game if (profile.GameName != _gameModel.Name) { DialogService.ShowErrorMessageBox( $"Oh oops! This profile is ment for {profile.GameName}, not {_gameModel.Name} :c"); return; } // Verify the keyboard var deviceManager = _mainManager.DeviceManager; if (profile.KeyboardSlug != deviceManager.ActiveKeyboard.Slug) { var adjustKeyboard = await DialogService.ShowQuestionMessageBox("Profile not inteded for this keyboard", $"Watch out, this profile wasn't ment for this keyboard, but for the {profile.KeyboardSlug}. " + "You can still import it but you'll probably have to do some adjusting\n\n" + "Continue?"); if (!adjustKeyboard.Value) { return; } // Resize layers that are on the full keyboard width profile.ResizeLayers(deviceManager.ActiveKeyboard); // Put layers back into the canvas if they fell outside it profile.FixBoundaries(deviceManager.ActiveKeyboard.KeyboardRectangle(1)); // Setup profile metadata to match the new keyboard profile.KeyboardSlug = deviceManager.ActiveKeyboard.Slug; profile.Width = deviceManager.ActiveKeyboard.Width; profile.Height = deviceManager.ActiveKeyboard.Height; } profile.IsDefault = false; // Verify the name while (ProfileProvider.GetAll().Contains(profile)) { profile.Name = await DialogService.ShowInputDialog("Rename imported profile", "A profile with this name already exists for this game. Please enter a new name"); // Null when the user cancelled if (string.IsNullOrEmpty(profile.Name)) { return; } } ProfileProvider.AddOrUpdate(profile); LoadProfiles(); SelectedProfile = Profiles.FirstOrDefault(p => p.Name == profile.Name); }
public async Task <ProfileModel> ImportProfile(ModuleModel moduleModel) { var dialog = new OpenFileDialog { Filter = "Artemis profile (*.json)|*.json" }; var result = dialog.ShowDialog(); if (result != DialogResult.OK) { return(null); } var profileModel = ProfileProvider.LoadProfileIfValid(dialog.FileName); if (profileModel == null) { _dialogService.ShowErrorMessageBox("Oh noes, the profile you provided is invalid. " + "If this keeps happening, please make an issue on GitHub and provide the profile."); return(null); } // Verify the game if (profileModel.GameName != moduleModel.Name) { _dialogService.ShowErrorMessageBox( $"Oh oops! This profile is ment for {profileModel.GameName}, not {moduleModel.Name} :c"); return(null); } // Verify the keyboard var deviceManager = _deviceManager; if (profileModel.KeyboardSlug != deviceManager.ActiveKeyboard.Slug) { var adjustKeyboard = await _dialogService.ShowQuestionMessageBox("Profile not made for this keyboard", $"Watch out, this profile wasn't ment for this keyboard, but for the {profileModel.KeyboardSlug}. " + "You can still import it but you'll probably have to do some adjusting\n\n" + "Continue?"); if (!adjustKeyboard.Value) { return(null); } // Resize layers that are on the full keyboard width profileModel.ResizeLayers(deviceManager.ActiveKeyboard); // Put layers back into the canvas if they fell outside it profileModel.FixBoundaries(deviceManager.ActiveKeyboard.KeyboardRectangle(1)); // Setup profile metadata to match the new keyboard profileModel.KeyboardSlug = deviceManager.ActiveKeyboard.Slug; profileModel.Width = deviceManager.ActiveKeyboard.Width; profileModel.Height = deviceManager.ActiveKeyboard.Height; } var name = await GetValidProfileName("Rename profile", "Please enter a unique new profile name"); // User cancelled if (name == null) { return(null); } var doRename = await MakeProfileUnique(profileModel, name, profileModel.Name); if (!doRename) { return(null); } profileModel.IsDefault = false; ProfileProvider.AddOrUpdate(profileModel); return(profileModel); }