예제 #1
0
파일: Restart.java 프로젝트: sks40gb/zunk
 private static void writeLog(String msg) {
   try {
     System.err.println(msg);
     if (logWriter == null) {
       FileWriter fileWriter = new FileWriter(LOG_NAME, true);
       logWriter = new PrintWriter(fileWriter, true);
       logWriter.println();
     }
     logWriter.println(msg);
     logWriter.flush();
   } catch (IOException e) {
     if (frame != null) {
       frame.setText("Error writing upgrade.log: " + e + " -- " + msg);
     }
     System.err.println("Error writing upgrade.log: " + e);
     System.err.println(msg);
     // downloadFailed();
   }
 }
예제 #2
0
파일: Restart.java 프로젝트: sks40gb/zunk
  private static final void main_aux(String[] args) throws Exception {

    boolean isNT;

    try {
      // force Windows look and feel
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {
    }

    {
      // start the log
      SimpleDateFormat nameFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
      logDateTime =
          nameFormatter.format(new Date(), new StringBuffer(19), new FieldPosition(0)).toString();
      writeLog("Starting install and restart " + logDateTime);

      String osName = System.getProperty("os.name");
      if ("Windows Me".equalsIgnoreCase(osName)
          || "Windows 98".equals(osName)
          || "Windows 95".equals(osName)) {
        isNT = false;
      } else {
        isNT = true;
      }
      writeLog("OS='" + osName + "' -- isNT=" + isNT);
    }

    boolean admin = false;
    int argPos = 0;
    if (args[0].equals("--admin")) {
      admin = true;
      argPos = 1;
    }

    // create a dialog to inform the user of the install and restart
    frame = new DownloadFrame(admin);
    frame.setText(
        "DIA is downloading an upgraded version of the DIA program."
            + "  This may take a few minutes."
            + "\n\nInstalling downloaded files.");
    frame.clearOkListener(null);
    frame.setVisible(true);

    // fetch the arguments
    String userName = args[argPos];
    String password = args[argPos + 1];
    try {
      // wait 2 sec. to give caller a chance to quit
      // (probably not needed)
      Thread.sleep(2000);
    } catch (InterruptedException e) {
      writeLog("sleep interrupted");
    }

    // install downloaded files by removing "~~" from end of names
    frame.setExitEnabled(false);
    renameDownloadedFiles(".");

    // check for failure
    if (errorCount > 0) {
      frame.setExitEnabled(true);
      frame.setText(
          "FAILED INSTALLING DOWNLOADED FILES"
              + "\n\nSee upgrade.log for details."
              + "\n\nPlease reboot the computer and try again.");
      writeLog("==== Restoring files after failure");
      restoreBackupFiles(".");
      closeLog();
      return;
    }

    // rewrite jexpress/...properties files
    // version 0.01.056 and before to be changed
    rewriteProperties("jexpress/DIAAdmin.properties");
    rewriteProperties("jexpress/i-BaseDIA.properties");

    // generate a random seed
    frame.setText(
        "DIA is downloading an upgraded version of the DIA program."
            + "  This may take a few minutes."
            + "\n\nSetting up for encrypted data transmission.  This may"
            + " take as long as a minute, depending on the speed of your"
            + " computer.");
    generateRandomSeed();

    frame.setText(
        "DIA is downloading an upgraded version of the DIA program."
            + "  This may take a few minutes."
            + "\n\nDeleting temporary files.");
    frame.setExitEnabled(true);

    // delete temporary backups
    deleteBackupFiles(".");

    // delete unused files
    deleteUnusedFiles();

    // delete temporary class files (all classes used should have been loaded)
    if (isNT) {
      Class.forName("tools.JniSystem"); // load this class before deleting
    }
    (new File("common/FileProperties.class")).delete();
    (new File("common/Log$1.class")).delete();
    (new File("common/Log.class")).delete();
    (new File("rcap/JniSystem.class")).delete(); // TEMPORARY
    (new File("tools/JniSystem.class")).delete();
    (new File("tools/Command.class")).delete();
    (new File("tools/CommandUtil.class")).delete();
    (new File("tools/LocalProperties.class")).delete();
    (new File("tools/ReadThread.class")).delete();
    (new File("tools/Restart.class")).delete();
    (new File("ui/DownloadFrame$1.class")).delete();
    (new File("ui/DownloadFrame$2.class")).delete();
    (new File("ui/DownloadFrame$3.class")).delete();
    (new File("ui/DownloadFrame$4.class")).delete();
    (new File("ui/DownloadFrame.class")).delete();
    (new File("common")).delete();
    (new File("rcap")).delete(); // TEMPORARY
    (new File("tools")).delete();
    (new File("ui")).delete();

    // Call DIA to start new instance, but do NOT wait for process to return
    try {
      StringBuffer buffer = new StringBuffer(80);
      buffer.append("i-BaseDIA.exe ");
      if (admin) {
        buffer.append("--admin ");
      }
      buffer.append("--restart ");
      buffer.append(userName);
      buffer.append(" ");
      buffer.append(password);
      String commandLine = buffer.toString();
      writeLog("restart command: " + commandLine);

      if (args.length >= 2 && (args[0].endsWith("DOSSC") || args[1].endsWith("DOSSC"))) {
        System.out.println("Courtney: Press any key to continue");
        System.in.read();
      }
      if (isNT) {
        Process dummy = Runtime.getRuntime().exec(commandLine);
      } else {
        new JniSystem().call(commandLine);
      }
    } catch (Exception e) {
      writeLog("Restarting DIA: " + e);
      frame.setText(
          "FAILED RESTARTING DIA"
              + "\n\nSee upgrade.log for details."
              + "\n\nPlease reboot and try again");
      if (args.length >= 2 && (args[0].endsWith("DOSSC") || args[1].endsWith("DOSSC"))) {
        System.out.println("Courtney: Press any key to exit program");
        System.in.read();
      }
    }
    closeLog();
    System.exit(0);
  }