| 602 | } |
| 603 | |
| 604 | std::wstring getUpdatePath(bool create) |
| 605 | { |
| 606 | // To prevent shenanigans with various TOCTOU exploits, the staged installer should be in Program Files, |
| 607 | // which is only writable by administrators |
| 608 | wchar_t* programFilesPath = NULL; |
| 609 | HRESULT hr = SHGetKnownFolderPath(FOLDERID_ProgramFiles, 0, NULL, &programFilesPath); |
| 610 | if (FAILED(hr)) { |
| 611 | spdlog::error("Failed to get Program Files dir"); |
| 612 | return L""; |
| 613 | } |
| 614 | |
| 615 | std::wstringstream filePath; |
| 616 | filePath << programFilesPath; |
| 617 | CoTaskMemFree(programFilesPath); |
| 618 | filePath << L"\\" WS_WIN_CONFIG_SUBDIR_W L"\\update"; |
| 619 | if (create) { |
| 620 | int ret = SHCreateDirectoryEx(NULL, filePath.str().c_str(), NULL); |
| 621 | if (ret != ERROR_SUCCESS && ret != ERROR_ALREADY_EXISTS) { |
| 622 | spdlog::error("Failed to create update dir"); |
| 623 | return L""; |
| 624 | } |
| 625 | } |
| 626 | |
| 627 | return filePath.str(); |
| 628 | } |
| 629 | |
| 630 | std::wstring getSystemDir() |
| 631 | { |
no outgoing calls
no test coverage detected