Add more logging to copying and deleting files
This commit is contained in:
parent
427b961fb0
commit
3a8f3695f6
1 changed files with 14 additions and 6 deletions
|
|
@ -93,6 +93,7 @@ public class Profiles {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Files.copy(options, profileOptions);
|
Files.copy(options, profileOptions);
|
||||||
|
OptionsProfilesMod.LOGGER.info("[Profile '{}']: Copied file '{}'", profile.getFileName().toString(), options.getFileName().toString());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
OptionsProfilesMod.LOGGER.error("[Profile '{}']: Unable to copy '{}'", profile.getFileName().toString(), options.getFileName().toString(), e);
|
OptionsProfilesMod.LOGGER.error("[Profile '{}']: Unable to copy '{}'", profile.getFileName().toString(), options.getFileName().toString(), e);
|
||||||
}
|
}
|
||||||
|
|
@ -103,14 +104,19 @@ public class Profiles {
|
||||||
Path profile = PROFILES_DIRECTORY.resolve(profileName);
|
Path profile = PROFILES_DIRECTORY.resolve(profileName);
|
||||||
Path profileOptions = profile.resolve("options.txt");
|
Path profileOptions = profile.resolve("options.txt");
|
||||||
|
|
||||||
ProfileConfiguration profileConfiguration = ProfileConfiguration.get(profileName);
|
|
||||||
|
|
||||||
if (overwriting) {
|
if (overwriting) {
|
||||||
try {
|
try (Stream<Path> files = Files.list(profile)) {
|
||||||
// Removes old option files
|
files.filter(file -> !file.getFileName().toString().equals("configuration.json"))
|
||||||
FileUtils.cleanDirectory(profile.toFile());
|
.forEach(file -> {
|
||||||
|
try {
|
||||||
|
Files.delete(file);
|
||||||
|
OptionsProfilesMod.LOGGER.info("[Profile '{}']: Deleted file '{}'", profileName, file.getFileName().toString());
|
||||||
|
} catch (IOException e) {
|
||||||
|
OptionsProfilesMod.LOGGER.error("[Profile '{}']: An error occurred when trying to delete the file '{}'", profileName, file.getFileName().toString(), e);
|
||||||
|
}
|
||||||
|
});
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
OptionsProfilesMod.LOGGER.error("[Profile '{}']: An error occurred when clearing old options files", profileName, e);
|
OptionsProfilesMod.LOGGER.error("[Profile '{}']: An error occurred when deleting old options files.", profileName, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -122,6 +128,8 @@ public class Profiles {
|
||||||
copyOptionFile(profile, DISTANT_HORIZONS_OPTIONS_FILE);
|
copyOptionFile(profile, DISTANT_HORIZONS_OPTIONS_FILE);
|
||||||
|
|
||||||
if (!overwriting) {
|
if (!overwriting) {
|
||||||
|
ProfileConfiguration profileConfiguration = ProfileConfiguration.get(profileName);
|
||||||
|
|
||||||
// Add every option value to configuration
|
// Add every option value to configuration
|
||||||
try (Stream<String> lines = Files.lines(profileOptions)) {
|
try (Stream<String> lines = Files.lines(profileOptions)) {
|
||||||
List<String> optionsToLoad = profileConfiguration.getOptionsToLoad();
|
List<String> optionsToLoad = profileConfiguration.getOptionsToLoad();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue