diff --git a/src/main/java/Bootstrapper.java b/src/main/java/Bootstrapper.java index 28a4375..5c166a1 100644 --- a/src/main/java/Bootstrapper.java +++ b/src/main/java/Bootstrapper.java @@ -1,9 +1,18 @@ import net.horizoncode.sysbackup.cli.CLIProcessor; +import java.io.File; +import java.net.URISyntaxException; + public class Bootstrapper { - public static void main(String[] args) { + public static void main(String[] args) throws URISyntaxException { + + File executionPath = + new File( + new File(Bootstrapper.class.getProtectionDomain().getCodeSource().getLocation().toURI()) + .getParent()); + CLIProcessor cliProcessor = new CLIProcessor(); - cliProcessor.startCLI(args); + cliProcessor.startCLI(args, executionPath); } } diff --git a/src/main/java/net/horizoncode/sysbackup/cli/CLIProcessor.java b/src/main/java/net/horizoncode/sysbackup/cli/CLIProcessor.java index 5b3ff6b..6204e1f 100644 --- a/src/main/java/net/horizoncode/sysbackup/cli/CLIProcessor.java +++ b/src/main/java/net/horizoncode/sysbackup/cli/CLIProcessor.java @@ -30,7 +30,7 @@ public class CLIProcessor { } } - public void startCLI(String[] args) { + public void startCLI(String[] args, File executionPath) { try { if ((args == null) || (args.length == 0)) { usage(); @@ -46,7 +46,7 @@ public class CLIProcessor { return; } String fileName = args[1]; - File tasksFolder = new File("tasks"); + File tasksFolder = new File(executionPath, "tasks"); if (!tasksFolder.exists()) if (!tasksFolder.mkdir()) System.err.println("Failed to create tasks folder!"); File taskFile = new File(tasksFolder, fileName + ".toml"); @@ -56,7 +56,8 @@ public class CLIProcessor { } Config taskConfig = new Config(taskFile); - TaskBuilder taskBuilder = TaskBuilder.builder().taskConfig(taskConfig).build(); + TaskBuilder taskBuilder = + TaskBuilder.builder().executionPath(executionPath).taskConfig(taskConfig).build(); taskBuilder.start(); break; } @@ -67,7 +68,7 @@ public class CLIProcessor { return; } String fileName = args[1]; - File tasksFolder = new File("tasks"); + File tasksFolder = new File(executionPath, "tasks"); if (!tasksFolder.exists()) if (!tasksFolder.mkdir()) System.err.println("Failed to create tasks folder!"); System.out.println("Saving task config " + fileName + ".toml..."); @@ -84,7 +85,7 @@ public class CLIProcessor { return; } String fileName = args[1]; - File tasksFolder = new File("tasks"); + File tasksFolder = new File(executionPath, "tasks"); if (!tasksFolder.exists()) if (!tasksFolder.mkdir()) System.err.println("Failed to create tasks folder!"); File taskFile = new File(tasksFolder, fileName + ".toml"); diff --git a/src/main/java/net/horizoncode/sysbackup/tasks/TaskBuilder.java b/src/main/java/net/horizoncode/sysbackup/tasks/TaskBuilder.java index fb7d157..7fc036c 100644 --- a/src/main/java/net/horizoncode/sysbackup/tasks/TaskBuilder.java +++ b/src/main/java/net/horizoncode/sysbackup/tasks/TaskBuilder.java @@ -9,7 +9,6 @@ import org.apache.commons.io.FilenameUtils; import org.tomlj.TomlArray; import java.io.File; -import java.nio.charset.StandardCharsets; import java.text.SimpleDateFormat; import java.util.Date; import java.util.concurrent.LinkedBlockingQueue; @@ -23,9 +22,11 @@ public class TaskBuilder { @Builder.Default private final LinkedBlockingQueue taskList = new LinkedBlockingQueue<>(); + private final File executionPath; + public void start() { - File backupDir = new File("backups"); + File backupDir = new File(executionPath, "backups"); if (!backupDir.exists()) if (!backupDir.mkdir()) { System.err.println("Failed to create backups directory!"); diff --git a/src/main/java/net/horizoncode/sysbackup/tasks/impl/DatabaseTask.java b/src/main/java/net/horizoncode/sysbackup/tasks/impl/DatabaseTask.java index f5a9ac4..24b6bd7 100644 --- a/src/main/java/net/horizoncode/sysbackup/tasks/impl/DatabaseTask.java +++ b/src/main/java/net/horizoncode/sysbackup/tasks/impl/DatabaseTask.java @@ -8,12 +8,9 @@ import me.tongfei.progressbar.ProgressBarStyle; import net.horizoncode.sysbackup.tasks.Task; import net.lingala.zip4j.ZipFile; import net.lingala.zip4j.progress.ProgressMonitor; -import org.apache.commons.io.FileUtils; -import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.RandomStringUtils; import java.io.*; -import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.util.stream.Collectors; @@ -96,7 +93,8 @@ public class DatabaseTask extends Task { new ProgressBarBuilder() .setStyle(ProgressBarStyle.ASCII) .setInitialMax(progressMonitor.getTotalWork()) - .setTaskName("Adding DB File..."); + .setTaskName("Adding DB File...") + .setUnit("MiB", 1048576); try (ProgressBar pb = pbb.build()) { while (!progressMonitor.getState().equals(ProgressMonitor.State.READY)) { diff --git a/src/main/java/net/horizoncode/sysbackup/tasks/impl/FileSystemTask.java b/src/main/java/net/horizoncode/sysbackup/tasks/impl/FileSystemTask.java index c1bad25..0f55145 100644 --- a/src/main/java/net/horizoncode/sysbackup/tasks/impl/FileSystemTask.java +++ b/src/main/java/net/horizoncode/sysbackup/tasks/impl/FileSystemTask.java @@ -3,16 +3,12 @@ package net.horizoncode.sysbackup.tasks.impl; import me.tongfei.progressbar.ProgressBar; import me.tongfei.progressbar.ProgressBarBuilder; import me.tongfei.progressbar.ProgressBarStyle; -import me.tongfei.progressbar.TerminalUtils; import net.horizoncode.sysbackup.tasks.Task; import net.horizoncode.sysbackup.threading.ThreadPool; import net.lingala.zip4j.ZipFile; import net.lingala.zip4j.progress.ProgressMonitor; -import org.jline.terminal.Terminal; -import org.jline.terminal.TerminalBuilder; import java.io.File; -import java.io.IOException; import java.nio.file.Paths; public class FileSystemTask extends Task { @@ -50,7 +46,8 @@ public class FileSystemTask extends Task { new ProgressBarBuilder() .setStyle(ProgressBarStyle.ASCII) .setInitialMax(progressMonitor.getTotalWork()) - .setTaskName("Adding Files..."); + .setTaskName("Adding Files...") + .setUnit("MiB", 1048576); try (ProgressBar pb = pbb.build()) { while (!progressMonitor.getState().equals(ProgressMonitor.State.READY)) {