From 0035720a84f20e3541bd6086480bec8b64b3c8a3 Mon Sep 17 00:00:00 2001 From: Gliniak Date: Fri, 15 Jan 2021 09:55:20 +0100 Subject: [PATCH] CloseContent: Close files related to closed content --- src/xenia/kernel/xam/content_manager.cc | 22 ++++++++++++++++++++++ src/xenia/kernel/xam/content_manager.h | 1 + 2 files changed, 23 insertions(+) diff --git a/src/xenia/kernel/xam/content_manager.cc b/src/xenia/kernel/xam/content_manager.cc index 277cf7b80..5c4be7edf 100644 --- a/src/xenia/kernel/xam/content_manager.cc +++ b/src/xenia/kernel/xam/content_manager.cc @@ -17,6 +17,7 @@ #include "xenia/kernel/kernel_state.h" #include "xenia/kernel/user_module.h" #include "xenia/kernel/xam/content_package.h" +#include "xenia/kernel/xfile.h" #include "xenia/kernel/xobject.h" #include "xenia/vfs/devices/host_path_device.h" #include "xenia/vfs/devices/stfs_container_device.h" @@ -231,6 +232,7 @@ X_RESULT ContentManager::CloseContent(const std::string_view root_name) { return X_ERROR_SUCCESS; } } + CloseOpenedFilesFromContent(root_name); return X_ERROR_FILE_NOT_FOUND; } @@ -289,6 +291,26 @@ std::filesystem::path ContentManager::ResolveGameUserContentPath() { return root_path_ / title_id / kGameUserContentDirName / user_name; } +void ContentManager::CloseOpenedFilesFromContent( + const std::string_view root_name) { + const std::vector> all_files_handles = + kernel_state_->object_table()->GetObjectsByType( + XObject::Type::File); + + std::string resolved_path = ""; + kernel_state_->file_system()->FindSymbolicLink(std::string(root_name) + ':', + resolved_path); + + for (const object_ref& file : all_files_handles) { + std::string file_path = file->entry()->absolute_path(); + file_path = file_path.substr(0, file_path.find_last_of('\\') + 1); + + if (file_path == resolved_path) { + file->ReleaseHandle(); + } + } +} + } // namespace xam } // namespace kernel } // namespace xe \ No newline at end of file diff --git a/src/xenia/kernel/xam/content_manager.h b/src/xenia/kernel/xam/content_manager.h index 9d4bd42c5..b6a3cadfb 100644 --- a/src/xenia/kernel/xam/content_manager.h +++ b/src/xenia/kernel/xam/content_manager.h @@ -132,6 +132,7 @@ class ContentManager { std::vector buffer); X_RESULT DeleteContent(const XCONTENT_DATA& data); std::filesystem::path ResolveGameUserContentPath(); + void CloseOpenedFilesFromContent(const std::string_view root_name); void SetTitleIdOverride(uint32_t title_id) { title_id_override_ = title_id; }