package be.msyben.vinylManager;

import be.msyben.vinylManager.gui.MainWindow;
import be.msyben.vinylManager.tools.FontTool;
import be.msyben.vinylManager.tools.ProxySettings;
import be.msyben.vinylManager.tools.VersionChecker;
import be.msyben.vinylManager.tools.log.VinylManagerLogger;
import be.msyben.vinylManager.tools.log.VinylManagerLoggerOutputStream;
import java.io.File;
import java.io.OutputStream;
import java.io.PrintStream;

/**
 * Vinyl manager.
 *
 * @author Mathieu Syben
 */
public final class VinylManager {

    /**
     * Version de l'application.
     */
    public static final String version = VersionChecker.currentVersion;

    /**
     * Constructeur privé pour ne pas instancier la classe.
     */
    private VinylManager() {
    }

    /**
     * Méthode main...
     *
     * @param args arguments
     */
    public static void main(String[] args) {
        if (!version.contains("beta") && !version.contains("SNAPSHOT")) {
            OutputStream os = new VinylManagerLoggerOutputStream();
            PrintStream pos = new PrintStream(os);
            System.setOut(pos);
            System.setErr(pos);
        }

        //ReportGenerator.createJasper();
        VinylManagerLogger.log("Démarrage");
        VinylManagerLogger.deleteOldLogFiles();

        ProxySettings.setProxy();

        FontTool.setFont();
        if (args.length == 1) {
            String fileToOpen = args[0];
            File f = new File(fileToOpen);
            if (f.exists() && f.isFile()) {
                MainWindow.getInstance(f);
            } else {
                MainWindow.getInstance();
            }
        } else {
            try {
                MainWindow.getInstance();
            } catch (Exception e) {

                e.printStackTrace();
            }
        }
        new VersionChecker().start();
    }
}
