Beispiel #1
0
 public static String localizeHomeDir() {
   String dir;
   if (OSInfo.isLinux()) {
     if (new File("portable").exists()) {
       dir = "";
     } else {
       dir = System.getProperty("user.home") + "/.alliance/";
     }
   } else if (OSInfo.isWindows()) {
     if (new File("portable").exists()) {
       dir = "";
     } else {
       dir = System.getenv("APPDATA") + "/Alliance/";
     }
   } else {
     dir = "";
   }
   return dir;
 }
Beispiel #2
0
  public static void main(String[] args) {
    // AutoUpgrade
    if (new File("alliance.tmp").exists()) {
      if (new File("alliance.tmp").length() == AutomaticUpgrade.SOURCE_JAR.length()) {
        new File("alliance.tmp").delete();
      } else {
        try {
          AutomaticUpgrade.copyFile(new File("alliance.tmp"), AutomaticUpgrade.SOURCE_JAR);
          Runtime.getRuntime().exec("." + System.getProperty("file.separator") + "alliance");
          System.exit(0);
        } catch (IOException ex) {
          ex.printStackTrace();
          System.exit(0);
        }
      }
    }

    try {
      System.out.println(
          "Launching " + Version.NAME + " v" + Version.VERSION + " build " + Version.BUILD_NUMBER);
      System.setProperty("alliance.build", "" + Version.BUILD_NUMBER);

      passArgumentLink(args);

      boolean allowMultipleInstances =
          argsContain(args, "/allowMultipleInstances")
              || new File("allowMultipleInstances").exists();
      boolean runMinimized = argsContain(args, "/min");

      if (!allowMultipleInstances) {
        checkIfAlreadyRunning(!runMinimized);
        listenExternalLinks();
        passArgumentLink(args);
      }

      Runnable r = null;
      if (!runMinimized) {
        try {
          r = (Runnable) Class.forName("org.alliance.launchers.SplashWindow").newInstance();
        } catch (Exception e) {
          e.printStackTrace();
        }
      }

      String s = getSettingsFile();
      for (int i = 0; i < args.length; i++) {
        if (!args[i].startsWith("/") && !args[i].endsWith(".alliance")) {
          s = args[i];
        }
      }
      Subsystem core = initCore(s, (StartupProgressListener) r);
      if (core == null) {
        return; // oops. core crashed. Error message has been displayd. just bail.
      }
      Subsystem tray = null;
      try {
        tray = initTrayIcon(core);
        OSInfo.setSupportsTrayIcon(true);
      } catch (Throwable t) {
        OSInfo.setSupportsTrayIcon(false);
      }

      if (OSInfo.supportsTrayIcon()) {
        if (!runMinimized) {
          ((Runnable) tray).run(); // open ui
          if (r != null) {
            r.run(); // close splashwindow
          }
        }

        if (!allowMultipleInstances) {
          startStartSignalThread(tray);
        }
      } else {
        initUI(core);
        if (r != null) {
          r.run();
        }
      }
    } catch (Throwable e) {
      try {
        new File(localizeHomeDir() + "logs").mkdirs();
        PrintWriter writer = new PrintWriter("logs/crash.log");
        e.printStackTrace(writer);
        writer.close();
      } catch (FileNotFoundException e2) {
        e.printStackTrace();
      }
    }
  }