Merge pull request #1388 from Stirling-Tools/disableConfigUpdater

remove settings files update for now
This commit is contained in:
Anthony Stirling 2024-06-06 20:23:04 +01:00 committed by GitHub
commit 04b0bcde61
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 41 additions and 56 deletions

View file

@ -12,7 +12,7 @@ plugins {
import com.github.jk1.license.render.* import com.github.jk1.license.render.*
group = 'stirling.software' group = 'stirling.software'
version = '0.25.1' version = '0.25.2'
//17 is lowest but we support and recommend 21 //17 is lowest but we support and recommend 21
sourceCompatibility = '17' sourceCompatibility = '17'

View file

@ -1,10 +1,8 @@
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;
@ -47,61 +45,48 @@ public class ConfigInitializer
} }
} }
} else { } else {
// Load the template content from classpath // Path templatePath =
List<String> templateLines; // Paths.get(
try (InputStream in = // getClass()
getClass().getClassLoader().getResourceAsStream("settings.yml.template")) { // .getClassLoader()
if (in == null) { // .getResource("settings.yml.template")
throw new FileNotFoundException( // .toURI());
"Resource file not found: settings.yml.template"); // Path userPath = Paths.get("configs", "settings.yml");
} //
templateLines = new ArrayList<>(); // List<String> templateLines = Files.readAllLines(templatePath);
try (var reader = new InputStreamReader(in)) { // List<String> userLines =
try (var bufferedReader = new BufferedReader(reader)) { // Files.exists(userPath) ? Files.readAllLines(userPath) : new ArrayList<>();
String line; //
while ((line = bufferedReader.readLine()) != null) { // List<String> resultLines = new ArrayList<>();
templateLines.add(line); // int position = 0;
} // for (String templateLine : templateLines) {
} // // Check if the line is a comment
} // if (templateLine.trim().startsWith("#")) {
} // String entry = templateLine.trim().substring(1).trim();
// if (!entry.isEmpty()) {
// Read the user settings file if it exists // // Check if this comment has been uncommented in userLines
Path userPath = Paths.get("configs", "settings.yml"); // String key = entry.split(":")[0].trim();
List<String> userLines = // addLine(resultLines, userLines, templateLine, key, position);
Files.exists(userPath) ? Files.readAllLines(userPath) : new ArrayList<>(); // } else {
// resultLines.add(templateLine);
List<String> resultLines = new ArrayList<>(); // }
int position = 0; // }
for (String templateLine : templateLines) { // // Check if the line is a key-value pair
// Check if the line is a comment // else if (templateLine.contains(":")) {
if (templateLine.trim().startsWith("#")) { // String key = templateLine.split(":")[0].trim();
String entry = templateLine.trim().substring(1).trim(); // addLine(resultLines, userLines, templateLine, key, position);
if (!entry.isEmpty()) { // }
// Check if this comment has been uncommented in userLines // // Handle empty lines
String key = entry.split(":")[0].trim(); // else if (templateLine.trim().length() == 0) {
addLine(resultLines, userLines, templateLine, key, position); // resultLines.add("");
} else { // }
resultLines.add(templateLine); // position++;
} // }
} //
// Check if the line is a key-value pair // // Write the result to the user settings file
else if (templateLine.contains(":")) { // Files.write(userPath, resultLines);
String key = templateLine.split(":")[0].trim();
addLine(resultLines, userLines, templateLine, key, position);
}
// Handle empty lines
else if (templateLine.trim().length() == 0) {
resultLines.add("");
}
position++;
}
// Write the result to the user settings file
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);