Skip to content

Commit

Permalink
Merge pull request #78 from DazedNConfused-/develop
Browse files Browse the repository at this point in the history
build: prepare for v0.3.2 release [macata #76]
  • Loading branch information
DazedNConfused- authored Aug 22, 2024
2 parents 72d6972 + f26c056 commit e86e5c8
Show file tree
Hide file tree
Showing 338 changed files with 2,358 additions and 15 deletions.
2 changes: 1 addition & 1 deletion 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.3.1</version>
<version>0.3.2</version>

<properties>
<maven.compiler.source>11</maven.compiler.source>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,12 @@ public static Optional<Thread> restoreBackup(File backup2beRestored, Consumer<In
Try.of(trashedSaves::mkdirs).onFailure(t -> LOGGER.error("There was an error while creating trashed saves' folder [{}]", trashedSaves, t));
}

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

if (!saveFilesExist()) {
LOGGER.info("No current saves found. Nothing to move to trash folder.");
} else {
LOGGER.debug("Trashing existent saves into [{}]...", trashedSavePath);
File currentSave = new File(Paths.getCustomSavePath());

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

return Optional.of(decompressFolderAsJob(
backup2beRestored,
Paths.getLauncherRootFolder(), // we don't decompress into CUSTOM_SAVE_PATH because we end up with ./saves/saves/<actual world saves>
Path.of(Paths.getCustomSavePath()).getParent().toString(), // we don't decompress into CUSTOM_SAVE_PATH because we end up with ./saves/saves/<actual world saves>
onPercentDoneCallback
));
}
Expand Down Expand Up @@ -113,9 +114,9 @@ public static List<File> listAllBackups() {

/**
* 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.
* if it has a {@code .sav} file in it.
* */
public static Optional<File> getLastModifiedValidSave() {
private static Optional<File> getLastModifiedValidSave() {
File savesFolder = new File(Paths.getCustomSavePath());
if (!saveFilesExist()) {
return Optional.empty();
Expand All @@ -133,10 +134,10 @@ public static Optional<File> getLastModifiedValidSave() {
return Optional.empty(); // No directory with .sav file found

}

/**
* Determines whether save files exist in {@link Paths#getCustomSavePath()}.
* */

public static boolean saveFilesExist() {
File savesFolder = new File(Paths.getCustomSavePath());
return savesFolder.exists() && Arrays.stream(Objects.requireNonNull(savesFolder.listFiles())).anyMatch(file -> !file.getName().equals(".DS_Store"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.sql.Connection;
import java.sql.PreparedStatement;
Expand All @@ -24,6 +31,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.apache.commons.io.FilenameUtils;
import org.slf4j.Logger;
Expand Down Expand Up @@ -274,16 +282,37 @@ protected List<String> getDatabaseMigrationFilesDatedAfter(Date from) {
* {@code new Date(0)} as argument instead.
*/
protected Result<Throwable, List<String>> getDatabaseMigrationFiles() {
LOGGER.trace("Searching for migration files inside [{}]...", this.getDatabaseMigrationsResourcePath());
List<String> filenames = new ArrayList<>();

try (InputStream in = this.getResourceAsStream(this.getDatabaseMigrationsResourcePath()); BufferedReader br = new BufferedReader(new InputStreamReader(in))) {
String resource;
try {
String resourcePath = this.getDatabaseMigrationsResourcePath();
URL resourceUrl = this.getResource(resourcePath);

if (resourceUrl == null) {
throw new IllegalArgumentException("Resource not found: " + resourcePath);
}

while ((resource = br.readLine()) != null) {
filenames.add(resource);
URI uri = resourceUrl.toURI();
Path myPath;

if ("jar".equals(uri.getScheme())) {
LOGGER.trace("URI [{}] is inside a .jar file. Walking the file tree though appropriate FileSystem provider...", uri);
try (FileSystem fs = FileSystems.newFileSystem(uri, Collections.emptyMap())) {
myPath = fs.getPath(resourcePath);
try (Stream<Path> walk = Files.walk(myPath, 1)) {
walk.filter(Files::isRegularFile).forEach(path -> filenames.add(path.getFileName().toString()));
}
}
} else {
LOGGER.trace("URI [{}] is not inside a .jar file. Walking the file tree through normal means...", uri);
myPath = Paths.get(uri);
try (Stream<Path> walk = Files.walk(myPath, 1)) {
walk.filter(Files::isRegularFile).forEach(path -> filenames.add(path.getFileName().toString()));
}
}
} catch (IOException e) {
LOGGER.error("There was an error while reading resource files from path [{}]", getDatabaseMigrationsResourcePath());
} catch (IOException | URISyntaxException e) {
LOGGER.error("There was an error while reading resource files from path [{}]", this.getDatabaseMigrationsResourcePath());
return Result.failure(e);
}

Expand All @@ -306,15 +335,28 @@ private Optional<Date> getDateFromFilename(String filename) {
}

/**
* Reads a specific {@code resource} from the classpath.
* Returns the {@link InputStream} corresponding to the given {@code resource} from the classpath.
*
* @implNote It's up to this method's callers to properly close the resulting {@link InputStream}.
*
* @apiNote This method is <b>not</b> suitable for performing filesystem operations (like reading a file-tree) when {@code resource}
* is bundled inside a {@code .jar} file. While individual files are perfectly accessible/readable, some other
* operations (like listing files inside a folder) will return empty results <i>without</i> throwing any kind
* of {@link Exception} whatsoever.
*/
private InputStream getResourceAsStream(String resource) {
InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource);
return in == null ? H2Database.class.getResourceAsStream(resource) : in;
}

/**
* Returns the {@link URL} corresponding to the given {@code resource} from the classpath.
*/
private URL getResource(String resource) {
URL in = Thread.currentThread().getContextClassLoader().getResource(resource);
return in == null ? H2Database.class.getResource(resource) : in;
}

/**
* Parses the provided {@code date} in {@code yyyyMMdd} format.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ public void keyPressed(KeyEvent e) {

saveBackupsTable.requestFocusInWindow();
soundpacksTable.requestFocusInWindow();
modsTable.requestFocusInWindow();
}
}
});
Expand Down Expand Up @@ -767,7 +768,7 @@ public void mouseReleased(MouseEvent e) { // mouseReleased event needed for othe
return () -> {
LOGGER.trace("Refreshing mod-management GUI elements...");

// SET SOUNDPACKS TABLE ---
// SET MODS TABLE ---
this.refreshModsTable();

// DETERMINE IF MOD DELETE BUTTON SHOULD BE DISABLED ---
Expand Down Expand Up @@ -865,6 +866,8 @@ private static JMenuBar buildMenuBarFor(Component parent) {

/**
* Refreshes all GUI elements according to diverse app statuses.
*
* @implNote Refresh is done in the background by means of individual {@link Thread}s.
*/
private void refreshGuiElements() {
for (Runnable guiRefreshRunnable : this.guiRefreshingRunnables) {
Expand Down
Loading

0 comments on commit e86e5c8

Please sign in to comment.