<commit_before>/*
 * Copyright ©1998-2020 by <NAME>. All rights reserved.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, version 2.0. If a copy of the MPL was not distributed with
 * this file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This Source Code Form is "Incompatible With Secondary Licenses", as
 * defined by the Mozilla Public License, version 2.0.
 */

package com.trollworks.gcs;

import com.trollworks.gcs.character.CmdLineExport;
import com.trollworks.gcs.menu.edit.PreferencesCommand;
import com.trollworks.gcs.menu.file.OpenCommand;
import com.trollworks.gcs.menu.file.OpenDataFileCommand;
import com.trollworks.gcs.menu.file.PrintCommand;
import com.trollworks.gcs.menu.file.QuitCommand;
import com.trollworks.gcs.menu.help.AboutCommand;
import com.trollworks.gcs.ui.Fonts;
import com.trollworks.gcs.ui.widget.WiderToolTipUI;
import com.trollworks.gcs.ui.widget.WindowUtils;
import com.trollworks.gcs.ui.widget.Workspace;
import com.trollworks.gcs.utility.I18n;
import com.trollworks.gcs.utility.Platform;
import com.trollworks.gcs.utility.UpdateChecker;
import com.trollworks.gcs.utility.Version;
import com.trollworks.gcs.utility.launchproxy.LaunchProxy;
import com.trollworks.gcs.utility.text.Text;

import java.awt.Desktop;
import java.awt.Desktop.Action;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.GraphicsEnvironment;
import java.awt.desktop.QuitStrategy;
import java.io.InputStream;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.Instant;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.jar.Attributes;
import java.util.jar.Manifest;
import javax.swing.UIManager;

/** The main entry point for the character sheet. */
public class GCS {
    public static final String  WEB_SITE        = "https://gurpscharactersheet.com";
    public static final Version VERSION         = new Version();
    public static final Version LIBRARY_VERSION = new Version();
    public static final String  COPYRIGHT;
    public static final String  COPYRIGHT_FOOTER;
    public static final String  APP_BANNER;
    private static      boolean NOTIFICATION_ALLOWED;

    static {
        // Fix the current working directory, as bundled apps break the normal logic.
        // Sadly, this still doesn't fix stuff referenced from the "default" filesystem
        // class, as it is already initialized to the wrong value and won't pick this
        // change up.
        String pwd = System.getenv("PWD");
        if (pwd != null && !pwd.isEmpty()) {
            System.setProperty("user.dir", pwd);
        }

        // Determine the version
        String years = null;
        try (InputStream in = GCS.class.getModule().getResourceAsStream("/META-INF/MANIFEST.MF")) {
            Attributes attributes = new Manifest(in).getMainAttributes();
            VERSION.extract(attributes.getValue("bundle-version"));
            years = attributes.getValue("bundle-copyright-years");
        } catch (Exception exception) {
            // Ignore... we'll fill in default values below
        }
        if (years == null || years.isBlank()) {
            years = "1998-" + DateTimeFormatter.ofPattern("yyyy").format(Instant.now().atZone(ZoneOffset.UTC));
        }

        // Setup localizations -- must be called AFTER the version is determined
        I18n.initialize();

        // Setup the copyright notices and such that rely on the version and year info
        COPYRIGHT = String.format(I18n.Text("Copyright ©%s by %s"), years, "<NAME>");
        COPYRIGHT_FOOTER = String.format("GCS " + I18n.Text(" is copyrighted ©%s by %s"), years, "<NAME>");
        StringBuilder buffer = new StringBuilder();
        buffer.append("GCS ");
        if (VERSION.isZero()) {
            buffer.append(I18n.Text("(development)"));
        } else {
            buffer.append(VERSION);
        }
        buffer.append('\n');
        if (Platform.isWindows()) {
            // The windows command prompt doesn't understand the copyright symbol, so translate it
            // to something it can deal with.
            buffer.append(COPYRIGHT.replaceAll("©", "(c)"));
        } else {
            buffer.append(COPYRIGHT);
        }
        buffer.append(". All rights reserved.");
        APP_BANNER = buffer.toString();
    }

