package com.axis.innovators.box;

import com.axis.innovators.box.decompilation.gui.ModernJarViewer;
import com.axis.innovators.box.events.GlobalEventBus;
import com.axis.innovators.box.events.OpenFileEvents;
import com.axis.innovators.box.gui.LoginWindow;
import com.axis.innovators.box.tools.ArgsParser;
import com.axis.innovators.box.tools.FolderCleaner;
import com.axis.innovators.box.tools.FolderCreator;
import com.axis.innovators.box.register.LanguageManager;

import javax.swing.*;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * @author tzdwindows 7
 */
public class Main {
    public static void main(String[] args) {
        FolderCleaner.cleanFolder(FolderCreator.getLogsFolder(), 10);

        LanguageManager.loadSavedLanguage();
        if (LanguageManager.getLoadedLanguages() == null){
            LanguageManager.loadLanguage("system:zh_CN");
        }

        List<Map<String, String>> validFiles = ArgsParser.parseArgs(args);
        for (Map<String, String> fileInfo : validFiles) {
            String extension = fileInfo.get("extension");
            String path = fileInfo.get("path");
            if (".jar".equals(extension)){
                SwingUtilities.invokeLater(() -> {
                    try {
                        UIManager.setLookAndFeel(new com.formdev.flatlaf.FlatDarculaLaf());
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
                    ModernJarViewer viewer = new ModernJarViewer(null, path);
                    viewer.setVisible(true);
                });
                return;
            }
        }

        AxisInnovatorsBox.run(args);
    }
}
