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 InstallGif() { var gif = Resources.redeemer; ProfileProvider.InsertGif(ProfileProvider.GetAll() .Where(p => (p.GameName == "UnrealTournament") && (p.Name == "Default")), "Redeemer GIF", gif, "redeemer"); }
/// <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; }
/// <summary> /// Loads all profiles for the current game and keyboard /// </summary> private void LoadProfiles() { Profiles.Clear(); if (_gameModel == null || _mainManager.DeviceManager.ActiveKeyboard == null) { return; } Profiles.AddRange(ProfileProvider.GetAll(_gameModel, _mainManager.DeviceManager.ActiveKeyboard)); // If a profile name was provided, try to load it ProfileModel lastProfileModel = null; if (!string.IsNullOrEmpty(LastProfile)) { lastProfileModel = Profiles.FirstOrDefault(p => p.Name == LastProfile); } SelectedProfile = lastProfileModel ?? Profiles.FirstOrDefault(); }
public async void RenameProfile() { if (SelectedProfile == null) { return; } var oldName = SelectedProfile.Name; SelectedProfile.Name = await DialogService .ShowInputDialog("Rename profile", "Please enter a unique new profile name"); // Null when the user cancelled if (string.IsNullOrEmpty(SelectedProfile.Name) || SelectedProfile.Name.Length < 2) { SelectedProfile.Name = oldName; return; } // Verify the name while (ProfileProvider.GetAll().Contains(SelectedProfile)) { SelectedProfile.Name = await DialogService. ShowInputDialog("Name already in use", "Please enter a unique new profile name"); // Null when the user cancelled if (string.IsNullOrEmpty(SelectedProfile.Name) || SelectedProfile.Name.Length < 2) { SelectedProfile.Name = oldName; return; } } var newName = SelectedProfile.Name; SelectedProfile.Name = oldName; ProfileProvider.RenameProfile(SelectedProfile, newName); LoadProfiles(); SelectedProfile = Profiles.FirstOrDefault(p => p.Name == newName); }
public async void RenameProfile() { if (SelectedProfile == null) { return; } var name = await DialogService.ShowInputDialog("Rename profile", "Please enter a unique new profile name"); // Null when the user cancelled if (string.IsNullOrEmpty(name) || name.Length < 2) { return; } // Verify the name while (ProfileProvider.GetAll().Any(p => p.Name == name && p.GameName == SelectedProfile.GameName && p.KeyboardSlug == SelectedProfile.KeyboardSlug)) { name = await DialogService.ShowInputDialog("Name already in use", "Please enter a unique new profile name"); // Null when the user cancelled if (string.IsNullOrEmpty(name) || name.Length < 2) { return; } } var profile = SelectedProfile; SelectedProfile = null; ProfileProvider.RenameProfile(profile, name); LastProfile = name; LoadProfiles(); }
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); }