private void Form1_Load(object sender, EventArgs e) { Text = "GoBeam v" + Application.ProductVersion; //var js = "{\"reportInterval\":50,\"tactiles\":[{\"id\":0,\"type\":\"tactiles\",\"blueprint\":[{\"width\":1,\"height\":1,\"grid\":\"large\",\"state\":\"default\",\"x\":7,\"y\":0},{\"width\":1,\"height\":1,\"grid\":\"small\",\"state\":\"default\",\"x\":1,\"y\":2},{\"width\":1,\"height\":1,\"grid\":\"medium\",\"state\":\"default\",\"x\":3,\"y\":0}],\"analysis\":{\"holding\":true,\"frequency\":true},\"cost\":{\"press\":{\"cost\":0}},\"cooldown\":{\"press\":0},\"text\":\"Left\",\"key\":81,\"help\":\"Left Paddle\"},{\"id\":1,\"type\":\"tactiles\",\"blueprint\":[{\"width\":1,\"height\":1,\"grid\":\"large\",\"state\":\"default\",\"x\":8,\"y\":0},{\"width\":1,\"height\":1,\"grid\":\"medium\",\"state\":\"default\",\"x\":5,\"y\":0},{\"width\":1,\"height\":1,\"grid\":\"small\",\"state\":\"default\",\"x\":5,\"y\":0}],\"analysis\":{\"holding\":true,\"frequency\":true},\"key\":87,\"text\":\"Right\",\"help\":\"Right Paddle\",\"cost\":{\"press\":{\"cost\":0}},\"cooldown\":{\"press\":0}}],\"joysticks\":[],\"screens\":[]}"; //BeamJson beamJson = Newtonsoft.Json.JsonConvert.DeserializeObject<BeamJson>(js); //prgLeft.ProgressBar.ForeColor = Color.Blue; //prgRight.ProgressBar.ForeColor = Color.Red; instance = this; String strAppDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase); openFileDialog1.InitialDirectory = strAppDir; saveFileDialog1.InitialDirectory = strAppDir; string path = (string)WinLibrary.GetRegistryValue("HKEY_CURRENT_USER\\SOFTWARE\\GoBeam", "DefaultFile", ""); if (path != "") { try { var newConfig = JsonConvert.DeserializeObject<Config>(File.ReadAllText(path)); if (newConfig == null) { MessageBox.Show("Config failed to load.", "Failed to load", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } config = newConfig; RebuildKeys(config.keys); txtAddr.Text = config.grpcAddress; txtProcess.Text = config.processName; SetStatus(Path.GetFileName(path) + " loaded."); } catch (Exception err) { //Fail silently return; //MessageBox.Show(err.Message, "Failed to load", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } }
private void ResetDefaults() { if (config != null && config.keys != null && config.keys.Length > 0) { var result = MessageBox.Show("Clear key settings without saving?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (result != DialogResult.Yes) return; } //Make sure disconnected DisconnectRPC(); detachProcess(); var newConfig = new Config(); //Set default values SetStatus("Reset config to default"); config = newConfig; }
private void LoadConfig(string path, bool isResetOnFail) { try { config = Newtonsoft.Json.JsonConvert.DeserializeObject<Config>(File.ReadAllText(@"poetionbot.ini")); } catch (System.IO.FileNotFoundException) { MessageBox.Show("Could not find file: " + path, "File not found", MessageBoxButtons.OK, MessageBoxIcon.Error); } if (config == null && isResetOnFail) ResetDefaults(); }
private void loadKeysToolStripMenuItem_Click(object sender, EventArgs e) { if (btnAttach.Text == "Detach") { MessageBox.Show("First Detach from Process before loading a config", "Detach First!", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (btnConnect.Text == "Disconnect") { MessageBox.Show("First Disconnect from gRPC before loading a config", "Disconnect First!", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } DialogResult result; if (config != null && config.keys != null && config.keys.Length > 0) { result = MessageBox.Show("Clear key settings without saving?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (result != DialogResult.Yes) return; } openFileDialog1.Filter = "JSON Files|*.json"; openFileDialog1.DefaultExt = ".json"; result = openFileDialog1.ShowDialog(); if (result != DialogResult.OK) return; try { var newConfig = JsonConvert.DeserializeObject<Config>(File.ReadAllText(Path.GetFullPath(openFileDialog1.FileName))); if (newConfig == null) { MessageBox.Show("Config failed to load.", "Failed to load", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } config = newConfig; RebuildKeys(config.keys); txtAddr.Text = config.grpcAddress; txtProcess.Text = config.processName; SetStatus(Path.GetFileName(openFileDialog1.FileName) + " loaded."); } catch (Exception err) { MessageBox.Show(err.Message, "Failed to load", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }