Preferences.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #include "main.h"
  2. #include "api__ml_downloads.h"
  3. #include "../winamp/wa_ipc.h"
  4. #include "Defaults.h"
  5. #include <shlobj.h>
  6. void Preferences_Init(HWND hwndDlg)
  7. {
  8. SetDlgItemText(hwndDlg, IDC_DOWNLOADLOCATION, defaultDownloadPath);
  9. }
  10. BOOL CALLBACK browseEnumProc(HWND hwnd, LPARAM lParam)
  11. {
  12. wchar_t cl[32] = {0};
  13. GetClassNameW(hwnd, cl, ARRAYSIZE(cl));
  14. if (!lstrcmpiW(cl, WC_TREEVIEW))
  15. {
  16. PostMessage(hwnd, TVM_ENSUREVISIBLE, 0, (LPARAM)TreeView_GetSelection(hwnd));
  17. return FALSE;
  18. }
  19. return TRUE;
  20. }
  21. int CALLBACK WINAPI BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData)
  22. {
  23. if(uMsg == BFFM_INITIALIZED)
  24. {
  25. SendMessageW(hwnd, BFFM_SETSELECTIONW, 1, (LPARAM)defaultDownloadPath);
  26. // this is not nice but it fixes the selection not working correctly on all OSes
  27. EnumChildWindows(hwnd, browseEnumProc, 0);
  28. }
  29. return 0;
  30. }
  31. void Preferences_Browse(HWND hwndDlg)
  32. {
  33. wchar_t folder[MAX_PATH] = {0};
  34. BROWSEINFO browse = {0};
  35. lstrcpyn(folder, defaultDownloadPath, MAX_PATH);
  36. browse.hwndOwner = hwndDlg;
  37. browse.lpszTitle = WASABI_API_LNGSTRINGW(IDS_CHOOSE_FOLDER);
  38. browse.ulFlags = BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE;
  39. browse.lpfn = BrowseCallbackProc;
  40. LPITEMIDLIST itemList = SHBrowseForFolder(&browse);
  41. if (itemList)
  42. {
  43. SHGetPathFromIDList(itemList, folder);
  44. lstrcpyn(defaultDownloadPath, folder, MAX_PATH);
  45. SetWindowText(GetDlgItem(hwndDlg, IDC_DOWNLOADLOCATION), folder);
  46. LPMALLOC malloc;
  47. SHGetMalloc(&malloc);
  48. malloc->Free(itemList);
  49. }
  50. }
  51. BOOL CALLBACK PreferencesDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  52. {
  53. switch (uMsg)
  54. {
  55. case WM_INITDIALOG:
  56. Preferences_Init(hwndDlg);
  57. break;
  58. case WM_COMMAND:
  59. switch (LOWORD(wParam))
  60. {
  61. case IDC_BROWSE:
  62. Preferences_Browse(hwndDlg);
  63. break;
  64. }
  65. break;
  66. }
  67. return 0;
  68. }