From fb6bf6023a8d0fe51e79995454efeac3c52b1d39 Mon Sep 17 00:00:00 2001 From: tunip3 <26260613+tunip3@users.noreply.github.com> Date: Wed, 22 Dec 2021 11:55:33 +0000 Subject: [PATCH] Move roms copied to localstate to a dedicated dir and clear on start up [XBOX/UWP] (#13392) * make roms copy to a specific cache dir in the localstate folder when its copied * auto delete vfs cache dir on start up Co-authored-by: Tunip3 --- tasks/task_content.c | 11 +++++++++-- uwp/uwp_main.cpp | 16 ++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/tasks/task_content.c b/tasks/task_content.c index 9573560bff..f804fc996c 100644 --- a/tasks/task_content.c +++ b/tasks/task_content.c @@ -1053,8 +1053,6 @@ static bool content_file_load( // I am genuinely really proud of these work arounds wchar_t wcontent_path[MAX_PATH]; mbstowcs(wcontent_path, content_path, MAX_PATH); - wchar_t wuwp_dir_data[MAX_PATH]; - mbstowcs(wuwp_dir_data, uwp_dir_data, MAX_PATH); uwp_set_acl(wcontent_path, L"S-1-15-2-1"); if (!is_path_accessible_using_standard_io(content_path)) { @@ -1080,6 +1078,15 @@ static bool content_file_load( "but cache directory was not set or found. " "Setting cache directory to root of writable app directory...\n"); strlcpy(new_basedir, uwp_dir_data, sizeof(new_basedir)); + strcat(new_basedir, "VFSCACHE\\"); + DWORD dwAttrib = GetFileAttributes(new_basedir); + if ((dwAttrib == INVALID_FILE_ATTRIBUTES) || (!(dwAttrib & FILE_ATTRIBUTE_DIRECTORY))) + { + if (!CreateDirectoryA(new_basedir, NULL)) + { + strlcpy(new_basedir, uwp_dir_data, sizeof(new_basedir)); + } + } } fill_pathname_join(new_path, new_basedir, path_basename(content_path), sizeof(new_path)); diff --git a/uwp/uwp_main.cpp b/uwp/uwp_main.cpp index 575d9e10ad..fab16de718 100644 --- a/uwp/uwp_main.cpp +++ b/uwp/uwp_main.cpp @@ -50,6 +50,7 @@ using namespace Windows::Foundation; using namespace Windows::Foundation::Collections; using namespace Windows::Graphics::Display; using namespace Windows::Devices::Enumeration; +using namespace Windows::Storage; char uwp_dir_install[PATH_MAX_LENGTH] = { 0 }; char uwp_dir_data[PATH_MAX_LENGTH] = { 0 }; @@ -217,6 +218,21 @@ int main(Platform::Array^) Platform::String^ data_dir = Windows::Storage::ApplicationData::Current->LocalFolder->Path + L"\\"; wcstombs(uwp_dir_data, data_dir->Data(), sizeof(uwp_dir_data)); + + // delete vfs cache dir, we do this because this allows a far far more consise implementation than manually implementing a function to do this + // this may be a little slower but shouldn't really matter as the cache dir should never have more than a few items + Platform::String^ vfs_dir = Windows::Storage::ApplicationData::Current->LocalFolder->Path + L"\\VFSCACHE"; + char vfs_cache_dir[MAX_PATH]; + wcstombs(vfs_cache_dir, vfs_dir->Data(), sizeof(vfs_cache_dir)); + DWORD dwAttrib = GetFileAttributesA(vfs_cache_dir); + if ((dwAttrib != INVALID_FILE_ATTRIBUTES) && (dwAttrib & FILE_ATTRIBUTE_DIRECTORY)) + { + concurrency::task vfsdirtask = concurrency::create_task(StorageFolder::GetFolderFromPathAsync(vfs_dir)); + vfsdirtask.wait(); + StorageFolder^ vfsdir = vfsdirtask.get(); + vfsdir->DeleteAsync(); + } + wcstombs(uwp_device_family, AnalyticsInfo::VersionInfo->DeviceFamily->Data(), sizeof(uwp_device_family));