Skip to content

Commit

Permalink
Merge pull request #56 from DazedNConfused-/develop
Browse files Browse the repository at this point in the history
build: prepare for v0.3.0 release [macata #2]
  • Loading branch information
DazedNConfused- authored Aug 9, 2024
2 parents e9d1732 + f2c35cf commit 5cd9211
Show file tree
Hide file tree
Showing 109 changed files with 6,991 additions and 159 deletions.
2 changes: 1 addition & 1 deletion .java-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
11.0.16
11.0.24
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,13 @@ While not mandatory, if commits are not properly formatted, they may get rejecte
- This shared data directory is located at `/<macata_launcher_folder>/userdir`
- [x] Soundpack management
- [x] Launcher autoupdater
- [x] Mod management

### Planned

- [ ] Mod support (soon)
- [ ] Tileset support (soon)
- [ ] Automatic CDDA binary updates & backups
- [ ] Bright Nights support

### Maybes

Expand Down
55 changes: 53 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.dazednconfused</groupId>
<artifactId>macatalauncher</artifactId>
<version>0.2.2</version>
<version>0.3.0</version>

<properties>
<maven.compiler.source>11</maven.compiler.source>
Expand All @@ -25,6 +25,15 @@
</activation>

<build>
<testResources>
<testResource>
<directory>${project.basedir}/src/test/resources</directory>
</testResource>
<testResource>
<directory>${project.basedir}/src/main/resources</directory>
</testResource>
</testResources>

<plugins>

<plugin>
Expand All @@ -36,7 +45,7 @@
<excludes></excludes>
<reportFormat>plain</reportFormat>
<reuseForks>true</reuseForks>
<forkCount>1C</forkCount>
<forkCount>4C</forkCount>
<forkedProcessExitTimeoutInSeconds>3000</forkedProcessExitTimeoutInSeconds>
<forkedProcessTimeoutInSeconds>0</forkedProcessTimeoutInSeconds>
<parallel>all</parallel>
Expand Down Expand Up @@ -71,6 +80,23 @@
<configuration>
<source>11</source>
<target>11</target>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.34</version>
</path>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>1.5.5.Final</version>
</path>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-mapstruct-binding</artifactId>
<version>0.2.0</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>

Expand Down Expand Up @@ -257,6 +283,31 @@
<version>2.14.2</version>
</dependency>

<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>2.2.224</version>
</dependency>

<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>1.5.5.Final</version>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.34</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-mapstruct-binding</artifactId>
<version>0.2.0</version>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,10 @@ public static void main(final String[] args) {
MainWindow.main(args);
}

/**
* Returns the folder where the current instance of the {@link Application} is running.
* */
public static String getRootFolder() {
return System.getProperty("user.dir");
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package com.dazednconfused.catalauncher.backup;

import static com.dazednconfused.catalauncher.helper.Constants.CUSTOM_SAVE_PATH;
import static com.dazednconfused.catalauncher.helper.Constants.CUSTOM_TRASHED_SAVE_PATH;
import static com.dazednconfused.catalauncher.helper.Constants.LAUNCHER_ROOT_FOLDER;
import static com.dazednconfused.catalauncher.helper.Constants.SAVE_BACKUP_PATH;

import com.dazednconfused.catalauncher.helper.Paths;
import com.dazednconfused.catalauncher.helper.Zipper;
import com.dazednconfused.catalauncher.helper.result.Result;

import io.vavr.control.Try;
Expand All @@ -29,8 +26,8 @@ public class SaveManager {
private static final Logger LOGGER = LoggerFactory.getLogger(SaveManager.class);

/**
* Returns the current {@link com.dazednconfused.catalauncher.helper.Constants#CUSTOM_SAVE_PATH} compression job, wrapped
* inside a {@link Thread} and ready to be executed.
* Returns the current {@link Paths#getCustomSavePath()} compression job, wrapped inside a {@link Thread} and ready to
* be executed.
* */
public static Optional<Thread> backupCurrentSaves(Consumer<Integer> onPercentDoneCallback) {
LOGGER.info("Backup-ing all saves...");
Expand All @@ -40,7 +37,7 @@ public static Optional<Thread> backupCurrentSaves(Consumer<Integer> onPercentDon
return Optional.empty();
}

File savesFolder = new File(CUSTOM_SAVE_PATH);
File savesFolder = new File(Paths.getCustomSavePath());
return Optional.of(compressFolderAsJob(
savesFolder,
getSaveBackupFolder().getAbsolutePath() + "/" + generateNameBasedOnCurrentTimestamp() + ".zip",
Expand All @@ -54,19 +51,19 @@ public static Optional<Thread> backupCurrentSaves(Consumer<Integer> onPercentDon
public static Optional<Thread> restoreBackup(File backup2beRestored, Consumer<Integer> onPercentDoneCallback) {
LOGGER.info("Restoring backup [{}]...", backup2beRestored);

File trashedSaves = new File(CUSTOM_TRASHED_SAVE_PATH);
File trashedSaves = new File(Paths.getCustomTrashedSavePath());

if (!trashedSaves.exists()) {
LOGGER.debug("Trashed saves' folder [{}] doesn't exist. Generating...", trashedSaves);
Try.of(trashedSaves::mkdirs).onFailure(t -> LOGGER.error("There was an error while creating trashed saves' folder [{}]", trashedSaves, t));
}

File trashedSavePath = new File(CUSTOM_TRASHED_SAVE_PATH + generateNameBasedOnCurrentTimestamp());
File trashedSavePath = new File(Paths.getCustomTrashedSavePath() + generateNameBasedOnCurrentTimestamp());

if (!saveFilesExist()) {
LOGGER.info("No current saves found. Nothing to move to trash folder.");
} else {
File currentSave = new File(CUSTOM_SAVE_PATH);
File currentSave = new File(Paths.getCustomSavePath());

Try.of(() -> Files.move(
currentSave.toPath(),
Expand All @@ -76,7 +73,7 @@ public static Optional<Thread> restoreBackup(File backup2beRestored, Consumer<In

return Optional.of(decompressFolderAsJob(
backup2beRestored,
LAUNCHER_ROOT_FOLDER, // we don't decompress into CUSTOM_SAVE_PATH because we end up with ./saves/saves/<actual world saves>
Paths.getLauncherRootFolder(), // we don't decompress into CUSTOM_SAVE_PATH because we end up with ./saves/saves/<actual world saves>
onPercentDoneCallback
));
}
Expand Down Expand Up @@ -105,7 +102,7 @@ public static Result<Throwable, File> renameBackup(File toBeRenamed, String newN
}

/**
* Returns all save backups currently found in {@link com.dazednconfused.catalauncher.helper.Constants#SAVE_BACKUP_PATH}.
* Returns all save backups currently found in {@link Paths#getSaveBackupPath()}.
* */
public static List<File> listAllBackups() {
LOGGER.debug("Listing all backups...");
Expand All @@ -115,11 +112,11 @@ public static List<File> listAllBackups() {
}

/**
* If save files exist in {@link com.dazednconfused.catalauncher.helper.Constants#CUSTOM_SAVE_PATH}, returns the last
* modified valid save file. Save file is valid if it has a .sav file in it.
* If save files exist in {@link Paths#getCustomSavePath()}, returns the last modified valid save file. Save file is valid
* if it has a .sav file in it.
* */
public static Optional<File> getLastModifiedValidSave() {
File savesFolder = new File(CUSTOM_SAVE_PATH);
File savesFolder = new File(Paths.getCustomSavePath());
if (!saveFilesExist()) {
return Optional.empty();
}
Expand All @@ -137,18 +134,17 @@ public static Optional<File> getLastModifiedValidSave() {

}
/**
* Determines whether save files exist in {@link com.dazednconfused.catalauncher.helper.Constants#CUSTOM_SAVE_PATH}.
* Determines whether save files exist in {@link Paths#getCustomSavePath()}.
* */

public static boolean saveFilesExist() {
File savesFolder = new File(CUSTOM_SAVE_PATH);
File savesFolder = new File(Paths.getCustomSavePath());
return savesFolder.exists() && Arrays.stream(Objects.requireNonNull(savesFolder.listFiles())).anyMatch(file -> !file.getName().equals(".DS_Store"));
}

/**
* Gets the latest save {@link File} from {@link com.dazednconfused.catalauncher.helper.Constants#CUSTOM_SAVE_PATH}, wrapped
* inside an {@link Optional}. {@link Optional#empty()} if given path doesn't exist or doesn't have any folders that could
* be assumed to be individual save files.
* Gets the latest save {@link File} from {@link Paths#getCustomSavePath()}, wrapped inside an {@link Optional}. {@link Optional#empty()}
* if given path doesn't exist or doesn't have any folders that could be assumed to be individual save files.
* */
public static Optional<File> getLatestSave() {

Expand All @@ -160,10 +156,10 @@ public static Optional<File> getLatestSave() {
}

/**
* Retrieves the {@link com.dazednconfused.catalauncher.helper.Constants#SAVE_BACKUP_PATH} as a {@link File}.
* Retrieves the {@link Paths#getSaveBackupPath()} as a {@link File}.
* */
private static File getSaveBackupFolder() {
File backupPath = new File(SAVE_BACKUP_PATH);
File backupPath = new File(Paths.getSaveBackupPath());
if (!backupPath.exists()) {
LOGGER.debug("Save backup destination folder [{}] not found. Creating...", backupPath);
Try.of(backupPath::mkdirs).onFailure(t -> LOGGER.error("Could not create backup destination folder [{}]", backupPath, t));
Expand All @@ -176,14 +172,14 @@ private static File getSaveBackupFolder() {
* Returns the requested compression job wrapped inside a {@link Thread} and ready to be executed.
* */
private static Thread compressFolderAsJob(File sourceDir, String outputFile, Consumer<Integer> onPercentDoneCallback) {
return new Thread(() -> Zipper.compressAndCallback(sourceDir, outputFile, onPercentDoneCallback, 100));
return new Thread(() -> Zipper.compressAndCallback(sourceDir, Path.of(outputFile), onPercentDoneCallback, 100));
}

/**
* Returns the requested decompression job wrapped inside a {@link Thread} and ready to be executed.
* */
private static Thread decompressFolderAsJob(File sourceFile, String destinationPath, Consumer<Integer> onPercentDoneCallback) {
return new Thread(() -> Zipper.decompressAndCallback(sourceFile, destinationPath, onPercentDoneCallback, 100));
return new Thread(() -> Zipper.decompressAndCallback(sourceFile, Path.of(destinationPath), onPercentDoneCallback, 100));
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.dazednconfused.catalauncher.configuration;

import static com.dazednconfused.catalauncher.helper.Constants.LAUNCHER_FILES;

import com.dazednconfused.catalauncher.helper.Paths;
import com.fasterxml.jackson.databind.ObjectMapper;

import io.vavr.control.Try;
Expand All @@ -20,7 +19,7 @@ public class ConfigurationManager {

private static final Logger LOGGER = LoggerFactory.getLogger(ConfigurationManager.class);

private static final String CONFIG_FILEPATH = LAUNCHER_FILES + "/configuration.json";
private static final String CONFIG_FILEPATH = Paths.getLauncherFiles() + "/configuration.json";

private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();

Expand Down
Loading

0 comments on commit 5cd9211

Please sign in to comment.