@Override
 public void start(Stage primaryStage) throws Exception {
   initApplicationDirs();
   File dataDir = new File(applicationDataDir());
   if (dataDir.exists()) {
     LoginWindow loginWindow = new LoginWindow();
     loginWindow.displayLoginAndWait();
     boolean isAuthenticated = SEAGridContext.getInstance().getAuthenticated();
     if (isAuthenticated) {
       HomeWindow homeWindow = new HomeWindow();
       Screen screen = Screen.getPrimary();
       Rectangle2D bounds = screen.getVisualBounds();
       primaryStage.setX(bounds.getMinX());
       primaryStage.setY(bounds.getMinY());
       primaryStage.setWidth(bounds.getWidth());
       primaryStage.setHeight(bounds.getHeight());
       homeWindow.start(primaryStage);
       primaryStage.setOnCloseRequest(
           t -> {
             Platform.exit();
             System.exit(0);
           });
     }
   } else {
     SEAGridDialogHelper.showExceptionDialogAndWait(
         new Exception("Application Data Dir Does Not Exists"),
         "Application Data Dir Does Not Exists",
         null,
         "Application Data Dir Does Not Exists");
     System.exit(0);
   }
 }
  public static void extractLegacyEditorResources() {
    try {
      String destParent = applicationDataDir() + ".ApplicationData" + File.separator;
      File appHome = new File(destParent);
      if (!appHome.exists()) {
        if (!appHome.mkdirs()) {
          SEAGridDialogHelper.showExceptionDialogAndWait(
              new Exception("Cannot Create Application Data Dir"),
              "Cannot Create Application Data Dir",
              null,
              "Cannot Create Application Data Dir");
        }
      }
      byte[] buf = new byte[1024];
      ZipInputStream zipinputstream;
      ZipEntry zipentry;
      zipinputstream =
          new ZipInputStream(
              SEAGridDesktop.class.getClassLoader().getResourceAsStream("legacy.editors.zip"));

      zipentry = zipinputstream.getNextEntry();
      if (zipentry == null) {
        SEAGridDialogHelper.showExceptionDialogAndWait(
            new Exception("Cannot Read Application Resources"),
            "Cannot Read Application Resources",
            null,
            "Cannot Read Application Resources");
      } else {
        while (zipentry != null) {
          // for each entry to be extracted
          String entryName = destParent + zipentry.getName();
          entryName = entryName.replace('/', File.separatorChar);
          entryName = entryName.replace('\\', File.separatorChar);
          logger.info("entryname " + entryName);
          int n;
          FileOutputStream fileoutputstream;
          File newFile = new File(entryName);
          if (zipentry.isDirectory()) {
            if (!newFile.mkdirs()) {
              break;
            }
            zipentry = zipinputstream.getNextEntry();
            continue;
          }
          fileoutputstream = new FileOutputStream(entryName);
          while ((n = zipinputstream.read(buf, 0, 1024)) > -1) {
            fileoutputstream.write(buf, 0, n);
          }
          fileoutputstream.close();
          zipinputstream.closeEntry();
          zipentry = zipinputstream.getNextEntry();
        }
        zipinputstream.close();
      }
    } catch (Exception e) {
      e.printStackTrace();
      logger.error(e.getMessage(), e);
    }
  }
  public static void initApplicationDirs() throws IOException {
    createTrustStoreFileIfNotExists();
    File appDataRoot = new File(applicationDataDir());
    if (!appDataRoot.exists()) {
      appDataRoot.mkdirs();
    }
    if (!appDataRoot.canWrite()) {
      SEAGridDialogHelper.showExceptionDialogAndWait(
          new Exception("Cannot Write to Application Data Dir"),
          "Cannot Write to Application Data Dir",
          null,
          "Cannot Write to Application Data Dir " + applicationDataDir());
    }

    // Legacy editors use stdout and stderr instead of loggers. This is a workaround to append them
    // to a file
    System.setProperty("app.data.dir", applicationDataDir() + "logs");
    logger = LoggerFactory.getLogger(SEAGridDesktop.class);
    File logParent = new File(applicationDataDir() + "logs");
    if (!logParent.exists()) logParent.mkdirs();
    PrintStream outPs = new PrintStream(applicationDataDir() + "logs/seagrid.std.out");
    PrintStream errPs = new PrintStream(applicationDataDir() + "logs/seagrid.std.err");
    System.setOut(outPs);
    System.setErr(errPs);
    Runtime.getRuntime()
        .addShutdownHook(
            new Thread() {
              public void run() {
                outPs.close();
                errPs.close();
              }
            });

    extractLegacyEditorResources();
  }