Search in sources :

Example 1 with DebuggableException

use of com.github.mob41.organdebug.exceptions.DebuggableException in project osumer by mob41.

the class UIFrame method addQuietBtQueue.

public boolean addQuietBtQueue(String url) {
    if (config.getCheckUpdateFreq() == Config.CHECK_UPDATE_FREQ_EVERY_ACT) {
        checkUpdate();
    }
    String user = config.getUser();
    String pass = config.getPass();
    if (user == null || user.isEmpty() || pass == null || pass.isEmpty()) {
        LoginPanel loginPanel = new LoginPanel();
        int option = JOptionPane.showOptionDialog(UIFrame.this, loginPanel, "Login to osu!", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, null, JOptionPane.CANCEL_OPTION);
        if (option == JOptionPane.OK_OPTION) {
            if (loginPanel.getUsername().isEmpty() || loginPanel.getPassword().isEmpty()) {
                JOptionPane.showMessageDialog(UIFrame.this, "Username or password cannot be empty.", "Error", JOptionPane.ERROR_MESSAGE);
                return false;
            }
            user = loginPanel.getUsername();
            pass = loginPanel.getPassword();
        } else {
            return false;
        }
    }
    try {
        osu.login(user, pass);
    } catch (DebuggableException e) {
        e.printStackTrace();
        JOptionPane.showMessageDialog(UIFrame.this, "Error logging in:\n" + e.getDump().getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        return false;
    }
    try {
        map = osu.getBeatmapInfo(url);
    } catch (DebuggableException e) {
        e.printStackTrace();
        JOptionPane.showMessageDialog(UIFrame.this, "Error getting beatmap info:\n" + e.getDump().getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        return false;
    }
    String modUrl = map.getThumbUrl();
    URL thumbUrl = null;
    try {
        thumbUrl = new URL("http:" + modUrl);
    } catch (MalformedURLException e) {
        e.printStackTrace();
        return false;
    }
    URLConnection conn = null;
    try {
        conn = thumbUrl.openConnection();
    } catch (IOException e) {
        e.printStackTrace();
        return false;
    }
    conn.setConnectTimeout(5000);
    conn.setReadTimeout(5000);
    try {
        thumb = ImageIO.read(conn.getInputStream());
    } catch (IOException e) {
        e.printStackTrace();
        thumb = null;
    }
    URL downloadUrl = null;
    try {
        downloadUrl = new URL("http://osu.ppy.sh" + map.getDwnUrl());
    } catch (MalformedURLException e1) {
        e1.printStackTrace();
        JOptionPane.showMessageDialog(UIFrame.this, "Error validating download URL:\n" + e1, "Error", JOptionPane.ERROR_MESSAGE);
        return false;
    }
    String tmpdir = System.getProperty("java.io.tmpdir");
    final String mapName = map.getName();
    OsuDownloader dwn = new OsuDownloader(tmpdir, map.getDwnUrl().substring(3, map.getDwnUrl().length()) + " " + map.getName(), osu, downloadUrl);
    QueueAction importAction;
    if (rdbtnUseDefaultSettings.isSelected()) {
        importAction = new BeatmapImportAction(config);
    } else {
        int action = -1;
        String targetFileOrFolder = null;
        if (rdbtnDownloadAndImport.isSelected()) {
            action = 0;
        } else if (rdbtnDownloadToOsu.isSelected()) {
            action = 1;
        } else if (rdbtnDownloadToFile.isSelected()) {
            action = 2;
            targetFileOrFolder = targetFile;
        } else if (rdbtnDownloadToFolder.isSelected()) {
            action = 3;
            targetFileOrFolder = targetFolder;
        }
        importAction = new CustomImportAction(action, targetFileOrFolder);
    }
    QueueAction[] beforeActions = new QueueAction[] { new BeforeSoundAction(config) };
    QueueAction[] afterActions = new QueueAction[] { new AfterSoundAction(config), new QueueAction() {

        @Override
        public void run(Queue queue) {
            icon.displayMessage("Download completed for \"" + mapName + "\"", "This osumer queue has completed downloading.", TrayIcon.MessageType.INFO);
        }
    }, importAction };
    boolean added = mgr.addQueue(new Queue(map.getName(), dwn, thumb, beforeActions, afterActions));
    if (added) {
        icon.displayMessage("Downloading \"" + mapName + "\"", "osumerExpress is downloading the requested beatmap!", TrayIcon.MessageType.INFO);
    } else {
        icon.displayMessage("Could not add \"" + mapName + "\" to queue", "It has already in queue/downloading or completed.", TrayIcon.MessageType.INFO);
    }
    tableModel.fireTableDataChanged();
    return true;
}
Also used : BeforeSoundAction(com.github.mob41.osumer.io.queue.actions.BeforeSoundAction) DebuggableException(com.github.mob41.organdebug.exceptions.DebuggableException) MalformedURLException(java.net.MalformedURLException) AfterSoundAction(com.github.mob41.osumer.io.queue.actions.AfterSoundAction) QueueAction(com.github.mob41.osumer.io.queue.QueueAction) IOException(java.io.IOException) URL(java.net.URL) URLConnection(java.net.URLConnection) CustomImportAction(com.github.mob41.osumer.io.queue.actions.CustomImportAction) OsuDownloader(com.github.mob41.osums.io.beatmap.OsuDownloader) BeatmapImportAction(com.github.mob41.osumer.io.queue.actions.BeatmapImportAction) Queue(com.github.mob41.osumer.io.queue.Queue) EventQueue(java.awt.EventQueue)

Example 2 with DebuggableException

use of com.github.mob41.organdebug.exceptions.DebuggableException in project osumer by mob41.

the class Main method main.

public static void main(String[] args) {
    ArgParser ap = new ArgParser(args);
    if (ap.isVersionFlag()) {
        System.out.println(Osumer.OSUMER_VERSION + "-" + Osumer.OSUMER_BRANCH + "-" + Osumer.OSUMER_BUILD_NUM);
        return;
    }
    if (!GraphicsEnvironment.isHeadless()) {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    // These are called by Windows when setting Default Programs
    if (ap.isHideIconsFlag() || ap.isShowIconsFlag() || ap.isReinstallFlag() || ap.isInstallFlag() || ap.isUninstallFlag()) {
        Installer installer = new Installer();
        if (ap.isHideIconsFlag()) {
            installer.hideIcons();
        } else if (ap.isShowIconsFlag()) {
            installer.showIcons();
        } else if (ap.isReinstallFlag()) {
            installer.reinstall();
        } else if (ap.isInstallFlag()) {
            if (!ap.isQuietFlag() && !ap.isForceFlag()) {
                int option = JOptionPane.showOptionDialog(null, "You are installing osumer " + Osumer.OSUMER_VERSION + "-" + Osumer.OSUMER_BRANCH + "-" + Osumer.OSUMER_BUILD_NUM + ".\n" + "Are you sure?", "Installing osumer", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, JOptionPane.NO_OPTION);
                if (option != JOptionPane.YES_OPTION) {
                    return;
                }
            }
            try {
                long startTime = System.currentTimeMillis();
                installer.install();
                if (!(ap.isQuietFlag() && ap.isForceFlag())) {
                    System.out.println("Info@U$\nInstallation success within " + (System.currentTimeMillis() - startTime) + " ms\nInfo@D$");
                }
            } catch (DebuggableException e) {
                if (!ap.isNoUiFlag() && !GraphicsEnvironment.isHeadless()) {
                    ErrorDumpDialog dialog = new ErrorDumpDialog(e.getDump());
                    dialog.setModal(true);
                    dialog.setVisible(true);
                }
                if (!(ap.isQuietFlag() && ap.isForceFlag())) {
                    System.out.println("Error@U$\n" + e.getDump().toString() + "Error@D$");
                }
            }
        } else if (ap.isUninstallFlag()) {
            if (!ap.isQuietFlag() && !ap.isForceFlag()) {
                int option = JOptionPane.showOptionDialog(null, "You are uninstalling osumer " + Osumer.OSUMER_VERSION + "-" + Osumer.OSUMER_BRANCH + "-" + Osumer.OSUMER_BUILD_NUM + ".\n" + "Are you sure?", "Uninstalling osumer", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, JOptionPane.NO_OPTION);
                if (option != JOptionPane.YES_OPTION) {
                    return;
                }
            }
            try {
                long startTime = System.currentTimeMillis();
                installer.uninstall();
                if (!(ap.isQuietFlag() && ap.isForceFlag())) {
                    System.out.println("Info@U$\nUninstallation success within " + (System.currentTimeMillis() - startTime) + " ms\nInfo@D$");
                }
            } catch (DebuggableException e) {
                if (!ap.isNoUiFlag() && !GraphicsEnvironment.isHeadless()) {
                    ErrorDumpDialog dialog = new ErrorDumpDialog(e.getDump());
                    dialog.setModal(true);
                    dialog.setVisible(true);
                }
                if (!(ap.isQuietFlag() && ap.isForceFlag())) {
                    System.out.println("Error@U$\n" + e.getDump().toString() + "Error@D$");
                }
            }
        }
        System.exit(0);
        return;
    }
    String configPath = Osumer.isWindows() ? System.getenv("localappdata") + "\\osumerExpress" : "";
    Config config = new Config(configPath, Config.DEFAULT_DATA_FILE_NAME);
    try {
        config.load();
    } catch (IOException e1) {
        System.err.println("Unable to load configuration");
        e1.printStackTrace();
        if (!GraphicsEnvironment.isHeadless()) {
            JOptionPane.showMessageDialog(null, "Could not load configuration: " + e1, "Configuration Error", JOptionPane.ERROR_MESSAGE);
        }
        System.exit(-1);
        return;
    }
    if (args != null && args.length > 0) {
        if (!config.isOEEnabled()) {
            System.out.println("osumerExpress is disabled.");
            runBrowser(config, args);
            System.exit(0);
            return;
        }
        runUi(config, args, ap);
    } else {
        if (GraphicsEnvironment.isHeadless()) {
            System.out.println("Error: Arguments are required to use this application. Otherwise, a graphics environment is required to show the downloader UI.");
            System.exit(0);
            return;
        }
        if (config.isSwitchToBrowserIfWithoutUiArg()) {
            runBrowser(config, args);
        } else {
            runUi(config, args, ap);
        }
    }
}
Also used : DebuggableException(com.github.mob41.organdebug.exceptions.DebuggableException) ErrorDumpDialog(com.github.mob41.osumer.ui.ErrorDumpDialog) Installer(com.github.mob41.osumer.io.Installer) IOException(java.io.IOException) DebuggableException(com.github.mob41.organdebug.exceptions.DebuggableException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) AWTException(java.awt.AWTException)

Example 3 with DebuggableException

use of com.github.mob41.organdebug.exceptions.DebuggableException in project osumer by mob41.

the class Installer method install.

public void install() throws DebuggableException {
    if (!Osumer.isWindows()) {
        throw new DebuggableException(null, "Validate OS is Windows", "Throw debuggable exception", "Validate is osumer elevated", "Installer does not support non-Windows environment", false);
    }
    if (!Osumer.isWindowsElevated()) {
        throw new DebuggableException(null, "Validate OS is Windows", "Validate is osumer elevated", "Create File instance of \"osumer.exe\"", "osumer is not elevated. Restart osumer with administrative privileges.", false);
    }
    String runningFilePath = null;
    try {
        runningFilePath = URLDecoder.decode(Installer.class.getProtectionDomain().getCodeSource().getLocation().getPath(), "UTF-8");
    } catch (UnsupportedEncodingException e1) {
        e1.printStackTrace();
        throw new DebuggableException(null, "Validate is osumer elevated", "Get current running file path", "Validate is running file name is ending with .exe", "Unsupported encoding UTF-8", false, e1);
    }
    if (!runningFilePath.endsWith(".exe")) {
        throw new DebuggableException(runningFilePath, "Get current running file path", "Validate is running file name is ending with .exe", "Create File instance of \"osumer.exe\"", "A Windows executable (.exe) version of osumer is required for installation. It can be downloaded from the releases. If you have it, rename it to \"osumer.exe\" to continue.", false);
    }
    File file = new File(runningFilePath);
    if (!file.exists()) {
        throw new DebuggableException(runningFilePath, "Validate is running file name is ending with .exe", "Create File instance of \"osumer.exe\"", "Create File instance of constant field winPath", "Unexpected? The running file-name does not exist!", false);
    }
    File destFolder = new File(winPath);
    if (!destFolder.exists()) {
        destFolder.mkdirs();
    }
    File verInfo = new File(winPath + "\\" + verInfoFile);
    try {
        if (verInfo.exists()) {
            verInfo.delete();
        }
        JSONObject verInfoJson = new JSONObject();
        verInfoJson.put("version", Osumer.OSUMER_VERSION);
        verInfoJson.put("branch", Osumer.OSUMER_BRANCH);
        verInfoJson.put("build", Osumer.OSUMER_BUILD_NUM);
        verInfo.createNewFile();
        FileOutputStream out = new FileOutputStream(verInfo);
        out.write(Base64.encodeBase64(verInfoJson.toString().getBytes(StandardCharsets.UTF_8)));
        out.flush();
        out.close();
    } catch (IOException e) {
        throw new DebuggableException(null, "Create new File instance with \"" + winPath + "\\" + verInfoFile + "\"", "Create application version info", "Create new File instance with \"" + winPath + "\\" + winFile + "\"", "Error creating version info", false, e);
    }
    File dest = new File(winPath + "\\" + winFile);
    try {
        if (dest.exists()) {
            dest.delete();
        }
        dest.createNewFile();
        FileOutputStream out = new FileOutputStream(dest);
        Files.copy(file.toPath(), out);
        out.flush();
        out.close();
    } catch (IOException e) {
        throw new DebuggableException(null, "Create new File instance with \"" + winPath + "\\" + winFile + "\"", "(Try scope) Copying file", "Creating Main osumer link in Start Menu", "Error copying file", false, e);
    }
    File startPathFolder = new File(START_MENU_PATH);
    if (!startPathFolder.exists() || !startPathFolder.isDirectory()) {
        startPathFolder.mkdir();
    }
    ShellLink slMain = ShellLink.createLink(Installer.winPath + "\\" + Installer.winFile);
    slMain.setWorkingDir(Installer.winPath);
    slMain.setIconLocation(Installer.winPath + "\\" + Installer.winFile);
    slMain.getHeader().setIconIndex(0);
    try {
        slMain.saveTo(START_MENU_PATH + "\\osumer.lnk");
    } catch (IOException e1) {
        throw new DebuggableException(null, "(Try scope) Copying file", "Creating Main osumer link in Start Menu", "Creating Daemon osumer link in Start Menu", "Error copying file", false, e1);
    }
    ShellLink slDaemon = ShellLink.createLink(Installer.winPath + "\\" + Installer.winFile);
    slDaemon.setWorkingDir(Installer.winPath);
    slDaemon.setCMDArgs("-daemon");
    slDaemon.setIconLocation(Installer.winPath + "\\" + Installer.winFile);
    slDaemon.getHeader().setIconIndex(0);
    try {
        slDaemon.saveTo(START_MENU_PATH + "\\osumer (Start as Daemon).lnk");
    } catch (IOException e1) {
        throw new DebuggableException(null, "Creating Main osumer link in Start Menu", "Creating Daemon osumer link in Start Menu", "(Next Try scope) Writing to registry", "Error copying file", false, e1);
    }
    try {
        // Create root key
        // HKLM/SOFTWARE/Clients/StartMenuInternet/osumerExpress
        boolean success = Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, WIN_REG_CLIENTS_PATH, WIN_REG_INTERNET_CLIENT_KEY);
        final String clientRegPath = WIN_REG_CLIENTS_PATH + "\\" + WIN_REG_INTERNET_CLIENT_KEY;
        // HKLM/SOFTWARE/Clients/StartMenuInternet/osumerExpress/@
        Advapi32Util.registrySetStringValue(WinReg.HKEY_LOCAL_MACHINE, clientRegPath, "", WIN_REG_INTERNET_CLIENT_DEFAULT_VALUE);
        // Capabilities
        // HKLM/SOFTWARE/Clients/StartMenuInternet/osumerExpress/Capabilities
        success = Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, clientRegPath, WIN_REG_CAP_KEY);
        final String capRegPath = clientRegPath + "\\" + WIN_REG_CAP_KEY;
        // HKLM/SOFTWARE/Clients/StartMenuInternet/osumerExpress/Capabilities/@ApplicationName,@ApplicationDescription,@ApplicationIcon
        Advapi32Util.registrySetStringValue(WinReg.HKEY_LOCAL_MACHINE, capRegPath, WIN_REG_CAP_APPNAME_PARA, WIN_REG_CAP_APPNAME_VALUE);
        Advapi32Util.registrySetStringValue(WinReg.HKEY_LOCAL_MACHINE, capRegPath, WIN_REG_CAP_APPDESC_PARA, WIN_REG_CAP_APPDESC_VALUE);
        Advapi32Util.registrySetStringValue(WinReg.HKEY_LOCAL_MACHINE, capRegPath, WIN_REG_CAP_APPICON_PARA, WIN_REG_CAP_APPICON_VALUE);
        // Capabilities: Startmenu
        // HKLM/SOFTWARE/Clients/StartMenuInternet/osumerExpress/Capabilities/Startmenu
        success = Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, capRegPath, WIN_REG_CAP_STARTMENU_KEY);
        // Legacy use
        final String capStartMenuRegPath = capRegPath + "\\" + WIN_REG_CAP_STARTMENU_KEY;
        // HKLM/SOFTWARE/Clients/StartMenuInternet/osumerExpress/Capabilities/Startmenu/@StartMenuInternet
        Advapi32Util.registrySetStringValue(WinReg.HKEY_LOCAL_MACHINE, capStartMenuRegPath, WIN_REG_CAP_STARTMENU_STARTMENUINTERNET_PARA, WIN_REG_CAP_STARTMENU_STARTMENUINTERNET_VALUE);
        // Capabilities: File associations
        // HKLM/SOFTWARE/Clients/StartMenuInternet/osumerExpress/Capabilities/FileAssociations
        success = Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, capRegPath, WIN_REG_CAP_FILEASSOC_KEY);
        // No file associations currently
        // Capabilities: URL Associations
        // HKLM/SOFTWARE/Clients/StartMenuInternet/osumerExpress/Capabilities/URLAssociations
        success = Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, capRegPath, WIN_REG_CAP_URLASSOC_KEY);
        final String urlAssocRegPath = capRegPath + "\\" + WIN_REG_CAP_URLASSOC_KEY;
        // HKLM/SOFTWARE/Clients/StartMenuInternet/osumerExpress/Capabilities/URLAssociations/@http,@https
        Advapi32Util.registrySetStringValue(WinReg.HKEY_LOCAL_MACHINE, urlAssocRegPath, WIN_REG_CAP_URLASSOC_HTTP_PARA, WIN_REG_CAP_URLASSOC_HTTP_VALUE);
        Advapi32Util.registrySetStringValue(WinReg.HKEY_LOCAL_MACHINE, urlAssocRegPath, WIN_REG_CAP_URLASSOC_HTTPS_PARA, WIN_REG_CAP_URLASSOC_HTTPS_VALUE);
        // Default icon
        // HKLM/SOFTWARE/Clients/StartMenuInternet/osumerExpress/DefaultIcon
        success = Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, clientRegPath, WIN_REG_DEFAULTICON_KEY);
        final String defaultIconRegPath = clientRegPath + "\\" + WIN_REG_DEFAULTICON_KEY;
        // HKLM/SOFTWARE/Clients/StartMenuInternet/osumerExpress/DefaultIcon/@
        Advapi32Util.registrySetStringValue(WinReg.HKEY_LOCAL_MACHINE, defaultIconRegPath, "", WIN_REG_DEFAULTICON_DEFAULT_VALUE);
        // Install info
        // HKLM/SOFTWARE/Clients/StartMenuInternet/osumerExpress/InstallInfo
        success = Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, clientRegPath, WIN_REG_INSTALLINFO_KEY);
        final String installInfoRegPath = clientRegPath + "\\" + WIN_REG_INSTALLINFO_KEY;
        // HKLM/SOFTWARE/Clients/StartMenuInternet/osumerExpress/InstallInfo/@HideIconsCommand
        Advapi32Util.registrySetStringValue(WinReg.HKEY_LOCAL_MACHINE, installInfoRegPath, WIN_REG_INSTALLINFO_HIDEICON_PARA, WIN_REG_INSTALLINFO_HIDEICON_VALUE);
        // HKLM/SOFTWARE/Clients/StartMenuInternet/osumerExpress/InstallInfo/@ShowIconsCommand
        Advapi32Util.registrySetStringValue(WinReg.HKEY_LOCAL_MACHINE, installInfoRegPath, WIN_REG_INSTALLINFO_SHOWICON_PARA, WIN_REG_INSTALLINFO_SHOWICON_VALUE);
        // HKLM/SOFTWARE/Clients/StartMenuInternet/osumerExpress/InstallInfo/@ReinstallCommand
        Advapi32Util.registrySetStringValue(WinReg.HKEY_LOCAL_MACHINE, installInfoRegPath, WIN_REG_INSTALLINFO_REINSTALL_PARA, WIN_REG_INSTALLINFO_REINSTALL_VALUE);
        // HKLM/SOFTWARE/Clients/StartMenuInternet/osumerExpress/InstallInfo/@IconsVisible
        Advapi32Util.registrySetIntValue(WinReg.HKEY_LOCAL_MACHINE, installInfoRegPath, WIN_REG_INSTALLINFO_ICONSVISIBLE_PARA, WIN_REG_INSTALLINFO_ICONSVISIBLE_VALUE);
        // Shell: Open: Command
        // HKLM/SOFTWARE/Clients/StartMenuInternet/osumerExpress/shell
        success = Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, clientRegPath, WIN_REG_SHELL_KEY);
        final String shellRegPath = clientRegPath + "\\" + WIN_REG_SHELL_KEY;
        // HKLM/SOFTWARE/Clients/StartMenuInternet/osumerExpress/shell/open
        success = Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, shellRegPath, WIN_REG_SHELL_OPEN_KEY);
        final String shellOpenRegPath = shellRegPath + "\\" + WIN_REG_SHELL_OPEN_KEY;
        // HKLM/SOFTWARE/Clients/StartMenuInternet/osumerExpress/shell/open/command
        success = Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, shellOpenRegPath, WIN_REG_SHELL_OPEN_COMMAND_KEY);
        final String shellOpenCmdRegPath = shellOpenRegPath + "\\" + WIN_REG_SHELL_OPEN_COMMAND_KEY;
        // HKLM/SOFTWARE/Clients/StartMenuInternet/osumerExpress/shell/open/command/@
        Advapi32Util.registrySetStringValue(WinReg.HKEY_LOCAL_MACHINE, shellOpenCmdRegPath, "", WIN_REG_SHELL_OPEN_COMMAND_DEFAULT_VALUE);
        // Registered Applications
        Advapi32Util.registrySetStringValue(WinReg.HKEY_LOCAL_MACHINE, WIN_REG_REGISTEREDAPPS_PATH, WIN_REG_REGISTEREDAPPS_OSUMEREXPRESS_PARA, WIN_REG_REGISTEREDAPPS_OSUMEREXPRESS_VALUE);
        // Classes
        // HKLM/SOFTWARE/Classes/osumer
        success = Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, WIN_REG_CLASSES_PATH, WIN_REG_CLASSES_OSUMER_KEY);
        final String osumerClassRegPath = WIN_REG_CLASSES_PATH + "\\" + WIN_REG_CLASSES_OSUMER_KEY;
        // HKLM/SOFTWARE/Classes/osumer/@
        Advapi32Util.registrySetStringValue(WinReg.HKEY_LOCAL_MACHINE, osumerClassRegPath, "", WIN_REG_CLASSES_OSUMER_DEFAULT_VALUE);
        // HKLM/SOFTWARE/Classes/osumer/@FriendlyTypeName
        Advapi32Util.registrySetStringValue(WinReg.HKEY_LOCAL_MACHINE, osumerClassRegPath, WIN_REG_CLASSES_OSUMER_FRIENDLYTYPENAME_PARA, WIN_REG_CLASSES_OSUMER_FRIENDLYTYPENAME_VALUE);
        Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, osumerClassRegPath, "shell");
        Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, osumerClassRegPath + "\\shell", "open");
        Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, osumerClassRegPath + "\\shell\\open", "command");
        Advapi32Util.registrySetStringValue(WinReg.HKEY_LOCAL_MACHINE, osumerClassRegPath + "\\shell\\open\\command", "", WIN_REG_SHELL_OPEN_COMMAND_DEFAULT_VALUE + " \"%1\"");
        // Run
        // HKLM/SOFTWARE/Microsoft/Windows/CurrentVersion/Run/@osumerDaemon
        Advapi32Util.registrySetStringValue(WinReg.HKEY_LOCAL_MACHINE, WIN_REG_RUN_PATH, WIN_REG_RUN_OSUMERDAEMON_PARA, WIN_REG_RUN_OSUMERDAEMON_VALUE);
    } catch (Win32Exception e) {
        throw new DebuggableException(null, "(Try&catch try) Writing to registry", "Throw debuggable exception", "(End of function)", "Error writing registry", false, e);
    }
}
Also used : DebuggableException(com.github.mob41.organdebug.exceptions.DebuggableException) JSONObject(org.json.JSONObject) FileOutputStream(java.io.FileOutputStream) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) ShellLink(mslinks.ShellLink) File(java.io.File) Win32Exception(com.sun.jna.platform.win32.Win32Exception)

Example 4 with DebuggableException

use of com.github.mob41.organdebug.exceptions.DebuggableException in project osumer by mob41.

the class Installer method uninstall.

public void uninstall() throws DebuggableException {
    File file = new File(winPath + "\\" + winFile);
    if (file.exists()) {
        file.delete();
    }
    file = new File(winPath + "\\" + verInfoFile);
    if (file.exists()) {
        file.delete();
    }
    file = new File(START_MENU_PATH + "\\osumer.lnk");
    if (file.exists()) {
        file.delete();
    }
    file = new File(START_MENU_PATH + "\\osumer (Start as Daemon).lnk");
    if (file.exists()) {
        file.delete();
    }
    try {
        final String clientRegPath = WIN_REG_CLIENTS_PATH + "\\" + WIN_REG_INTERNET_CLIENT_KEY;
        final String capRegPath = clientRegPath + "\\" + WIN_REG_CAP_KEY;
        final String shellRegPath = clientRegPath + "\\" + WIN_REG_SHELL_KEY;
        final String shellOpenRegPath = shellRegPath + "\\" + WIN_REG_SHELL_OPEN_KEY;
        // Capabilities
        Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, capRegPath, WIN_REG_CAP_FILEASSOC_KEY);
        Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, capRegPath, WIN_REG_CAP_URLASSOC_KEY);
        Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, capRegPath, WIN_REG_CAP_STARTMENU_KEY);
        Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, clientRegPath, WIN_REG_CAP_KEY);
        // Shell open command
        Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, shellOpenRegPath, WIN_REG_SHELL_OPEN_COMMAND_KEY);
        Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, shellRegPath, WIN_REG_SHELL_OPEN_KEY);
        Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, clientRegPath, WIN_REG_SHELL_KEY);
        Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, clientRegPath, WIN_REG_DEFAULTICON_KEY);
        Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, clientRegPath, WIN_REG_INSTALLINFO_KEY);
        Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, WIN_REG_CLIENTS_PATH, WIN_REG_INTERNET_CLIENT_KEY);
        // Classes and Registered applications
        Advapi32Util.registryDeleteValue(WinReg.HKEY_LOCAL_MACHINE, WIN_REG_REGISTEREDAPPS_PATH, WIN_REG_REGISTEREDAPPS_OSUMEREXPRESS_PARA);
        Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, WIN_REG_CLASSES_PATH + "\\" + WIN_REG_CLASSES_OSUMER_KEY + "\\shell\\open", "command");
        Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, WIN_REG_CLASSES_PATH + "\\" + WIN_REG_CLASSES_OSUMER_KEY + "\\shell", "open");
        Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, WIN_REG_CLASSES_PATH + "\\" + WIN_REG_CLASSES_OSUMER_KEY, "shell");
        Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, WIN_REG_CLASSES_PATH, WIN_REG_CLASSES_OSUMER_KEY);
        Advapi32Util.registryDeleteValue(WinReg.HKEY_LOCAL_MACHINE, WIN_REG_RUN_PATH, WIN_REG_RUN_OSUMERDAEMON_PARA);
    } catch (Win32Exception e) {
        e.printStackTrace();
        throw new DebuggableException(null, "(Try&catch try) Writing to registry", "Throw debuggable exception", "(End of function)", "Error writing registry", false, e);
    }
}
Also used : DebuggableException(com.github.mob41.organdebug.exceptions.DebuggableException) File(java.io.File) Win32Exception(com.sun.jna.platform.win32.Win32Exception)

Example 5 with DebuggableException

use of com.github.mob41.organdebug.exceptions.DebuggableException in project osumer by mob41.

the class UIFrame method checkUpdate.

public void checkUpdate() {
    if (checkingUpdate) {
        return;
    }
    checkingUpdate = true;
    Thread thread = new Thread() {

        public void run() {
            lblUpdateStatus.setForeground(Color.BLACK);
            lblUpdateStatus.setText("Checking for updates...");
            UpdateInfo verInfo = null;
            try {
                verInfo = getUpdateInfoByConfig();
            } catch (NoBuildsForVersionException e) {
                lblUpdateStatus.setForeground(Color.RED);
                lblUpdateStatus.setText("No builds available for the new version. See dump.");
                checkingUpdate = false;
                return;
            } catch (NoSuchVersionException e) {
                lblUpdateStatus.setForeground(Color.RED);
                lblUpdateStatus.setText("No current version in the selected branch. See dump.");
                JOptionPane.showMessageDialog(UIFrame.this, "We don't have version " + Osumer.OSUMER_VERSION + " in the current update branch\n\nPlease try another update branch (snapshot, beta, stable).", "Version not available", JOptionPane.INFORMATION_MESSAGE);
                checkingUpdate = false;
                return;
            } catch (NoSuchBuildNumberException e) {
                lblUpdateStatus.setForeground(Color.RED);
                lblUpdateStatus.setText("This version has a invalid build number. See dump");
                JOptionPane.showMessageDialog(UIFrame.this, "We don't have build number greater or equal to " + Osumer.OSUMER_BUILD_NUM + " in version " + Osumer.OSUMER_VERSION + ".\n" + "If you are using a modified/development osumer,\n" + " you can just ignore this message.\n" + "If not, this might be the versions.json in GitHub goes wrong,\n" + " post a new issue about this.", "Build not available", JOptionPane.WARNING_MESSAGE);
                checkingUpdate = false;
                return;
            } catch (DebuggableException e) {
                e.printStackTrace();
                lblUpdateStatus.setForeground(Color.RED);
                lblUpdateStatus.setText("Could not connect to update server.");
                JOptionPane.showMessageDialog(UIFrame.this, "Could not connect to update server.", "Error", JOptionPane.ERROR_MESSAGE);
                checkingUpdate = false;
                return;
            }
            if (verInfo == null) {
                lblUpdateStatus.setForeground(Color.RED);
                lblUpdateStatus.setText("Could not obtain update info.");
                JOptionPane.showMessageDialog(UIFrame.this, "Could not obtain update info.", "Error", JOptionPane.ERROR_MESSAGE);
                checkingUpdate = false;
                return;
            }
            if (verInfo.isThisVersion()) {
                lblUpdateStatus.setForeground(Color.BLACK);
                lblUpdateStatus.setText("You are running the latest version of osumer" + " (" + verInfo.getVersion() + "-" + Updater.getBranchStr(verInfo.getBranch()) + "-" + verInfo.getBuildNum() + ")");
                checkingUpdate = false;
                return;
            }
            lblUpdateStatus.setForeground(new Color(0, 153, 0));
            lblUpdateStatus.setText((verInfo.isUpgradedVersion() ? "Upgrade" : "Update") + " available! New version: " + verInfo.getVersion() + "-" + Updater.getBranchStr(verInfo.getBranch()) + "-b" + verInfo.getBuildNum());
            int option;
            String desc = verInfo.getDescription();
            if (desc == null) {
                option = JOptionPane.showOptionDialog(UIFrame.this, "New " + (verInfo.isUpgradedVersion() ? "upgrade" : "update") + " available! New version:\n" + verInfo.getVersion() + "-" + Updater.getBranchStr(verInfo.getBranch()) + "-b" + verInfo.getBuildNum() + "\n\n" + "Do you want to update it now?", "Update available", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE, null, null, JOptionPane.NO_OPTION);
            } else {
                option = JOptionPane.showOptionDialog(UIFrame.this, "New " + (verInfo.isUpgradedVersion() ? "upgrade" : "update") + " available! New version:\n" + verInfo.getVersion() + "-" + Updater.getBranchStr(verInfo.getBranch()) + "-b" + verInfo.getBuildNum() + "\n\n" + "Do you want to update it now?", "Update available", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE, null, new String[] { "Yes", "No", "Description/Changelog" }, JOptionPane.NO_OPTION);
                if (option == 2) {
                    option = JOptionPane.showOptionDialog(UIFrame.this, new TextPanel(desc), "Update description/change-log", JOptionPane.YES_NO_OPTION, JOptionPane.PLAIN_MESSAGE, null, null, 0);
                }
            }
            if (option == JOptionPane.YES_OPTION) {
                /*
                    try {
                        Desktop.getDesktop().browse(new URI(verInfo.getWebLink()));
                    } catch (IOException | URISyntaxException e) {
                        DebugDump dump = new DebugDump(
                                verInfo.getWebLink(),
                                "Show option dialog of updating osumer or not",
                                "Set checkingUpdate to false",
                                "(End of function / thread)",
                                "Error when opening the web page",
                                false,
                                e);
                        DumpManager.getInstance().addDump(dump);
                        DebugDump.showDebugDialog(dump);
                    }
                    */
                try {
                    String updaterLink = Updater.getUpdaterLink();
                    if (updaterLink == null) {
                        System.out.println("No latest updater .exe defined! Falling back to legacy updater!");
                        updaterLink = Updater.LEGACY_UPDATER_JAR;
                    }
                    URL url;
                    try {
                        url = new URL(updaterLink);
                    } catch (MalformedURLException e) {
                        e.printStackTrace();
                        JOptionPane.showMessageDialog(null, "Error:\n" + e, "Error", JOptionPane.ERROR_MESSAGE);
                        return;
                    }
                    final String folder = System.getProperty("java.io.tmpdir");
                    final String fileName = "osumer_updater_" + Calendar.getInstance().getTimeInMillis() + ".exe";
                    mgr.addQueue(new Queue("osumer Updater", new URLDownloader(folder, fileName, url), null, null, new QueueAction[] { new UpdaterRunAction(folder + fileName) }));
                    tab.setSelectedIndex(1);
                    new Thread() {

                        public void run() {
                            JOptionPane.showMessageDialog(UIFrame.this, "The web updater will be downloaded and started very soon.", "Notice", JOptionPane.INFORMATION_MESSAGE);
                        }
                    }.start();
                } catch (DebuggableException e) {
                    e.printStackTrace();
                    JOptionPane.showMessageDialog(null, "Error:\n" + e, "Error", JOptionPane.ERROR_MESSAGE);
                    checkingUpdate = false;
                }
            }
            checkingUpdate = false;
        }
    };
    thread.start();
}
Also used : NoSuchVersionException(com.github.mob41.osumer.exceptions.NoSuchVersionException) DebuggableException(com.github.mob41.organdebug.exceptions.DebuggableException) MalformedURLException(java.net.MalformedURLException) UpdaterRunAction(com.github.mob41.osumer.io.queue.actions.UpdaterRunAction) Color(java.awt.Color) QueueAction(com.github.mob41.osumer.io.queue.QueueAction) NoBuildsForVersionException(com.github.mob41.osumer.exceptions.NoBuildsForVersionException) URLDownloader(com.github.mob41.osumer.io.legacy.URLDownloader) URL(java.net.URL) SockThread(com.github.mob41.osumer.sock.SockThread) NoSuchBuildNumberException(com.github.mob41.osumer.exceptions.NoSuchBuildNumberException) Queue(com.github.mob41.osumer.io.queue.Queue) EventQueue(java.awt.EventQueue) UpdateInfo(com.github.mob41.osumer.updater.UpdateInfo)

