[RAPPS] Don't delete downloaded ZIP/CAB even if configured to (#7791)

This commit is contained in:
Whindmar Saksit 2025-03-20 14:32:07 +01:00 committed by GitHub
parent 7f49ae633b
commit 7dc7b866b1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 78 additions and 3 deletions

View file

@ -119,6 +119,59 @@ ShowPopupMenuEx(HWND hwnd, HWND hwndOwner, UINT MenuID, UINT DefaultItem, POINT
}
}
extern BOOL IsZipFile(PCWSTR Path);
UINT
ClassifyFile(PCWSTR Path)
{
const UINT share = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
HANDLE hFile = CreateFileW(Path, GENERIC_READ, share, NULL, OPEN_EXISTING, 0, NULL);
if (hFile != INVALID_HANDLE_VALUE)
{
BYTE buf[8];
DWORD io;
if (!ReadFile(hFile, buf, sizeof(buf), &io, NULL) || io != sizeof(buf))
buf[0] = 0;
CloseHandle(hFile);
if (buf[0] == 0xD0 && buf[1] == 0xCF && buf[2] == 0x11 && buf[3] == 0xE0 &&
buf[4] == 0xA1 && buf[5] == 0xB1 && buf[6] == 0x1A && buf[7] == 0xE1)
{
return MAKEWORD('M', PERCEIVED_TYPE_APPLICATION); // MSI
}
if (buf[0] == 'M' || buf[0] == 'Z')
{
SHFILEINFO shfi;
if (SHGetFileInfoW(Path, 0, &shfi, sizeof(shfi), SHGFI_EXETYPE))
return MAKEWORD('E', PERCEIVED_TYPE_APPLICATION);
}
if (buf[0] == 'M' && buf[1] == 'S' && buf[2] == 'C' && buf[3] == 'F')
{
return MAKEWORD('C', PERCEIVED_TYPE_COMPRESSED); // CAB
}
}
if (IsZipFile(Path)) // .zip last because we want to return SFX.exe with higher priority
{
return MAKEWORD('Z', PERCEIVED_TYPE_COMPRESSED);
}
return PERCEIVED_TYPE_UNKNOWN;
}
BOOL
OpensWithExplorer(PCWSTR Path)
{
WCHAR szCmd[MAX_PATH * 2];
DWORD cch = _countof(szCmd);
PCWSTR pszExt = PathFindExtensionW(Path);
HRESULT hr = AssocQueryStringW(ASSOCF_INIT_IGNOREUNKNOWN | ASSOCF_NOTRUNCATE,
ASSOCSTR_COMMAND, pszExt, NULL, szCmd, &cch);
if (SUCCEEDED(hr) && StrStrIW(szCmd, L" zipfldr.dll,")) // .zip
return TRUE;
PathRemoveArgsW(szCmd);
return SUCCEEDED(hr) && !StrCmpIW(PathFindFileNameW(szCmd), L"explorer.exe"); // .cab
}
BOOL
StartProcess(const CStringW &Path, BOOL Wait)
{