Note folder can and usually does contain spaces.
| 3432 | |
| 3433 | // Note folder can and usually does contain spaces. |
| 3434 | static |
| 3435 | std::string |
| 3436 | get_unzip_program() |
| 3437 | { |
| 3438 | std::string path; |
| 3439 | |
| 3440 | // 7-Zip appears to note its location in the registry. |
| 3441 | // If that doesn't work, fall through and take a guess, but it will likely be wrong. |
| 3442 | HKEY hKey = nullptr; |
| 3443 | if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\7-Zip", 0, KEY_READ, &hKey) == ERROR_SUCCESS) |
| 3444 | { |
| 3445 | char value_buffer[MAX_PATH + 1]; // fyi 260 at time of writing. |
| 3446 | // in/out parameter. Documentation say that size is a count of bytes not chars. |
| 3447 | DWORD size = sizeof(value_buffer) - sizeof(value_buffer[0]); |
| 3448 | DWORD tzi_type = REG_SZ; |
| 3449 | // Testing shows Path key value is "C:\Program Files\7-Zip\" i.e. always with trailing \. |
| 3450 | bool got_value = (RegQueryValueExA(hKey, "Path", nullptr, &tzi_type, |
| 3451 | reinterpret_cast<LPBYTE>(value_buffer), &size) == ERROR_SUCCESS); |
| 3452 | RegCloseKey(hKey); // Close now incase of throw later. |
| 3453 | if (got_value) |
| 3454 | { |
| 3455 | // Function does not guarantee to null terminate. |
| 3456 | value_buffer[size / sizeof(value_buffer[0])] = '\0'; |
| 3457 | path = value_buffer; |
| 3458 | if (!path.empty()) |
| 3459 | { |
| 3460 | path += "7z.exe"; |
| 3461 | return path; |
| 3462 | } |
| 3463 | } |
| 3464 | } |
| 3465 | path += get_program_folder(); |
| 3466 | path += folder_delimiter; |
| 3467 | path += "7-Zip\\7z.exe"; |
| 3468 | return path; |
| 3469 | } |
| 3470 | |
| 3471 | # if !USE_SHELL_API |
| 3472 | static |
no test coverage detected