From 4ff58d5b7b2bef1db7dc151976e111ddea9b91a3 Mon Sep 17 00:00:00 2001
From: "Olivier F. R. Dierick" <o.dierick@piezo-forte.be>
Date: Sat, 28 Nov 2015 06:25:33 +0100
Subject: shell32: Check IsWoW64Process before calling Wow64 functions (try 2)

Replace patch entry 116937.

Fix one of the error leak source that prevents the installer to succeed
(bug 36838).

On 32 bit Wine, the original code did set last error to
ERROR_CALL_NOT_IMPLEMENTED when calling wow64 functions. The game
installer chokes at some point when the last error is anything but zero
and fails to complete the installation. Checking if wow64 is available
before calling wow64 functions avoids that. The affected wow64 function
calls themselves are not required for proper operation on 32 bit
systems.

Signed-off-by: Olivier F. R. Dierick <o.dierick@piezo-forte.be>
---
 dlls/shell32/shfldr_unixfs.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/dlls/shell32/shfldr_unixfs.c b/dlls/shell32/shfldr_unixfs.c
index 85383e8..7de38ba 100644
--- a/dlls/shell32/shfldr_unixfs.c
+++ b/dlls/shell32/shfldr_unixfs.c
@@ -392,6 +392,7 @@ static BOOL UNIXFS_get_unix_path(LPCWSTR pszDosPath, char *pszCanonicalPath)
     BOOL has_failed = FALSE;
     WCHAR wszDrive[] = { '?', ':', '\\', 0 }, dospath[MAX_PATH], *dospath_end;
     int cDriveSymlinkLen;
+    BOOL is_wow64;
     void *redir;
 
     TRACE("(pszDosPath=%s, pszCanonicalPath=%p)\n", debugstr_w(pszDosPath), pszCanonicalPath);
@@ -408,13 +409,14 @@ static BOOL UNIXFS_get_unix_path(LPCWSTR pszDosPath, char *pszCanonicalPath)
     HeapFree(GetProcessHeap(), 0, pszUnixPath);
     if (!pElement) return FALSE;
     if (szPath[strlen(szPath)-1] != '/') strcat(szPath, "/");
+    if (!IsWow64Process(GetCurrentProcess(), &is_wow64)) is_wow64 = FALSE;
 
     /* Append the part relative to the drive symbolic link target. */
     lstrcpyW(dospath, pszDosPath);
     dospath_end = dospath + lstrlenW(dospath);
     /* search for the most valid UNIX path possible, then append missing
      * path parts */
-    Wow64DisableWow64FsRedirection(&redir);
+    if(is_wow64) Wow64DisableWow64FsRedirection(&redir);
     while(!(pszUnixPath = wine_get_unix_file_name(dospath))){
         if(has_failed){
             *dospath_end = '/';
@@ -428,7 +430,7 @@ static BOOL UNIXFS_get_unix_path(LPCWSTR pszDosPath, char *pszCanonicalPath)
         }
         *dospath_end = '\0';
     }
-    Wow64RevertWow64FsRedirection(redir);
+    if(is_wow64) Wow64RevertWow64FsRedirection(redir);
     if(dospath_end < dospath)
         return FALSE;
     strcat(szPath, pszUnixPath + cDriveSymlinkLen);
-- 
2.6.4

