Exemplo n.º 1
0
        public void Reload(String filename, Dictionary <PropertyKey, String> defaultValues = null)
        {
            string AppRoot = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);

            this.filename = Path.Combine(AppRoot, filename);;
            if (defaultValues != null)
            {
                list = defaultValues;
            }

            if (File.Exists(this.filename))
            {
                LoadFromFile(this.filename);
            }

            if (!CheckCRC())
            {
                list = GameProperties.GetDefaultConfigValues();
                Save();
            }
        }
Exemplo n.º 2
0
        private void LoadFromFile(String file)
        {
            foreach (String line in File.ReadAllLines(file))
            {
                if ((!String.IsNullOrEmpty(line)) &&
                    (!line.StartsWith(";", StringComparison.Ordinal)) &&
                    (!line.StartsWith("#", StringComparison.Ordinal)) &&
                    (line.Contains('=')))
                {
                    int    index = line.IndexOf('=');
                    String key   = line.Substring(0, index).Trim();
                    String value = line.Substring(index + 1).Trim();

                    if ((value.StartsWith("\"", StringComparison.Ordinal) && value.EndsWith("\"", StringComparison.Ordinal)) ||
                        (value.StartsWith("'", StringComparison.Ordinal) && value.EndsWith("'", StringComparison.Ordinal)))
                    {
                        value = value.Substring(1, value.Length - 2);
                    }

                    try
                    {
                        PropertyKey k = (PropertyKey)Enum.Parse(typeof(PropertyKey), key);
                        if (list.ContainsKey(k))
                        {
                            list[k] = value;
                        }
                        else
                        {
                            list.Add(k, value);
                        }

                        if (k == PropertyKey.PLAYER_NAME && value.Length > 10)
                        {
                            Reload("", GameProperties.GetDefaultConfigValues());
                        }
                    }
                    catch { }
                }
            }
        }