mirror of
https://github.com/waynebian01/Shigure.git
synced 2026-09-03 07:15:24 +08:00
- 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.
27 lines
771 B
C#
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);
|
|
}
|
|
}
|
|
}
|
|
}
|