Search in sources :

Example 1 with InstallationDetectionException

use of com.vaklinov.zcashui.ZCashInstallationObserver.InstallationDetectionException in project zencash-swing-wallet-ui by ZencashOfficial.

the class ZCashUI method main.

public static void main(String[] argv) throws IOException {
    try {
        OS_TYPE os = OSUtil.getOSType();
        if ((os == OS_TYPE.WINDOWS) || (os == OS_TYPE.MAC_OS)) {
            possiblyCreateZENConfigFile();
        }
        LanguageUtil langUtil = LanguageUtil.instance();
        Log.info("Starting ZENCash Swing Wallet ...");
        Log.info("OS: " + System.getProperty("os.name") + " = " + os);
        Log.info("Current directory: " + new File(".").getCanonicalPath());
        Log.info("Class path: " + System.getProperty("java.class.path"));
        Log.info("Environment PATH: " + System.getenv("PATH"));
        // Look and feel settings - a custom OS-look and feel is set for Windows
        if (os == OS_TYPE.WINDOWS) {
            // Custom Windows L&F and font settings
            UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
        // This font looks good but on Windows 7 it misses some chars like the stars...
        // FontUIResource font = new FontUIResource("Lucida Sans Unicode", Font.PLAIN, 11);
        // UIManager.put("Table.font", font);
        } else if (os == OS_TYPE.MAC_OS) {
            // The MacOS L&F is active by default - the property sets the menu bar Mac style
            System.setProperty("apple.laf.useScreenMenuBar", "true");
        } else {
            for (LookAndFeelInfo ui : UIManager.getInstalledLookAndFeels()) {
                Log.info("Available look and feel: " + ui.getName() + " " + ui.getClassName());
                if (ui.getName().equals("Nimbus")) {
                    Log.info("Setting look and feel: {0}", ui.getClassName());
                    UIManager.setLookAndFeel(ui.getClassName());
                    break;
                }
                ;
            }
        }
        // If zend is currently not running, do a startup of the daemon as a child process
        // It may be started but not ready - then also show dialog
        ZCashInstallationObserver initialInstallationObserver = new ZCashInstallationObserver(OSUtil.getProgramDirectory());
        DaemonInfo zcashdInfo = initialInstallationObserver.getDaemonInfo();
        initialInstallationObserver = null;
        ZCashClientCaller initialClientCaller = new ZCashClientCaller(OSUtil.getProgramDirectory());
        boolean daemonStartInProgress = false;
        try {
            if (zcashdInfo.status == DAEMON_STATUS.RUNNING) {
                NetworkAndBlockchainInfo info = initialClientCaller.getNetworkAndBlockchainInfo();
                // If more than 20 minutes behind in the blockchain - startup in progress
                if ((System.currentTimeMillis() - info.lastBlockDate.getTime()) > (20 * 60 * 1000)) {
                    Log.info("Current blockchain synchronization date is " + new Date(info.lastBlockDate.getTime()));
                    daemonStartInProgress = true;
                }
            }
        } catch (WalletCallException wce) {
            if (// Started but not ready
            (wce.getMessage().indexOf("{\"code\":-28") != -1) || (wce.getMessage().indexOf("error code: -28") != -1)) {
                Log.info("zend is currently starting...");
                daemonStartInProgress = true;
            }
        }
        StartupProgressDialog startupBar = null;
        if ((zcashdInfo.status != DAEMON_STATUS.RUNNING) || (daemonStartInProgress)) {
            Log.info("zend is not runing at the moment or has not started/synchronized 100% - showing splash...");
            startupBar = new StartupProgressDialog(initialClientCaller);
            startupBar.setVisible(true);
            startupBar.waitForStartup();
        }
        initialClientCaller = null;
        // Main GUI is created here
        ZCashUI ui = new ZCashUI(startupBar);
        ui.setVisible(true);
    } catch (InstallationDetectionException ide) {
        Log.error("Unexpected error: ", ide);
        JOptionPane.showMessageDialog(null, LanguageUtil.instance().getString("main.frame.option.pane.installation.error.text", OSUtil.getProgramDirectory(), ide.getMessage()), LanguageUtil.instance().getString("main.frame.option.pane.installation.error.title"), JOptionPane.ERROR_MESSAGE);
        System.exit(1);
    } catch (WalletCallException wce) {
        Log.error("Unexpected error: ", wce);
        if ((wce.getMessage().indexOf("{\"code\":-28,\"message\"") != -1) || (wce.getMessage().indexOf("error code: -28") != -1)) {
            JOptionPane.showMessageDialog(null, LanguageUtil.instance().getString("main.frame.option.pane.wallet.communication.error.text"), LanguageUtil.instance().getString("main.frame.option.pane.wallet.communication.error.title"), JOptionPane.ERROR_MESSAGE);
        } else {
            JOptionPane.showMessageDialog(null, LanguageUtil.instance().getString("main.frame.option.pane.wallet.communication.error.2.text", wce.getMessage()), LanguageUtil.instance().getString("main.frame.option.pane.wallet.communication.error.2.title"), JOptionPane.ERROR_MESSAGE);
        }
        System.exit(2);
    } catch (Exception e) {
        Log.error("Unexpected error: ", e);
        JOptionPane.showMessageDialog(null, LanguageUtil.instance().getString("main.frame.option.pane.wallet.critical.error.text", e.getMessage()), LanguageUtil.instance().getString("main.frame.option.pane.wallet.critical.error.title"), JOptionPane.ERROR_MESSAGE);
        System.exit(3);
    } catch (Error err) {
        // Last resort catch for unexpected problems - just to inform the user
        err.printStackTrace();
        JOptionPane.showMessageDialog(null, LanguageUtil.instance().getString("main.frame.option.pane.wallet.critical.error.2.text", err.getMessage()), LanguageUtil.instance().getString("main.frame.option.pane.wallet.critical.error.2.title"), JOptionPane.ERROR_MESSAGE);
        System.exit(4);
    }
}
Also used : LookAndFeelInfo(javax.swing.UIManager.LookAndFeelInfo) OS_TYPE(com.vaklinov.zcashui.OSUtil.OS_TYPE) Date(java.util.Date) InstallationDetectionException(com.vaklinov.zcashui.ZCashInstallationObserver.InstallationDetectionException) IOException(java.io.IOException) WalletCallException(com.vaklinov.zcashui.ZCashClientCaller.WalletCallException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) DaemonInfo(com.vaklinov.zcashui.ZCashInstallationObserver.DaemonInfo) NetworkAndBlockchainInfo(com.vaklinov.zcashui.ZCashClientCaller.NetworkAndBlockchainInfo) InstallationDetectionException(com.vaklinov.zcashui.ZCashInstallationObserver.InstallationDetectionException) WalletCallException(com.vaklinov.zcashui.ZCashClientCaller.WalletCallException) File(java.io.File)

Aggregations

OS_TYPE (com.vaklinov.zcashui.OSUtil.OS_TYPE)1 NetworkAndBlockchainInfo (com.vaklinov.zcashui.ZCashClientCaller.NetworkAndBlockchainInfo)1 WalletCallException (com.vaklinov.zcashui.ZCashClientCaller.WalletCallException)1 DaemonInfo (com.vaklinov.zcashui.ZCashInstallationObserver.DaemonInfo)1 InstallationDetectionException (com.vaklinov.zcashui.ZCashInstallationObserver.InstallationDetectionException)1 File (java.io.File)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Date (java.util.Date)1 LookAndFeelInfo (javax.swing.UIManager.LookAndFeelInfo)1