/**
* Per prima cosa riordino in base alla priorita.
*/
Collections.sort(data_table, table_comparator);
Task task = new Task<Void>() {
@Override
protected Void call() throws Exception {
String message = "";
backup_running = true;
try {
List<File> fileList = Collections.synchronizedList(new ArrayList<>());
long millis = System.currentTimeMillis();
int prec = 0;
int total = data_table.size();
for (int i = 0; i < total; i++) {
//----------------------------------------------------//
EncryptedNode node = data_table.get(i).getNode();
String source_path = node.getProperties().get("source");
String dest_path = node.getProperties().get("destination");
String action = node.getProperties().get("action");
//----------------------------------------------------//
File file_source = new File(source_path);
File file_dest = new File(dest_path);
if (!file_source.exists()) {
ini.store("last_result_bck", "Error - " + UtilityFX.data());
message = "Can't find souce path: " + file_source + "\n";
showMessage(message);
return null;
}
if (!file_dest.exists()) {
ini.store("last_result_bck", "Error - " + UtilityFX.data());
message = message + "Can't find dest. path: " + file_dest;
showMessage(message);
return null;
}
}
for (int i = 0; i < total; i++) {
//----------------------------------------------------//
EncryptedNode node = data_table.get(i).getNode();
String source_path = node.getProperties().get("source");
String dest_path = node.getProperties().get("destination");
String action = node.getProperties().get("action");
//----------------------------------------------------//
File file_source = new File(source_path);
File file_dest = new File(dest_path);
boolean exits_all = true;
if (!file_source.exists()) {
ini.store("last_result_bck", "Error - " + UtilityFX.data());
message = "Can't find souce path: " + file_source + "\n";
exits_all = false;
}
if (!file_dest.exists()) {
ini.store("last_result_bck", "Error - " + UtilityFX.data());
message = message + "Can't find dest. path: " + file_dest;
exits_all = false;
}
if (exits_all) {
//------------------------------------------------//
//------------------------------------------------//
//------------------------------------------------//
node.getProperties().put("status", "Running");
updateTable();
fileList.clear();
if (!fileList.isEmpty()) {
UtilityFX.log("ERROR CAN'T CLEAR FILE LIST!");
showMessage("Application Error, can't clear file list.");
return null;
}
//------------------------------------------------//
//------------------------------------------------//
//------------------------------------------------//
/**
* Da ricordare che: 1) NIO nella copia dei file mi
* da' dei problemi su alcuni attributi per win7,
* quindi in caso di errore faccio la copia
* "normale" 2) Lo Zip mi dava problemi con le
* cartelle vuote quindi le creo io con il path
* "cartella/"
*/
switch (action) {
case ACTION_ZIP: {
visitor.setAction("Analyse");
UtilityFX.listFiles(file_source, fileList, visitor);
File result = new File(file_dest + File.separator + file_source.getName() + ".zip");
visitor.setAction("Processing");
UtilityFX.createZipFile(result, file_source, fileList, visitor);
break;
}
case ACTION_COPY: {
if (file_source.isFile()) {
visitor.setAction("Processing");
UtilityFX.copyFile(file_source.toString(), file_dest + File.separator + file_source.getName(), visitor);
} else {
visitor.setAction("Processing");
UtilityFX.copyRecursively(file_source.toString(), file_dest + File.separator + file_source.getName(), visitor);
}
break;
}
}
node.getProperties().put("status", "Done");
updateTable();
} else {
showMessage(message);
return null;
}
prec += (i + 1 * 100) / total;
updateProgress(prec, 100);
setPercentValue(prec);
}
String __val_total_time = String.format("%d hour, %d min, %d sec",
TimeUnit.MILLISECONDS.toHours(System.currentTimeMillis() - millis),
TimeUnit.MILLISECONDS.toMinutes(System.currentTimeMillis() - millis),
TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - millis)
- TimeUnit.MINUTES.toSeconds(
TimeUnit.MILLISECONDS.toMinutes(System.currentTimeMillis() - millis)));
setCenterMessage("Backup completed. Time Total: " + __val_total_time);
ini.store("last_result_bck", "OK - " + UtilityFX.data());
} catch (Exception exc) {
UtilityFX.exc(exc);
exc.printStackTrace();
message = exc.getMessage();
showMessage(message);
ini.store("last_result_bck", "Error - " + UtilityFX.data());
} finally {
Thread.currentThread().sleep(5000);
setLastResult();
}
return null;
}
@Override
protected void succeeded() {
backup_running = false;
setAllStatusValue("");
setPercentValue(0);
endProg();
__btn_bck_add.setDisable(false);
__btn_bck_remove.setDisable(false);
__btn_bck_remove_all.setDisable(false);
__btn_bck_start_backup.setDisable(false);
super.succeeded();
}
};
prog_bk_total.progressProperty().unbind();
prog_bk_total.progressProperty().bind(task.progressProperty());
__btn_bck_add.setDisable(true);
__btn_bck_remove.setDisable(true);
__btn_bck_remove_all.setDisable(true);
__btn_bck_start_backup.setDisable(true);