UWP support

This commit is contained in:
Jack Andersen 2017-12-05 17:23:58 -10:00
parent 63ae60a967
commit 3d70a568dc
4 changed files with 26 additions and 38 deletions

View File

@ -11,6 +11,11 @@
#define NOMINMAX #define NOMINMAX
#endif #endif
#include <windows.h> #include <windows.h>
#if defined(WINAPI_FAMILY) && WINAPI_FAMILY != WINAPI_FAMILY_DESKTOP_APP
#define WINDOWS_STORE 1
#else
#define WINDOWS_STORE 0
#endif
#else #else
#include <ctype.h> #include <ctype.h>
#include <sys/file.h> #include <sys/file.h>

View File

@ -254,43 +254,6 @@ bool DiscBase::IPartition::extractSysFiles(SystemStringView basePath, const Extr
return true; return true;
} }
static uint64_t GetInode(const SystemChar* path)
{
uint64_t inode;
#if _WIN32
HANDLE fp = CreateFileW(path,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
nullptr,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
nullptr);
if (!fp)
{
LogModule.report(logvisor::Error, _S("unable to open %s"), path);
return 0;
}
BY_HANDLE_FILE_INFORMATION info;
if (!GetFileInformationByHandle(fp, &info))
{
LogModule.report(logvisor::Error, _S("unable to GetFileInformationByHandle %s"), path);
return 0;
}
inode = uint64_t(info.nFileIndexHigh) << 32;
inode |= uint64_t(info.nFileIndexLow);
CloseHandle(fp);
#else
struct stat st;
if (stat(path, &st))
{
LogModule.report(logvisor::Error, _S("unable to stat %s"), path);
return 0;
}
inode = uint64_t(st.st_ino);
#endif
return inode;
}
static bool IsSystemFile(SystemStringView name, bool& isDol) static bool IsSystemFile(SystemStringView name, bool& isDol)
{ {
isDol = false; isDol = false;

View File

@ -17,8 +17,12 @@ public:
bool exists() bool exists()
{ {
#if !WINDOWS_STORE
HANDLE fp = CreateFileW(m_path.c_str(), GENERIC_READ, FILE_SHARE_READ, HANDLE fp = CreateFileW(m_path.c_str(), GENERIC_READ, FILE_SHARE_READ,
nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
#else
HANDLE fp = CreateFile2(m_path.c_str(), GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, nullptr);
#endif
if (fp == INVALID_HANDLE_VALUE) if (fp == INVALID_HANDLE_VALUE)
return false; return false;
CloseHandle(fp); CloseHandle(fp);
@ -27,8 +31,12 @@ public:
uint64_t size() uint64_t size()
{ {
#if !WINDOWS_STORE
HANDLE fp = CreateFileW(m_path.c_str(), GENERIC_READ, FILE_SHARE_READ, HANDLE fp = CreateFileW(m_path.c_str(), GENERIC_READ, FILE_SHARE_READ,
nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
#else
HANDLE fp = CreateFile2(m_path.c_str(), GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, nullptr);
#endif
if (fp == INVALID_HANDLE_VALUE) if (fp == INVALID_HANDLE_VALUE)
return 0; return 0;
LARGE_INTEGER sz; LARGE_INTEGER sz;
@ -48,8 +56,12 @@ public:
WriteStream(SystemStringView path, int64_t maxWriteSize, bool& err) WriteStream(SystemStringView path, int64_t maxWriteSize, bool& err)
: m_maxWriteSize(maxWriteSize) : m_maxWriteSize(maxWriteSize)
{ {
#if !WINDOWS_STORE
fp = CreateFileW(path.data(), GENERIC_WRITE, FILE_SHARE_WRITE, fp = CreateFileW(path.data(), GENERIC_WRITE, FILE_SHARE_WRITE,
nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
#else
fp = CreateFile2(path.data(), GENERIC_WRITE, FILE_SHARE_WRITE, CREATE_ALWAYS, nullptr);
#endif
if (fp == INVALID_HANDLE_VALUE) if (fp == INVALID_HANDLE_VALUE)
{ {
LogModule.report(logvisor::Error, _S("unable to open '%s' for writing"), path.data()); LogModule.report(logvisor::Error, _S("unable to open '%s' for writing"), path.data());
@ -59,8 +71,12 @@ public:
WriteStream(SystemStringView path, uint64_t offset, int64_t maxWriteSize, bool& err) WriteStream(SystemStringView path, uint64_t offset, int64_t maxWriteSize, bool& err)
: m_maxWriteSize(maxWriteSize) : m_maxWriteSize(maxWriteSize)
{ {
#if !WINDOWS_STORE
fp = CreateFileW(path.data(), GENERIC_WRITE, FILE_SHARE_WRITE, fp = CreateFileW(path.data(), GENERIC_WRITE, FILE_SHARE_WRITE,
nullptr, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); nullptr, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
#else
fp = CreateFile2(path.data(), GENERIC_WRITE, FILE_SHARE_WRITE, OPEN_ALWAYS, nullptr);
#endif
if (fp == INVALID_HANDLE_VALUE) if (fp == INVALID_HANDLE_VALUE)
{ {
LogModule.report(logvisor::Error, _S("unable to open '%s' for writing"), path.data()); LogModule.report(logvisor::Error, _S("unable to open '%s' for writing"), path.data());
@ -116,8 +132,12 @@ public:
HANDLE fp; HANDLE fp;
ReadStream(SystemStringView path, bool& err) ReadStream(SystemStringView path, bool& err)
{ {
#if !WINDOWS_STORE
fp = CreateFileW(path.data(), GENERIC_READ, FILE_SHARE_READ, fp = CreateFileW(path.data(), GENERIC_READ, FILE_SHARE_READ,
nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
#else
fp = CreateFile2(path.data(), GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, nullptr);
#endif
if (fp == INVALID_HANDLE_VALUE) if (fp == INVALID_HANDLE_VALUE)
{ {
err = true; err = true;

@ -1 +1 @@
Subproject commit 59741b63b88ce6c1135733a326e3cbfaf8d22e0c Subproject commit 408ae926d76128fa23a12607d0a1e0a970ab3554