Skip to content

Commit

Permalink
configure: Initialize the folder browse dialog at the current directo…
Browse files Browse the repository at this point in the history
…ry. [V]
  • Loading branch information
nmlgc committed Jun 5, 2017
1 parent 9222424 commit bbd39e9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
25 changes: 25 additions & 0 deletions thcrap_configure/src/configure_search.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,25 @@ static const char* ChooseLocation(const char *id, json_t *locs)
return NULL;
}

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
switch(uMsg) {
case BFFM_INITIALIZED:
case BFFM_SELCHANGED:
SendMessageW(hWnd, BFFM_SETSELECTION, FALSE, pData);
}
}
return 0;
}

json_t* ConfigureLocateGames(const char *games_js_path)
{
json_t *games;
ITEMIDLIST *pidl_start = NULL;
BROWSEINFO bi = {0};
int repeat = 0;

Expand Down Expand Up @@ -116,9 +132,17 @@ json_t* ConfigureLocateGames(const char *games_js_path)
);
pause();
}

// 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);

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;

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

0 comments on commit bbd39e9

Please sign in to comment.