Beispiel #1
0
        static Config()
        {
            if (DataStorage.LocalFileExists(ConfigFile))
            {
                BotConfig = DataStorage.RestoreObject <BotConfig>(ConfigFile);
                if (BotConfig.Equals(null))
                {
                    Process.Start(@"cmd.exe ", @"/c """ + (DataStorage.GetFileStream(ConfigFile).Name) + @"""");
                    Utilities.Log("Settings error", "Could not read the Settings, is your file incomplete? ", LogSeverity.Critical);
                }
                BotConfig = DataStorage.RestoreObject <BotConfig>(ConfigFile);
                SaveSettings();
                Utilities.Log("Config", "Configuration file restored and saved. ");
            }
            else
            {
                BotConfig = new BotConfig();
                var file = SaveSettings();
                Utilities.Log("Config", file.Name, Discord.LogSeverity.Critical);
                Process.Start("notepad.exe", file.Name);
                Utilities.Log("Config", "Configuration file created. Please fill out the data.", Discord.LogSeverity.Critical);
            }

            foreach (var field in typeof(BotConfig).GetFields(BindingFlags.Instance |
                                                              BindingFlags.NonPublic |
                                                              BindingFlags.Public))
            {
                string fieldName  = Utilities.GetBetween(field.Name, "<", ">");
                var    fieldValue = field.GetValue(BotConfig);
                if (fieldValue == null)
                {
                    Utilities.Log("Config", fieldName + " is empty, review your config if this is not the intention", LogSeverity.Warning);
                }
                else if (fieldValue as string == "")
                {
                    Utilities.Log("Config", fieldName + " is empty, review your config if this is not the intention", LogSeverity.Verbose);
                }
                else
                {
                    Utilities.Log("Config", fieldName + " is currently " + fieldValue, LogSeverity.Verbose);
                }
            }
        }