mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-11-03 14:41:37 -05:00
Ahead of the new laser schedule, three ways a post could silently cut with the wrong process, and one way its settings silently reset: - Cincinnati CL wrote no G89 when no cut library matched the nest's material, thickness and gas (or no etch library for etch features), so the controller cut with whatever library it loaded last. It now refuses, unless the new "Require libraries" setting is turned off. - Cincinnati CL declared G20/G21 from its own setting without comparing the nest's units, so a metric nest posted 25.4x too large. It now refuses a mismatch. - CI Fiber posted any material missing from its table as the default code (MSN), so stainless or aluminum ran with mild-steel technology. A named, unmapped material is now refused; the default code covers only nests with no material. - Posts saved their settings beside their DLL, inside the install folder a Velopack update replaces, so every update reset them to the shipped defaults. Saves now go to %APPDATA%\OpenNest\Posts and the shipped JSON only seeds them; constructing a post no longer writes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
49 lines
2.0 KiB
C#
49 lines
2.0 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Reflection;
|
|
|
|
namespace OpenNest
|
|
{
|
|
/// <summary>
|
|
/// Where a post keeps its own settings: %APPDATA%\OpenNest\Posts\<post assembly>.json.
|
|
/// The install folder holds only the shipped defaults, because an update replaces it and
|
|
/// would silently reset every edit saved there. The shipped JSON is read until the first save.
|
|
/// </summary>
|
|
public static class PostSettingsFile
|
|
{
|
|
/// <summary>Replaces <see cref="Directory"/>, so test runs never read or write the user's settings.</summary>
|
|
public static string DirectoryOverride { get; set; }
|
|
|
|
public static string Directory => DirectoryOverride ?? Path.Combine(
|
|
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "OpenNest", "Posts");
|
|
|
|
public static string PathFor(Assembly post) =>
|
|
Path.Combine(Directory, Path.GetFileNameWithoutExtension(post.Location) + ".json");
|
|
|
|
/// <summary>The defaults deployed beside the post's assembly.</summary>
|
|
public static string ShippedPathFor(Assembly post) => Path.ChangeExtension(post.Location, ".json");
|
|
|
|
/// <summary>The saved settings, else the shipped defaults, else null.</summary>
|
|
public static string Read(Assembly post)
|
|
{
|
|
var saved = PathFor(post);
|
|
if (File.Exists(saved))
|
|
return File.ReadAllText(saved);
|
|
var shipped = ShippedPathFor(post);
|
|
return File.Exists(shipped) ? File.ReadAllText(shipped) : null;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Saves through a temporary file, so a failed write leaves the previous settings intact.
|
|
/// </summary>
|
|
public static void Write(Assembly post, string json)
|
|
{
|
|
var path = PathFor(post);
|
|
System.IO.Directory.CreateDirectory(Path.GetDirectoryName(path));
|
|
var temp = path + ".tmp";
|
|
File.WriteAllText(temp, json);
|
|
File.Move(temp, path, overwrite: true);
|
|
}
|
|
}
|
|
}
|