Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Inno Setup: Compile Script",
"type": "process",
"command": "ISCC.exe",
"args": [
"${file}"
],
"presentation": {
"reveal": "always",
"echo": false
},
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
4 changes: 2 additions & 2 deletions BackupManager_convert_to_exe_launch4j.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
<maxVersion></maxVersion>
</jre>
<versionInfo>
<fileVersion>2.1.0.0</fileVersion>
<fileVersion>2.2.1.0</fileVersion>
<txtFileVersion>2.0.RC1</txtFileVersion>
<fileDescription>Backup management and automation utility</fileDescription>
<copyright>Copyright © 2024 Shard</copyright>
<productVersion>2.1.0.0</productVersion>
<productVersion>2.2.1.0</productVersion>
<txtProductVersion>2.0.RC1</txtProductVersion>
<productName>Backup Manager</productName>
<companyName>Shard</companyName>
Expand Down
4 changes: 2 additions & 2 deletions BackupManager_installer_inno_setup.iss
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

[Setup]
AppName=BackupManager
AppVersion=2.1.0
AppVersion=2.2.1
AppPublisher=Shard
AppPublisherURL=https://www.shardpc.it/
DefaultDirName={userdocs}\Shard\BackupManager
DisableDirPage=yes
DisableProgramGroupPage=no
PrivilegesRequired=lowest
OutputBaseFilename=BackupManager_v2.1.0_Setup
OutputBaseFilename=BackupManager_v2.2.1_Setup
SetupIconFile=src\main\resources\res\img\logo.ico
SetupLogging=yes
Compression=lzma
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Each backup is carefully saved, and the program maintains a detailed log of all

## Code Ducumentation

$\rightarrow$ [Code tecnical documentation](./docs/code_documentation.md)
$\rightarrow$ [Code tecnical documentation](./code_documentation.md)

## Important Notes

Expand Down
3 changes: 1 addition & 2 deletions src/main/java/backupmanager/BackupOperations.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import backupmanager.Entities.ConfigurationBackup;
import backupmanager.Entities.TimeInterval;
import backupmanager.Entities.ZippingContext;
import backupmanager.Enums.BackupStatus;
import backupmanager.Enums.BackupTriggerType;
import backupmanager.Enums.ErrorType;
import backupmanager.Enums.TranslationLoaderEnum.TranslationCategory;
Expand Down Expand Up @@ -283,7 +282,7 @@ public static void deletePotentiallyIncompletedBackupsFromLastExecution() {
for (BackupRequest request : requests) {
boolean deleted = deletePartialBackup(request.outputPath());
if (deleted) {
BackupRequestRepository.updateRequestStatusByRequestId(request.backupRequestId(), BackupStatus.TERMINATED);
BackupHelper.forceBackupTermination(request.backupRequestId());
}
}
}
Expand Down
191 changes: 191 additions & 0 deletions src/main/java/backupmanager/Controllers/BackupEntryController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
package backupmanager.Controllers;

import java.time.LocalDateTime;

import javax.swing.JOptionPane;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import backupmanager.BackupOperations;
import backupmanager.Entities.ConfigurationBackup;
import backupmanager.Entities.TimeInterval;
import backupmanager.Entities.ZippingContext;
import backupmanager.Enums.BackupTriggerType;
import backupmanager.Enums.TranslationLoaderEnum.TranslationCategory;
import backupmanager.Enums.TranslationLoaderEnum.TranslationKey;
import backupmanager.Exceptions.BackupAlreadyRunningException;
import backupmanager.Exceptions.InvalidTimeInterval;
import backupmanager.GUI.BackupManagerGUI;
import backupmanager.GUI.BackupProgressGUI;
import backupmanager.Helpers.BackupHelper;
import backupmanager.Table.BackupTable;
import backupmanager.database.Repositories.BackupRequestRepository;

