public static void estimateKeyDerivationTime() {
   // This is run in the background after startup. If we haven't recorded it before, do a key
   // derivation to see
   // how long it takes. This helps us produce better progress feedback, as on Windows we don't
   // currently have a
   // native Scrypt impl and the Java version is ~3 times slower, plus it depends a lot on CPU
   // speed.
   checkGuiThread();
   estimatedKeyDerivationTime = Main.instance.prefs.getExpectedKeyDerivationTime();
   if (estimatedKeyDerivationTime == null) {
     new Thread(
             () -> {
               log.info("Doing background test key derivation");
               KeyCrypterScrypt scrypt = new KeyCrypterScrypt(SCRYPT_PARAMETERS);
               long start = System.currentTimeMillis();
               scrypt.deriveKey("test password");
               long msec = System.currentTimeMillis() - start;
               log.info("Background test key derivation took {}msec", msec);
               Platform.runLater(
                   () -> {
                     estimatedKeyDerivationTime = Duration.ofMillis(msec);
                     Main.instance.prefs.setExpectedKeyDerivationTime(estimatedKeyDerivationTime);
                   });
             })
         .start();
   }
 }
Exemplo n.º 2
0
  /** Met fin au programme et demande à l'utilisateur s'il veut sauvegarder. */
  protected void quitter() {

    if (model.flagModif) {

      Alert alert = new Alert(AlertType.CONFIRMATION);
      alert.setTitle("Sauvegarde du dictionnaire");
      alert.setContentText("Voulez-vous enregistrer les nouvelles modifications au dictionnaire?");
      alert.setHeaderText(null);

      ButtonType yes = new ButtonType("Oui");
      ButtonType no = new ButtonType("Non");

      alert.getButtonTypes().setAll(yes, no);
      Optional<ButtonType> result = alert.showAndWait();

      if (result.get() == yes) {
        try {
          model.sauvegardeFichier();
        } catch (IOException e) {
          e.printStackTrace();
          Alert alertSave = new Alert(AlertType.ERROR);
          alertSave.setTitle("IO Error");
          alertSave.setContentText("Save File error");
          alertSave.showAndWait();
        }
      }
    }
    System.exit(0);
  }
 /**
  * Cancel button click handler.
  *
  * @param event {@link javafx.event.ActionEvent}
  */
 @FXML
 private void cancelButtonClick(ActionEvent event) {
   System.exit(0);
 }