Ejemplo n.º 1
0
 private void LoadCfg()
 {
     if (File.Exists(ConfigPath))
     {
         Log.AddLogMessage("Loading Config...", "MW::LoadCfg", Log.LogLevel.DEBUG);
         string   ConfigFile        = File.ReadAllText(ConfigPath);
         string[] ConfigFileEntries = ConfigFile.Split(';');
         foreach (string ConfigFileEntry in ConfigFileEntries)
         {
             if (ConfigFileEntry == "")
             {
                 continue;
             }
             string key = ConfigFileEntry.Split('=')[0];
             string val = ConfigFileEntry.Split('=')[1];
             Log.AddLogMessage($"|> Config option {key} is set to {val}", "MW::LoadCfg", Log.LogLevel.DEBUG);
             Cfg.Add(key, val);
         }
         Log.AddLogMessage("Config loaded", "MW::LoadCfg", Log.LogLevel.DEBUG);
     }
     else
     {
         Log.AddLogMessage("No config file found, applying default config...", "MW::LoadConfig", Log.LogLevel.DEBUG);
         Cfg["GamePath"] = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\My Games\\Trainsimworld2\\Saved\\SaveGames\\UGCLiveries_0.sav";
         SaveCfg();
         Log.AddLogMessage("Default config applied", "MW::LoadCfg", Log.LogLevel.DEBUG);
     }
 }
Ejemplo n.º 2
0
        public void Load()
        {
            ApplyDefaults(false);
            if (File.Exists(ConfigPath))
            {
                Log.AddLogMessage("Loading Config...", "Config::Load", Log.LogLevel.DEBUG);
                string   ConfigFile        = File.ReadAllText(ConfigPath);
                string[] ConfigFileEntries = ConfigFile.Split(';');
                foreach (string ConfigFileEntry in ConfigFileEntries)
                {
                    if (ConfigFileEntry == "")
                    {
                        continue;
                    }
                    string key = ConfigFileEntry.Split('=')[0];
                    string val = ConfigFileEntry.Split('=')[1];
                    Log.AddLogMessage($"|> Config option '{key}' is set to '{val}'", "Config::Load", Log.LogLevel.DEBUG);
                    try
                    {
                        switch (key)
                        {
                        case "GamePath": _gamePath = val; break;

                        case "LibraryPath": _libraryPath = val; break;

                        case "MaxGameLiveries": _maxGameLiveries = int.Parse(val); break;

                        case "NoUpdate": _noUpdate = val == "true"; break;

                        case "DevUpdates": _devUpdates = val == "true"; break;
                        }
                    }
                    catch (Exception)
                    {
                        Log.AddLogMessage("Error loading config; applying default config...", "Config::Load", Log.LogLevel.WARNING);
                        ApplyDefaults();
                    }
                }
                Log.AddLogMessage("Config loaded", "Config::Load", Log.LogLevel.DEBUG);
            }
        }