From 256b83d92adbffe2d928e74b95466fefd7cff60b Mon Sep 17 00:00:00 2001
From: Dmitry Timoshkov <dmitry@baikal.ru>
Date: Thu, 20 Apr 2017 17:08:11 +0800
Subject: [PATCH] setupapi: Fix parameters of SPFILENOTIFY_FILEINCABINET
 handler.

Bug 42827 references the setup application that depends on this.
---
 dlls/setupapi/setupcab.c       | 17 ++++++++---------
 dlls/setupapi/tests/setupcab.c |  4 ----
 2 files changed, 8 insertions(+), 13 deletions(-)

diff --git a/dlls/setupapi/setupcab.c b/dlls/setupapi/setupcab.c
index 0146e575d41..6a02faa4cb3 100644
--- a/dlls/setupapi/setupcab.c
+++ b/dlls/setupapi/setupcab.c
@@ -323,7 +323,7 @@ static INT_PTR CDECL sc_FNNOTIFY_A(FDINOTIFICATIONTYPE fdint, PFDINOTIFICATION p
     fici.DosAttribs = pfdin->attribs;
     memset(fici.FullTargetName, 0, MAX_PATH);
     err = phsc->msghandler(phsc->context, SPFILENOTIFY_FILEINCABINET,
-                           (UINT_PTR)&fici, (UINT_PTR)pfdin->psz1);
+                           (UINT_PTR)&fici, (UINT_PTR)phsc->most_recent_cabinet_name);
     if (err == FILEOP_DOIT) {
       TRACE("  Callback specified filename: %s\n", debugstr_a(fici.FullTargetName));
       if (!fici.FullTargetName[0]) {
@@ -459,7 +459,7 @@ static INT_PTR CDECL sc_FNNOTIFY_W(FDINOTIFICATIONTYPE fdint, PFDINOTIFICATION p
     fici.DosAttribs = pfdin->attribs;
     memset(fici.FullTargetName, 0, MAX_PATH * sizeof(WCHAR));
     err = phsc->msghandler(phsc->context, SPFILENOTIFY_FILEINCABINET,
-                           (UINT_PTR)&fici, (UINT_PTR)pfdin->psz1);
+                           (UINT_PTR)&fici, (UINT_PTR)phsc->most_recent_cabinet_name);
     if (err == FILEOP_DOIT) {
       TRACE("  Callback specified filename: %s\n", debugstr_w(fici.FullTargetName));
       if (fici.FullTargetName[0]) {
@@ -587,8 +587,8 @@ BOOL WINAPI SetupIterateCabinetA(PCSTR CabinetFile, DWORD Reserved,
 
   TRACE("path: %s, cabfile: %s\n", debugstr_a(pszCabPath), debugstr_a(pszCabinet));
 
-  /* remember the cabinet name */
-  strcpy(my_hsc.most_recent_cabinet_name, pszCabinet);
+  /* remember original cabinet name */
+  strcpy(my_hsc.most_recent_cabinet_name, CabinetFile);
 
   my_hsc.magic = SC_HSC_A_MAGIC;
   my_hsc.msghandler = MsgHandler;
@@ -638,19 +638,18 @@ BOOL WINAPI SetupIterateCabinetW(PCWSTR CabinetFile, DWORD Reserved,
   }
 
   if (p) {
-    strcpyW(my_hsc.most_recent_cabinet_name, p);
+    WideCharToMultiByte(CP_ACP, 0, p, -1, pszCabinet, MAX_PATH, 0, 0);
     *p = 0;
     len = WideCharToMultiByte(CP_ACP, 0, pszCabPathW, -1, pszCabPath,
 				MAX_PATH, 0, 0);
     if (!len) return FALSE;
   } else {
-    strcpyW(my_hsc.most_recent_cabinet_name, CabinetFile);
+    WideCharToMultiByte(CP_ACP, 0, CabinetFile, -1, pszCabinet, MAX_PATH, 0, 0);
     pszCabPath[0] = '\0';
   }
 
-  len = WideCharToMultiByte(CP_ACP, 0, my_hsc.most_recent_cabinet_name, -1,
-				pszCabinet, MAX_PATH, 0, 0);
-  if (!len) return FALSE;
+  /* remember original cabinet name */
+  strcpyW(my_hsc.most_recent_cabinet_name, CabinetFile);
 
   TRACE("path: %s, cabfile: %s\n",
 	debugstr_a(pszCabPath), debugstr_a(pszCabinet));
diff --git a/dlls/setupapi/tests/setupcab.c b/dlls/setupapi/tests/setupcab.c
index 88516a67b0c..2e776e66879 100644
--- a/dlls/setupapi/tests/setupcab.c
+++ b/dlls/setupapi/tests/setupcab.c
@@ -336,7 +336,6 @@ static UINT CALLBACK simple_callbackA(PVOID Context, UINT Notification,
             ok(!strcmp(expected_files[index], info->NameInCabinet),
                "[%d] Expected file \"%s\", got \"%s\"\n",
                index, expected_files[index], info->NameInCabinet);
-todo_wine
             ok(!strcmp(ctx->cabinet, cabinet_file),
                "[%d] Expected cabinet \"%s\", got \"%s\"\n",
                index, ctx->cabinet, cabinet_file);
@@ -354,7 +353,6 @@ todo_wine
     {
         FILEPATHS_A *info = (FILEPATHS_A *)Param1;
 
-todo_wine
         ok(!strcmp(ctx->cabinet, info->Source),
            "[%d] Expected cabinet \"%s\", got \"%s\"\n",
            index, ctx->cabinet, info->Source);
@@ -440,7 +438,6 @@ static UINT CALLBACK simple_callbackW(PVOID Context, UINT Notification,
             ok(!lstrcmpW(expected_filesW[index], info->NameInCabinet),
                "[%d] Expected file %s, got %s\n",
                index, wine_dbgstr_w(expected_filesW[index]), wine_dbgstr_w(info->NameInCabinet));
-todo_wine
             ok(!lstrcmpW(ctx->cabinet, cabinet_file),
                "[%d] Expected cabinet %s, got %s\n",
                index, wine_dbgstr_w(ctx->cabinet), wine_dbgstr_w(cabinet_file));
@@ -458,7 +455,6 @@ todo_wine
     {
         FILEPATHS_W *info = (FILEPATHS_W *)Param1;
 
-todo_wine
         ok(!lstrcmpW(ctx->cabinet, info->Source),
            "[%d] Expected cabinet %s, got %s\n",
            index, wine_dbgstr_w(ctx->cabinet), wine_dbgstr_w(info->Source));
-- 
2.17.1

