Skip to content

Commit

Permalink
Fixes issue with file exporting in Windows system. (#2256)
Browse files Browse the repository at this point in the history
JAR files does not store files inside it with filesystem separator. Only spot where it makes sense to transform "/" into file separator is in output file saving.
  • Loading branch information
BONNe authored Jan 4, 2024
1 parent bfb4873 commit 38d845d
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/main/java/world/bentobox/bentobox/api/addons/Addon.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.logging.Logger;
import java.util.regex.Matcher;

import org.bukkit.Bukkit;
import org.bukkit.Server;
Expand Down Expand Up @@ -263,7 +264,7 @@ public File saveResource(String jarResource, File destinationFolder, boolean rep
throw new IllegalArgumentException("ResourcePath cannot be null or empty");
}

jarResource = jarResource.replace("\\", File.separator).replace("/", File.separator);
jarResource = jarResource.replace('\\', '/');
try (JarFile jar = new JarFile(file)) {
JarEntry jarConfig = jar.getJarEntry(jarResource);
if (jarConfig != null) {
Expand All @@ -273,7 +274,9 @@ public File saveResource(String jarResource, File destinationFolder, boolean rep
"The embedded resource '" + jarResource + "' cannot be found in " + jar.getName());
}
// There are two options, use the path of the resource or not
File outFile = new File(destinationFolder, jarResource);
File outFile = new File(destinationFolder,
jarResource.replaceAll("/", Matcher.quoteReplacement(File.separator)));

if (noPath) {
outFile = new File(destinationFolder, outFile.getName());
}
Expand Down Expand Up @@ -308,7 +311,7 @@ public YamlConfiguration getYamlFromJar(String jarResource) throws IOException,
throw new IllegalArgumentException("jarResource cannot be null or empty");
}
YamlConfiguration result = new YamlConfiguration();
jarResource = jarResource.replace("\\", File.separator).replace("/", File.separator);
jarResource = jarResource.replace('\\', '/');
try (JarFile jar = new JarFile(file)) {
JarEntry jarConfig = jar.getJarEntry(jarResource);
if (jarConfig != null) {
Expand All @@ -330,7 +333,7 @@ public InputStream getResource(String jarResource) {
throw new IllegalArgumentException("ResourcePath cannot be null or empty");
}

jarResource = jarResource.replace("\\", File.separator).replace("/", File.separator);
jarResource = jarResource.replace('\\', '/');
try (JarFile jar = new JarFile(file)) {
JarEntry jarConfig = jar.getJarEntry(jarResource);
if (jarConfig != null) {
Expand Down

0 comments on commit 38d845d

Please sign in to comment.