[RAPPS] Replace Extract with FDI for handling .cab

FDI allows to have user-defined callbacks for file handling.
Since it doesn't provide support for Unicode we convert strings to
multi-byte UTF-8 and handle them appropriately in the callbacks. They
are properly null-terminated so FDI won't choke when doing operations
with strings.

Thanks to hbelusca and mjansen for the help.

CORE-14466
This commit is contained in:
Alexander Shaposhnikov 2018-02-25 15:20:00 +02:00
parent 602db40277
commit 9591550116
No known key found for this signature in database
GPG key ID: 2BC6459908479EFC
7 changed files with 348 additions and 90 deletions

View file

@ -11,11 +11,6 @@
#include "gui.h"
#include "misc.h"
#include "cabinet.h"
/* SESSION Operation */
#define EXTRACT_FILLFILELIST 0x00000001
#define EXTRACT_EXTRACTFILES 0x00000002
static HANDLE hLog = NULL;
@ -203,55 +198,6 @@ BOOL GetStorageDirectory(ATL::CStringW& Directory)
return (CreateDirectoryW(Directory.GetString(), NULL) || GetLastError() == ERROR_ALREADY_EXISTS);
}
BOOL ExtractFilesFromCab(const ATL::CStringW &CabName, const ATL::CStringW &OutputPath)
{
return ExtractFilesFromCab(CabName.GetString(), OutputPath.GetString());
}
BOOL ExtractFilesFromCab(LPCWSTR lpCabName, LPCWSTR lpOutputPath)
{
HINSTANCE hCabinetDll;
CHAR szCabName[MAX_PATH];
SESSION Dest;
HRESULT Result;
fnExtract pfnExtract;
hCabinetDll = LoadLibraryW(L"cabinet.dll");
if (hCabinetDll)
{
pfnExtract = (fnExtract) GetProcAddress(hCabinetDll, "Extract");
if (pfnExtract)
{
ZeroMemory(&Dest, sizeof(Dest));
WideCharToMultiByte(CP_ACP, 0, lpOutputPath, -1, Dest.Destination, MAX_PATH, NULL, NULL);
WideCharToMultiByte(CP_ACP, 0, lpCabName, -1, szCabName, _countof(szCabName), NULL, NULL);
Dest.Operation = EXTRACT_FILLFILELIST;
Result = pfnExtract(&Dest, szCabName);
if (Result == S_OK)
{
Dest.Operation = EXTRACT_EXTRACTFILES;
CreateDirectoryW(lpOutputPath, NULL);
Result = pfnExtract(&Dest, szCabName);
if (Result == S_OK)
{
FreeLibrary(hCabinetDll);
return TRUE;
}
else
{
RemoveDirectoryW(lpOutputPath);
}
}
}
FreeLibrary(hCabinetDll);
}
return FALSE;
}
VOID InitLogs()
{
if (!SettingsInfo.bLogEnabled)