1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Some tiny changes, only commiting as a backup

This commit is contained in:
SpoinkyNL 2016-03-20 19:21:22 +01:00
parent 04158dce39
commit a959d10263
3 changed files with 37 additions and 20 deletions

View File

@ -8,18 +8,18 @@ using Newtonsoft.Json;
namespace Artemis.DAL 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> /// <summary>
/// Get all profiles /// Get all profiles
/// </summary> /// </summary>
/// <returns>All profiles</returns> /// <returns>All profiles</returns>
public List<ProfileModel> GetAll() public static List<ProfileModel> GetAll()
{ {
ReadProfiles(); return ReadProfiles();
return new List<ProfileModel>();
} }
/// <summary> /// <summary>
@ -27,7 +27,7 @@ namespace Artemis.DAL
/// </summary> /// </summary>
/// <param name="game">The game to match</param> /// <param name="game">The game to match</param>
/// <returns>All profiles matching the provided game</returns> /// <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(); return GetAll().Where(g => g.GameName.Equals(game.Name)).ToList();
} }
@ -36,37 +36,43 @@ namespace Artemis.DAL
/// Adds or update the given profile. /// Adds or update the given profile.
/// Updates occur when a profile with the same name and game exist. /// Updates occur when a profile with the same name and game exist.
/// </summary> /// </summary>
/// <param name="profile">The profile to add or update</param> /// <param name="prof">The profile to add or update</param>
public void AddOrUpdate(ProfileModel profile) 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(); CheckProfiles();
_profiles = new List<ProfileModel>(); var profiles = new List<ProfileModel>();
// Create the directory structure // 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 // Parse the JSON files into objects and add them if they are valid
foreach (var file in profileFiles) foreach (var file in profileFiles)
{ {
var prof = JsonConvert.DeserializeObject<ProfileModel>(File.ReadAllText(file)); var prof = JsonConvert.DeserializeObject<ProfileModel>(File.ReadAllText(file));
if (prof.GameName?.Length > 1 && prof.KeyboardName?.Length > 1 && prof.Name?.Length > 1) 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 // Create the directory structure
var profileFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\Artemis\profiles"; if (Directory.Exists(ProfileFolder))
if (Directory.Exists(profileFolder))
return; return;
Directory.CreateDirectory(profileFolder); Directory.CreateDirectory(ProfileFolder);
Debug.WriteLine("Place presets"); Debug.WriteLine("Place presets");
} }
} }

View File

@ -17,7 +17,7 @@ namespace Artemis.Modules.Games.TheDivision
GameModel = new TheDivisionModel(mainManager, (TheDivisionSettings) GameSettings); GameModel = new TheDivisionModel(mainManager, (TheDivisionSettings) GameSettings);
MainManager.EffectManager.EffectModels.Add(GameModel); MainManager.EffectManager.EffectModels.Add(GameModel);
ProfileEditor = new ProfileEditorViewModel(MainManager.KeyboardManager.ActiveKeyboard); ProfileEditor = new ProfileEditorViewModel(GameModel, MainManager.KeyboardManager.ActiveKeyboard);
} }
public ProfileEditorViewModel ProfileEditor { get; set; } public ProfileEditorViewModel ProfileEditor { get; set; }

View File

@ -1,18 +1,29 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Windows.Media; using System.Windows.Media;
using Artemis.Components; using Artemis.DAL;
using Artemis.KeyboardProviders; using Artemis.KeyboardProviders;
using Artemis.Models;
using Caliburn.Micro; using Caliburn.Micro;
namespace Artemis.ViewModels namespace Artemis.ViewModels
{ {
public class ProfileEditorViewModel : Screen public class ProfileEditorViewModel : Screen
{ {
private readonly GameModel _gameModel;
private readonly KeyboardProvider _keyboard; private readonly KeyboardProvider _keyboard;
private List<ProfileModel> _profiles;
public ProfileEditorViewModel(KeyboardProvider keyboard) public ProfileEditorViewModel(GameModel gameModel, KeyboardProvider keyboard)
{ {
_gameModel = gameModel;
_keyboard = keyboard; _keyboard = keyboard;
GetProfiles();
}
public void GetProfiles()
{
_profiles = ProfileProvider.GetAll(_gameModel);
} }
private ImageSource GenerateKeyboardImage() private ImageSource GenerateKeyboardImage()