/// <summary> /// Initializes a new instance of the <see cref="ConfigurationViewModel"/> class. /// </summary> public ConfigurationViewModel() { m_config = new KinectLoungeConfig(); if(SeeingSharpApplication.IsInitialized) { m_config = KinectLoungeConfig.TryLoadFromDefaultLocation(); } // Apply configuration and leave configuration screen this.CommandApply = new DelegateCommand( () => { this.Config.SaveToDefaultLocation(); SeeingSharpApplication.Current.UIMessenger.Publish<MessageManualExit>(); }); // Discard settings and leave configuration screen this.CommandHome = new DelegateCommand( () => { m_config= KinectLoungeConfig.TryLoadFromDefaultLocation(); SeeingSharpApplication.Current.UIMessenger.Publish<MessageManualExit>(); }); }
/// <summary> /// Initializes a new instance of the <see cref="MainFolderViewModel"/> class. /// </summary> public MainFolderViewModel(KinectLoungeConfig config) : base(null, config.DataPath) { m_config = config; }
public static KinectLoungeConfig TryLoadFromDefaultLocation() { // Get directory path (create it, if it is not available) string defaultLoc = Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "RKKinectLounge"); if(!Directory.Exists(defaultLoc)){ Directory.CreateDirectory(defaultLoc); } // Try to open the file string filePath = Path.Combine(defaultLoc, "Config.json"); if (!File.Exists(filePath)) { return new KinectLoungeConfig(); } else { try { using (Stream inStream = File.OpenRead(filePath)) using (StreamReader inStreamReader = new StreamReader(inStream, Encoding.Unicode)) using (JsonTextReader jsonReader = new JsonTextReader(inStreamReader)) { KinectLoungeConfig result = SerializerCollection.DEFAULT_JSON.Deserialize<KinectLoungeConfig>(jsonReader); if(result == null) { result = new KinectLoungeConfig(); } return result; } } catch(Exception) { return new KinectLoungeConfig(); } } }