private void loadFinalSettings() { string path = Application.StartupPath + "/"; string path2 = path + @"settings.json"; Presettings settings = new Presettings() { p1 = textBox1.Text, p2 = textBox2.Text, p3 = textBox3.Text, p4 = textBox4.Text, p5 = textBox5.Text }; string json = JsonConvert.SerializeObject(settings, Formatting.Indented); System.IO.File.WriteAllText(path2, json); }
private void loadSettings() { string path = Application.StartupPath + "/"; string path2 = path + @"settings.json"; if (!System.IO.File.Exists(path2)) { Presettings settings = new Presettings() { p1 = "0,063", p2 = "2", p3 = "0,25", p4 = "0,5", p5 = "0,7" }; textBox1.Text = settings.p1; textBox2.Text = settings.p2; textBox3.Text = settings.p3; textBox4.Text = settings.p4; textBox5.Text = settings.p5; string json = JsonConvert.SerializeObject(settings, Formatting.Indented); System.IO.File.WriteAllText(path2, json); } else { using (StreamReader r = new StreamReader(path2)) { string json = r.ReadToEnd(); Presettings settings = JsonConvert.DeserializeObject <Presettings>(json); textBox1.Text = settings.p1; textBox2.Text = settings.p2; textBox3.Text = settings.p3; textBox4.Text = settings.p4; textBox5.Text = settings.p5; } } }