Skip to content

Commit ddc3392

Browse files
committed
Read module.json and overwrite
1 parent e7e152f commit ddc3392

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

Milil/Models/Module.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class Module
99
public string Name { get; set; }
1010

1111
[JsonPropertyName("author")]
12-
public string Author { get; set; } = "";
12+
public string Author { get; set; } = "Milil";
1313

1414
[JsonPropertyName("title")]
1515
public string Title { get; set; }

Milil/Program.cs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,19 @@ public static async Task Main()
118118
var flushPackTask = dbFile.FlushAsync().ConfigureAwait(false);
119119

120120
// module.json
121-
var module = new Module
121+
Module module = null;
122+
123+
try
124+
{
125+
await using var moduleFileR = File.Open(MODULE_FILE, FileMode.OpenOrCreate, FileAccess.Read, FileShare.Read);
126+
module = await JsonSerializer.DeserializeAsync<Module>(moduleFileR);
127+
}
128+
catch (JsonException jEx)
129+
{
130+
await Console.Error.WriteLineAsync(jEx.Message);
131+
}
132+
133+
module ??= new Module
122134
{
123135
Name = root.Name,
124136
Title = root.Name,
@@ -134,9 +146,15 @@ public static async Task Main()
134146
}
135147
};
136148

137-
await using var moduleFile = File.Open(MODULE_FILE, FileMode.Create, FileAccess.ReadWrite, FileShare.Read);
138-
await JsonSerializer.SerializeAsync(moduleFile, module, ModuleSerializationRules);
139-
var flushModuleTask = moduleFile.FlushAsync().ConfigureAwait(false);
149+
if (Version.TryParse(module.Version, out var ver))
150+
{
151+
// Formatting, ignore and trim Revision.
152+
module.Version = $"{ver.Major}.{ver.Minor}.{ver.Build + 1}";
153+
}
154+
155+
await using var moduleFileW = File.Open(MODULE_FILE, FileMode.Create, FileAccess.ReadWrite, FileShare.Read);
156+
await JsonSerializer.SerializeAsync(moduleFileW, module, ModuleSerializationRules);
157+
var flushModuleTask = moduleFileW.FlushAsync().ConfigureAwait(false);
140158

141159
await flushPackTask;
142160
await flushModuleTask;

0 commit comments

Comments
 (0)