From: Jean-Baptiste Kempf <j...@videolan.org>

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

diff --git a/mingw-w64-libraries/winstorecompat/src/SHGetFolderPathW.c 
b/mingw-w64-libraries/winstorecompat/src/SHGetFolderPathW.c
index 9ae7d3c..c15136f 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,112 @@
 */
 
 #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);
+
+        IApplicationDataStatics_Release(appDataStatics);
+        IApplicationData_Release(appData);
+
+    } 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;
+        }
+        
+        IKnownFoldersStatics_Release(knownFoldersStatics);
+    }
+
+    {
+        HSTRING path = NULL;
+        IStorageItem *item = NULL;
+        PCWSTR pszPathTemp;
+
+        IStorageFolder_QueryInterface(folder, &IID_IStorageItem, 
(void**)&item);
+        IStorageItem_get_Path(item, &path);
+
+        pszPathTemp = WindowsGetStringRawBuffer(path, NULL);
+        wcscpy(pszPath, pszPathTemp);
+        WindowsDeleteString(path);
+    }
 
-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.3.2


------------------------------------------------------------------------------
DreamFactory - Open Source REST & JSON Services for HTML5 & Native Apps
OAuth, Users, Roles, SQL, NoSQL, BLOB Storage and External API Access
Free app hosting. Or install the open source package on any LAMP server.
Sign up and see examples for AngularJS, jQuery, Sencha Touch and Native!
http://pubads.g.doubleclick.net/gampad/clk?id=63469471&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