mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-11-17 21:07:40 -05:00
fix(io): save nests safely and reopen them with their cut-off settings
Reopening a nest regenerated its cut-offs with built-in defaults (no overtravel, a different minimum segment) rather than the machine's settings it was made with, so a nest saved, reopened and posted could cut scrap that never separates. Plates now record the settings their cut-offs were last generated with, and files carry them; older files still load with the defaults. Saving over a nest file truncated it before writing, so any failure part way lost the only good copy, and the error reached the user as an unhandled exception after the save path had already changed. Nest and settings files are now written beside the target and swapped in, and a failed save is reported with the old file left intact. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e8c52a354d
commit
d29f919aa2
11 files changed
+227
-13
No files matched your search
@@ -6,8 +6,9 @@ namespace OpenNest.Data;
|
||||
internal static class SettingsFile
|
||||
{
|
||||
/// <summary>
|
||||
/// Writes the file, creating the parent directory, and retries briefly on IO collisions.
|
||||
/// The last failure propagates; the host handles a persistent write failure.
|
||||
/// Writes the file through a temporary file swapped into place, so a failed write keeps
|
||||
/// the previous settings, creating the parent directory and retrying briefly on IO
|
||||
/// collisions. The last failure propagates; the host handles a persistent write failure.
|
||||
/// </summary>
|
||||
public static void Write(string path, string json, int maxRetries = 3)
|
||||
{
|
||||
@@ -19,7 +20,9 @@ internal static class SettingsFile
|
||||
{
|
||||
if (!string.IsNullOrEmpty(directory))
|
||||
Directory.CreateDirectory(directory);
|
||||
File.WriteAllText(path, json);
|
||||
var temp = path + ".tmp";
|
||||
File.WriteAllText(temp, json);
|
||||
File.Move(temp, path, overwrite: true);
|
||||
return;
|
||||
}
|
||||
catch (IOException) when (attempt < maxRetries - 1)
|
||||
|
||||
Reference in new issue
Block a user