feat: add embedded CL-980 default config with first-run EnsureDefaults

Embeds CL-980.json as a resource in OpenNest.Data and adds EnsureDefaults()
to LocalJsonProvider, which seeds the machines directory on first run when empty.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-27 20:23:00 -04:00
parent a6e813bc85
commit 7081c7b4d0
4 changed files with 275 additions and 0 deletions
+23
View File
@@ -71,6 +71,29 @@ public class LocalJsonProvider : IDataProvider
}
}
public void EnsureDefaults()
{
if (Directory.GetFiles(_directory, "*.json").Length > 0)
return;
var assembly = typeof(LocalJsonProvider).Assembly;
var resourceName = assembly.GetManifestResourceNames()
.FirstOrDefault(n => n.EndsWith("CL-980.json"));
if (resourceName is null) return;
using var stream = assembly.GetManifestResourceStream(resourceName);
if (stream is null) return;
using var reader = new StreamReader(stream);
var json = reader.ReadToEnd();
var config = JsonSerializer.Deserialize<MachineConfig>(json, JsonOptions);
if (config is null) return;
SaveMachine(config);
}
private static void WriteWithRetry(string path, string json, int maxRetries = 3)
{
for (var attempt = 0; attempt < maxRetries; attempt++)