コード例 #1
0
        /// <summary>
        /// Loads config.
        /// </summary>
        private static void LoadConfig()
        {
            // check if file exist
            var configFilePath = GetConfigFilePath();

            if (!File.Exists(configFilePath))
            {
                _config = CreateDefault();
                return;
            }

            lock (_fileLock)
            {
                // deserialize file
                using (var file = File.OpenRead(configFilePath))
                {
                    //Debug.Log("Deserializing " + configFilePath);
                    try
                    {
                        _config = Serializer.Deserialize <MasterConfig>(file);
                    }
                    catch (Exception e)
                    {
                        Debug.LogException(e);
                        Debug.LogError(String.Format("#Delight# Failed to deserialize config file \"{0}\". Creating new config.", ConfigFile));
                        _config = CreateDefault();
                        return;
                    }
                    finally
                    {
                        file.Close();
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Creates a default configuration object.
        /// </summary>
        public static MasterConfig CreateDefault()
        {
            var defaultConfig = new MasterConfig();

            defaultConfig.Clear(); // set default values
            return(defaultConfig);
        }