From a29ddd46746d7dd95d764990ef06e9a1f148b7f7 Mon Sep 17 00:00:00 2001 From: scgm0 <2682963017@qq.com> Date: Thu, 12 Sep 2024 07:12:01 +0800 Subject: [PATCH] C#: Clear existing data directory extracted from PCK --- modules/mono/godotsharp_dirs.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/modules/mono/godotsharp_dirs.cpp b/modules/mono/godotsharp_dirs.cpp index 3935854a293..039263b405d 100644 --- a/modules/mono/godotsharp_dirs.cpp +++ b/modules/mono/godotsharp_dirs.cpp @@ -192,8 +192,14 @@ private: } } if (!has_data) { - // 3. Extract the data to a temporary location to load from there. - Ref da = DirAccess::create_for_path(packed_path); + // 3. Extract the data to a temporary location to load from there, delete old data if it exists but is not up-to-date. + Ref da; + if (DirAccess::exists(data_dir_root)) { + da = DirAccess::open(data_dir_root); + ERR_FAIL_COND(da.is_null()); + ERR_FAIL_COND(da->erase_contents_recursive() != OK); + } + da = DirAccess::create_for_path(packed_path); ERR_FAIL_COND(da.is_null()); ERR_FAIL_COND(da->copy_dir(packed_path, data_dir_root) != OK); }