Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/setupapi/setupcab.c | 318 ++++++++++++--------------------------- 1 file changed, 98 insertions(+), 220 deletions(-)
diff --git a/dlls/setupapi/setupcab.c b/dlls/setupapi/setupcab.c index b9783b81356..55d0fe6f64c 100644 --- a/dlls/setupapi/setupcab.c +++ b/dlls/setupapi/setupcab.c @@ -84,16 +84,6 @@ typedef struct { CHAR most_recent_target[MAX_PATH]; } SC_HSC_A, *PSC_HSC_A;
-#define SC_HSC_W_MAGIC 0x0CABFEED -typedef struct { - UINT magic; - HFDI hfdi; - PSP_FILE_CALLBACK_W msghandler; - PVOID context; - WCHAR most_recent_cabinet_name[MAX_PATH]; - WCHAR most_recent_target[MAX_PATH]; -} SC_HSC_W, *PSC_HSC_W; - WINE_DEFAULT_DEBUG_CHANNEL(setupapi);
static BOOL LoadCABINETDll(void) @@ -386,158 +376,6 @@ static INT_PTR CDECL sc_FNNOTIFY_A(FDINOTIFICATIONTYPE fdint, PFDINOTIFICATION p } }
-static INT_PTR CDECL sc_FNNOTIFY_W(FDINOTIFICATIONTYPE fdint, PFDINOTIFICATION pfdin) -{ - FILE_IN_CABINET_INFO_W fici; - PSC_HSC_W phsc; - CABINET_INFO_W ci; - FILEPATHS_W fp; - UINT err; - int len; - - WCHAR mysterio[SIZEOF_MYSTERIO]; /* how big? undocumented! */ - WCHAR buf[MAX_PATH], buf2[MAX_PATH]; - CHAR charbuf[MAX_PATH]; - - memset(mysterio, 0, SIZEOF_MYSTERIO * sizeof(WCHAR)); - memset(buf, 0, MAX_PATH * sizeof(WCHAR)); - memset(buf2, 0, MAX_PATH * sizeof(WCHAR)); - memset(charbuf, 0, MAX_PATH); - - TRACE("(fdint == %d, pfdin == ^%p)\n", fdint, pfdin); - - if (pfdin && pfdin->pv && (((PSC_HSC_W) pfdin->pv)->magic == SC_HSC_W_MAGIC)) - phsc = pfdin->pv; - else { - ERR("pv %p is not an SC_HSC_W.\n", (pfdin) ? pfdin->pv : NULL); - return -1; - } - - switch (fdint) { - case fdintCABINET_INFO: - TRACE("Cabinet info notification\n"); - /* TRACE(" Cabinet name: %s\n", debugstr_a(pfdin->psz1)); - TRACE(" Cabinet disk: %s\n", debugstr_a(pfdin->psz2)); - TRACE(" Cabinet path: %s\n", debugstr_a(pfdin->psz3)); - TRACE(" Cabinet Set#: %d\n", pfdin->setID); - TRACE(" Cabinet Cab#: %d\n", pfdin->iCabinet); */ - WARN("SPFILENOTIFY_CABINETINFO undocumented: guess implementation.\n"); - ci.CabinetFile = phsc->most_recent_cabinet_name; - len = 1 + MultiByteToWideChar(CP_ACP, 0, pfdin->psz3, -1, buf, MAX_PATH); - if ((len > MAX_PATH) || (len <= 1)) - buf[0] = '\0'; - ci.CabinetPath = buf; - len = 1 + MultiByteToWideChar(CP_ACP, 0, pfdin->psz2, -1, buf2, MAX_PATH); - if ((len > MAX_PATH) || (len <= 1)) - buf2[0] = '\0'; - ci.DiskName = buf2; - ci.SetId = pfdin->setID; - ci.CabinetNumber = pfdin->iCabinet; - phsc->msghandler(phsc->context, SPFILENOTIFY_CABINETINFO, (UINT_PTR)&ci, 0); - return 0; - case fdintPARTIAL_FILE: - TRACE("Partial file notification\n"); - /* TRACE(" Partial file name: %s\n", debugstr_a(pfdin->psz1)); */ - return 0; - case fdintCOPY_FILE: - TRACE("Copy file notification\n"); - TRACE(" File name: %s\n", debugstr_a(pfdin->psz1)); - /* TRACE(" File size: %ld\n", pfdin->cb); - TRACE(" File date: %u\n", pfdin->date); - TRACE(" File time: %u\n", pfdin->time); - TRACE(" File attr: %u\n", pfdin->attribs); */ - len = 1 + MultiByteToWideChar(CP_ACP, 0, pfdin->psz1, -1, buf2, MAX_PATH); - if ((len > MAX_PATH) || (len <= 1)) - buf2[0] = '\0'; - fici.NameInCabinet = buf2; - fici.FileSize = pfdin->cb; - fici.Win32Error = 0; - fici.DosDate = pfdin->date; - fici.DosTime = pfdin->time; - 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); - if (err == FILEOP_DOIT) { - TRACE(" Callback specified filename: %s\n", debugstr_w(fici.FullTargetName)); - if (fici.FullTargetName[0]) { - len = lstrlenW(fici.FullTargetName) + 1; - if ((len > MAX_PATH ) || (len <= 1)) - return 0; - if (!WideCharToMultiByte(CP_ACP, 0, fici.FullTargetName, len, charbuf, MAX_PATH, 0, 0)) - return 0; - } else { - WARN("Empty buffer string caused abort.\n"); - SetLastError(ERROR_PATH_NOT_FOUND); - return -1; - } - lstrcpyW( phsc->most_recent_target, fici.FullTargetName ); - return sc_cb_open(charbuf, _O_BINARY | _O_CREAT | _O_WRONLY, _S_IREAD | _S_IWRITE); - } else { - TRACE(" Callback skipped file.\n"); - return 0; - } - case fdintCLOSE_FILE_INFO: - TRACE("Close file notification\n"); - /* TRACE(" File name: %s\n", debugstr_a(pfdin->psz1)); - TRACE(" Exec file? %s\n", (pfdin->cb) ? "Yes" : "No"); - TRACE(" File hndl: %d\n", pfdin->hf); */ - fp.Source = phsc->most_recent_cabinet_name; - fp.Target = phsc->most_recent_target; - fp.Win32Error = 0; - fp.Flags = 0; - /* a valid fixme -- but occurs too many times */ - /* FIXME("Should set file date/time/attribs (and execute files?)\n"); */ - if (sc_cb_close(pfdin->hf)) - WARN("_close failed.\n"); - err = phsc->msghandler(phsc->context, SPFILENOTIFY_FILEEXTRACTED, (UINT_PTR)&fp, 0); - if (err) { - SetLastError(err); - return FALSE; - } else - return TRUE; - case fdintNEXT_CABINET: - TRACE("Next cabinet notification\n"); - /* TRACE(" Cabinet name: %s\n", debugstr_a(pfdin->psz1)); - TRACE(" Cabinet disk: %s\n", debugstr_a(pfdin->psz2)); - TRACE(" Cabinet path: %s\n", debugstr_a(pfdin->psz3)); - TRACE(" Cabinet Set#: %d\n", pfdin->setID); - TRACE(" Cabinet Cab#: %d\n", pfdin->iCabinet); */ - /* remember the new cabinet name */ - len = 1 + MultiByteToWideChar(CP_ACP, 0, pfdin->psz1, -1, phsc->most_recent_cabinet_name, MAX_PATH); - if ((len > MAX_PATH) || (len <= 1)) - phsc->most_recent_cabinet_name[0] = '\0'; - ci.CabinetFile = phsc->most_recent_cabinet_name; - len = 1 + MultiByteToWideChar(CP_ACP, 0, pfdin->psz3, -1, buf, MAX_PATH); - if ((len > MAX_PATH) || (len <= 1)) - buf[0] = '\0'; - ci.CabinetPath = buf; - len = 1 + MultiByteToWideChar(CP_ACP, 0, pfdin->psz2, -1, buf2, MAX_PATH); - if ((len > MAX_PATH) || (len <= 1)) - buf2[0] = '\0'; - ci.DiskName = buf2; - ci.SetId = pfdin->setID; - ci.CabinetNumber = pfdin->iCabinet; - err = phsc->msghandler(phsc->context, SPFILENOTIFY_NEEDNEWCABINET, (UINT_PTR)&ci, (UINT_PTR)mysterio); - if (err) { - SetLastError(err); - return -1; - } else { - if (mysterio[0]) { - len = lstrlenW(mysterio) + 1; - if ((len > 255) || (len <= 1)) - return 0; - if (!WideCharToMultiByte(CP_ACP, 0, mysterio, len, pfdin->psz3, 255, 0, 0)) - return 0; - } - return 0; - } - default: - FIXME("Unknown notification type %d.\n", fdint); - return 0; - } -} - /*********************************************************************** * SetupIterateCabinetA (SETUPAPI.@) */ @@ -602,72 +440,112 @@ BOOL WINAPI SetupIterateCabinetA(PCSTR CabinetFile, DWORD Reserved, return ret; }
+struct iterate_wtoa_ctx +{ + PSP_FILE_CALLBACK_A orig_cb; + void *orig_ctx; +}; + +static UINT WINAPI iterate_wtoa_cb(void *pctx, UINT message, UINT_PTR param1, UINT_PTR param2) +{ + struct iterate_wtoa_ctx *ctx = pctx; + + switch (message) + { + case SPFILENOTIFY_CABINETINFO: + case SPFILENOTIFY_NEEDNEWCABINET: + { + const CABINET_INFO_A *infoA = (const CABINET_INFO_A *)param1; + WCHAR pathW[MAX_PATH], fileW[MAX_PATH], diskW[MAX_PATH]; + CABINET_INFO_W infoW = + { + .CabinetPath = pathW, + .CabinetFile = fileW, + .DiskName = diskW, + .SetId = infoA->SetId, + .CabinetNumber = infoA->CabinetNumber, + }; + + MultiByteToWideChar(CP_ACP, 0, infoA->CabinetPath, -1, pathW, ARRAY_SIZE(pathW)); + MultiByteToWideChar(CP_ACP, 0, infoA->CabinetFile, -1, fileW, ARRAY_SIZE(fileW)); + MultiByteToWideChar(CP_ACP, 0, infoA->DiskName, -1, diskW, ARRAY_SIZE(diskW)); + + if (message == SPFILENOTIFY_CABINETINFO) + return ctx->orig_cb(ctx->orig_ctx, message, (UINT_PTR)&infoW, 0); + else + { + char *newpathA = (char *)param2; + WCHAR newpathW[MAX_PATH] = {0}; + BOOL ret = ctx->orig_cb(ctx->orig_ctx, message, (UINT_PTR)&infoW, (UINT_PTR)newpathW); + + WideCharToMultiByte(CP_ACP, 0, newpathW, -1, newpathA, MAX_PATH, NULL, NULL); + return ret; + } + } + case SPFILENOTIFY_FILEINCABINET: + { + FILE_IN_CABINET_INFO_A *infoA = (FILE_IN_CABINET_INFO_A *)param1; + const char *cabA = (const char *)param2; + WCHAR cabW[MAX_PATH], fileW[MAX_PATH]; + FILE_IN_CABINET_INFO_W infoW = + { + .NameInCabinet = fileW, + .FileSize = infoA->FileSize, + .Win32Error = infoA->Win32Error, + .DosDate = infoA->DosDate, + .DosTime = infoA->DosTime, + .DosAttribs = infoA->DosAttribs, + }; + BOOL ret; + + MultiByteToWideChar(CP_ACP, 0, infoA->NameInCabinet, -1, fileW, ARRAY_SIZE(fileW)); + MultiByteToWideChar(CP_ACP, 0, cabA, -1, cabW, ARRAY_SIZE(cabW)); + + ret = ctx->orig_cb(ctx->orig_ctx, message, (UINT_PTR)&infoW, (UINT_PTR)cabW); + + WideCharToMultiByte(CP_ACP, 0, infoW.FullTargetName, -1, infoA->FullTargetName, + ARRAY_SIZE(infoA->FullTargetName), NULL, NULL); + + return ret; + } + case SPFILENOTIFY_FILEEXTRACTED: + { + const FILEPATHS_A *pathsA = (const FILEPATHS_A *)param1; + WCHAR targetW[MAX_PATH], sourceW[MAX_PATH]; + FILEPATHS_W pathsW = + { + .Target = targetW, + .Source = sourceW, + .Win32Error = pathsA->Win32Error, + .Flags = pathsA->Flags, + }; + + MultiByteToWideChar(CP_ACP, 0, pathsA->Target, -1, targetW, ARRAY_SIZE(targetW)); + MultiByteToWideChar(CP_ACP, 0, pathsA->Source, -1, sourceW, ARRAY_SIZE(sourceW)); + + return ctx->orig_cb(ctx->orig_ctx, message, (UINT_PTR)&pathsW, 0); + } + default: + FIXME("Unexpected callback %#x.\n", message); + return FALSE; + } +}
/*********************************************************************** - * SetupIterateCabinetW (SETUPAPI.@) + * SetupIterateCabinetW (SETUPAPI.@) */ -BOOL WINAPI SetupIterateCabinetW(PCWSTR CabinetFile, DWORD Reserved, - PSP_FILE_CALLBACK_W MsgHandler, PVOID Context) +BOOL WINAPI SetupIterateCabinetW(const WCHAR *fileW, DWORD reserved, + PSP_FILE_CALLBACK_W handler, void *context) { - CHAR pszCabinet[MAX_PATH], pszCabPath[MAX_PATH]; - UINT len; - SC_HSC_W my_hsc; - ERF erf; - WCHAR pszCabPathW[MAX_PATH], *p = NULL; - DWORD fpnsize; - BOOL ret; - - TRACE("(CabinetFile == %s, Reserved == %u, MsgHandler == ^%p, Context == ^%p)\n", - debugstr_w(CabinetFile), Reserved, MsgHandler, Context); - - if (!LoadCABINETDll()) - return FALSE; - - if (!CabinetFile) - { - SetLastError(ERROR_INVALID_PARAMETER); - return FALSE; - } + struct iterate_wtoa_ctx ctx = {handler, context}; + char fileA[MAX_PATH];
- fpnsize = GetFullPathNameW(CabinetFile, MAX_PATH, pszCabPathW, &p); - if (fpnsize > MAX_PATH) { - SetLastError(ERROR_BAD_PATHNAME); - return FALSE; - } + if (!WideCharToMultiByte(CP_ACP, 0, fileW, -1, fileA, ARRAY_SIZE(fileA), NULL, NULL)) + return FALSE;
- if (p) { - lstrcpyW(my_hsc.most_recent_cabinet_name, p); - *p = 0; - len = WideCharToMultiByte(CP_ACP, 0, pszCabPathW, -1, pszCabPath, - MAX_PATH, 0, 0); - if (!len) return FALSE; - } else { - lstrcpyW(my_hsc.most_recent_cabinet_name, CabinetFile); - pszCabPath[0] = '\0'; - } - - len = WideCharToMultiByte(CP_ACP, 0, my_hsc.most_recent_cabinet_name, -1, - pszCabinet, MAX_PATH, 0, 0); - if (!len) return FALSE; - - TRACE("path: %s, cabfile: %s\n", - debugstr_a(pszCabPath), debugstr_a(pszCabinet)); - - my_hsc.magic = SC_HSC_W_MAGIC; - my_hsc.msghandler = MsgHandler; - my_hsc.context = Context; - my_hsc.hfdi = sc_FDICreate( sc_cb_alloc, sc_cb_free, sc_cb_open, sc_cb_read, - sc_cb_write, sc_cb_close, sc_cb_lseek, cpuUNKNOWN, &erf ); - - if (!my_hsc.hfdi) return FALSE; - - ret = sc_FDICopy(my_hsc.hfdi, pszCabinet, pszCabPath, 0, sc_FNNOTIFY_W, NULL, &my_hsc); - - sc_FDIDestroy(my_hsc.hfdi); - return ret; + return SetupIterateCabinetA(fileA, reserved, iterate_wtoa_cb, &ctx); }
- /*********************************************************************** * DllMain *
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/setupapi/Makefile.in | 2 +- dlls/setupapi/setupcab.c | 36 +++--------------------------------- 2 files changed, 4 insertions(+), 34 deletions(-)
diff --git a/dlls/setupapi/Makefile.in b/dlls/setupapi/Makefile.in index 539bfed0caa..70ffd23d245 100644 --- a/dlls/setupapi/Makefile.in +++ b/dlls/setupapi/Makefile.in @@ -2,7 +2,7 @@ EXTRADEFS = -D_SETUPAPI_ MODULE = setupapi.dll IMPORTLIB = setupapi IMPORTS = uuid version advapi32 rpcrt4 kernelbase -DELAYIMPORTS = shell32 wintrust ole32 winspool.drv comdlg32 user32 +DELAYIMPORTS = cabinet shell32 wintrust ole32 winspool.drv comdlg32 user32
EXTRADLLFLAGS = -mno-cygwin
diff --git a/dlls/setupapi/setupcab.c b/dlls/setupapi/setupcab.c index 55d0fe6f64c..02245a10b7f 100644 --- a/dlls/setupapi/setupcab.c +++ b/dlls/setupapi/setupcab.c @@ -63,17 +63,8 @@
OSVERSIONINFOW OsVersionInfo;
-static HINSTANCE CABINET_hInstance = 0; HINSTANCE SETUPAPI_hInstance = 0;
-static HFDI (__cdecl *sc_FDICreate)(PFNALLOC, PFNFREE, PFNOPEN, - PFNREAD, PFNWRITE, PFNCLOSE, PFNSEEK, int, PERF); - -static BOOL (__cdecl *sc_FDICopy)(HFDI, char *, char *, int, - PFNFDINOTIFY, PFNFDIDECRYPT, void *); - -static BOOL (__cdecl *sc_FDIDestroy)(HFDI); - #define SC_HSC_A_MAGIC 0xACABFEED typedef struct { UINT magic; @@ -86,23 +77,6 @@ typedef struct {
WINE_DEFAULT_DEBUG_CHANNEL(setupapi);
-static BOOL LoadCABINETDll(void) -{ - if (!CABINET_hInstance) { - CABINET_hInstance = LoadLibraryA("cabinet.dll"); - if (CABINET_hInstance) { - sc_FDICreate = (void *)GetProcAddress(CABINET_hInstance, "FDICreate"); - sc_FDICopy = (void *)GetProcAddress(CABINET_hInstance, "FDICopy"); - sc_FDIDestroy = (void *)GetProcAddress(CABINET_hInstance, "FDIDestroy"); - return TRUE; - } else { - ERR("load cabinet dll failed.\n"); - return FALSE; - } - } else - return TRUE; -} - /* FDICreate callbacks */
static void * CDECL sc_cb_alloc(ULONG cb) @@ -392,9 +366,6 @@ BOOL WINAPI SetupIterateCabinetA(PCSTR CabinetFile, DWORD Reserved, TRACE("(CabinetFile == %s, Reserved == %u, MsgHandler == ^%p, Context == ^%p)\n", debugstr_a(CabinetFile), Reserved, MsgHandler, Context);
- if (!LoadCABINETDll()) - return FALSE; - if (!CabinetFile) { SetLastError(ERROR_INVALID_PARAMETER); @@ -429,14 +400,14 @@ BOOL WINAPI SetupIterateCabinetA(PCSTR CabinetFile, DWORD Reserved, my_hsc.magic = SC_HSC_A_MAGIC; my_hsc.msghandler = MsgHandler; my_hsc.context = Context; - my_hsc.hfdi = sc_FDICreate( sc_cb_alloc, sc_cb_free, sc_cb_open, sc_cb_read, + my_hsc.hfdi = FDICreate( sc_cb_alloc, sc_cb_free, sc_cb_open, sc_cb_read, sc_cb_write, sc_cb_close, sc_cb_lseek, cpuUNKNOWN, &erf );
if (!my_hsc.hfdi) return FALSE;
- ret = sc_FDICopy(my_hsc.hfdi, pszCabinet, pszCabPath, 0, sc_FNNOTIFY_A, NULL, &my_hsc); + ret = FDICopy(my_hsc.hfdi, pszCabinet, pszCabPath, 0, sc_FNNOTIFY_A, NULL, &my_hsc);
- sc_FDIDestroy(my_hsc.hfdi); + FDIDestroy(my_hsc.hfdi); return ret; }
@@ -572,7 +543,6 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) case DLL_PROCESS_DETACH: if (lpvReserved) break; SetupCloseLog(); - if (CABINET_hInstance) FreeLibrary(CABINET_hInstance); break; }
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/setupapi/setupcab.c | 128 +++++++++------------------------------ 1 file changed, 29 insertions(+), 99 deletions(-)
diff --git a/dlls/setupapi/setupcab.c b/dlls/setupapi/setupcab.c index 02245a10b7f..e98178ff045 100644 --- a/dlls/setupapi/setupcab.c +++ b/dlls/setupapi/setupcab.c @@ -16,11 +16,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA - * - * - * Many useful traces are commented in code, uncomment them if you have - * trouble and run with WINEDEBUG=+setupapi - * */
#include <stdarg.h> @@ -77,8 +72,6 @@ typedef struct {
WINE_DEFAULT_DEBUG_CHANNEL(setupapi);
-/* FDICreate callbacks */ - static void * CDECL sc_cb_alloc(ULONG cb) { return HeapAlloc(GetProcessHeap(), 0, cb); @@ -93,11 +86,8 @@ static INT_PTR CDECL sc_cb_open(char *pszFile, int oflag, int pmode) { DWORD creation = 0, sharing = 0; int ioflag = 0; - INT_PTR ret = 0; SECURITY_ATTRIBUTES sa;
- /* TRACE("(pszFile == %s, oflag == %d, pmode == %d)\n", debugstr_a(pszFile), oflag, pmode); */ - switch(oflag & (_O_RDONLY | _O_WRONLY | _O_RDWR)) { case _O_RDONLY: ioflag |= GENERIC_READ; @@ -120,7 +110,7 @@ static INT_PTR CDECL sc_cb_open(char *pszFile, int oflag, int pmode) creation = CREATE_ALWAYS; else creation = OPEN_ALWAYS; - } else /* no _O_CREAT */ { + } else { if (oflag & _O_TRUNC) creation = TRUNCATE_EXISTING; else @@ -146,90 +136,52 @@ static INT_PTR CDECL sc_cb_open(char *pszFile, int oflag, int pmode) return -1; }
- if (oflag & ~(_O_BINARY | _O_TRUNC | _O_EXCL | _O_CREAT | _O_RDWR | _O_WRONLY | _O_NOINHERIT)) - WARN("unsupported oflag 0x%04x\n",oflag); - sa.nLength = sizeof( SECURITY_ATTRIBUTES ); sa.lpSecurityDescriptor = NULL; sa.bInheritHandle = !(ioflag & _O_NOINHERIT);
- ret = (INT_PTR) CreateFileA(pszFile, ioflag, sharing, &sa, creation, FILE_ATTRIBUTE_NORMAL, NULL); - - /* TRACE("<-- %d\n", ret); */ - - return ret; + return (INT_PTR) CreateFileA(pszFile, ioflag, sharing, &sa, creation, FILE_ATTRIBUTE_NORMAL, NULL); }
static UINT CDECL sc_cb_read(INT_PTR hf, void *pv, UINT cb) { - DWORD num_read; - BOOL rslt; + DWORD num_read;
- /* TRACE("(hf == %d, pv == ^%p, cb == %u)\n", hf, pv, cb); */ - - rslt = ReadFile((HANDLE) hf, pv, cb, &num_read, NULL); - - - /* eof and failure both give "-1" return */ - if ((! rslt) || ((cb > 0) && (num_read == 0))) { - /* TRACE("<-- -1\n"); */ - return -1; - } - - /* TRACE("<-- %lu\n", num_read); */ - return num_read; + if (!ReadFile((HANDLE)hf, pv, cb, &num_read, NULL)) + return -1; + return num_read; }
static UINT CDECL sc_cb_write(INT_PTR hf, void *pv, UINT cb) { - DWORD num_written; - /* BOOL rv; */ - - /* TRACE("(hf == %d, pv == ^%p, cb == %u)\n", hf, pv, cb); */ + DWORD num_written;
- if ( /* (rv = */ WriteFile((HANDLE) hf, pv, cb, &num_written, NULL) /* ) */ - && (num_written == cb)) { - /* TRACE("<-- %lu\n", num_written); */ + if (!WriteFile((HANDLE)hf, pv, cb, &num_written, NULL)) + return -1; return num_written; - } else { - /* TRACE("rv == %d, num_written == %lu, cb == %u\n", rv, num_written,cb); */ - /* TRACE("<-- -1\n"); */ - return -1; - } }
static int CDECL sc_cb_close(INT_PTR hf) { - /* TRACE("(hf == %d)\n", hf); */ - - if (CloseHandle((HANDLE) hf)) + if (!CloseHandle((HANDLE)hf)) + return -1; return 0; - else - return -1; }
static LONG CDECL sc_cb_lseek(INT_PTR hf, LONG dist, int seektype) { - DWORD ret; - - /* TRACE("(hf == %d, dist == %ld, seektype == %d)\n", hf, dist, seektype); */ + DWORD ret;
- if (seektype < 0 || seektype > 2) - return -1; + if (seektype < 0 || seektype > 2) + return -1;
- if (((ret = SetFilePointer((HANDLE) hf, dist, NULL, seektype)) != INVALID_SET_FILE_POINTER) || !GetLastError()) { - /* TRACE("<-- %lu\n", ret); */ + if (((ret = SetFilePointer((HANDLE)hf, dist, NULL, seektype)) == INVALID_SET_FILE_POINTER) && GetLastError()) + return -1; return ret; - } else { - /* TRACE("<-- -1\n"); */ - return -1; - } }
#define SIZEOF_MYSTERIO (MAX_PATH*3)
-/* FDICopy callbacks */ - static INT_PTR CDECL sc_FNNOTIFY_A(FDINOTIFICATIONTYPE fdint, PFDINOTIFICATION pfdin) { FILE_IN_CABINET_INFO_A fici; @@ -242,8 +194,6 @@ static INT_PTR CDECL sc_FNNOTIFY_A(FDINOTIFICATIONTYPE fdint, PFDINOTIFICATION p
memset(mysterio, 0, SIZEOF_MYSTERIO);
- TRACE("(fdint == %d, pfdin == ^%p)\n", fdint, pfdin); - if (pfdin && pfdin->pv && (((PSC_HSC_A) pfdin->pv)->magic == SC_HSC_A_MAGIC)) phsc = pfdin->pv; else { @@ -253,13 +203,8 @@ static INT_PTR CDECL sc_FNNOTIFY_A(FDINOTIFICATIONTYPE fdint, PFDINOTIFICATION p
switch (fdint) { case fdintCABINET_INFO: - TRACE("Cabinet info notification\n"); - /* TRACE(" Cabinet name: %s\n", debugstr_a(pfdin->psz1)); - TRACE(" Cabinet disk: %s\n", debugstr_a(pfdin->psz2)); - TRACE(" Cabinet path: %s\n", debugstr_a(pfdin->psz3)); - TRACE(" Cabinet Set#: %d\n", pfdin->setID); - TRACE(" Cabinet Cab#: %d\n", pfdin->iCabinet); */ - WARN("SPFILENOTIFY_CABINETINFO undocumented: guess implementation.\n"); + TRACE("New cabinet, path %s, set %u, number %u, next disk %s.\n", + debugstr_a(pfdin->psz3), pfdin->setID, pfdin->iCabinet, debugstr_a(pfdin->psz2)); ci.CabinetFile = phsc->most_recent_cabinet_name; ci.CabinetPath = pfdin->psz3; ci.DiskName = pfdin->psz2; @@ -268,16 +213,10 @@ static INT_PTR CDECL sc_FNNOTIFY_A(FDINOTIFICATIONTYPE fdint, PFDINOTIFICATION p phsc->msghandler(phsc->context, SPFILENOTIFY_CABINETINFO, (UINT_PTR) &ci, 0); return 0; case fdintPARTIAL_FILE: - TRACE("Partial file notification\n"); - /* TRACE(" Partial file name: %s\n", debugstr_a(pfdin->psz1)); */ return 0; case fdintCOPY_FILE: - TRACE("Copy file notification\n"); - TRACE(" File name: %s\n", debugstr_a(pfdin->psz1)); - /* TRACE(" File size: %ld\n", pfdin->cb); - TRACE(" File date: %u\n", pfdin->date); - TRACE(" File time: %u\n", pfdin->time); - TRACE(" File attr: %u\n", pfdin->attribs); */ + TRACE("Copy file %s, length %d, date %#x, time %#x, attributes %#x.\n", + debugstr_a(pfdin->psz1), pfdin->cb, pfdin->date, pfdin->time, pfdin->attribs); fici.NameInCabinet = pfdin->psz1; fici.FileSize = pfdin->cb; fici.Win32Error = 0; @@ -288,31 +227,26 @@ static INT_PTR CDECL sc_FNNOTIFY_A(FDINOTIFICATIONTYPE fdint, PFDINOTIFICATION p err = phsc->msghandler(phsc->context, SPFILENOTIFY_FILEINCABINET, (UINT_PTR)&fici, (UINT_PTR)pfdin->psz1); if (err == FILEOP_DOIT) { - TRACE(" Callback specified filename: %s\n", debugstr_a(fici.FullTargetName)); + TRACE("Callback specified filename: %s\n", debugstr_a(fici.FullTargetName)); if (!fici.FullTargetName[0]) { - WARN(" Empty return string causing abort.\n"); + WARN("Empty return string causing abort.\n"); SetLastError(ERROR_PATH_NOT_FOUND); return -1; } strcpy( phsc->most_recent_target, fici.FullTargetName ); return sc_cb_open(fici.FullTargetName, _O_BINARY | _O_CREAT | _O_WRONLY, _S_IREAD | _S_IWRITE); } else { - TRACE(" Callback skipped file.\n"); + TRACE("Callback skipped file.\n"); return 0; } case fdintCLOSE_FILE_INFO: - TRACE("Close file notification\n"); - /* TRACE(" File name: %s\n", debugstr_a(pfdin->psz1)); - TRACE(" Exec file? %s\n", (pfdin->cb) ? "Yes" : "No"); - TRACE(" File hndl: %d\n", pfdin->hf); */ + TRACE("File extracted.\n"); fp.Source = phsc->most_recent_cabinet_name; fp.Target = phsc->most_recent_target; fp.Win32Error = 0; fp.Flags = 0; - /* the following should be a fixme -- but it occurs too many times */ - WARN("Should set file date/time/attribs (and execute files?)\n"); - if (sc_cb_close(pfdin->hf)) - WARN("_close failed.\n"); + /* FIXME: set file time and attributes */ + sc_cb_close(pfdin->hf); err = phsc->msghandler(phsc->context, SPFILENOTIFY_FILEEXTRACTED, (UINT_PTR)&fp, 0); if (err) { SetLastError(err); @@ -320,18 +254,14 @@ static INT_PTR CDECL sc_FNNOTIFY_A(FDINOTIFICATIONTYPE fdint, PFDINOTIFICATION p } else return TRUE; case fdintNEXT_CABINET: - TRACE("Next cabinet notification\n"); - /* TRACE(" Cabinet name: %s\n", debugstr_a(pfdin->psz1)); - TRACE(" Cabinet disk: %s\n", debugstr_a(pfdin->psz2)); - TRACE(" Cabinet path: %s\n", debugstr_a(pfdin->psz3)); - TRACE(" Cabinet Set#: %d\n", pfdin->setID); - TRACE(" Cabinet Cab#: %d\n", pfdin->iCabinet); */ + TRACE("Need new cabinet, path %s, file %s, disk %s, set %u, number %u.\n", + debugstr_a(pfdin->psz3), debugstr_a(pfdin->psz1), + debugstr_a(pfdin->psz2), pfdin->setID, pfdin->iCabinet); ci.CabinetFile = pfdin->psz1; ci.CabinetPath = pfdin->psz3; ci.DiskName = pfdin->psz2; ci.SetId = pfdin->setID; ci.CabinetNumber = pfdin->iCabinet; - /* remember the new cabinet name */ strcpy(phsc->most_recent_cabinet_name, pfdin->psz1); err = phsc->msghandler(phsc->context, SPFILENOTIFY_NEEDNEWCABINET, (UINT_PTR)&ci, (UINT_PTR)mysterio); if (err) {
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/setupapi/setupcab.c | 23 +---------------------- 1 file changed, 1 insertion(+), 22 deletions(-)
diff --git a/dlls/setupapi/setupcab.c b/dlls/setupapi/setupcab.c index e98178ff045..675a1923071 100644 --- a/dlls/setupapi/setupcab.c +++ b/dlls/setupapi/setupcab.c @@ -38,16 +38,11 @@ #define _O_WRONLY 1 #define _O_RDWR 2 #define _O_ACCMODE (_O_RDONLY|_O_WRONLY|_O_RDWR) -#define _O_APPEND 0x0008 -#define _O_RANDOM 0x0010 -#define _O_SEQUENTIAL 0x0020 #define _O_TEMPORARY 0x0040 #define _O_NOINHERIT 0x0080 #define _O_CREAT 0x0100 #define _O_TRUNC 0x0200 #define _O_EXCL 0x0400 -#define _O_SHORT_LIVED 0x1000 -#define _O_TEXT 0x4000 #define _O_BINARY 0x8000
#define _SH_COMPAT 0x00 @@ -60,9 +55,7 @@ OSVERSIONINFOW OsVersionInfo;
HINSTANCE SETUPAPI_hInstance = 0;
-#define SC_HSC_A_MAGIC 0xACABFEED typedef struct { - UINT magic; HFDI hfdi; PSP_FILE_CALLBACK_A msghandler; PVOID context; @@ -98,9 +91,6 @@ static INT_PTR CDECL sc_cb_open(char *pszFile, int oflag, int pmode) case _O_RDWR: ioflag |= GENERIC_READ | GENERIC_WRITE; break; - case _O_WRONLY | _O_RDWR: /* hmmm.. */ - ERR("_O_WRONLY & _O_RDWR in oflag?\n"); - return -1; }
if (oflag & _O_CREAT) { @@ -131,9 +121,6 @@ static INT_PTR CDECL sc_cb_open(char *pszFile, int oflag, int pmode) case _SH_DENYNO: sharing = FILE_SHARE_READ | FILE_SHARE_WRITE; break; - default: - ERR("<-- -1 (Unhandled pmode 0x%x)\n", pmode); - return -1; }
sa.nLength = sizeof( SECURITY_ATTRIBUTES ); @@ -185,7 +172,7 @@ static LONG CDECL sc_cb_lseek(INT_PTR hf, LONG dist, int seektype) static INT_PTR CDECL sc_FNNOTIFY_A(FDINOTIFICATIONTYPE fdint, PFDINOTIFICATION pfdin) { FILE_IN_CABINET_INFO_A fici; - PSC_HSC_A phsc; + PSC_HSC_A phsc = pfdin->pv; CABINET_INFO_A ci; FILEPATHS_A fp; UINT err; @@ -194,13 +181,6 @@ static INT_PTR CDECL sc_FNNOTIFY_A(FDINOTIFICATIONTYPE fdint, PFDINOTIFICATION p
memset(mysterio, 0, SIZEOF_MYSTERIO);
- if (pfdin && pfdin->pv && (((PSC_HSC_A) pfdin->pv)->magic == SC_HSC_A_MAGIC)) - phsc = pfdin->pv; - else { - ERR("pv %p is not an SC_HSC_A.\n", (pfdin) ? pfdin->pv : NULL); - return -1; - } - switch (fdint) { case fdintCABINET_INFO: TRACE("New cabinet, path %s, set %u, number %u, next disk %s.\n", @@ -327,7 +307,6 @@ BOOL WINAPI SetupIterateCabinetA(PCSTR CabinetFile, DWORD Reserved, /* remember the cabinet name */ strcpy(my_hsc.most_recent_cabinet_name, pszCabinet);
- my_hsc.magic = SC_HSC_A_MAGIC; my_hsc.msghandler = MsgHandler; my_hsc.context = Context; my_hsc.hfdi = FDICreate( sc_cb_alloc, sc_cb_free, sc_cb_open, sc_cb_read,
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/setupapi/setupcab.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/dlls/setupapi/setupcab.c b/dlls/setupapi/setupcab.c index 675a1923071..e041dd965e3 100644 --- a/dlls/setupapi/setupcab.c +++ b/dlls/setupapi/setupcab.c @@ -56,7 +56,6 @@ OSVERSIONINFOW OsVersionInfo; HINSTANCE SETUPAPI_hInstance = 0;
typedef struct { - HFDI hfdi; PSP_FILE_CALLBACK_A msghandler; PVOID context; CHAR most_recent_cabinet_name[MAX_PATH]; @@ -271,6 +270,7 @@ BOOL WINAPI SetupIterateCabinetA(PCSTR CabinetFile, DWORD Reserved, ERF erf; CHAR pszCabinet[MAX_PATH], pszCabPath[MAX_PATH], *p = NULL; DWORD fpnsize; + HFDI hfdi; BOOL ret;
TRACE("(CabinetFile == %s, Reserved == %u, MsgHandler == ^%p, Context == ^%p)\n", @@ -309,14 +309,14 @@ BOOL WINAPI SetupIterateCabinetA(PCSTR CabinetFile, DWORD Reserved,
my_hsc.msghandler = MsgHandler; my_hsc.context = Context; - my_hsc.hfdi = FDICreate( sc_cb_alloc, sc_cb_free, sc_cb_open, sc_cb_read, - sc_cb_write, sc_cb_close, sc_cb_lseek, cpuUNKNOWN, &erf ); + hfdi = FDICreate(sc_cb_alloc, sc_cb_free, sc_cb_open, sc_cb_read, + sc_cb_write, sc_cb_close, sc_cb_lseek, cpuUNKNOWN, &erf);
- if (!my_hsc.hfdi) return FALSE; + if (!hfdi) return FALSE;
- ret = FDICopy(my_hsc.hfdi, pszCabinet, pszCabPath, 0, sc_FNNOTIFY_A, NULL, &my_hsc); + ret = FDICopy(hfdi, pszCabinet, pszCabPath, 0, sc_FNNOTIFY_A, NULL, &my_hsc);
- FDIDestroy(my_hsc.hfdi); + FDIDestroy(hfdi); return ret; }