Merge pull request #1352 from Ludy87/fix_admin_exe_windows
Fix: Initialization Issue and Enhance Configuration Management for Co…
This commit is contained in:
commit
aa42806a9e
1 changed files with 23 additions and 8 deletions
|
@ -1,8 +1,10 @@
|
||||||
package stirling.software.SPDF.config;
|
package stirling.software.SPDF.config;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
@ -45,15 +47,27 @@ public class ConfigInitializer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Path templatePath =
|
// Load the template content from classpath
|
||||||
Paths.get(
|
List<String> templateLines;
|
||||||
getClass()
|
try (InputStream in =
|
||||||
.getClassLoader()
|
getClass().getClassLoader().getResourceAsStream("settings.yml.template")) {
|
||||||
.getResource("settings.yml.template")
|
if (in == null) {
|
||||||
.toURI());
|
throw new FileNotFoundException(
|
||||||
Path userPath = Paths.get("configs", "settings.yml");
|
"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 =
|
List<String> userLines =
|
||||||
Files.exists(userPath) ? Files.readAllLines(userPath) : new ArrayList<>();
|
Files.exists(userPath) ? Files.readAllLines(userPath) : new ArrayList<>();
|
||||||
|
|
||||||
|
@ -87,6 +101,7 @@ public class ConfigInitializer
|
||||||
Files.write(userPath, resultLines);
|
Files.write(userPath, resultLines);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ensure the custom settings file exists
|
||||||
Path customSettingsPath = Paths.get("configs", "custom_settings.yml");
|
Path customSettingsPath = Paths.get("configs", "custom_settings.yml");
|
||||||
if (!Files.exists(customSettingsPath)) {
|
if (!Files.exists(customSettingsPath)) {
|
||||||
Files.createFile(customSettingsPath);
|
Files.createFile(customSettingsPath);
|
||||||
|
|
Loading…
Reference in a new issue