1
0
mirror of https://github.com/Stirling-Tools/Stirling-PDF.git synced 2024-09-21 04:10:38 +02:00

Merge pull request #1352 from Ludy87/fix_admin_exe_windows

Fix: Initialization Issue and Enhance Configuration Management for Co…
This commit is contained in:
Anthony Stirling 2024-06-01 09:41:54 +01:00 committed by GitHub
commit aa42806a9e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,8 +1,10 @@
package stirling.software.SPDF.config;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
@ -45,15 +47,27 @@ public class ConfigInitializer
}
}
} else {
Path templatePath =
Paths.get(
getClass()
.getClassLoader()
.getResource("settings.yml.template")
.toURI());
Path userPath = Paths.get("configs", "settings.yml");
// Load the template content from classpath
List<String> templateLines;
try (InputStream in =
getClass().getClassLoader().getResourceAsStream("settings.yml.template")) {
if (in == null) {
throw new FileNotFoundException(
"Resource file not found: settings.yml.template");
}
templateLines = new ArrayList<>();
try (var reader = new InputStreamReader(in)) {
try (var bufferedReader = new BufferedReader(reader)) {
String line;
while ((line = bufferedReader.readLine()) != null) {
templateLines.add(line);
}
}
}
}
List<String> templateLines = Files.readAllLines(templatePath);
// Read the user settings file if it exists
Path userPath = Paths.get("configs", "settings.yml");
List<String> userLines =
Files.exists(userPath) ? Files.readAllLines(userPath) : new ArrayList<>();
@ -87,6 +101,7 @@ public class ConfigInitializer
Files.write(userPath, resultLines);
}
// Ensure the custom settings file exists
Path customSettingsPath = Paths.get("configs", "custom_settings.yml");
if (!Files.exists(customSettingsPath)) {
Files.createFile(customSettingsPath);