mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-12 21:38:38 +00:00
Some tiny changes, only commiting as a backup
This commit is contained in:
parent
04158dce39
commit
a959d10263
@ -8,18 +8,18 @@ using Newtonsoft.Json;
|
||||
|
||||
namespace Artemis.DAL
|
||||
{
|
||||
internal class ProfileProvider
|
||||
public static class ProfileProvider
|
||||
{
|
||||
private List<ProfileModel> _profiles;
|
||||
private static readonly string ProfileFolder =
|
||||
Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\Artemis\profiles";
|
||||
|
||||
/// <summary>
|
||||
/// Get all profiles
|
||||
/// </summary>
|
||||
/// <returns>All profiles</returns>
|
||||
public List<ProfileModel> GetAll()
|
||||
public static List<ProfileModel> GetAll()
|
||||
{
|
||||
ReadProfiles();
|
||||
return new List<ProfileModel>();
|
||||
return ReadProfiles();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -27,7 +27,7 @@ namespace Artemis.DAL
|
||||
/// </summary>
|
||||
/// <param name="game">The game to match</param>
|
||||
/// <returns>All profiles matching the provided game</returns>
|
||||
public List<ProfileModel> GetAll(GameModel game)
|
||||
public static List<ProfileModel> GetAll(GameModel game)
|
||||
{
|
||||
return GetAll().Where(g => g.GameName.Equals(game.Name)).ToList();
|
||||
}
|
||||
@ -36,37 +36,43 @@ namespace Artemis.DAL
|
||||
/// Adds or update the given profile.
|
||||
/// Updates occur when a profile with the same name and game exist.
|
||||
/// </summary>
|
||||
/// <param name="profile">The profile to add or update</param>
|
||||
public void AddOrUpdate(ProfileModel profile)
|
||||
/// <param name="prof">The profile to add or update</param>
|
||||
public static void AddOrUpdate(ProfileModel prof)
|
||||
{
|
||||
if (!(prof.GameName?.Length > 1) || !(prof.KeyboardName?.Length > 1) || !(prof.Name?.Length > 1))
|
||||
throw new ArgumentException("Profile is invalid. Name, GameName and KeyboardName are required");
|
||||
|
||||
var serialized = JsonConvert.SerializeObject(prof);
|
||||
var path = ProfileFolder + $@"\{prof.KeyboardName}\{prof.GameName}\{prof.Name}.json";
|
||||
File.WriteAllText(path, serialized);
|
||||
}
|
||||
|
||||
private void ReadProfiles()
|
||||
private static List<ProfileModel> ReadProfiles()
|
||||
{
|
||||
CheckProfiles();
|
||||
_profiles = new List<ProfileModel>();
|
||||
var profiles = new List<ProfileModel>();
|
||||
|
||||
// Create the directory structure
|
||||
var profileFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\Artemis\profiles";
|
||||
var profileFiles = Directory.GetFiles(profileFolder, "*.json", SearchOption.AllDirectories);
|
||||
var profileFiles = Directory.GetFiles(ProfileFolder, "*.json", SearchOption.AllDirectories);
|
||||
|
||||
// Parse the JSON files into objects and add them if they are valid
|
||||
foreach (var file in profileFiles)
|
||||
{
|
||||
var prof = JsonConvert.DeserializeObject<ProfileModel>(File.ReadAllText(file));
|
||||
if (prof.GameName?.Length > 1 && prof.KeyboardName?.Length > 1 && prof.Name?.Length > 1)
|
||||
_profiles.Add(prof);
|
||||
profiles.Add(prof);
|
||||
}
|
||||
|
||||
return profiles;
|
||||
}
|
||||
|
||||
private void CheckProfiles()
|
||||
private static void CheckProfiles()
|
||||
{
|
||||
// Create the directory structure
|
||||
var profileFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\Artemis\profiles";
|
||||
if (Directory.Exists(profileFolder))
|
||||
if (Directory.Exists(ProfileFolder))
|
||||
return;
|
||||
|
||||
Directory.CreateDirectory(profileFolder);
|
||||
Directory.CreateDirectory(ProfileFolder);
|
||||
Debug.WriteLine("Place presets");
|
||||
}
|
||||
}
|
||||
|
||||
@ -17,7 +17,7 @@ namespace Artemis.Modules.Games.TheDivision
|
||||
GameModel = new TheDivisionModel(mainManager, (TheDivisionSettings) GameSettings);
|
||||
MainManager.EffectManager.EffectModels.Add(GameModel);
|
||||
|
||||
ProfileEditor = new ProfileEditorViewModel(MainManager.KeyboardManager.ActiveKeyboard);
|
||||
ProfileEditor = new ProfileEditorViewModel(GameModel, MainManager.KeyboardManager.ActiveKeyboard);
|
||||
}
|
||||
|
||||
public ProfileEditorViewModel ProfileEditor { get; set; }
|
||||
|
||||
@ -1,18 +1,29 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Windows.Media;
|
||||
using Artemis.Components;
|
||||
using Artemis.DAL;
|
||||
using Artemis.KeyboardProviders;
|
||||
using Artemis.Models;
|
||||
using Caliburn.Micro;
|
||||
|
||||
namespace Artemis.ViewModels
|
||||
{
|
||||
public class ProfileEditorViewModel : Screen
|
||||
{
|
||||
private readonly GameModel _gameModel;
|
||||
private readonly KeyboardProvider _keyboard;
|
||||
private List<ProfileModel> _profiles;
|
||||
|
||||
public ProfileEditorViewModel(KeyboardProvider keyboard)
|
||||
public ProfileEditorViewModel(GameModel gameModel, KeyboardProvider keyboard)
|
||||
{
|
||||
_gameModel = gameModel;
|
||||
_keyboard = keyboard;
|
||||
|
||||
GetProfiles();
|
||||
}
|
||||
|
||||
public void GetProfiles()
|
||||
{
|
||||
_profiles = ProfileProvider.GetAll(_gameModel);
|
||||
}
|
||||
|
||||
private ImageSource GenerateKeyboardImage()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user