You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
1.3 KiB

5 years ago
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<KeyHandler> keyHandlers)
{
List<KeyInfo> keyinfo = new List<KeyInfo>();
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<KeyInfo> Read()
{
string path = Environment.ExpandEnvironmentVariables(Path);
if (!File.Exists(path + Filename)) return null;
string filestring = File.ReadAllText(path + Filename, Encoding.UTF8);
List<KeyInfo> keyInfo = JsonConvert.DeserializeObject<List<KeyInfo>>(filestring);
return keyInfo;
}
}
}