Exemple #1
0
  MainFrame() {
    defaultTitle = Main.makeTitle();
    enableShadow = Settings.getInstance().isEnableShadow();
    if (enableShadow) setSize(834, 542);
    else setSize(802, 511);
    setDefaultCloseOperation(3);
    setTitle(Main.makeTitle());
    initComponents();
    selectTab("main");
    loadBackground();

    setLocationRelativeTo(null);

    if (enableShadow)
      try {
        setBackground(new Color(0, 0, 0, 0));
        getRootPane().setBorder(border = new DropShadowBorder(borderColor, 4));
      } catch (Throwable ex) {
        HMCLog.err("Failed to set window transparent.", ex);
        Settings.getInstance().setEnableShadow(false);
        setSize(802, 511);
      }

    ((JPanel) getContentPane()).setOpaque(true);
  }
Exemple #2
0
  private void executeTask(Task t) {
    if (!shouldContinue || t == null) return;
    processTasks(t.getDependTasks());

    HMCLog.log("Executing task: " + t.getInfo());
    for (DoingDoneListener<Task> d : taskListener) d.onDoing(t);
    for (DoingDoneListener<Task> d : t.getTaskListeners()) d.onDoing(t);

    boolean flag = true;
    try {
      t.executeTask();
    } catch (Throwable e) {
      t.setFailReason(e);
      flag = false;
    }
    if (flag) {
      HMCLog.log((t.isAborted() ? "Task aborted: " : "Task finished: ") + t.getInfo());
      for (DoingDoneListener<Task> d : taskListener) d.onDone(t);
      for (DoingDoneListener<Task> d : t.getTaskListeners()) d.onDone(t);
      processTasks(t.getAfterTasks());
    } else {
      HMCLog.err("Task failed: " + t.getInfo(), t.getFailReason());
      for (DoingDoneListener<Task> d : taskListener) d.onFailed(t);
      for (DoingDoneListener<Task> d : t.getTaskListeners()) d.onFailed(t);
    }
  }
Exemple #3
0
  public static void main(String[] args) {
    Thread.currentThread().setName("launcher");
    println("*** " + Main.makeTitle() + " ***");

    LogWindow.instance.setTerminateGame(Utils::shutdownForcely);

    boolean showInfo = false;
    String classPath = "";
    String mainClass = "net.minecraft.client.Minecraft";

    ArrayList<String> cmdList = new ArrayList<>();

    for (String s : args)
      if (s.startsWith("-cp=")) classPath = classPath.concat(s.substring("-cp=".length()));
      else if (s.startsWith("-mainClass=")) mainClass = s.substring("-mainClass=".length());
      else if (s.equals("-debug")) showInfo = true;
      else cmdList.add(s);

    String[] cmds = (String[]) cmdList.toArray(new String[cmdList.size()]);

    String[] tokenized = StrUtils.tokenize(classPath, File.pathSeparator);
    int len = tokenized.length;

    if (showInfo) {
      try {
        File logFile = new File("hmclmc.log");
        if (!logFile.exists()) logFile.createNewFile();
        FileOutputStream tc = new FileOutputStream(logFile);
        DoubleOutputStream out = new DoubleOutputStream(tc, System.out);
        System.setOut(new LauncherPrintStream(out));
        DoubleOutputStream err = new DoubleOutputStream(tc, System.err);
        System.setErr(new LauncherPrintStream(err));
      } catch (Exception e) {
        println("Failed to add log file appender.");
        e.printStackTrace();
      }

      println("Arguments: {\n" + StrUtils.parseParams("    ", args, "\n") + "\n}");
      println("Main Class: " + mainClass);
      println("Class Path: {\n" + StrUtils.parseParams("    ", tokenized, "\n") + "\n}");
      SwingUtilities.invokeLater(() -> LogWindow.instance.setVisible(true));
    }

    URL[] urls = new URL[len];

    try {
      for (int j = 0; j < len; j++) urls[j] = new File(tokenized[j]).toURI().toURL();
    } catch (Throwable e) {
      MessageBox.Show(C.i18n("crash.main_class_not_found"));
      println("Failed to get classpath.");
      e.printStackTrace();
      return;
    }

    if (!JdkVersion.isJava64Bit() && Platform.getPlatform() == Platform.BIT_64)
      MessageBox.Show(C.i18n("advice.os64butjdk32"));

    Method minecraftMain;
    try {
      minecraftMain =
          new URLClassLoader(urls).loadClass(mainClass).getMethod("main", String[].class);
    } catch (ClassNotFoundException | NoSuchMethodException | SecurityException t) {
      MessageBox.Show(C.i18n("crash.main_class_not_found"));
      println("Minecraft main class not found.");
      t.printStackTrace();
      return;
    }

    println("*** Launching Game ***");

    try {
      minecraftMain.invoke(null, new Object[] {cmds});
    } catch (Throwable throwable) {
      HMCLog.err("Cought exception!");
      String trace = StrUtils.getStackTrace(throwable);
      final String advice = MinecraftCrashAdvicer.getAdvice(trace);
      MessageBox.Show(C.i18n("crash.minecraft") + ": " + advice);

      LogWindow.instance.log(C.i18n("crash.minecraft"));
      LogWindow.instance.log(advice);
      LogWindow.instance.log(trace);
      LogWindow.instance.setExit(TrueFunction.instance);
      LogWindow.instance.setVisible(true);
    }

    println("*** Game Exited ***");
  }