From: Serge Gautherie Date: Fri, 9 Dec 2016 12:41:27 +0100 Subject: [SETUPAPI] queue.c, do_file_copyW(), CORE-10000 compressed file support: Add "#ifdef __REACTOS__", Check return values. CORE-12542 diff --git a/reactos/dll/win32/setupapi/queue.c b/reactos/dll/win32/setupapi/queue.c index 9d1e5b2..5e47dc4 100644 --- a/reactos/dll/win32/setupapi/queue.c +++ b/reactos/dll/win32/setupapi/queue.c @@ -987,26 +987,60 @@ static BOOL do_file_copyW( LPCWSTR source, LPCWSTR target, DWORD style, { BOOL rc = FALSE; BOOL docopy = TRUE; - WCHAR TempFile[MAX_PATH]; - INT hSource, hTemp; - OFSTRUCT OfStruct; - WCHAR TempPath[MAX_PATH]; +#ifdef __REACTOS__ + /* Past CORE-10000, current CORE-12542 and future wine-staging 568: support compressed files. */ + DWORD gtpw_length; + HFILE hsource, htemp; + LONG lzc_length; + OFSTRUCT dumb_ofstruct; + WCHAR temp_file[MAX_PATH], temp_path[MAX_PATH]; +#endif TRACE("copy %s to %s style 0x%x\n",debugstr_w(source),debugstr_w(target),style); - hSource = LZOpenFileW((LPWSTR)source, &OfStruct, OF_READ); - if (hSource < 0) +#ifdef __REACTOS__ + if ((hsource = LZOpenFileW((LPWSTR)source, &dumb_ofstruct, OF_READ)) < 0) + { + ERR("LZOpenFileW() failed: %d %s\n", hsource, debugstr_w(source)); return FALSE; + } /* Get a temp file name */ - GetTempPathW(sizeof(TempPath) / sizeof(WCHAR), TempPath); - GetTempFileNameW(TempPath, L"", 0, TempFile); + gtpw_length = GetTempPathW(sizeof(temp_path) / sizeof(temp_path[0]), temp_path); + if (gtpw_length == 0 || gtpw_length > sizeof(temp_path) / sizeof(temp_path[0])) + { + ERR("GetTempPathW() failed: %d %s\n", gtpw_length, GetLastError()); + LZClose(hsource); + return FALSE; + } + if (GetTempFileNameW(temp_path, NULL, 0, temp_file) == 0) + { + ERR("GetTempFileNameW() failed: %s %s\n", debugstr_w(temp_path), GetLastError()); + LZClose(hsource); + return FALSE; + } + + if ((htemp = LZOpenFileW(temp_file, &dumb_ofstruct, OF_CREATE)) < 0) + { + ERR("LZOpenFileW() failed: %d %s\n", htemp, debugstr_w(temp_file)); + DeleteFileW(temp_file); + LZClose(hsource); + return FALSE; + } /* Extract the compressed file to a temp location */ - hTemp = LZOpenFileW(TempFile, &OfStruct, OF_CREATE); - LZCopy(hSource, hTemp); - LZClose(hSource); - LZClose(hTemp); + lzc_length = LZCopy(hsource, htemp); + + LZClose(htemp); + LZClose(hsource); + + if (lzc_length < 0) + { + ERR("LZCopy() failed: %d %s -> %s\n", lzc_length, debugstr_w(source), debugstr_w(temp_file)); + DeleteFileW(temp_file); + return FALSE; + } +#endif /* before copy processing */ if (style & SP_COPY_REPLACEONLY) @@ -1030,12 +1064,21 @@ static BOOL do_file_copyW( LPCWSTR source, LPCWSTR target, DWORD style, * So I will test for the existence of the files first so that * we just basically unconditionally replace the builtin versions. */ +#ifdef __REACTOS__ if ((GetFileAttributesW(target) != INVALID_FILE_ATTRIBUTES) && - (GetFileAttributesW(TempFile) != INVALID_FILE_ATTRIBUTES)) + (GetFileAttributesW(temp_file) != INVALID_FILE_ATTRIBUTES)) { - VersionSizeSource = GetFileVersionInfoSizeW(TempFile,&zero); + VersionSizeSource = GetFileVersionInfoSizeW(temp_file, &zero); + VersionSizeTarget = GetFileVersionInfoSizeW((LPWSTR)target, &zero); + } +#else + if ((GetFileAttributesW(target) != INVALID_FILE_ATTRIBUTES) && + (GetFileAttributesW(source) != INVALID_FILE_ATTRIBUTES)) + { + VersionSizeSource = GetFileVersionInfoSizeW((LPWSTR)source,&zero); VersionSizeTarget = GetFileVersionInfoSizeW((LPWSTR)target,&zero); } +#endif TRACE("SizeTarget %i ... SizeSource %i\n",VersionSizeTarget, VersionSizeSource); @@ -1053,7 +1096,11 @@ static BOOL do_file_copyW( LPCWSTR source, LPCWSTR target, DWORD style, VersionSource = HeapAlloc(GetProcessHeap(),0,VersionSizeSource); VersionTarget = HeapAlloc(GetProcessHeap(),0,VersionSizeTarget); - ret = GetFileVersionInfoW(TempFile,0,VersionSizeSource,VersionSource); +#ifdef __REACTOS__ + ret = GetFileVersionInfoW(temp_file, 0, VersionSizeSource, VersionSource); +#else + ret = GetFileVersionInfoW((LPWSTR)source,0,VersionSizeSource,VersionSource); +#endif if (ret) ret = GetFileVersionInfoW((LPWSTR)target, 0, VersionSizeTarget, VersionTarget); @@ -1128,14 +1175,30 @@ static BOOL do_file_copyW( LPCWSTR source, LPCWSTR target, DWORD style, if (docopy) { - rc = MoveFileExW(TempFile,target,MOVEFILE_REPLACE_EXISTING); +#ifdef __REACTOS__ + rc = MoveFileExW(temp_file, target, MOVEFILE_REPLACE_EXISTING); + if (!rc) + DeleteFileW(temp_file); +#else + rc = CopyFileW(source,target,FALSE); +#endif TRACE("Did copy... rc was %i\n",rc); } +#ifdef __REACTOS__ + else + { + DeleteFileW(temp_file); + } +#endif /* after copy processing */ if (style & SP_COPY_DELETESOURCE) { +#ifdef __REACTOS__ + if (rc) +#else if (rc) +#endif DeleteFileW(source); } diff --git a/reactos/dll/win32/setupapi/setupapi_private.h b/reactos/dll/win32/setupapi/setupapi_private.h index 8bb89b5..6a51f22 100644 --- a/reactos/dll/win32/setupapi/setupapi_private.h +++ b/reactos/dll/win32/setupapi/setupapi_private.h @@ -45,7 +45,9 @@ #include #include #include +#ifdef __REACTOS__ #include +#endif #include #include #define NTOS_MODE_USER