diff --git a/src/main/java/net/knarcraft/minecraftserverlauncher/userinterface/BackupGUI.java b/src/main/java/net/knarcraft/minecraftserverlauncher/userinterface/BackupGUI.java index 4357647..e325836 100644 --- a/src/main/java/net/knarcraft/minecraftserverlauncher/userinterface/BackupGUI.java +++ b/src/main/java/net/knarcraft/minecraftserverlauncher/userinterface/BackupGUI.java @@ -75,19 +75,19 @@ public class BackupGUI implements ActionListener { * Destroys the backup GUI */ public static void destroy() { - BackupUtil.abortBackup(); - progressTextArea = null; - progressBar = null; - cancelButton = null; if (frame != null) { frame.dispose(); + frame = null; + progressBar = null; + progressTextArea = null; + cancelButton = null; } - frame = null; } @Override public void actionPerformed(ActionEvent actionEvent) { if (actionEvent.getSource() == cancelButton) { + BackupUtil.abortBackup(); destroy(); } } diff --git a/src/main/java/net/knarcraft/minecraftserverlauncher/utility/BackupUtil.java b/src/main/java/net/knarcraft/minecraftserverlauncher/utility/BackupUtil.java index ed6df5d..cfd5e0c 100644 --- a/src/main/java/net/knarcraft/minecraftserverlauncher/utility/BackupUtil.java +++ b/src/main/java/net/knarcraft/minecraftserverlauncher/utility/BackupUtil.java @@ -36,18 +36,21 @@ public class BackupUtil { /** * Recursively copies a folder to another location * - * @param source
The folder to copy
- * @param destinationTarget destination
+ * @param sourceThe folder to copy
+ * @param destinationTarget destination
+ * @param backupFileSizeThe total file size of the backup in progress
+ * @param alreadyCopiedThe amount of bytes already copied
* @throws IOExceptionIf we can't start a file stream
*/ - private static synchronized long backupFolder(File source, File destination, long backupFileSize, long alreadyCopied) throws IOException { + private static synchronized long backupFolder(File source, File destination, long backupFileSize, + long alreadyCopied) throws IOException { if (backupAborted) { return 0L; } if (!source.isDirectory()) { long copiedFileSize = copyFile(source, destination); BackupGUI.updateProgress("Copying " + source + "\n to " + destination, - (int)((alreadyCopied + copiedFileSize) * 100 / backupFileSize)); + (int) ((alreadyCopied + copiedFileSize) * 100 / backupFileSize)); return copiedFileSize; } else { if (!destination.exists() && !destination.mkdir()) { @@ -62,7 +65,7 @@ public class BackupUtil { copiedFilesSize += backupFolder(srcFile, destinationFile, backupFileSize, alreadyCopied + copiedFilesSize); BackupGUI.updateProgress("Copying " + source + "\n to " + destination, - (int)((alreadyCopied + copiedFilesSize) * 100 / backupFileSize)); + (int) ((alreadyCopied + copiedFilesSize) * 100 / backupFileSize)); } } return copiedFilesSize; @@ -72,8 +75,8 @@ public class BackupUtil { /** * Copies a file from one location to another * - * @param sourceThe file to copy
- * @param destinationThe location of the copied file
+ * @param sourceThe file to copy
+ * @param destinationThe location of the copied file
* @throws IOExceptionIf reading or writing fails
*/ private static long copyFile(File source, File destination) throws IOException { @@ -91,6 +94,8 @@ public class BackupUtil { /** * Copies all server directories to a folder specified by the user + * + * @param guiThe GUI to use for informing the user
*/ public synchronized static void backup(GUI gui) { backupAborted = false; @@ -116,46 +121,70 @@ public class BackupUtil { gui.setStatus("Backing up " + (backupFileSize / 1000000) + "MB"); + performBackup(gui, serverFolders, backupFileSize); + } + + /** + * Performs the actual backup after checks have passed and necessary info is available + * @param guiThe GUI to use for informing the user
+ * @param serverFoldersThe folders of the servers to backup
+ * @param backupFileSizeThe total size of the folders to backup
+ */ + private static void performBackup(GUI gui, ListThe GUI to use for informing the user
+ * @param serverFolderThe server's input and output folders
+ * @param backupFileSizeThe total size of the files to backup
+ * @param alreadyCopiedThe amount of bytes already copied
+ * @returnThe new amount of bytes copied
+ */ + private static long backupServerFiles(GUI gui, ListThe GUI to write any errors to
+ * @param guiThe GUI to write any errors to
* @param serverFoldersThe folder to find the size of
* @returnThe size of the given folders
*/ @@ -208,6 +237,7 @@ public class BackupUtil { /** * Gets the size of a file given its path + * * @param pathThe path to a file
* @returnThe size of the file in bytes, or 0 if an exception is thrown
*/