Files
Shigure/Infrastructure/AtomicFile.cs
waynebian01 1b78ca9c61 feat: Implement module dependency management and unsaved changes tracking
- Added `HasUnsavedChanges` property to `ClassConfigEditorControl` and `ClassMacrosEditorControl` to track unsaved changes.
- Introduced `ModuleDependencyService` for handling module dependencies, including capturing and importing configurations and macros.
- Implemented atomic file writing in `AtomicFile` to ensure safe file operations.
- Enhanced `MainForm` to check for unsaved changes before importing module dependencies and added feedback mechanisms for users.
- Updated `ModuleEditorControl` to support dependency capturing and module reloading.
- Created data structures for module dependency snapshots, configurations, and macros.
- Improved error handling and user notifications during module import processes.
2026-08-14 17:36:45 +08:00

27 lines
771 B
C#

using System.Text;
namespace Shigure;
internal static class AtomicFile
{
public static void WriteAllText(string path, string contents, Encoding encoding)
{
var directory = Path.GetDirectoryName(Path.GetFullPath(path))
?? throw new InvalidOperationException($"无法确定文件目录: {path}");
Directory.CreateDirectory(directory);
var tempPath = Path.Combine(directory, $".{Path.GetFileName(path)}.{Guid.NewGuid():N}.tmp");
try
{
File.WriteAllText(tempPath, contents, encoding);
File.Move(tempPath, path, overwrite: true);
}
finally
{
if (File.Exists(tempPath))
{
File.Delete(tempPath);
}
}
}
}