Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes issue with file exporting in Windows system. #2256

Merged
merged 1 commit into from
Jan 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading