MCPcopy Create free account
hub / github.com/bailey27/cppcryptfs / transform_path

Function transform_path

cppcryptfs/dokan/cryptdokan.cpp:2501–2572  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2499}
2500
2501wstring transform_path(const wchar_t* path, wstring& mes)
2502{
2503 vector<CryptThreadData*> tdatas;
2504
2505 const auto fetch = [&tdatas](const wchar_t* p, CryptThreadData* td) -> bool {
2506 tdatas.push_back(td);
2507 return true;
2508 };
2509
2510 MountPointManager::getInstance().apply(fetch);
2511
2512 _locale_t locale = _create_locale(LC_ALL, "");
2513
2514 if (locale == NULL) {
2515 mes = LocUtils::GetStringFromResources(IDS_CANNOT_CREATE_LOCALE);
2516 return nullptr;
2517 }
2518
2519 bool encrypted = false;
2520
2521 CryptThreadData* tdata = nullptr;
2522 for (auto td : tdatas) {
2523 auto mp = td->mountpoint.c_str();
2524 if (!_wcsnicmp_l(mp, path, wcslen(mp), locale)) {
2525 tdata = td;
2526 encrypted = false;
2527 break;
2528 } else if (!_wcsnicmp_l(td->con.GetConfig()->m_basedir.c_str(), (wstring(L"\\\\?\\") + path).c_str(), wcslen(td->con.GetConfig()->m_basedir.c_str()), locale)) {
2529 tdata = td;
2530 encrypted = true;
2531 break;
2532 }
2533 }
2534
2535 _free_locale(locale);
2536
2537 if (!tdata) {
2538 mes = LocUtils::GetStringFromResources(IDS_NOT_FOUND_MPOINT_BASE_DIR);
2539 return L"";
2540 }
2541
2542 wstring storage;
2543 if (encrypted) {
2544 auto p = path + tdata->con.GetConfig()->m_basedir.length() - (std::size(L"\\\\?\\") - 1);
2545
2546 if (tdata->con.GetConfig()->m_reverse) {
2547 if (!encrypt_path(&tdata->con, p, storage)) {
2548 mes = LocUtils::GetStringFromResources(IDS_FAILED_CONVERT_PATH);
2549 return L"";
2550 }
2551 } else {
2552 if (!unencrypt_path(&tdata->con, p, storage)) {
2553 mes = LocUtils::GetStringFromResources(IDS_FAILED_UNENCRYPT_PATH);
2554 return L"";
2555 }
2556 }
2557 return tdata->mountpoint + storage;
2558 } else {

Callers 1

ProcessCommandLineMethod · 0.85

Calls 4

encrypt_pathFunction · 0.85
unencrypt_pathFunction · 0.85
applyMethod · 0.80
GetConfigMethod · 0.80

Tested by

no test coverage detected