/// <summary> /// Keyboard added event called /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void keyboardAdded(object sender, EventArgs e) { //Collect new keyboard information string name = _addKeyboardContr.KeyboardName; string uuid = _addKeyboardContr.KeyboardID; string port = _addKeyboardContr.KeyboardPort; //Create new keyboard class/userControl Keyboard kb = new Keyboard(Properties.Resources.KeyboardScanner__staticId); _keyboards.Add(kb); kb.KeyboardName = name; kb.KeyboardComPort = port; kb.KeyboardUuid = uuid; kb.Connect(); KeyBoardGUI obj = new KeyBoardGUI(kb); obj.Visible = true; MAIN_PANEL.Controls.Add(obj); obj.Dock = DockStyle.Fill; obj.BringToFront(); obj.SaveFile = MainDirectory + @"/saves/" + uuid + ".mkb"; //Add new keyboard class to the keyboard list control _listkeyboardElement.addItem(name, uuid, port, obj); //Add new keyboard to keyboard list _keyboardGUIList.Add(obj); SaveKeyboardSaveFile(); }
private void LoadKeyboardConfig(string path) { if (File.Exists(path)) { string text = File.ReadAllText(path, Encoding.UTF8); JKeyboard deserializedKeyboard = JsonConvert.DeserializeObject <JKeyboard>(text); Keyboard kb = new Keyboard(deserializedKeyboard, Properties.Resources.KeyboardScanner__staticId); kb.ConnectTimeoutDelay = Properties.Settings.Default.TimeOutDelay; Debug.WriteLine("loading keyboard " + kb.KeyboardUuid); string com = GetPortFromId(kb.KeyboardUuid); if (com == null) { AddError(true, kb.KeyboardName + " --> not found!"); Debug.WriteLine(kb.KeyboardName + " --> not found!"); } else { kb.KeyboardComPort = com; kb.Connect(); } _keyboards.Add(kb); KeyBoardGUI obj = new KeyBoardGUI(kb); obj.Visible = false; MAIN_PANEL.Controls.Add(obj); obj.Dock = DockStyle.Fill; obj.SaveFile = path; obj.LoadKeys(); _listkeyboardElement.addItem(kb.KeyboardName, kb.KeyboardUuid, kb.KeyboardComPort, obj); _keyboardGUIList.Add(obj); } }
/// <summary> /// Load keyboards from main keyboard file /// </summary> private void LegacySaveFileLoader() { Debug.WriteLine("loading boards"); //Check for file exists if (!File.Exists(MainDirectory + @"\keyboards.inf")) { //Check for directory if (!Directory.Exists(MainDirectory)) { //Create directory Directory.CreateDirectory(MainDirectory); } //Create File File.Create(MainDirectory + @"\keyboards.inf").Close(); } int counter = 0; string line; List <string> temp = new List <string>(); string[] boards; // read main file //============================ System.IO.StreamReader file = new System.IO.StreamReader(MainDirectory + @"\keyboards.inf"); while ((line = file.ReadLine()) != null) { if (line != "") { temp.Add(line); counter++; } } boards = temp.ToArray(); file.Close(); //add boards to form //================================= int count = 0; for (int i = 0; i < boards.Length; i++) { if (boards[i] == "" || boards[i] == null) { } else { string[] splits = boards[i].Split('|'); Debug.WriteLine("loading keyboard " + splits[0]); //Create boards Keyboard kb = new Keyboard(Properties.Resources.KeyboardScanner__staticId); kb.ConnectTimeoutDelay = Properties.Settings.Default.TimeOutDelay; string com = GetPortFromId(splits[0]); kb.KeyboardUuid = splits[0]; kb.KeyboardName = splits[1]; if (com == null) { AddError(true, kb.KeyboardName + " --> not found!"); Debug.WriteLine(kb.KeyboardName + " --> not found!"); } else { kb.KeyboardComPort = com; kb.Connect(); } _keyboards.Add(kb); KeyBoardGUI obj = new KeyBoardGUI(kb); obj.Visible = false; MAIN_PANEL.Controls.Add(obj); obj.Dock = DockStyle.Fill; _listkeyboardElement.addItem(splits[1], splits[0], splits[2], obj); obj.LegacyLoadKeys(MainDirectory); _keyboardGUIList.Add(obj); count++; } } if (count == 0) { //When no keyboards added show "add keyboards" control _listkeyboardElement.Visible = false; _addKeyboardContr.Visible = true; } }