public static bool Load(string filename) { try { var configFile = new ConfigFile(); if (!configFile.Load(filename)) { SetDefaults(); return(false); } // Game if (int.TryParse(configFile.Value("game", "options", "57"), out int options)) { Game.Options = options | 0x01; // bit 0 must be set always } Game.GraphicDataUsage = configFile.Value <Data.DataSourceMixed.DataUsage>("game", "graphic_data_usage", Data.DataSourceMixed.DataUsage.PreferDos); Game.SoundDataUsage = configFile.Value <Data.DataSourceMixed.DataUsage>("game", "sound_data_usage", Data.DataSourceMixed.DataUsage.PreferDos); Game.MusicDataUsage = configFile.Value <Data.DataSourceMixed.DataUsage>("game", "music_data_usage", Data.DataSourceMixed.DataUsage.PreferAmiga); // Audio Audio.Music = configFile.Value("audio", "music", "0") == "1"; Audio.Sound = configFile.Value("audio", "sound", "0") == "1"; if (float.TryParse(configFile.Value("audio", "volume", "0.0"), System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out float volume)) { Audio.Volume = volume; } // Video if (int.TryParse(configFile.Value("video", "resolution_width", "1280"), out int resolutionWidth)) { Video.ResolutionWidth = resolutionWidth; } if (int.TryParse(configFile.Value("video", "resolution_height", "960"), out int resolutionHeight)) { Video.ResolutionHeight = resolutionHeight; } Video.Fullscreen = configFile.Value("video", "fullscreen", "0") == "1"; return(true); } catch { return(false); } }
public SaveReaderTextFile(StreamReader reader) { var file = new ConfigFile(); file.Read(reader); var sections = file.GetSections(); foreach (string name in sections) { var section = new SaveReaderTextSection(file, name); this.sections.Add(section); } var values = file.GetValues("main"); foreach (string vname in values) { if (!this.values.ContainsKey(vname)) { this.values.Add(vname, new SaveReaderTextValue(file.Value("main", vname, ""))); } } }
public SaveReaderTextSection(ConfigFile file, string name) { this.name = name; number = 0; var spacePosition = name.IndexOf(' '); if (spacePosition != -1) { string value = name.Substring(spacePosition + 1, name.Length - spacePosition - 1); this.name = this.name.Substring(0, spacePosition); number = int.Parse(value); } var vals = file.GetValues(name); foreach (string vname in vals) { if (!values.ContainsKey(vname)) { values.Add(vname, new SaveReaderTextValue(file.Value(name, vname, ""))); } } }
public static bool Load(string filename) { try { var configFile = new ConfigFile(); if (!configFile.Load(filename)) { Log.Info.Write(ErrorSystemType.Config, "Fallback to default settings."); SetDefaults(); try { if (Save(filename)) { Log.Info.Write(ErrorSystemType.Config, $"Saved default settings to config file '{filename}'."); return(false); } } catch { // ignore } Log.Info.Write(ErrorSystemType.Config, $"Failed to save settings to config file '{filename}'."); return(false); } // Game const string game = "game"; if (int.TryParse(configFile.Value(game, "options", DefaultOptions.ToString()), out int options)) { Game.Options = options | 0x01; // bit 0 must be always set } Game.GraphicDataUsage = configFile.Value(game, "graphic_data_usage", DefaultGraphicDataUsage); Game.SoundDataUsage = configFile.Value(game, "sound_data_usage", DefaultSoundDataUsage); Game.MusicDataUsage = configFile.Value(game, "music_data_usage", DefaultMusicDataUsage); // Audio const string audio = "audio"; Audio.Music = configFile.Value(audio, "music", DefaultMusic); Audio.Sound = configFile.Value(audio, "sound", DefaultSound); if (float.TryParse(configFile.Value(audio, "volume", DefaultVolume.ToString()), NumberStyles.Float, CultureInfo.InvariantCulture, out float volume)) { Audio.Volume = volume; } // Video const string video = "video"; if (int.TryParse(configFile.Value(video, "resolution_width", DefaultResolutionX.ToString()), out int resolutionWidth)) { Video.ResolutionWidth = resolutionWidth; } if (int.TryParse(configFile.Value(video, "resolution_height", DefaultResolutionY.ToString()), out int resolutionHeight)) { Video.ResolutionHeight = resolutionHeight; } Video.Fullscreen = configFile.Value(video, "fullscreen", DefaultFullscreen); // Logging const string logging = "logging"; Logging.LogLevel = configFile.Value(logging, "level", DefaultLogLevel); if (long.TryParse(configFile.Value(logging, "max_log_size", DefaultMaxLogSize.ToString()), out long maxLogSize)) { Logging.MaxLogSize = maxLogSize; } Logging.LogFileName = configFile.Value(logging, "log_file", DefaultLogFile); Logging.LogToConsole = configFile.Value(logging, "log_to_console", DefaultLogToConsole); if (Logging.MaxLogSize < MinLogSize) { Logging.MaxLogSize = MinLogSize; } return(true); } catch { return(false); } }