From c91efe009577ba07f41cb5b3136d4e17d711fafd Mon Sep 17 00:00:00 2001 From: kuwacom Date: Sun, 8 Mar 2026 10:31:00 +0900 Subject: [PATCH] update: changed file read/write operations to use `FileUtils`. - As a side effect, saving has become faster! --- Minecraft.Server/ServerProperties.cpp | 53 ++++++++++++++++++++------- 1 file changed, 39 insertions(+), 14 deletions(-) diff --git a/Minecraft.Server/ServerProperties.cpp b/Minecraft.Server/ServerProperties.cpp index 74858cae3..b06fb4531 100644 --- a/Minecraft.Server/ServerProperties.cpp +++ b/Minecraft.Server/ServerProperties.cpp @@ -4,9 +4,9 @@ #include "ServerLogger.h" #include "Common\\StringUtils.h" +#include "Common\\FileUtils.h" #include -#include #include #include #include @@ -16,6 +16,7 @@ namespace ServerRuntime { using StringUtils::ToLowerAscii; using StringUtils::TrimAscii; +using StringUtils::StripUtf8Bom; using StringUtils::Utf8ToWide; using StringUtils::WideToUtf8; @@ -288,29 +289,48 @@ static bool ReadServerPropertiesFile(const char *filePath, std::unordered_map &properties) { - FILE *outFile = fopen(filePath, "wb"); - if (outFile == NULL) + if (filePath == NULL) { return false; } - fprintf(outFile, "# Minecraft server properties\n"); - fprintf(outFile, "# Auto-generated and normalized when missing\n"); + std::string text; + text += "# Minecraft server properties\n"; + text += "# Auto-generated and normalized when missing\n"; std::map sortedProperties(properties.begin(), properties.end()); for (std::map::const_iterator it = sortedProperties.begin(); it != sortedProperties.end(); ++it) { - fprintf(outFile, "%s=%s\n", it->first.c_str(), it->second.c_str()); + text += it->first; + text += "="; + text += it->second; + text += "\n"; } - fclose(outFile); - return true; + return FileUtils::WriteTextFileAtomic(filePath, text); } static bool ReadNormalizedBoolProperty(