[RAPPS] Initialize SHBrowseForFolder to current download folder (#7505)

This commit is contained in:
Whindmar Saksit 2024-11-18 16:42:43 +01:00 committed by GitHub
parent e0759a5e35
commit 2834e5b3c8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -9,6 +9,20 @@
SETTINGS_INFO NewSettingsInfo; SETTINGS_INFO NewSettingsInfo;
static int CALLBACK
BrowseFolderCallback(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData)
{
switch (uMsg)
{
case BFFM_INITIALIZED:
SendMessageW(hwnd, BFFM_SETSELECTIONW, TRUE, lpData);
break;
case BFFM_VALIDATEFAILED:
return TRUE;
}
return 0;
}
BOOL BOOL
ChooseFolder(HWND hwnd) ChooseFolder(HWND hwnd)
{ {
@ -25,24 +39,24 @@ ChooseFolder(HWND hwnd)
bi.ulFlags = bi.ulFlags =
BIF_USENEWUI | BIF_DONTGOBELOWDOMAIN | BIF_RETURNONLYFSDIRS | /* BIF_BROWSEFILEJUNCTIONS | */ BIF_VALIDATE; BIF_USENEWUI | BIF_DONTGOBELOWDOMAIN | BIF_RETURNONLYFSDIRS | /* BIF_BROWSEFILEJUNCTIONS | */ BIF_VALIDATE;
if (SUCCEEDED(CoInitializeEx(NULL, COINIT_APARTMENTTHREADED))) if (SUCCEEDED(CoInitialize(NULL)))
{ {
CStringW szBuf; WCHAR szDir[MAX_PATH];
if (GetWindowTextW(GetDlgItem(hwnd, IDC_DOWNLOAD_DIR_EDIT), szDir, _countof(szDir)))
{
bi.lpfn = BrowseFolderCallback;
bi.lParam = (LPARAM)szDir;
}
LPITEMIDLIST lpItemList = SHBrowseForFolderW(&bi); LPITEMIDLIST lpItemList = SHBrowseForFolderW(&bi);
if (lpItemList && SHGetPathFromIDListW(lpItemList, szBuf.GetBuffer(MAX_PATH))) if (lpItemList && SHGetPathFromIDListW(lpItemList, szDir))
{ {
szBuf.ReleaseBuffer(); if (*szDir)
if (!szBuf.IsEmpty())
{ {
SetDlgItemTextW(hwnd, IDC_DOWNLOAD_DIR_EDIT, szBuf); SetDlgItemTextW(hwnd, IDC_DOWNLOAD_DIR_EDIT, szDir);
bRet = TRUE; bRet = TRUE;
} }
} }
else
{
szBuf.ReleaseBuffer();
}
CoTaskMemFree(lpItemList); CoTaskMemFree(lpItemList);
CoUninitialize(); CoUninitialize();
@ -94,7 +108,9 @@ InitSettingsControls(HWND hDlg, PSETTINGS_INFO Info)
SendDlgItemMessageW(hDlg, IDC_LOG_ENABLED, BM_SETCHECK, Info->bLogEnabled, 0); SendDlgItemMessageW(hDlg, IDC_LOG_ENABLED, BM_SETCHECK, Info->bLogEnabled, 0);
SendDlgItemMessageW(hDlg, IDC_DEL_AFTER_INSTALL, BM_SETCHECK, Info->bDelInstaller, 0); SendDlgItemMessageW(hDlg, IDC_DEL_AFTER_INSTALL, BM_SETCHECK, Info->bDelInstaller, 0);
SetWindowTextW(GetDlgItem(hDlg, IDC_DOWNLOAD_DIR_EDIT), Info->szDownloadDir); HWND hCtl = GetDlgItem(hDlg, IDC_DOWNLOAD_DIR_EDIT);
SetWindowTextW(hCtl, Info->szDownloadDir);
SendMessageW(hCtl, EM_LIMITTEXT, MAX_PATH - 1, 0);
CheckRadioButton(hDlg, IDC_PROXY_DEFAULT, IDC_USE_PROXY, IDC_PROXY_DEFAULT + Info->Proxy); CheckRadioButton(hDlg, IDC_PROXY_DEFAULT, IDC_USE_PROXY, IDC_PROXY_DEFAULT + Info->Proxy);