mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-12-01 12:11:34 -05:00
refactor: share duplicated fill, cache, settings and toggle code
- fill_plate and fill_area share one MCP fill helper - FillLinear uses FillHelpers.HasOverlappingParts - BestFitCache and FillResultCache entries derive from DrawingCacheEntry - NestDefaults and ClampSettings read through SettingsFile.TryReadText - MainForm view toggles share one ToggleView handler Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4b61d249c0
commit
d77693aaff
10 files changed
+178
-217
No files matched your search
@@ -1,3 +1,4 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace OpenNest.Data;
|
||||
@@ -51,6 +52,32 @@ internal static class SettingsFile
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the file's text. Returns false when the file is missing (<paramref name="missing"/>
|
||||
/// true) or exists but cannot be read, for example locked or access-denied.
|
||||
/// </summary>
|
||||
public static bool TryReadText(
|
||||
string path,
|
||||
[NotNullWhen(true)] out string? text,
|
||||
out bool missing
|
||||
)
|
||||
{
|
||||
text = null;
|
||||
missing = string.IsNullOrWhiteSpace(path) || !File.Exists(path);
|
||||
if (missing)
|
||||
return false;
|
||||
|
||||
try
|
||||
{
|
||||
text = File.ReadAllText(path);
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex) when (IsUnreadableFile(ex))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool IsUnreadableFile(Exception ex) =>
|
||||
ex
|
||||
is JsonException
|
||||
|
||||
Reference in new issue
Block a user