diff --git a/src/Data/Json/AbstractJsonFile.cs b/src/Data/Json/AbstractJsonFile.cs index 3021772..70802ab 100644 --- a/src/Data/Json/AbstractJsonFile.cs +++ b/src/Data/Json/AbstractJsonFile.cs @@ -35,7 +35,7 @@ internal abstract class AbstractJsonFile if (_hasInit) return; _hasInit = true; - if (!CheckFile()) + if (!IsFileValid()) { Save(); return; @@ -106,15 +106,6 @@ internal abstract class AbstractJsonFile } } - /// - /// Reads the content from the JSON file. - /// - /// The content of the JSON file. - protected virtual string ReadFromFile() - { - return File.ReadAllText(FilePath); - } - /// /// Saves the current instance's data to the JSON file. /// @@ -136,19 +127,10 @@ internal abstract class AbstractJsonFile } /// - /// Writes the JSON string to the file. + /// Determines whether the file specified by the current FilePath exists and contains valid, non-empty JSON content. /// - /// The JSON string to write. - protected virtual void WriteToFile(string json) - { - File.WriteAllText(FilePath, json); - } - - /// - /// Checks if the JSON file exists and contains valid data. - /// - /// True if the file exists and contains valid JSON data, false otherwise. - private bool CheckFile() + /// true if the file exists, is not empty, and contains valid, non-empty JSON content; otherwise, false. + private bool IsFileValid() { var directory = Path.GetDirectoryName(FilePath); if (!string.IsNullOrEmpty(directory) && !Directory.Exists(directory)) @@ -163,26 +145,23 @@ internal abstract class AbstractJsonFile var content = TryReadFromFile(); if (string.IsNullOrEmpty(content.Trim())) return false; - var jsonElement = JsonSerializer.Deserialize(content); - - var fileInfo = new FileInfo(FilePath); - if (fileInfo.Length == 0) - { - return false; - } try { + var jsonElement = JsonSerializer.Deserialize(content); + + var fileInfo = new FileInfo(FilePath); + if (fileInfo.Length == 0) + { + return false; + } + if (jsonElement.ValueKind == JsonValueKind.Object && !jsonElement.EnumerateObject().Any() || jsonElement.ValueKind == JsonValueKind.Array && !jsonElement.EnumerateArray().Any()) { return false; } } - catch (JsonException) - { - return false; - } catch (Exception) { return false; @@ -190,4 +169,22 @@ internal abstract class AbstractJsonFile return true; } + + /// + /// Reads the content from the JSON file. + /// + /// The content of the JSON file. + protected virtual string ReadFromFile() + { + return File.ReadAllText(FilePath); + } + + /// + /// Writes the JSON string to the file. + /// + /// The JSON string to write. + protected virtual void WriteToFile(string json) + { + File.WriteAllText(FilePath, json); + } } \ No newline at end of file diff --git a/src/ModInfo.cs b/src/ModInfo.cs index 68837ef..02d94e6 100644 --- a/src/ModInfo.cs +++ b/src/ModInfo.cs @@ -31,7 +31,7 @@ internal static class ModInfo /// /// The hotfix number for hotfix releases. /// - internal const string HOTFIX_NUM = "2"; + internal const string HOTFIX_NUM = "3"; /// /// Indicates whether this is a hotfix release.