Aggregations

DebuggableException (com.github.mob41.organdebug.exceptions.DebuggableException)8 IOException (java.io.IOException)5 MalformedURLException (java.net.MalformedURLException)4 Queue (com.github.mob41.osumer.io.queue.Queue)3 QueueAction (com.github.mob41.osumer.io.queue.QueueAction)3 Win32Exception (com.sun.jna.platform.win32.Win32Exception)3 EventQueue (java.awt.EventQueue)3 URL (java.net.URL)3 AfterSoundAction (com.github.mob41.osumer.io.queue.actions.AfterSoundAction)2 BeatmapImportAction (com.github.mob41.osumer.io.queue.actions.BeatmapImportAction)2 BeforeSoundAction (com.github.mob41.osumer.io.queue.actions.BeforeSoundAction)2 CustomImportAction (com.github.mob41.osumer.io.queue.actions.CustomImportAction)2 SockThread (com.github.mob41.osumer.sock.SockThread)2 OsuDownloader (com.github.mob41.osums.io.beatmap.OsuDownloader)2 File (java.io.File)2 URLConnection (java.net.URLConnection)2 Config (com.github.mob41.osumer.Config)1 NoBuildsForVersionException (com.github.mob41.osumer.exceptions.NoBuildsForVersionException)1 NoSuchBuildNumberException (com.github.mob41.osumer.exceptions.NoSuchBuildNumberException)1 NoSuchVersionException (com.github.mob41.osumer.exceptions.NoSuchVersionException)1