Exemple #1
0
  public InstallUSB() {
    ClassLoader loader = getClass().getClassLoader();
    iconUrl = loader.getResource(iconResourcePath);
    String msg;
    if (os.equals("Linux"))
      msg =
          "Installing USB devices requires sudo rights.\n"
              + "You will be asked for your sudo password...";
    else msg = "Installation for Linux platform only.";
    mop = new ModelessOptionPane(50, 50, msg, iconUrl);
    mop.showTitle(TITLE);
    SystemTools.delay(3000);
    if (!os.equals("Linux")) System.exit(0);

    String zipPath = "", scriptPath = "";

    try {
      tempDir = SystemTools.createTempDirectory();
      zipPath = tempDir + fs + zipName;
      scriptPath = tempDir + fs + scriptName;
      Downloader.copyFile(dlURL, zipPath);
      Unzipper.unzip(zipPath, tempDir);
    } catch (IOException e) {
      mop.setText("Download/Extracting failed. \nTerminating now...", false);
      System.out.println(e.getMessage());
      cleanUp();
      SystemTools.delay(4000);
      System.exit(1);
    }
    mop.setText("Installing now. Please wait...\n(Click cancel to quit.)", false);
    try {
      runCommand("gksudo " + scriptPath, tempDir);
    } catch (IOException ex) {
      System.out.println("Failed to spawn script '" + scriptPath + "'");
      cleanUp();
      System.exit(1);
    }

    while (state == Status.INSTALLING) {
      SystemTools.delay(10);
    }
    if (state == Status.ERROR)
      mop.setText("Can't install.\nPossibly wrong administrator password.", false);
    else mop.setText("Installation successful. Please reconnect\nyour smartphone to the USB port.");
    cleanUp();
    SystemTools.delay(6000);
    System.exit(0);
  }
Exemple #2
0
 private void cleanUp() {
   if (SystemTools.deleteDir(tempDir)) System.out.println("Cleanup successful");
 }