/*
 * Decompiled with CFR 0.152.
 */
package net.minecraft.launcher;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.minecraft.launcher.Launcher;
import net.minecraft.launcher.NetLauncherMain;
import org.apache.logging.log4j.LogManager;
import org.yaml.snakeyaml.Yaml;

public class Language {
    private static final org.apache.logging.log4j.Logger LOGGER = LogManager.getLogger();
    public static Map<String, Object> data;
    public static Map<String, String> langs;
    private static String lang;

    static {
        langs = new HashMap<String, String>();
        lang = "en";
    }

    public static String get(String id) {
        return (String)data.get(id);
    }

    public static Boolean getBoolean(String id) {
        return (Boolean)data.get(id);
    }

    public static String getLanguage() {
        return lang;
    }

    public void loadFileNames() throws URISyntaxException {
        String path = "langs";
        File jarFile = new File(NetLauncherMain.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath());
        if (jarFile.isFile()) {
            try {
                JarFile jar = new JarFile(jarFile);
                Enumeration<JarEntry> entries = jar.entries();
                while (entries.hasMoreElements()) {
                    String name = entries.nextElement().getName();
                    if (!name.startsWith(String.valueOf(path) + "/")) continue;
                    System.out.println(name);
                    try {
                        Yaml yaml = new Yaml();
                        Map data2 = (Map)yaml.load(this.getClass().getResourceAsStream("/" + name));
                        langs.put((String)data2.get("langcode"), (String)data2.get("description"));
                        LOGGER.info("[Skaia Launcher Log] SUCCESSFULLY LOADED LANGUAGE: " + (String)data2.get("langcode") + " " + (String)data2.get("description"));
                    }
                    catch (Exception ex) {
                        System.out.println("Exception " + ex.getLocalizedMessage());
                    }
                }
                jar.close();
            }
            catch (IOException ex) {
                Logger.getLogger(Language.class.getName()).log(Level.SEVERE, null, ex);
            }
        } else {
            URL url = Launcher.class.getResource("/" + path);
            if (url != null) {
                try {
                    File apps = new File(url.toURI());
                    File[] fileArray = apps.listFiles();
                    int n = fileArray.length;
                    int n2 = 0;
                    while (n2 < n) {
                        File app = fileArray[n2];
                        Yaml yaml = new Yaml();
                        FileInputStream ios = new FileInputStream(app);
                        System.out.println("Trying to load: " + app);
                        Map data2 = (Map)yaml.load(ios);
                        langs.put((String)data2.get("langcode"), (String)data2.get("description"));
                        System.out.println("LOADED LANGUAGE: " + (String)data2.get("langcode") + " " + (String)data2.get("description"));
                        ++n2;
                    }
                }
                catch (URISyntaxException apps) {
                }
                catch (FileNotFoundException ex) {
                    Logger.getLogger(Language.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }

    public void load(String lang) {
        Language.lang = lang;
        try {
            Yaml yaml = new Yaml();
            data = (Map)yaml.load(this.getClass().getResourceAsStream("/langs/" + lang + ".yml"));
            System.out.println("LOADED LANGUAGES");
        }
        catch (Exception exception) {
            // empty catch block
        }
    }
}
