Skip to content

Commit e86e5c8

Browse files
Merge pull request #78 from DazedNConfused-/develop
build: prepare for v0.3.2 release [macata #76]
2 parents 72d6972 + f26c056 commit e86e5c8

File tree

338 files changed

+2358
-15
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

338 files changed

+2358
-15
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.dazednconfused</groupId>
88
<artifactId>macatalauncher</artifactId>
9-
<version>0.3.1</version>
9+
<version>0.3.2</version>
1010

1111
<properties>
1212
<maven.compiler.source>11</maven.compiler.source>

src/main/java/com/dazednconfused/catalauncher/backup/SaveManager.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,12 @@ public static Optional<Thread> restoreBackup(File backup2beRestored, Consumer<In
5858
Try.of(trashedSaves::mkdirs).onFailure(t -> LOGGER.error("There was an error while creating trashed saves' folder [{}]", trashedSaves, t));
5959
}
6060

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

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

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

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

114115
/**
115116
* If save files exist in {@link Paths#getCustomSavePath()}, returns the last modified valid save file. Save file is valid
116-
* if it has a .sav file in it.
117+
* if it has a {@code .sav} file in it.
117118
* */
118-
public static Optional<File> getLastModifiedValidSave() {
119+
private static Optional<File> getLastModifiedValidSave() {
119120
File savesFolder = new File(Paths.getCustomSavePath());
120121
if (!saveFilesExist()) {
121122
return Optional.empty();
@@ -133,10 +134,10 @@ public static Optional<File> getLastModifiedValidSave() {
133134
return Optional.empty(); // No directory with .sav file found
134135

135136
}
137+
136138
/**
137139
* Determines whether save files exist in {@link Paths#getCustomSavePath()}.
138140
* */
139-
140141
public static boolean saveFilesExist() {
141142
File savesFolder = new File(Paths.getCustomSavePath());
142143
return savesFolder.exists() && Arrays.stream(Objects.requireNonNull(savesFolder.listFiles())).anyMatch(file -> !file.getName().equals(".DS_Store"));

src/main/java/com/dazednconfused/catalauncher/database/h2/migration/MigrateableH2Database.java

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@
99
import java.io.IOException;
1010
import java.io.InputStream;
1111
import java.io.InputStreamReader;
12+
import java.net.URI;
13+
import java.net.URISyntaxException;
14+
import java.net.URL;
15+
import java.nio.file.FileSystem;
16+
import java.nio.file.FileSystems;
17+
import java.nio.file.Files;
18+
import java.nio.file.Path;
1219
import java.nio.file.Paths;
1320
import java.sql.Connection;
1421
import java.sql.PreparedStatement;
@@ -24,6 +31,7 @@
2431
import java.util.regex.Matcher;
2532
import java.util.regex.Pattern;
2633
import java.util.stream.Collectors;
34+
import java.util.stream.Stream;
2735

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

279-
try (InputStream in = this.getResourceAsStream(this.getDatabaseMigrationsResourcePath()); BufferedReader br = new BufferedReader(new InputStreamReader(in))) {
280-
String resource;
288+
try {
289+
String resourcePath = this.getDatabaseMigrationsResourcePath();
290+
URL resourceUrl = this.getResource(resourcePath);
291+
292+
if (resourceUrl == null) {
293+
throw new IllegalArgumentException("Resource not found: " + resourcePath);
294+
}
281295

282-
while ((resource = br.readLine()) != null) {
283-
filenames.add(resource);
296+
URI uri = resourceUrl.toURI();
297+
Path myPath;
298+
299+
if ("jar".equals(uri.getScheme())) {
300+
LOGGER.trace("URI [{}] is inside a .jar file. Walking the file tree though appropriate FileSystem provider...", uri);
301+
try (FileSystem fs = FileSystems.newFileSystem(uri, Collections.emptyMap())) {
302+
myPath = fs.getPath(resourcePath);
303+
try (Stream<Path> walk = Files.walk(myPath, 1)) {
304+
walk.filter(Files::isRegularFile).forEach(path -> filenames.add(path.getFileName().toString()));
305+
}
306+
}
307+
} else {
308+
LOGGER.trace("URI [{}] is not inside a .jar file. Walking the file tree through normal means...", uri);
309+
myPath = Paths.get(uri);
310+
try (Stream<Path> walk = Files.walk(myPath, 1)) {
311+
walk.filter(Files::isRegularFile).forEach(path -> filenames.add(path.getFileName().toString()));
312+
}
284313
}
285-
} catch (IOException e) {
286-
LOGGER.error("There was an error while reading resource files from path [{}]", getDatabaseMigrationsResourcePath());
314+
} catch (IOException | URISyntaxException e) {
315+
LOGGER.error("There was an error while reading resource files from path [{}]", this.getDatabaseMigrationsResourcePath());
287316
return Result.failure(e);
288317
}
289318

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

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

352+
/**
353+
* Returns the {@link URL} corresponding to the given {@code resource} from the classpath.
354+
*/
355+
private URL getResource(String resource) {
356+
URL in = Thread.currentThread().getContextClassLoader().getResource(resource);
357+
return in == null ? H2Database.class.getResource(resource) : in;
358+
}
359+
318360
/**
319361
* Parses the provided {@code date} in {@code yyyyMMdd} format.
320362
*/

src/main/java/com/dazednconfused/catalauncher/gui/MainWindow.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ public void keyPressed(KeyEvent e) {
170170

171171
saveBackupsTable.requestFocusInWindow();
172172
soundpacksTable.requestFocusInWindow();
173+
modsTable.requestFocusInWindow();
173174
}
174175
}
175176
});
@@ -767,7 +768,7 @@ public void mouseReleased(MouseEvent e) { // mouseReleased event needed for othe
767768
return () -> {
768769
LOGGER.trace("Refreshing mod-management GUI elements...");
769770

770-
// SET SOUNDPACKS TABLE ---
771+
// SET MODS TABLE ---
771772
this.refreshModsTable();
772773

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

866867
/**
867868
* Refreshes all GUI elements according to diverse app statuses.
869+
*
870+
* @implNote Refresh is done in the background by means of individual {@link Thread}s.
868871
*/
869872
private void refreshGuiElements() {
870873
for (Runnable guiRefreshRunnable : this.guiRefreshingRunnables) {

0 commit comments

Comments
 (0)