using Newtonsoft.Json; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using VDash.Overlay.Config; namespace VDash { public class ProfileManager { public static string ConfigDirectory { get { return Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments, Environment.SpecialFolderOption.None) + @"\VRDash\"; } } public static string ConfigLocation { get { return ConfigDirectory + "DefaultProfile.vdc"; } } JsonSerializerSettings m_Settings = new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.All, Formatting = Formatting.Indented, ContractResolver = new JsonNet.PrivateSettersContractResolvers.PrivateSetterContractResolver() }; public ProfileManager() { } public void SaveProfile() { var path = Path.GetDirectoryName(ConfigLocation); //Make sure directory tree exists if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } SaveProfile(ConfigLocation); } /// /// Saves config to ConfigLocation /// public void SaveProfile(string location) { IOverlayConfig[] selection = MainWindow.OverlayManager.Overlays.Select(x => x.Overlay.OverlayConfig).ToArray(); var profile = new Profile(selection); var json = JsonConvert.SerializeObject(profile, m_Settings); File.WriteAllText(location, json); } public Profile LoadProfile() { return LoadProfile(ConfigLocation); } public Profile LoadProfile(string location) { var json = File.ReadAllText(location); var profile = JsonConvert.DeserializeObject(json, m_Settings); return profile; } } public class Profile { public Profile(IOverlayConfig[] overlayConfigs) { OverlayConfigs = overlayConfigs; } public Profile() { } public IOverlayConfig[] OverlayConfigs { get; private set; } } }