    /**
     * The main entry point for the character sheet.
     *
     * @param args Arguments to the program.
     */
    public static void main(String[] args) {
        boolean      showVersion  = false;
        boolean      generatePDF  = false;
        boolean      generatePNG  = false;
        boolean      generateText = false;
        Path         template     = null;
        String       margins      = null;
        String       paper        = null;
        List<Path>   files        = new ArrayList<>();
        List<String> msgs         = new ArrayList<>();
        int          length       = args.length;
        for (int i = 0; i < length; i++) {
            String arg = args[i];
            if (arg.startsWith("-")) {
                if (arg.startsWith("=")) {
                    files.add(Paths.get(arg));
                    continue;
                }
                String[] parts = arg.split("=", 2);
                switch (parts[0]) {
                case "-h":
                case "--help":
                    showHelp();<commit_msg>Fix opening files from macOS Finder<commit_after>/*
 * Copyright ©1998-2020 by <NAME>. All rights reserved.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, version 2.0. If a copy of the MPL was not distributed with
 * this file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This Source Code Form is "Incompatible With Secondary Licenses", as
 * defined by the Mozilla Public License, version 2.0.
 */

package com.trollworks.gcs;

import com.trollworks.gcs.character.CmdLineExport;
import com.trollworks.gcs.menu.edit.PreferencesCommand;
import com.trollworks.gcs.menu.file.OpenCommand;
import com.trollworks.gcs.menu.file.OpenDataFileCommand;
import com.trollworks.gcs.menu.file.PrintCommand;
import com.trollworks.gcs.menu.file.QuitCommand;
import com.trollworks.gcs.menu.help.AboutCommand;
import com.trollworks.gcs.ui.Fonts;
import com.trollworks.gcs.ui.widget.WiderToolTipUI;
import com.trollworks.gcs.ui.widget.WindowUtils;
import com.trollworks.gcs.ui.widget.Workspace;
import com.trollworks.gcs.utility.I18n;
import com.trollworks.gcs.utility.Platform;
import com.trollworks.gcs.utility.UpdateChecker;
import com.trollworks.gcs.utility.Version;
import com.trollworks.gcs.utility.launchproxy.LaunchProxy;
import com.trollworks.gcs.utility.text.Text;

import java.awt.Desktop;
import java.awt.Desktop.Action;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.GraphicsEnvironment;
import java.awt.desktop.QuitStrategy;
import java.io.InputStream;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.Instant;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.jar.Attributes;
import java.util.jar.Manifest;
import javax.swing.UIManager;

/** The main entry point for the character sheet. */
public class GCS {
    public static final String  WEB_SITE        = "https://gurpscharactersheet.com";
    public static final Version VERSION         = new Version();
    public static final Version LIBRARY_VERSION = new Version();
    public static final String  COPYRIGHT;
    public static final String  COPYRIGHT_FOOTER;
    public static final String  APP_BANNER;
    private static      boolean NOTIFICATION_ALLOWED;

    static {
        // Fix the current working directory, as bundled apps break the normal logic.
        // Sadly, this still doesn't fix stuff referenced from the "default" filesystem
        // class, as it is already initialized to the wrong value and won't pick this
        // change up.
        String pwd = System.getenv("PWD");
        if (pwd != null && !pwd.isEmpty()) {
            System.setProperty("user.dir", pwd);
        }

        // Determine the version
        String years = null;
        try (InputStream in = GCS.class.getModule().getResourceAsStream("/META-INF/MANIFEST.MF")) {
            Attributes attributes = new Manifest(in).getMainAttributes();
            VERSION.extract(attributes.getValue("bundle-version"));
            years = attributes.getValue("bundle-copyright-years");
        } catch (Exception exception) {
            // Ignore... we'll fill in default values below
        }
        if (years == null || years.isBlank()) {
            years = "1998-" + DateTimeFormatter.ofPattern("yyyy").format(Instant.now().atZone(ZoneOffset.UTC));
        }

        // Setup localizations -- must be called AFTER the version is determined
        I18n.initialize();

        // Setup the copyright notices and such that rely on the version and year info
        COPYRIGHT = String.format(I18n.Text("Copyright ©%s by %s"), years, "<NAME>");
        COPYRIGHT_FOOTER = String.format("GCS " + I18n.Text(" is copyrighted ©%s by %s"), years, "<NAME>");
        StringBuilder buffer = new StringBuilder();
        buffer.append("GCS ");
        if (VERSION.isZero()) {
            buffer.append(I18n.Text("(development)"));
        } else {
            buffer.append(VERSION);
        }
        buffer.append('\n');
        if (Platform.isWindows()) {
            // The windows command prompt doesn't understand the copyright symbol, so translate it
            // to something it can deal with.
            buffer.append(COPYRIGHT.replaceAll("©", "(c)"));
        } else {
            buffer.append(COPYRIGHT);
        }
        buffer.append(". All rights reserved.");
        APP_BANNER = buffer.toString();
    }

    /**
     * The main entry point for the character sheet.
     *
     * @param args Arguments to the program.
     */
    public static void main(String[] args) {
        boolean      showVersion  = false;
        boolean      generatePDF  = false;
        boolean      generatePNG  = false;
        boolean      generateText = false;
        Path         template     = null;
        String       margins      = null;
        String       paper        = null;
        List<Path>   files        = new ArrayList<>();
        List<String> msgs         = new ArrayList<>();
        int          length       = args.length;
        for (int i = 0; i < length; i++) {
            String arg = args[i];
            if (i == 0 && Platform.isMacintosh() && arg.startsWith("-psn_")) {
                continue;
            }
            if (arg.startsWith("-")) {
                if (arg.startsWith("=")) {
                    files.add(Paths.get(arg));
                    continue;
                }
                String[] parts = arg.split("=", 2);
                switch (parts[0]) {
                case "-h":
                case "--help":
                    showHelp();
{'fraction_non_alphanumeric': 0.11300351446336848, 'fraction_numerical': 0.0056772100567721, 'mean_word_length': 2.4231955582973472, 'pattern_counts': {'":': 4, '<': 19, '<?xml version=': 0, '>': 17, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3827519', 'n_tokens_mistral': 3205, 'n_tokens_neox': 3104, 'n_words': 858}