---
 .../winstorecompat/src/SHGetFolderPathW.c          | 103 +++++++++++++++++++--
 1 file changed, 97 insertions(+), 6 deletions(-)

diff --git a/mingw-w64-libraries/winstorecompat/src/SHGetFolderPathW.c 
b/mingw-w64-libraries/winstorecompat/src/SHGetFolderPathW.c
index 9ae7d3c..36b956f 100644
--- a/mingw-w64-libraries/winstorecompat/src/SHGetFolderPathW.c
+++ b/mingw-w64-libraries/winstorecompat/src/SHGetFolderPathW.c
@@ -1,7 +1,8 @@
 /*
     Copyright (c) 2013 mingw-w64 project
 
-    Contributing authors: Rafaël Carré
+    Contributing authors: Jean-Baptiste Kempf
+                          Rafaël Carré
 
     Permission is hereby granted, free of charge, to any person obtaining a
     copy of this software and associated documentation files (the "Software"),
@@ -23,15 +24,105 @@
 */
 
 #define SHGetFolderPathW __SHGetFolderPathW
+
+#define _WIN32_WINNT 0x602
+#define COBJMACROS
+#define INITGUID
+#include <winstring.h>
 #include <windows.h>
-#include <shfolder.h>
+#include <shlobj.h>
+#include <roapi.h>
+#include <windows.storage.h>
 #undef SHGetFolderPathW
 
-HRESULT WINAPI SHGetFolderPathW(HWND hwnd,int csidl,HANDLE hToken,DWORD 
dwFlags,LPWSTR pszPath);
+HRESULT WINAPI SHGetFolderPathW(HWND hwnd, int csidl, HANDLE hToken, DWORD 
dwFlags, LPWSTR pszPath) {
+
+    IStorageFolder *folder;
+
+    (void)hwnd;
+    (void)hToken;
+
+    if (dwFlags != SHGFP_TYPE_CURRENT)
+        return E_NOTIMPL;
+
+    folder = NULL;
+
+    if (csidl == CSIDL_APPDATA) {
+        IApplicationDataStatics *appDataStatics = NULL;
+        IApplicationData *appData = NULL;
+        static const WCHAR *className = L"Windows.Storage.ApplicationData";
+        const UINT32 clen = wcslen(className);
+
+        HSTRING hClassName = NULL;
+        HSTRING_HEADER header;
+        HRESULT hr = WindowsCreateStringReference(className, clen, &header, 
&hClassName);
+        if (hr) {
+            WindowsDeleteString(hClassName);
+            return E_FAIL;
+        }
+
+        hr = RoGetActivationFactory(hClassName, &IID_IApplicationDataStatics, 
(void**)&appDataStatics);
+        WindowsDeleteString(hClassName);
+
+        if (hr)
+            return E_FAIL;
+
+        IApplicationDataStatics_get_Current(appDataStatics, &appData);
+
+        if (!appData)
+            return E_FAIL;
+
+        IApplicationData_get_LocalFolder(appData, &folder);
+
+    } else {
+        IKnownFoldersStatics *knownFoldersStatics = NULL;
+        static const WCHAR *className = L"Windows.Storage.KnownFolders";
+        const UINT32 clen = wcslen(className);
+
+        HSTRING hClassName = NULL;
+        HSTRING_HEADER header;
+        HRESULT hr = WindowsCreateStringReference(className, clen, &header, 
&hClassName);
+        if (hr) {
+            WindowsDeleteString(hClassName);
+            return E_FAIL;
+        }
+
+        hr = RoGetActivationFactory(hClassName, &IID_IKnownFoldersStatics, 
(void**)&knownFoldersStatics);
+        WindowsDeleteString(hClassName);
+
+        if (hr)
+            return E_FAIL;
+
+        switch(csidl) {
+            case CSIDL_PERSONAL:
+                IKnownFoldersStatics_get_DocumentsLibrary(knownFoldersStatics, 
&folder);
+                break;
+            case CSIDL_MYMUSIC:
+                IKnownFoldersStatics_get_MusicLibrary(knownFoldersStatics, 
&folder);
+                break;
+            case CSIDL_MYPICTURES:
+                IKnownFoldersStatics_get_PicturesLibrary(knownFoldersStatics, 
&folder);
+                break;
+            case CSIDL_MYVIDEO:
+                IKnownFoldersStatics_get_VideosLibrary(knownFoldersStatics, 
&folder);
+                break;
+            default:
+                return E_INVALIDARG;
+        }
+    }
+
+    {
+        HSTRING path = NULL;
+        IStorageItem *item = NULL;
+        PCWSTR pszPathTemp;
+        IStorageFolder_QueryInterface(folder, &IID_IStorageItem, 
(void**)&item);
+        IStorageItem_get_Path(item, &path);
+        pszPathTemp = WindowsGetStringRawBuffer(path, NULL);
+        WindowsDeleteString(path);
+        wcscpy(pszPath, pszPathTemp);
+    }
 
-HRESULT WINAPI SHGetFolderPathW(HWND hwnd,int csidl,HANDLE hToken,DWORD 
dwFlags,LPWSTR pszPath)
-{
-    return S_FALSE;
+    return S_OK;
 }
 
 HRESULT (WINAPI *__MINGW_IMP_SYMBOL(SHGetFolderPathW))(HWND hwnd,int 
csidl,HANDLE hToken,DWORD dwFlags,LPWSTR pszPath) 
asm("__imp__SHGetFolderPathW@20") = SHGetFolderPathW;
-- 
1.8.4.rc2


------------------------------------------------------------------------------
Get 100% visibility into Java/.NET code with AppDynamics Lite!
It's a free troubleshooting tool designed for production.
Get down to code-level detail for bottlenecks, with <2% overhead. 
Download for free and get started troubleshooting in minutes. 
http://pubads.g.doubleclick.net/gampad/clk?id=48897031&iu=/4140/ostg.clktrk
_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to