using Newtonsoft.Json; using System; using System.Collections.Generic; using System.IO; using System.Text; namespace NumpadMonitor { internal class KeyCodeReaderWriter { private const string Path = @"%APPDATA%\KeyboardCalculator\"; private const string Filename = "KeyConfig.json"; static public void Write(List keyHandlers) { List keyinfo = new List(); foreach (KeyHandler handler in keyHandlers) { keyinfo.Add(handler.KeyInfo); } string output = JsonConvert.SerializeObject(keyinfo); string path = Environment.ExpandEnvironmentVariables(Path); Directory.CreateDirectory(path); File.WriteAllText(path + Filename, output, Encoding.UTF8); } internal static List Read() { string path = Environment.ExpandEnvironmentVariables(Path); if (!File.Exists(path + Filename)) return null; string filestring = File.ReadAllText(path + Filename, Encoding.UTF8); List keyInfo = JsonConvert.DeserializeObject>(filestring); return keyInfo; } } }