From da9699a7e29d2f7627e450f3d182e63a5140151d Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Tue, 5 Dec 2017 17:22:03 -1000 Subject: [PATCH] UWP support --- atdna/CMakeLists.txt | 3 +++ include/athena/Global.hpp | 6 ++++++ src/athena/FileInfo.cpp | 3 +++ src/athena/FileReaderWin32.cpp | 9 +++++++-- src/athena/FileWriterWin32.cpp | 10 ++++++++++ 5 files changed, 29 insertions(+), 2 deletions(-) diff --git a/atdna/CMakeLists.txt b/atdna/CMakeLists.txt index b8016ec..2f39f11 100644 --- a/atdna/CMakeLists.txt +++ b/atdna/CMakeLists.txt @@ -178,6 +178,9 @@ macro(atdna out) get_property(cdefs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY COMPILE_DEFINITIONS) set(cdefcli "") foreach(def ${cdefs}) + if(def MATCHES "^WINAPI_FAMILY.*") + continue() # C++/CX gives clang a stomach ache + endif() list(APPEND cdefcli "-D${def}") endforeach() diff --git a/include/athena/Global.hpp b/include/athena/Global.hpp index d4a91e1..ccad7b0 100644 --- a/include/athena/Global.hpp +++ b/include/athena/Global.hpp @@ -8,6 +8,12 @@ #ifdef _MSC_VER #pragma warning(disable : 4996) +#if defined(WINAPI_FAMILY) && WINAPI_FAMILY != WINAPI_FAMILY_DESKTOP_APP +#define WINDOWS_STORE 1 +#else +#define WINDOWS_STORE 0 +#endif + #include #if !defined(S_ISREG) && defined(S_IFMT) && defined(S_IFREG) diff --git a/src/athena/FileInfo.cpp b/src/athena/FileInfo.cpp index e212139..44fda4f 100644 --- a/src/athena/FileInfo.cpp +++ b/src/athena/FileInfo.cpp @@ -128,7 +128,9 @@ bool FileInfo::touch() const HANDLE fh; wchar_t date[80], time[80]; +#if !WINDOWS_STORE fh = CreateFileA(m_path.c_str(), GENERIC_READ | FILE_WRITE_ATTRIBUTES, 0, NULL, CREATE_NEW, 0, NULL); + if (fh == INVALID_HANDLE_VALUE) return false; @@ -168,6 +170,7 @@ bool FileInfo::touch() const } CloseHandle(fh); +#endif #elif (defined(HW_RVL) || defined(HW_DOL)) && defined(GEKKO) // Generic portable version, not extremely reliable but does work atUint64 val = 0xCDCDCDCDCD; diff --git a/src/athena/FileReaderWin32.cpp b/src/athena/FileReaderWin32.cpp index 877f1c3..7fe71c4 100644 --- a/src/athena/FileReaderWin32.cpp +++ b/src/athena/FileReaderWin32.cpp @@ -38,8 +38,13 @@ void FileReader::open() int attempt = 0; do { - m_fileHandle = CreateFileW(m_filename.c_str(), GENERIC_READ, FILE_SHARE_READ, - nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); +#if WINDOWS_STORE + m_fileHandle = CreateFile2(m_filename.c_str(), GENERIC_READ, FILE_SHARE_READ, + OPEN_EXISTING, nullptr); +#else + m_fileHandle = CreateFileW(m_filename.c_str(), GENERIC_READ, FILE_SHARE_READ, + nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); +#endif } while (m_fileHandle == INVALID_HANDLE_VALUE && attempt++ < 100); if (m_fileHandle == INVALID_HANDLE_VALUE) diff --git a/src/athena/FileWriterWin32.cpp b/src/athena/FileWriterWin32.cpp index 484a641..e280859 100644 --- a/src/athena/FileWriterWin32.cpp +++ b/src/athena/FileWriterWin32.cpp @@ -37,13 +37,23 @@ void FileWriter::open(bool overwrite) if (overwrite) { std::wstring tmpFilename = m_filename + L'~'; +#if WINDOWS_STORE + m_fileHandle = CreateFile2(tmpFilename.c_str(), GENERIC_WRITE, FILE_SHARE_WRITE, + CREATE_ALWAYS, nullptr); +#else m_fileHandle = CreateFileW(tmpFilename.c_str(), GENERIC_WRITE, FILE_SHARE_WRITE, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); +#endif } else { +#if WINDOWS_STORE + m_fileHandle = CreateFile2(m_filename.c_str(), GENERIC_WRITE, FILE_SHARE_WRITE, + OPEN_ALWAYS, nullptr); +#else m_fileHandle = CreateFileW(m_filename.c_str(), GENERIC_WRITE, FILE_SHARE_WRITE, nullptr, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); +#endif } } while (m_fileHandle == INVALID_HANDLE_VALUE && attempt++ < 100);