Skip to content

Commit

Permalink
configure: Fix folder selection. [V]
Browse files Browse the repository at this point in the history
…and correctly work around that bug. Fixes #67.
  • Loading branch information
nmlgc committed Jun 21, 2017
1 parent 11de5fa commit a44ac18
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions thcrap_configure/src/configure_search.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,27 @@ static const char* ChooseLocation(const char *id, json_t *locs)
return NULL;
}

// Work around a bug in Windows 7 and later by sending
// BFFM_SETSELECTION a second time.
// https://connect.microsoft.com/VisualStudio/feedback/details/518103/bffm-setselection-does-not-work-with-shbrowseforfolder-on-windows-7
typedef struct {
ITEMIDLIST *path;
int attempts;
} initial_path_t;

int CALLBACK SetInitialBrowsePathProc(HWND hWnd, UINT uMsg, LPARAM lp, LPARAM pData)
{
if(pData) {
// Work around a bug in Windows 7 and later by sending
// BFFM_SETSELECTION a second time.
// https://connect.microsoft.com/VisualStudio/feedback/details/518103/bffm-setselection-does-not-work-with-shbrowseforfolder-on-windows-7
initial_path_t *ip = (initial_path_t *)pData;
if(ip) {
switch(uMsg) {
case BFFM_INITIALIZED:
ip->attempts = 0;
// fallthrough
case BFFM_SELCHANGED:
SendMessageW(hWnd, BFFM_SETSELECTION, FALSE, pData);
if(ip->attempts < 2) {
SendMessageW(hWnd, BFFM_SETSELECTION, FALSE, (LPARAM)ip->path);
ip->attempts++;
}
}
}
return 0;
Expand All @@ -75,7 +86,7 @@ int CALLBACK SetInitialBrowsePathProc(HWND hWnd, UINT uMsg, LPARAM lp, LPARAM pD
json_t* ConfigureLocateGames(const char *games_js_path)
{
json_t *games;
ITEMIDLIST *pidl_start = NULL;
initial_path_t ip = {0};
BROWSEINFO bi = {0};
int repeat = 0;

Expand Down Expand Up @@ -136,13 +147,13 @@ json_t* ConfigureLocateGames(const char *games_js_path)
// BFFM_SETSELECTION does this anyway if we pass a string, so we
// might as well do the slash conversion in win32_utf8's wrapper
// while we're at it.
SHParseDisplayNameU(games_js_path, NULL, &pidl_start, 0, NULL);
SHParseDisplayNameU(games_js_path, NULL, &ip.path, 0, NULL);

bi.lpszTitle = "Root path for game search (cancel to search entire system):";
bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_NONEWFOLDERBUTTON | BIF_USENEWUI;
bi.hwndOwner = GetConsoleWindow();
bi.lpfn = SetInitialBrowsePathProc;
bi.lParam = (LPARAM)pidl_start;
bi.lParam = (LPARAM)&ip;

do {
char search_path[MAX_PATH * 2] = {0};
Expand Down Expand Up @@ -200,6 +211,6 @@ json_t* ConfigureLocateGames(const char *games_js_path)
}
json_decref(found);
} while(repeat);
CoTaskMemFree(pidl_start);
CoTaskMemFree(ip.path);
return games;
}

0 comments on commit a44ac18

Please sign in to comment.