Skip to content

Commit

Permalink
when synching using 7z extension, detect 'real' 7z files that are syn…
Browse files Browse the repository at this point in the history
…ched

closes #70
  • Loading branch information
stefankueng committed Sep 28, 2021
1 parent 84e28b1 commit 9334945
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/FolderSync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,29 @@ std::map<std::wstring, FileData, ci_lessW> CFolderSync::GetFileList(bool orig, c
fd.filenameEncrypted = (_wcsicmp(decryptedRelPath.c_str(), fd.fileRelPath.c_str()) != 0);
if (fd.filenameEncrypted)
{
relPath = decryptedRelPath;
if (use7Z && !orig)
{
// if we use .7z as the file extension and the user tries to sync her/his own .7z files,
// we have to detect that here
auto lastDotPos = filePath.rfind('.');
if (lastDotPos != std::wstring::npos)
{
if (_wcsicmp(filePath.substr(lastDotPos + 1).c_str(), L"7z") == 0)
{
auto preLastDotPos = filePath.rfind('.', lastDotPos - 1);
if (preLastDotPos != std::wstring::npos)
relPath = decryptedRelPath;
else if (encnames && decryptedRelPath != relPath)
relPath = decryptedRelPath;
}
else
relPath = decryptedRelPath;
}
else
relPath = decryptedRelPath;
}
else
relPath = decryptedRelPath;
}

fileList[relPath] = fd;
Expand Down Expand Up @@ -1278,7 +1300,7 @@ std::wstring CFolderSync::GetDecryptedFilename(const std::wstring& filename, con
uint8_t* cDecoded = nullptr;
if (base4k::base4KDecode(reinterpret_cast<const uint16_t*>(it->data()), &ccData, &cDecoded) == base4k::B4K_SUCCESS)
{
memcpy(buffer.get(), cDecoded, ccData+1);
memcpy(buffer.get(), cDecoded, ccData + 1);
CryptDecrypt(hKey, 0, true, 0, static_cast<BYTE*>(buffer.get()), &dwLength);
decryptName = CUnicodeUtils::StdGetUnicode(std::string(reinterpret_cast<char*>(buffer.get()), ccData));
}
Expand Down

0 comments on commit 9334945

Please sign in to comment.