From 766a73f2a91992396abcaca68bf10a5fa7031531 Mon Sep 17 00:00:00 2001 From: GeWuYou <95328647+GeWuYou@users.noreply.github.com> Date: Mon, 19 Jan 2026 20:12:20 +0800 Subject: [PATCH] =?UTF-8?q?feat(storage):=20=E5=AE=9E=E7=8E=B0=20Godot=20?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=AD=98=E5=82=A8=E5=88=A0=E9=99=A4=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加 Godot 命名空间引用 - 实现 Delete 方法的具体逻辑 - 支持 Godot 路径和普通文件路径的删除操作 - 添加文件存在性检查避免删除不存在的文件 - 实现线程安全的锁机制防止并发冲突 - 添加删除完成后的锁清理防止内存泄漏 - 提供详细的错误处理和异常抛出机制 --- GFramework.Godot/storage/GodotFileStorage.cs | 27 +++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/GFramework.Godot/storage/GodotFileStorage.cs b/GFramework.Godot/storage/GodotFileStorage.cs index 6f8cde3..324f590 100644 --- a/GFramework.Godot/storage/GodotFileStorage.cs +++ b/GFramework.Godot/storage/GodotFileStorage.cs @@ -3,6 +3,7 @@ using System.Text; using GFramework.Core.Abstractions.storage; using GFramework.Game.Abstractions.serializer; using GFramework.Godot.extensions; +using Godot; using FileAccess = Godot.FileAccess; namespace GFramework.Godot.storage; @@ -37,7 +38,31 @@ public sealed class GodotFileStorage : IStorage /// 存储键 public void Delete(string key) { - throw new NotImplementedException(); + var path = ToAbsolutePath(key); + var keyLock = GetLock(path); + + lock (keyLock) + { + if (path.IsGodotPath()) + { + if (FileAccess.FileExists(path)) + { + var err = DirAccess.RemoveAbsolute(path); + if (err != Error.Ok) + throw new IOException($"Failed to delete Godot file: {path}, error: {err}"); + } + } + else + { + if (File.Exists(path)) + { + File.Delete(path); + } + } + } + + // 删除完成后尝试移除锁,防止锁字典无限增长 + _keyLocks.TryRemove(path, out _); } #endregion