| 481 | } |
| 482 | |
| 483 | DWORD WINAPI ExplorerMonitorThread(LPVOID lpvParam) |
| 484 | { |
| 485 | auto bThreadRun = static_cast<bool*>(lpvParam); |
| 486 | CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED); |
| 487 | |
| 488 | Microsoft::WRL::ComPtr<IShellWindows> shellWindows; |
| 489 | if (FAILED(CoCreateInstance(CLSID_ShellWindows, nullptr, CLSCTX_ALL, IID_IShellWindows, reinterpret_cast<void**>(shellWindows.GetAddressOf())))) |
| 490 | return 1; |
| 491 | |
| 492 | auto titleTextBuf = std::make_unique<wchar_t[]>(MAX_PATH); |
| 493 | int titleTextBufLength = MAX_PATH; |
| 494 | while (*bThreadRun) |
| 495 | { |
| 496 | Sleep(500); |
| 497 | |
| 498 | if (CRegStdDWORD(L"Software\\TortoiseGit\\ModifyExplorerTitle", TRUE) == FALSE) |
| 499 | { |
| 500 | Sleep(60000); |
| 501 | continue; |
| 502 | } |
| 503 | |
| 504 | VARIANT v{}; |
| 505 | V_VT(&v) = VT_I4; |
| 506 | long shellCount = 0; |
| 507 | if (shellWindows->get_Count(&shellCount) != S_OK) |
| 508 | continue; |
| 509 | |
| 510 | for (long i = 0; i < shellCount; ++i) |
| 511 | { |
| 512 | v.lVal = i; |
| 513 | Microsoft::WRL::ComPtr<IDispatch> disp; |
| 514 | shellWindows->Item(v, disp.GetAddressOf()); |
| 515 | if (!disp) |
| 516 | continue; |
| 517 | Microsoft::WRL::ComPtr<IWebBrowserApp> webBrowserApp; |
| 518 | if (FAILED(disp->QueryInterface(webBrowserApp.GetAddressOf()))) |
| 519 | continue; |
| 520 | HWND hwndWba = nullptr; |
| 521 | if (FAILED(webBrowserApp->get_HWND(reinterpret_cast<LONG_PTR*>(&hwndWba)))) |
| 522 | continue; |
| 523 | Microsoft::WRL::ComPtr<IServiceProvider> serviceProvider; |
| 524 | if (FAILED(webBrowserApp->QueryInterface(serviceProvider.GetAddressOf()))) |
| 525 | continue; |
| 526 | Microsoft::WRL::ComPtr<IShellBrowser> shellBrowser; |
| 527 | if (FAILED(serviceProvider->QueryService(SID_STopLevelBrowser, shellBrowser.GetAddressOf()))) |
| 528 | continue; |
| 529 | Microsoft::WRL::ComPtr<IShellView> psv; |
| 530 | if (FAILED(shellBrowser->QueryActiveShellView(psv.GetAddressOf()))) |
| 531 | continue; |
| 532 | Microsoft::WRL::ComPtr<IFolderView> pfv; |
| 533 | if (FAILED(psv->QueryInterface(pfv.GetAddressOf()))) |
| 534 | continue; |
| 535 | Microsoft::WRL::ComPtr<IPersistFolder2> ppf2; |
| 536 | if (FAILED(pfv->GetFolder(IID_IPersistFolder2, &ppf2))) |
| 537 | continue; |
| 538 | CComHeapPtr<ITEMIDLIST> pidlFolder; |
| 539 | if (FAILED(ppf2->GetCurFolder(&pidlFolder))) |
| 540 | continue; |
nothing calls this directly
no test coverage detected