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 <tunip3@users.noreply.github.com>
This commit is contained in:
tunip3 2021-12-22 11:55:33 +00:00 committed by GitHub
parent eff6f41a38
commit fb6bf6023a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 2 deletions

View File

@ -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));

View File

@ -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^>^)
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<StorageFolder^> 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));