From e4793e3d5e86d46c8c3247f1ef99553d2b8c1569 Mon Sep 17 00:00:00 2001 From: GregoryMorse Date: Mon, 18 Nov 2013 20:25:50 +0800 Subject: [PATCH] Update system.cpp Fixed to use native C++ instead of C++/CX although it does require significantly more code, it goes along with the spirit of keeping the project in native C++ Update system.cpp Cleaned up whitespace, removed redundant code and added edge cases for string cleanup Update system.cpp Fixed compiler warning over comma operator clause Update system.cpp NULL initialization Update system.cpp Fixed use of WindowsGetStringRawBuffer which returns internal pointer to buffer Update system.cpp Support C++/CX and native C++ through conditional compilation. Fixed style - long lines, comma operators, long conditional. Optimized string usage to use reference. Update system.cpp Fixed conditional compilation around include and library Update system.cpp Fixed trailing space Update system.cpp Cleaned up whitespace, removed redundant code and added edge cases for string cleanup Update system.cpp Fixed compiler warning over comma operator clause Update system.cpp NULL initialization Update system.cpp Fixed use of WindowsGetStringRawBuffer which returns internal pointer to buffer Update system.cpp Support C++/CX and native C++ through conditional compilation. Fixed style - long lines, comma operators, long conditional. Optimized string usage to use reference. Update system.cpp Fixed conditional compilation around include and library Update system.cpp Fixed trailing space --- modules/core/src/system.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/modules/core/src/system.cpp b/modules/core/src/system.cpp index c45ffa0..729903b 100644 --- a/modules/core/src/system.cpp +++ b/modules/core/src/system.cpp @@ -87,10 +87,41 @@ #ifdef HAVE_WINRT #include +#ifndef __cplusplus_winrt +#include +#pragma comment(lib, "runtimeobject.lib") +#endif std::wstring GetTempPathWinRT() { +#ifdef __cplusplus_winrt return std::wstring(Windows::Storage::ApplicationData::Current->TemporaryFolder->Path->Data()); +#else + Microsoft::WRL::ComPtr appdataFactory; + Microsoft::WRL::ComPtr appdataRef; + Microsoft::WRL::ComPtr storagefolderRef; + Microsoft::WRL::ComPtr storageitemRef; + HSTRING str; + HSTRING_HEADER hstrHead; + std::wstring wstr; + if (FAILED(WindowsCreateStringReference(RuntimeClass_Windows_Storage_ApplicationData, + (UINT32)wcslen(RuntimeClass_Windows_Storage_ApplicationData), &hstrHead, &str))) + return wstr; + if (FAILED(RoGetActivationFactory(str, IID_PPV_ARGS(appdataFactory.ReleaseAndGetAddressOf())))) + return wstr; + if (FAILED(appdataFactory->get_Current(appdataRef.ReleaseAndGetAddressOf()))) + return wstr; + if (FAILED(appdataRef->get_TemporaryFolder(storagefolderRef.ReleaseAndGetAddressOf()))) + return wstr; + if (FAILED(storagefolderRef.As(&storageitemRef))) + return wstr; + str = NULL; + if (FAILED(storageitemRef->get_Path(&str))) + return wstr; + wstr = WindowsGetStringRawBuffer(str, NULL); + WindowsDeleteString(str); + return wstr; +#endif } std::wstring GetTempFileNameWinRT(std::wstring prefix) -- 2.7.4