public KeyCode GetKeyCode(string settingName, KeyCode defaultKeyCode)
        {
            KeyCode result = defaultKeyCode;

            if (settingsDictionary.ContainsKey(settingName))
            {
                try
                {
                    result = (KeyCode)Enum.Parse(typeof(KeyCode), settingsDictionary[settingName]);
                }
                catch
                {
                    PluginConsole.WriteLine(string.Concat(new string[]
                    {
                        "Error converting '",
                        settingName,
                        "' = '",
                        settingsDictionary[settingName],
                        "' to a UnityEngine.KeyCode"
                    }), this);
                }
            }
            else
            {
                SetKeyCode(settingName, defaultKeyCode);
            }

            return(result);
        }
        public bool SetKeyCode(string settingName, KeyCode keyCode)
        {
            bool result = true;

            if (settingsDictionary.ContainsValue(keyCode.ToString()))
            {
                result = false;
                PluginConsole.WriteLine("KeyCode '" + keyCode.ToString() + "' is already bound", this);
            }
            else
            {
                if (settingsDictionary.ContainsKey(settingName))
                {
                    settingsDictionary[settingName] = keyCode.ToString();
                }
                else
                {
                    settingsDictionary.Add(settingName, keyCode.ToString());
                }

                SaveSettings();
            }

            return(result);
        }
        private PluginSettings()
        {
            settingsDictionary = new Dictionary <string, string>();
            settingsLocation   = GlobalVars.RootFolder + "\\dcpm-settings\\";
            settingsFile       = "settings.txt";

            LoadSettings();

            PluginConsole.WriteLine("Version " + Version + " Initialized", this);
        }
        void LoadSettings()
        {
            if (!Directory.Exists(settingsLocation))
            {
                Directory.CreateDirectory(settingsLocation);
            }

            if (File.Exists(settingsLocation + settingsFile))
            {
                PluginConsole.WriteLine("Loading Dictionary from file", this);

                using (StreamReader streamReader = new StreamReader(new FileStream(settingsLocation + settingsFile, FileMode.OpenOrCreate, FileAccess.Read)))
                {
                    while (streamReader.Peek() >= 0)
                    {
                        string   text  = streamReader.ReadLine();
                        string[] array = text.Split(new string[] { " = " }, StringSplitOptions.None);

                        if (array.Length == 2)
                        {
                            settingsDictionary.Add(array[0], array[1]);

                            PluginConsole.WriteLine(string.Concat(new string[]
                            {
                                "Added setting '",
                                array[0],
                                "' = '",
                                array[1],
                                "' to the settings dictionary"
                            }), this);
                        }
                    }
                }
                PluginConsole.WriteLine("Settings Dictionary loaded from file", this);
            }
            else
            {
                PluginConsole.WriteLine("No settings file found, creating an empty one", this);
            }
        }
        void SaveSettings()
        {
            if (!Directory.Exists(settingsLocation))
            {
                Directory.CreateDirectory(settingsLocation);
            }

            try
            {
                using (StreamWriter streamWriter = new StreamWriter(new FileStream(settingsLocation + settingsFile, FileMode.Create, FileAccess.Write, FileShare.None)))
                {
                    foreach (KeyValuePair <string, string> keyValuePair in settingsDictionary)
                    {
                        streamWriter.WriteLine("{0} = {1}", keyValuePair.Key, keyValuePair.Value);
                    }
                }
            }
            catch (Exception ex)
            {
                PluginConsole.WriteLine(ex.ToString(), this);
            }

            PluginConsole.WriteLine("Settings saved to file", this);
        }