public static AlgorithmSettings LoadAlgorithmSettings(String path) { String targetPath = Path.Combine(path, ALGORITHM_CONF_FILE_NAME); AlgorithmSettings settings = new AlgorithmSettings(); try { string raw = File.ReadAllText(targetPath); settings = JsonConvert.DeserializeObject<AlgorithmSettings>(raw); if (settings.Version < AlgorithmSettings.SchemaVersion) { MessageBox.Show("Your algorithm parameters are outdated and have been set to defaults. Please updated them.", "Settings Outdated"); settings = new AlgorithmSettings(); throw new SettingsFileOutdatedException(); } } catch { try { WriteAlgorithmSettingsToFile(path, settings); } catch { throw new SettingFileException(string.Format("Could not access settings file at {0}", targetPath)); } } Console.WriteLine(settings); return settings; }
public static string WriteAlgorithmSettingsToFile(string path, AlgorithmSettings settings) { String outputFile = Path.Combine(path, ALGORITHM_CONF_FILE_NAME); File.Delete(outputFile); StreamWriter writer = new StreamWriter( new FileStream( outputFile, FileMode.OpenOrCreate, FileAccess.Write) ); String content = JsonConvert.SerializeObject(settings); writer.Write(content); writer.Close(); return outputFile; }