static SettingsApply() { try { ProgramSett tempp = new ProgramSett(); } catch { string path = Directory.GetCurrentDirectory() + @"\settings.json"; using (StreamReader sr = new StreamReader(path)) { string errorstring = sr.ReadToEnd(); bool end = false; string good = ""; int i = 0; while (!end) { good = good + errorstring[i]; if (errorstring[i] == '}') { end = true; } i++; } sr.Close(); using (StreamWriter sw = new StreamWriter(path, false)) { sw.WriteLine(good); } } } finally { psettings = new ProgramSett(); } }
public ProgramSett() { DataContractJsonSerializer jsonFormatter = new DataContractJsonSerializer(typeof(ProgramSett)); string path = Directory.GetCurrentDirectory() + @"\settings.json"; if (File.Exists(path)) { using (FileStream fs = new FileStream(path, FileMode.OpenOrCreate)) { ProgramSett ps = (ProgramSett)jsonFormatter.ReadObject(fs); this.res_height = ps.res_height; this.res_width = ps.res_width; this.lang = ps.lang; this.fullscreen = ps.fullscreen; } } else { this.res_height = 720; this.res_width = 1280; this.lang = "english"; this.fullscreen = false; } }