mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-21 05:50:18 +08:00
Fixed ResourceSvc file write if no directory exists
This commit is contained in:
parent
b7c84980e3
commit
6470832ef6
@ -35,6 +35,7 @@ import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.OpenOption;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.util.*;
|
||||
import java.util.function.Supplier;
|
||||
@ -171,7 +172,9 @@ public class ResourceSvc implements ResourceService {
|
||||
WebResource original = source.get();
|
||||
byte[] bytes = original.asBytes();
|
||||
OpenOption[] overwrite = {StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE};
|
||||
Files.write(files.getCustomizationDirectory().resolve(fileName), bytes, overwrite);
|
||||
Path to = files.getCustomizationDirectory().resolve(fileName);
|
||||
Files.createDirectories(to.getParent());
|
||||
Files.write(to, bytes, overwrite);
|
||||
return original;
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,7 @@ import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.util.Collections;
|
||||
|
||||
public class ResourceSettings {
|
||||
|
||||
@ -33,13 +34,17 @@ public class ResourceSettings {
|
||||
|
||||
public boolean shouldBeCustomized(String plugin, String fileName) {
|
||||
ConfigNode fileCustomization = config.getNode("Customized_files").orElseGet(() -> config.addNode("Customized_files"));
|
||||
fileCustomization.setComment(Collections.singletonList("The files are placed in /Plan/web/ if the setting is 'true' when accessed."));
|
||||
|
||||
ConfigNode pluginCustomization = fileCustomization.getNode(plugin).orElseGet(() -> fileCustomization.addNode(plugin));
|
||||
String fileNameNonPath = StringUtils.replaceChars(fileName, '.', ',');
|
||||
|
||||
if (pluginCustomization.contains(fileNameNonPath)) {
|
||||
return pluginCustomization.getBoolean(fileNameNonPath);
|
||||
} else {
|
||||
pluginCustomization.set(fileNameNonPath, false);
|
||||
try {
|
||||
pluginCustomization.sort();
|
||||
pluginCustomization.save();
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException("Could not save config.yml: " + e.getMessage(), e);
|
||||
|
Loading…
Reference in New Issue
Block a user