mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Implemented functionality on all the profile management buttons
This commit is contained in:
parent
5a19bf9e30
commit
d9ad83d73e
@ -1,6 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Xml.Serialization;
|
using System.Xml.Serialization;
|
||||||
@ -87,6 +86,9 @@ namespace Artemis.DAL
|
|||||||
return profiles;
|
return profiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Makes sure the profile directory structure is in order and places default profiles
|
||||||
|
/// </summary>
|
||||||
private static void CheckProfiles()
|
private static void CheckProfiles()
|
||||||
{
|
{
|
||||||
// Create the directory structure
|
// Create the directory structure
|
||||||
@ -94,9 +96,13 @@ namespace Artemis.DAL
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
Directory.CreateDirectory(ProfileFolder);
|
Directory.CreateDirectory(ProfileFolder);
|
||||||
Debug.WriteLine("Place presets");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Attempts to load a profile from a given path
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="path">The absolute path to load the profile from</param>
|
||||||
|
/// <returns>The loaded profile, or null if invalid</returns>
|
||||||
public static ProfileModel LoadProfileIfValid(string path)
|
public static ProfileModel LoadProfileIfValid(string path)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@ -115,5 +121,47 @@ namespace Artemis.DAL
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Exports the given profile to the provided path in XML
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="selectedProfile">The profile to export</param>
|
||||||
|
/// <param name="path">The path to save the profile to</param>
|
||||||
|
public static void ExportProfile(ProfileModel selectedProfile, string path)
|
||||||
|
{
|
||||||
|
var serializer = new XmlSerializer(typeof(ProfileModel));
|
||||||
|
using (var file = new StreamWriter(path))
|
||||||
|
{
|
||||||
|
serializer.Serialize(file, selectedProfile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Renames the profile on the model and filesystem
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="profile">The profile to rename</param>
|
||||||
|
/// <param name="name">The new name</param>
|
||||||
|
public static void RenameProfile(ProfileModel profile, string name)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(name))
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Remove the old file
|
||||||
|
var path = ProfileFolder + $@"\{profile.KeyboardName}\{profile.GameName}\{profile.Name}.xml";
|
||||||
|
if (File.Exists(path))
|
||||||
|
File.Delete(path);
|
||||||
|
|
||||||
|
// Update the profile, creating a new file
|
||||||
|
profile.Name = name;
|
||||||
|
AddOrUpdate(profile);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void DeleteProfile(ProfileModel profile)
|
||||||
|
{
|
||||||
|
// Remove the file
|
||||||
|
var path = ProfileFolder + $@"\{profile.KeyboardName}\{profile.GameName}\{profile.Name}.xml";
|
||||||
|
if (File.Exists(path))
|
||||||
|
File.Delete(path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -263,45 +263,6 @@ namespace Artemis.ViewModels
|
|||||||
SelectedProfile = Profiles.FirstOrDefault();
|
SelectedProfile = Profiles.FirstOrDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Adds a new profile to the current game and keyboard
|
|
||||||
/// </summary>
|
|
||||||
public async void AddProfile()
|
|
||||||
{
|
|
||||||
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 < 1)
|
|
||||||
{
|
|
||||||
DialogService.ShowMessageBox("Invalid profile name", "Please provide a valid profile name");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var profile = new ProfileModel
|
|
||||||
{
|
|
||||||
Name = name,
|
|
||||||
KeyboardName = ActiveKeyboard.Name,
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void EditLayer()
|
public void EditLayer()
|
||||||
{
|
{
|
||||||
if (SelectedLayer == null)
|
if (SelectedLayer == null)
|
||||||
@ -620,6 +581,115 @@ namespace Artemis.ViewModels
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds a new profile to the current game and keyboard
|
||||||
|
/// </summary>
|
||||||
|
public async void AddProfile()
|
||||||
|
{
|
||||||
|
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 < 1)
|
||||||
|
{
|
||||||
|
DialogService.ShowMessageBox("Invalid profile name", "Please provide a valid profile name");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var profile = new ProfileModel
|
||||||
|
{
|
||||||
|
Name = name,
|
||||||
|
KeyboardName = ActiveKeyboard.Name,
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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");
|
||||||
|
// 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 = oldName;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var newName = SelectedProfile.Name;
|
||||||
|
SelectedProfile.Name = oldName;
|
||||||
|
ProfileProvider.RenameProfile(SelectedProfile, newName);
|
||||||
|
|
||||||
|
LoadProfiles();
|
||||||
|
SelectedProfile = Profiles.FirstOrDefault(p => p.Name == newName);
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
ProfileProvider.AddOrUpdate(newProfile);
|
||||||
|
LoadProfiles();
|
||||||
|
SelectedProfile = Profiles.FirstOrDefault(p => p.Name == newProfile.Name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async void DeleteProfile()
|
||||||
|
{
|
||||||
|
if (SelectedProfile == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var confirm = await
|
||||||
|
DialogService.ShowQuestionMessageBox("Delete profile",
|
||||||
|
$"Are you sure you want to delete the profile named: {SelectedProfile.Name}?\n\n" +
|
||||||
|
"This cannot be undone.");
|
||||||
|
if (!confirm.Value)
|
||||||
|
return;
|
||||||
|
|
||||||
|
ProfileProvider.DeleteProfile(SelectedProfile);
|
||||||
|
LoadProfiles();
|
||||||
|
}
|
||||||
|
|
||||||
public async void ImportProfile()
|
public async void ImportProfile()
|
||||||
{
|
{
|
||||||
var dialog = new OpenFileDialog {Filter = "Artemis profile (*.xml)|*.xml"};
|
var dialog = new OpenFileDialog {Filter = "Artemis profile (*.xml)|*.xml"};
|
||||||
@ -673,5 +743,18 @@ namespace Artemis.ViewModels
|
|||||||
|
|
||||||
SelectedProfile = Profiles.FirstOrDefault(p => p.Name == profile.Name);
|
SelectedProfile = Profiles.FirstOrDefault(p => p.Name == profile.Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ExportProfile()
|
||||||
|
{
|
||||||
|
if (SelectedProfile == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var dialog = new SaveFileDialog {Filter = "Artemis profile (*.xml)|*.xml"};
|
||||||
|
var result = dialog.ShowDialog();
|
||||||
|
if (result != DialogResult.OK)
|
||||||
|
return;
|
||||||
|
|
||||||
|
ProfileProvider.ExportProfile(SelectedProfile, dialog.FileName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -65,7 +65,7 @@
|
|||||||
</Rectangle>
|
</Rectangle>
|
||||||
</Button.Content>
|
</Button.Content>
|
||||||
</Button>
|
</Button>
|
||||||
<Button x:Name="EditProfile" VerticalAlignment="Top" Style="{DynamicResource SquareButtonStyle}"
|
<Button x:Name="RenameProfile" VerticalAlignment="Top" Style="{DynamicResource SquareButtonStyle}"
|
||||||
Width="26" Height="26" HorizontalAlignment="Right" Margin="10,0,0,0" ToolTip="Rename profile">
|
Width="26" Height="26" HorizontalAlignment="Right" Margin="10,0,0,0" ToolTip="Rename profile">
|
||||||
<Button.Content>
|
<Button.Content>
|
||||||
<Rectangle
|
<Rectangle
|
||||||
@ -89,7 +89,7 @@
|
|||||||
</Rectangle>
|
</Rectangle>
|
||||||
</Button.Content>
|
</Button.Content>
|
||||||
</Button>
|
</Button>
|
||||||
<Button x:Name="RemoveProfile" VerticalAlignment="Top" Style="{DynamicResource SquareButtonStyle}"
|
<Button x:Name="DeleteProfile" VerticalAlignment="Top" Style="{DynamicResource SquareButtonStyle}"
|
||||||
Width="26" Height="26" HorizontalAlignment="Right" Margin="10,0,0,0" ToolTip="Delete profile">
|
Width="26" Height="26" HorizontalAlignment="Right" Margin="10,0,0,0" ToolTip="Delete profile">
|
||||||
<Button.Content>
|
<Button.Content>
|
||||||
<Rectangle
|
<Rectangle
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user