public class BackupEntryController {
private static final Logger logger = LoggerFactory.getLogger(BackupEntryController.class);

private ConfigurationBackup currentBackup;

public BackupEntryController(ConfigurationBackup currentBackup) {
this.currentBackup = currentBackup;
}

public ConfigurationBackup getBackup(String name, String initialPath, String destinationPath, String notes, boolean autoBackup, int maxBackupsToKeep) {
LocalDateTime nextDateBackup = null;
TimeInterval timeInterval = currentBackup != null ? currentBackup.getTimeIntervalBackup() : null;
if (timeInterval != null){
nextDateBackup = BackupHelper.getNexDateBackup(timeInterval);
}

if (!autoBackup) {
timeInterval = null;
nextDateBackup = null;
}

if (currentBackup == null) {
LocalDateTime lastBackup = null;
LocalDateTime creationDate = LocalDateTime.now();
LocalDateTime lastUpdateDate = creationDate;
int backupCount = 0;
return new ConfigurationBackup(name, initialPath, destinationPath, lastBackup, autoBackup, nextDateBackup, timeInterval, notes, creationDate, lastUpdateDate, backupCount, maxBackupsToKeep);
} else {
int id = currentBackup.getId();
LocalDateTime lastBackup = currentBackup.getLastBackupDate();
LocalDateTime creationDate = currentBackup.getCreationDate();
LocalDateTime lastUpdateDate = LocalDateTime.now();
int backupCount = currentBackup.getCount();
return new ConfigurationBackup(id, name, initialPath, destinationPath, lastBackup, autoBackup, nextDateBackup, timeInterval, notes, creationDate, lastUpdateDate, backupCount, maxBackupsToKeep);
}
}

public TimeInterval handleTimePickerAction(javax.swing.JDialog dialog, String target, String destination) throws InvalidTimeInterval {
TimeInterval time = BackupHelper.openTimePicker(dialog, currentBackup.getTimeIntervalBackup());
if (time == null) throw new InvalidTimeInterval();

LocalDateTime nextDateBackup = BackupHelper.getNexDateBackup(time);

currentBackup.setTimeIntervalBackup(time);
currentBackup.setNextBackupDate(nextDateBackup);
currentBackup.setTargetPath(target);
currentBackup.setDestinationPath(destination);

return time;
}

public boolean canDisposeAfterOk(String name, String initialPath, String destinationPath, String notes, boolean autoBackup, int maxBackupsToKeep, boolean create) {
if (name.isBlank() || destinationPath.isBlank() || initialPath.isBlank())
return false;

currentBackup = getBackup(name, initialPath, destinationPath, notes, autoBackup, maxBackupsToKeep);

if (create) {
if (ConfigurationBackup.getBackupByName(currentBackup.getName()) != null) {
int response = JOptionPane.showConfirmDialog(null, TranslationCategory.DIALOGS.getTranslation(TranslationKey.DUPLICATED_BACKUP_NAME_MESSAGE), TranslationCategory.DIALOGS.getTranslation(TranslationKey.CONFIRMATION_REQUIRED_TITLE), JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
if (response == JOptionPane.YES_OPTION) {
BackupHelper.removeBackup(currentBackup.getName());
} else {
return false;
}
}
BackupHelper.newBackup(currentBackup);
} else {
BackupHelper.updateBackup(currentBackup);
}

return true;
}

public boolean toggleAutomaticBackup(String name, String initialPath, String destinationPath, String notes, boolean autoBackup, int maxBackupsToKeep) {
currentBackup = getBackup(name, initialPath, destinationPath, notes, autoBackup, maxBackupsToKeep);
currentBackup.setAutomatic(!currentBackup.isAutomatic());

ConfigurationBackup backup = BackupHelper.toggleAutomaticBackup(currentBackup);

if (backup == null)
return false;

currentBackup = backup;

if (backup.getTimeIntervalBackup() != null) {
TimeInterval timeInterval = backup.getTimeIntervalBackup();
currentBackup.setNextBackupDate(BackupHelper.getNexDateBackup(timeInterval));
return true;
}

return false;
}

public void handleSingleBackupRequest(BackupTable backupTable, String name, String initialPath, String destinationPath, String notes, boolean autoBackup, int maxBackupsToKeep) throws BackupAlreadyRunningException {
if (BackupRequestRepository.isAnyBackupRunning()) {
JOptionPane.showMessageDialog(null, TranslationCategory.DIALOGS.getTranslation(TranslationKey.WARNING_BACKUP_ALREADY_IN_PROGRESS_MESSAGE), TranslationCategory.DIALOGS.getTranslation(TranslationKey.WARNING_GENERIC_TITLE), JOptionPane.WARNING_MESSAGE);
throw new BackupAlreadyRunningException();
}

// update currentBackup
if (currentBackup == null) {
currentBackup = getBackup(name, initialPath, destinationPath, notes, autoBackup, maxBackupsToKeep);
}

singleBackup(initialPath, destinationPath, backupTable);
}

private void singleBackup(String target, String destination, BackupTable backupTable) {
logger.info("Event --> single backup");

String path1 = target;
String path2 = destination;

currentBackup.setTargetPath(path2);

String temp = "\\";

if (!BackupOperations.checkInputCorrect(currentBackup.getName(), path1, path2, null)) return;

LocalDateTime dateNow = LocalDateTime.now();

String name1; // folder name/initial file
String date = dateNow.format(BackupHelper.dateForfolderNameFormatter);

//------------------------------SET ALL THE STRINGS------------------------------
name1 = path1.substring(path1.length()-1, path1.length()-1);

for(int i=path1.length()-1; i>=0; i--) {
if(path1.charAt(i) != temp.charAt(0)) name1 = path1.charAt(i) + name1;
else break;
}

name1 = BackupOperations.removeExtension(name1);
path2 = path2 + "\\" + name1 + " (Backup " + date + ")";

//------------------------------COPY THE FILE OR DIRECTORY------------------------------
logger.info("date backup: " + date);

BackupManagerGUI.progressBar = new BackupProgressGUI(path1, path2);
BackupManagerGUI.progressBar.setVisible(true);

ZippingContext context = ZippingContext.create(currentBackup, null, backupTable, BackupManagerGUI.progressBar, null, null);

BackupOperations.executeBackup(context, BackupTriggerType.USER, path1, path2);

//if current_file_opened is null it means they are not in a backup but it is a backup not registered
if (currentBackup.getName() != null && !currentBackup.getName().isEmpty()) {
currentBackup.setTargetPath(target);
currentBackup.setDestinationPath(destination);
currentBackup.setLastBackupDate(LocalDateTime.now());
}
}

public void handleOpenBackupActivationMessage(TimeInterval newtimeInterval, String target, String destination) {
currentBackup.setTimeIntervalBackup(newtimeInterval);
BackupHelper.showMessageActivationAutoBackup(newtimeInterval, target, destination);
}

public ConfigurationBackup getCurrentBackup() {
return currentBackup;
}

public void setCurrentBackup(ConfigurationBackup currentBackup) {
this.currentBackup = currentBackup;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package backupmanager.Controllers;

import backupmanager.Services.ZippingThread;

public class BackupProgressController {
public void cancelBackup() {
ZippingThread.stopExecutorService(1);
}
}
13 changes: 13 additions & 0 deletions src/main/java/backupmanager/Controllers/GuiController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package backupmanager.Controllers;

import java.awt.Image;

import javax.swing.ImageIcon;

import backupmanager.Enums.ConfigKey;

public class GuiController {
public static Image getIcon(Class<?> obj) {
return new ImageIcon(obj.getResource(ConfigKey.LOGO_IMG.getValue())).getImage();
}
}
27 changes: 27 additions & 0 deletions src/main/java/backupmanager/Controllers/PreferenceController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package backupmanager.Controllers;

import java.io.IOException;
import java.util.Arrays;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import backupmanager.GUI.BackupManagerGUI;
import backupmanager.Managers.ExceptionManager;
import backupmanager.Services.PreferenceService;

public record PreferenceController (PreferenceService service, BackupManagerGUI mainGui) {
private static final Logger logger = LoggerFactory.getLogger(PreferenceController.class);

public void applyPreferences(String language, String theme) {
logger.info("Updating preferences -> Language: {}; Theme: ()", language, theme);

try {
service.updatePreferences(language, theme);
mainGui.reloadPreferences();
} catch (IOException ex) {
logger.error("An error occurred during applying preferences: " + ex.getMessage(), ex);
ExceptionManager.openExceptionMessage(ex.getMessage(), Arrays.toString(ex.getStackTrace()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public class TrayController {
private final Runnable onOpen;
private final Runnable onExit;


public TrayController(Runnable onOpen, Runnable onExit) {
this.onOpen = onOpen;
this.onExit = onExit;
Expand Down
Loading