/*
 * Skybot, a multipurpose discord bot
 *      Copyright (C) 2017  Duncan "duncte123" Sterken
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published
 * by the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package ml.duncte123.skybot.utils;

import ml.duncte123.skybot.config.Config;
import ml.duncte123.skybot.config.ConfigLoader;
import org.slf4j.event.Level;

import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;

import java.io.File;

public class ConfigUtils {

    private Config config;

    /**
     * This will try to load the bot config and kill the program if it fails
     */
    public ConfigUtils() {
        try {
            AirUtils.log(Level.INFO, "Loading config.json");
            this.config = ConfigLoader.getConfig(new File("config.json"));
            AirUtils.log(Level.INFO, "Loaded config.json");
        } catch (Exception e) {
            if(System.getProperty("debug") != null) {
                AirUtils.log(Level.ERROR, "Could not load config, aborting");
                System.exit(-1);
            } else {
                JsonObject jo = new JsonObject();
                
                for(Object prop : System.getProperties().keySet()) {
                    jo.addProperty(prop.toString(), System.getProperty(prop.toString()));
                }
                
                this.config = new Config(null, jo) {
                    
                };
                
                AirUtils.log(Level.DEBUG, "Using system properties for the configuration!");
                System.out.println(new GsonBuilder().setPrettyPrinting().serializeNulls().create().toJson(jo));
            }
        }
    }

    /**
     * This will return the config that we have
     * @return the config for the bot
     */
    public Config loadConfig() {
        return config;
    }
}

@@ -925,80 +925,8 @@
 l;%0A%0A
-import com.google.gson.GsonBuilder;%0Aimport com.google.gson.JsonObject;%0A%0A
 impo
@@ -942,16 +942,16 @@
 o.File;%0A
+
 %0Apublic 
@@ -1365,66 +1365,8 @@
 ) %7B%0A
-            if(System.getProperty(%22debug%22) != null) %7B%0A    
     
@@ -1443,28 +1443,24 @@
             
-    
 System.exit(
@@ -1468,619 +1468,8 @@
 1);%0A
-            %7D else %7B%0A                JsonObject jo = new JsonObject();%0A                %0A                for(Object prop : System.getProperties().keySet()) %7B%0A                    jo.addProperty(prop.toString(), System.getProperty(prop.toString()));%0A                %7D%0A                %0A                this.config = new Config(null, jo) %7B%0A                    %0A                %7D;%0A                %0A                AirUtils.log(Level.DEBUG, %22Using system properties for the configuration!%22);%0A                System.out.println(new GsonBuilder().setPrettyPrinting().serializeNulls().create().toJson(jo));%0A            %7D%0A
     

Debug is too buggy right now