public static ConfigurationContainer LoadConfiguration(string filename)
        {
            ModLogger.Debug("Loading configuration from '{0}'", filename);

            // Assign the filename to the result. This is used later on when saving the configuration.
            ConfigurationContainer result = new ConfigurationContainer();

            // Check if the file exists. If so, deserialize it to a new instance. If not so, create a new empty instance
            if (File.Exists(filename))
            {
                try
                {
                    using (StreamReader sr = new StreamReader(filename))
                    {
                        var attempt = (ConfigurationContainer)new XmlSerializer(typeof(ConfigurationContainer)).Deserialize(sr);
                        result = attempt;
                    }
                }
                catch (Exception ex)
                {
                    ModLogger.Debug("An error occured while loading the configuration file, default configuration will be applied:{0}{1}", Environment.NewLine, ex.ToString());
                }
            }
            
            result._filename = filename;

            ModLogger.Debug("Configuration loaded from '{0}'", filename);

            return result;
        }
Ejemplo n.º 2
0
        private void Load()
        {
            try
            {
                _configuration = ConfigurationContainer.LoadConfiguration(_settingsFilePath);
            }
            catch (Exception ex)
            {
                ModLogger.Warning("An error occured while loading mod configuration from file '{0}', the default configuration will be applied", _settingsFilePath);
                ModLogger.Exception(ex);

                // Always create a configuration object, even when the file could not be loaded. This way the mod will not crash on configuration issues
                _configuration = new ConfigurationContainer();
            }

            // Apply the configuration to the running mod.
            _configuration.ApplyConfiguration();
        }
 public void Initialize(ConfigurationContainer configurationContainer)
 {
     UseAlt = configurationContainer.UseAlt;
     UseCtrl = configurationContainer.UseCtrl;
     UseShift = configurationContainer.UseShift;
 }
 public UIModOptionsPanelBuilder(UIHelper uiHelper, ConfigurationContainer configuration)
 {
     _uiHelper = uiHelper;
     _configuration = configuration;
     _rootPanel = uiHelper.self as UIScrollablePanel;
 }