[RAPPS] Add directory extraction capabilities for the .cab file

This commit is contained in:
Mark Jansen 2020-09-06 23:14:11 +02:00
parent 4f25a47677
commit a3a12271e1
No known key found for this signature in database
GPG key ID: B39240EE84BEAE8B

View file

@ -5,6 +5,7 @@
* COPYRIGHT: Copyright 2018 Alexander Shaposhnikov (sanchaez@reactos.org)
*/
#include "rapps.h"
#include <debug.h>
#include <fdi.h>
#include <fcntl.h>
@ -178,18 +179,42 @@ FNFDINOTIFY(fnNotify)
{
case fdintCOPY_FILE:
{
ATL::CStringW szNewFileName, szExtractDir, szCabFileName;
ATL::CStringA szFilePathUTF8;
CStringW szExtractDir, szCabFileName;
// Append the destination directory to the file name.
MultiByteToWide((LPCSTR) pfdin->pv, szExtractDir, CP_UTF8);
MultiByteToWide(pfdin->psz1, szCabFileName, CP_ACP);
szNewFileName = szExtractDir + L"\\" + szCabFileName;
if (szCabFileName.Find('\\') >= 0)
{
CStringW szNewDirName = szExtractDir;
int nTokenPos = 0;
// We do not want to interpret the filename as directory,
// so bail out before the last token!
while (szCabFileName.Find('\\', nTokenPos) >= 0)
{
CStringW token = szCabFileName.Tokenize(L"\\", nTokenPos);
if (token.IsEmpty())
break;
szNewDirName += L"\\" + token;
if (!CreateDirectoryW(szNewDirName, NULL))
{
DWORD dwErr = GetLastError();
if (dwErr != ERROR_ALREADY_EXISTS)
{
DPRINT1("ERROR: Unable to create directory %S (err %lu)\n", szNewDirName.GetString(), dwErr);
}
}
}
}
CStringW szNewFileName = szExtractDir + L"\\" + szCabFileName;
CStringA szFilePathUTF8;
WideToMultiByte(szNewFileName, szFilePathUTF8, CP_UTF8);
// Copy file
// Open the file
iResult = fnFileOpen((LPSTR) szFilePathUTF8.GetString(),
_O_WRONLY | _O_CREAT,
0);