Skip to content

Commit

Permalink
Merge pull request jagrosh#825 from MichailiK/fix/path-loading-bug
Browse files Browse the repository at this point in the history
Fix Windows path loading bug
  • Loading branch information
jagrosh authored Sep 18, 2021
2 parents c6e5b8c + ddf95da commit 48263ec
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/jagrosh/jmusicbot/BotConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void load()
if(path.toFile().exists())
{
if(System.getProperty("config.file") == null)
System.setProperty("config.file", System.getProperty("config", "config.txt"));
System.setProperty("config.file", System.getProperty("config", path.toAbsolutePath().toString()));
ConfigFactory.invalidateCaches();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public List<String> getPlaylistNames()
{
if(folderExists())
{
File folder = new File(config.getPlaylistsFolder());
File folder = new File(OtherUtil.getPath(config.getPlaylistsFolder()).toString());
return Arrays.asList(folder.listFiles((pathname) -> pathname.getName().endsWith(".txt")))
.stream().map(f -> f.getName().substring(0,f.getName().length()-4)).collect(Collectors.toList());
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/jagrosh/jmusicbot/utils/OtherUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,17 @@ public class OtherUtil
*/
public static Path getPath(String path)
{
Path result = Paths.get(path);
// special logic to prevent trying to access system32
if(path.toLowerCase().startsWith(WINDOWS_INVALID_PATH))
if(result.toAbsolutePath().toString().toLowerCase().startsWith(WINDOWS_INVALID_PATH))
{
String filename = path.substring(WINDOWS_INVALID_PATH.length());
try
{
path = new File(JMusicBot.class.getProtectionDomain().getCodeSource().getLocation().toURI()).getParentFile().getPath() + File.separator + filename;
result = Paths.get(new File(JMusicBot.class.getProtectionDomain().getCodeSource().getLocation().toURI()).getParentFile().getPath() + File.separator + path);
}
catch(URISyntaxException ex) {}
}
return Paths.get(path);
return result;
}

/**
Expand Down

0 comments on commit 48263ec

Please sign in to comment.