Update system.cpp
authorGregoryMorse <gregory.morse@live.com>
Mon, 18 Nov 2013 12:25:50 +0000 (20:25 +0800)
committerGregoryMorse <gregory.morse@live.com>
Mon, 25 Nov 2013 16:22:14 +0000 (00:22 +0800)
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

index c45ffa0..729903b 100644 (file)
 
 #ifdef HAVE_WINRT
 #include <wrl/client.h>
+#ifndef __cplusplus_winrt
+#include <windows.storage.h>
+#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<ABI::Windows::Storage::IApplicationDataStatics> appdataFactory;
+    Microsoft::WRL::ComPtr<ABI::Windows::Storage::IApplicationData> appdataRef;
+    Microsoft::WRL::ComPtr<ABI::Windows::Storage::IStorageFolder> storagefolderRef;
+    Microsoft::WRL::ComPtr<ABI::Windows::Storage::IStorageItem> 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)