Skip to content

Commit

Permalink
fixed NPE validating user-specified VLC path
Browse files Browse the repository at this point in the history
  • Loading branch information
SrRapero720 committed Nov 20, 2024
1 parent fddc30d commit a74c95d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/watermedia/WaterMedia.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void start() throws Exception {
public static ILoader getLoader() { return bootstrap; }

public static Path getConfigDir() {
return bootstrap.processDir().resolve("config/watermedia/");
return bootstrap.processDir().resolve("config/watermedia");
}

public static void setSlavismMode(boolean mode) {
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/org/watermedia/api/player/PlayerAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,15 @@ public Priority priority() {

@Override
public boolean supported() {
// first we check
if (content == null)
content = IOTool.readString(customPathFile);

// then we reinforce
if (content == null)
return false;

// now we validate
File f = new File(content);
return f.exists() && f.isDirectory();
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/watermedia/core/tools/IOTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public static String readString(Path from) {
byte[] bytes = DataTool.readAllBytes(in);
return new String(bytes, StandardCharsets.UTF_8);
} catch (Exception e) {
LOGGER.error(IT, "Failed to read text file", e);
return null;
}
}
Expand All @@ -40,7 +41,7 @@ public static GifDecoder readGif(Path path) {

throw new IOException("Failed to process GIF - Decoder status: " + status);
} catch (Exception e) {
LOGGER.error(IT, "Failed loading GIF from WaterMedia resources", e);
LOGGER.error(IT, "Failed reading GIF from disk", e);
}
return null;
}
Expand All @@ -54,6 +55,7 @@ public static boolean writeData(Path to, byte[] data) {
os.write(data);
return true;
} catch (Exception e) {
LOGGER.error(IT, "Failed to write text file from disk", e);
return false;
}
}
Expand Down

0 comments on commit a74c95d

Please sign in to comment.