improve uwp fileio by using from app variants whereever possible

This commit is contained in:
Tunip3 2021-07-31 04:36:08 +01:00
parent 78341e5824
commit be1a768bca
5 changed files with 24 additions and 19 deletions

1
.gitignore vendored
View File

@ -223,3 +223,4 @@ param.sfo
*.elf *.elf
*.self *.self
*.vpk *.vpk
/.vs

View File

@ -31,6 +31,7 @@
#include <robuffer.h> #include <robuffer.h>
#include <collection.h> #include <collection.h>
#include <functional> #include <functional>
#include <fileapifromapp.h>
using namespace Windows::Foundation; using namespace Windows::Foundation;
using namespace Windows::Foundation::Collections; using namespace Windows::Foundation::Collections;
@ -388,7 +389,7 @@ libretro_vfs_implementation_file *retro_vfs_file_open_impl(
OPEN_ALWAYS : CREATE_ALWAYS; OPEN_ALWAYS : CREATE_ALWAYS;
} }
file_handle = CreateFile2(path_str->Data(), desireAccess, FILE_SHARE_READ, creationDisposition, NULL); file_handle = CreateFile2FromAppW(path_str->Data(), desireAccess, FILE_SHARE_READ, creationDisposition, NULL);
if (file_handle != INVALID_HANDLE_VALUE) if (file_handle != INVALID_HANDLE_VALUE)
{ {
@ -744,7 +745,7 @@ int retro_vfs_file_remove_impl(const char *path)
free(path_wide); free(path_wide);
/* Try Win32 first, this should work in AppData */ /* Try Win32 first, this should work in AppData */
result = DeleteFileW(path_str->Data()); result = DeleteFileFromAppW(path_str->Data());
if (result) if (result)
return 0; return 0;
@ -827,6 +828,7 @@ int retro_vfs_stat_impl(const char *path, int32_t *size)
Platform::String^ path_str; Platform::String^ path_str;
IStorageItem^ item; IStorageItem^ item;
DWORD file_info; DWORD file_info;
_WIN32_FILE_ATTRIBUTE_DATA attribdata;
if (!path || !*path) if (!path || !*path)
return 0; return 0;
@ -837,21 +839,22 @@ int retro_vfs_stat_impl(const char *path, int32_t *size)
free(path_wide); free(path_wide);
/* Try Win32 first, this should work in AppData */ /* Try Win32 first, this should work in AppData */
file_info = GetFileAttributesW(path_str->Data()); if (GetFileAttributesExFromAppW(path_str->Data(), GetFileExInfoStandard, &attribdata))
if (file_info != INVALID_FILE_ATTRIBUTES)
{ {
HANDLE file_handle = CreateFile2(path_str->Data(), GENERIC_READ, FILE_SHARE_READ, OPEN_ALWAYS, NULL); file_info = attribdata.dwFileAttributes;
if (file_handle != INVALID_HANDLE_VALUE) if (file_info != INVALID_FILE_ATTRIBUTES)
{ {
LARGE_INTEGER sz; if (!(file_info & FILE_ATTRIBUTE_DIRECTORY))
if (GetFileSizeEx(file_handle, &sz)) {
{ LARGE_INTEGER sz;
if (size) if (size)
*size = sz.QuadPart; {
} sz.HighPart = attribdata.nFileSizeHigh;
CloseHandle(file_handle); sz.LowPart = attribdata.nFileSizeLow;
} }
return (file_info & FILE_ATTRIBUTE_DIRECTORY) ? RETRO_VFS_STAT_IS_VALID | RETRO_VFS_STAT_IS_DIRECTORY : RETRO_VFS_STAT_IS_VALID; }
return (file_info & FILE_ATTRIBUTE_DIRECTORY) ? RETRO_VFS_STAT_IS_VALID | RETRO_VFS_STAT_IS_DIRECTORY : RETRO_VFS_STAT_IS_VALID;
}
} }
if (GetLastError() == ERROR_FILE_NOT_FOUND) if (GetLastError() == ERROR_FILE_NOT_FOUND)
@ -917,7 +920,7 @@ int retro_vfs_mkdir_impl(const char *dir)
free(dir_local); free(dir_local);
/* Try Win32 first, this should work in AppData */ /* Try Win32 first, this should work in AppData */
result = CreateDirectoryW(dir_str->Data(), NULL); result = CreateDirectoryFromAppW(dir_str->Data(), NULL);
if (result) if (result)
return 0; return 0;

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities" IgnorableNamespaces="uap mp rescap"> <Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities" IgnorableNamespaces="uap mp rescap">
<Identity Name="1e4cf179-f3c2-404f-b9f3-cb2070a5aad8" Publisher="CN=libretro" Version="1.9.0.0" /> <Identity Name="1e4cf179-f3c2-404f-b9f3-cb2070a5aad8" Publisher="CN=t3" Version="1.9.0.0" />
<mp:PhoneIdentity PhoneProductId="1e4cf179-f3c2-404f-b9f3-cb2070a5aad8" PhonePublisherId="00000000-0000-0000-0000-000000000000" /> <mp:PhoneIdentity PhoneProductId="1e4cf179-f3c2-404f-b9f3-cb2070a5aad8" PhonePublisherId="00000000-0000-0000-0000-000000000000" />
<Properties> <Properties>
<DisplayName>RetroArch</DisplayName> <DisplayName>RetroArch</DisplayName>

View File

@ -232,11 +232,12 @@
<AppInstallerUpdateFrequency>1</AppInstallerUpdateFrequency> <AppInstallerUpdateFrequency>1</AppInstallerUpdateFrequency>
<AppInstallerCheckForUpdateFrequency>OnApplicationRun</AppInstallerCheckForUpdateFrequency> <AppInstallerCheckForUpdateFrequency>OnApplicationRun</AppInstallerCheckForUpdateFrequency>
<AppxBundle>Always</AppxBundle> <AppxBundle>Always</AppxBundle>
<PackageCertificateThumbprint>B86DAF5EC706754FEBABD0B011B0C4C3C2F73251</PackageCertificateThumbprint> <PackageCertificateThumbprint>261A18AB51F9C1DC1956AF9084285F82A2A7FD30</PackageCertificateThumbprint>
<AppxPackageSigningTimestampDigestAlgorithm>SHA256</AppxPackageSigningTimestampDigestAlgorithm> <AppxPackageSigningTimestampDigestAlgorithm>SHA256</AppxPackageSigningTimestampDigestAlgorithm>
<GenerateTestArtifacts>True</GenerateTestArtifacts> <GenerateTestArtifacts>True</GenerateTestArtifacts>
<HoursBetweenUpdateChecks>0</HoursBetweenUpdateChecks> <HoursBetweenUpdateChecks>0</HoursBetweenUpdateChecks>
<AppxPackageSigningEnabled>True</AppxPackageSigningEnabled> <AppxPackageSigningEnabled>True</AppxPackageSigningEnabled>
<PackageCertificateKeyFile>RetroArch-msvc2019-UWP_TemporaryKey.pfx</PackageCertificateKeyFile>
</PropertyGroup> </PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">
<Link> <Link>