use of com.github.mob41.osumer.installer.Installer 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);
}
}
}
use of com.github.mob41.osumer.installer.Installer 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);
}
}
use of com.github.mob41.osumer.installer.Installer in project osumer by mob41.
the class Main method main.
public static void main(String[] args) {
try {
DumpManager.init(Osumer.getVersionString(), Osumer.getVersionString());
} catch (IOException e2) {
e2.printStackTrace();
System.err.println("DumpManager: Error initializing dump manager");
}
DumpManager.reportEvent("active", "launcher");
ArgParser ap = new ArgParser(args);
if (ap.isVersionFlag()) {
System.out.println(Osumer.OSUMER_VERSION + "-" + Osumer.OSUMER_BRANCH + "-" + Osumer.OSUMER_BUILD_NUM);
return;
}
// 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()) {
DumpManager.reportEvent("event", "launcherHideIcons");
installer.hideIcons();
} else if (ap.isShowIconsFlag()) {
DumpManager.reportEvent("event", "launcherShowIcons");
installer.showIcons();
} else if (ap.isReinstallFlag()) {
DumpManager.reportEvent("event", "launcherReinstall");
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 (WithDumpException e) {
if (!ap.isNoUiFlag() && !GraphicsEnvironment.isHeadless()) {
//TODO: Error Dump Dialog Control
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 (WithDumpException e) {
if (!ap.isNoUiFlag() && !GraphicsEnvironment.isHeadless()) {
//TODO: Error Dump Dialog Control
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$");
}
}
}*/
DumpManager.forceMetricsReport();
System.exit(0);
return;
}
//
// Launch osumer system right here if no installation arguments
//
String configPath = Osumer.isWindows() ? System.getenv("localappdata") + "\\osumerExpress" : "";
Configuration config = new Configuration(configPath, Configuration.DEFAULT_DATA_FILE_NAME);
try {
config.load();
} catch (IOException e1) {
System.err.println("Unable to load configuration");
e1.printStackTrace();
DumpManager.addDump(new DebugDump(null, "Configuration initialization", "Load configuration", "Set String urlStr to null", "Unable to load configuration", false, e1));
DumpManager.forceMetricsReport();
if (!GraphicsEnvironment.isHeadless()) {
JOptionPane.showMessageDialog(null, "Could not load configuration. For more details, check dump:\n" + e1, "Configuration Error", JOptionPane.ERROR_MESSAGE);
}
System.exit(-1);
return;
}
String urlStr = null;
for (int i = 0; i < args.length; i++) {
if (config.isUseOldParser() ? OsumsOldParser.checkVaildBeatmapUrl(args[i]) : OsumsNewParser.checkVaildBeatmapUrl(args[i])) {
urlStr = args[i];
break;
}
}
if (// Configuration
(config.isSwitchToBrowserIfWithoutUiArg() && !ap.isUiFlag() && ap.isNoUiFlag()) || (urlStr != null && !config.isOEEnabled()) || (args != null && args.length > 0 && urlStr == null)) {
// Browser if disabled OE
runBrowser(config, args);
DumpManager.reportEvent("event", "launcherRunBrowser");
DumpManager.forceMetricsReport();
System.exit(0);
return;
} else {
IDaemon d = null;
try {
// Contact the daemon via RMI
d = (IDaemon) Naming.lookup("rmi://localhost:46726/daemon");
} catch (Exception e) {
}
if (d == null) {
try {
Runtime.getRuntime().exec("\"" + OsumerNative.getProgramFiles() + "\\osumer2\\osumer-daemon.exe\"");
} catch (IOException e) {
e.printStackTrace();
DumpManager.addDump(new DebugDump(null, "Check if \"d\" is null", "Execute osumer-daemon.exe", "Initialize \"c\" as 0", "Could not start daemon. Terminating", false, e));
DumpManager.forceMetricsReport();
JOptionPane.showMessageDialog(null, "Could not start daemon. For more details, check dump. Terminating:\n" + e, "osumer launcher Error", JOptionPane.ERROR_MESSAGE);
System.exit(-1);
return;
}
int c = 0;
while (c < 20) {
try {
// Contact the daemon via RMI
d = (IDaemon) Naming.lookup("rmi://localhost:46726/daemon");
} catch (Exception e) {
}
try {
Thread.sleep(50);
} catch (InterruptedException e) {
break;
}
c++;
}
if (d == null) {
DumpManager.addDump(new DebugDump(null, "(While-loop) Look up daemon RMI", "Check if \\\"d\\\" is null", "Check if \"urlStr\" is null", false, "Could not connect to daemon. Terminating"));
DumpManager.forceMetricsReport();
JOptionPane.showMessageDialog(null, "Could not connect to daemon. For more details, check dump. Terminating", "osumer launcher Error", JOptionPane.ERROR_MESSAGE);
System.exit(-1);
return;
}
}
if (urlStr != null) {
try {
d.addQueue(urlStr);
System.exit(0);
return;
} catch (RemoteException e) {
e.printStackTrace();
DumpManager.addDump(new DebugDump(null, "Check if \\\"urlStr\\\" is null", "Request daemon to add queue", "System Exit", "Could not connect or add queue to daemon", false, e));
DumpManager.forceMetricsReport();
JOptionPane.showMessageDialog(null, "Could not connect or add queue to daemon. For more details, check dump:\n" + e, "osumer launcher Error", JOptionPane.ERROR_MESSAGE);
System.exit(-1);
return;
}
}
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;
}
runUi(config, args, ap, d);
}
DumpManager.forceMetricsReport();
}
use of com.github.mob41.osumer.installer.Installer in project osumer by mob41.
the class Installer method install.
public void install() throws WithDumpException {
if (!Osumer.isWindows()) {
throw new WithDumpException(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 WithDumpException(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 WithDumpException(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 WithDumpException(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 WithDumpException(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 WithDumpException(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 WithDumpException(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 WithDumpException(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 WithDumpException(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 WithDumpException(null, "(Try&catch try) Writing to registry", "Throw debuggable exception", "(End of function)", "Error writing registry", false, e);
}
}
Aggregations