diff --git a/src/config.c b/src/config.c index f72a78c252..af8ac6ca44 100644 --- a/src/config.c +++ b/src/config.c @@ -25,6 +25,7 @@ #include "addresses.h" #include "config.h" #include "rct2.h" +#include // Current keyboard shortcuts uint16 gShortcutKeys[SHORTCUT_COUNT]; @@ -146,6 +147,7 @@ void config_save() configuration_t gConfig; +static char *config_show_directory_browser(); static void config_parse_settings(FILE *fp); static int config_get_line(FILE *fp, char *setting, char *value); static int config_parse_setting(FILE *fp, char *setting); @@ -169,7 +171,7 @@ void config_init() DWORD dwAttrib = GetFileAttributes(path); if (dwAttrib == INVALID_FILE_ATTRIBUTES || !(dwAttrib & FILE_ATTRIBUTE_DIRECTORY)) { // folder does not exist if (!CreateDirectory(path, NULL)) { - config_error("Could not create config file (do you have write acces to you documents folder?)"); + config_error("Could not create config file (do you have write access to your documents folder?)"); } } strcat(path, "\\config.ini"); @@ -228,8 +230,9 @@ static void config_create_default(char *path) FILE* fp; if (!config_find_rct2_path(gConfig.game_path)) { - MessageBox(NULL, "Unable to find RCT2 installation directory. Please correct in config.ini.", "OpenRCT2", MB_OK); - strcpy(gConfig.game_path, "C:\\"); + MessageBox(NULL, "Unable to find RCT2 installation directory. Please select the directoy where you installed RCT2!", "OpenRCT2", MB_OK); + char *res = config_show_directory_browser(); + strcpy(gConfig.game_path, res); } fp = fopen(path, "w"); @@ -240,6 +243,51 @@ static void config_create_default(char *path) fclose(fp); } +/** + * A directory browser allowing for semi-automatic config.ini for non standard installs. + */ +static char *config_show_directory_browser() +{ + BROWSEINFO bi; + char pszBuffer[MAX_PATH]; + LPITEMIDLIST pidl; + LPMALLOC lpMalloc; + + // Initialize COM + if (CoInitializeEx(0, COINIT_APARTMENTTHREADED) != S_OK) { + MessageBox(NULL, _T("Error opening browse window"), _T("ERROR"), MB_OK); + CoUninitialize(); + return 0; + } + + // Get a pointer to the shell memory allocator + if (SHGetMalloc(&lpMalloc) != S_OK) { + MessageBox(NULL, _T("Error opening browse window"), _T("ERROR"), MB_OK); + CoUninitialize(); + return 0; + } + + bi.hwndOwner = NULL; + bi.pidlRoot = NULL; + bi.pszDisplayName = pszBuffer; + bi.lpszTitle = _T("Select your RCT2 installation directory"); + bi.ulFlags = BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS; + bi.lpfn = NULL; + bi.lParam = 0; + + char *outPath = "C:\\"; + + if (pidl = SHBrowseForFolder(&bi)) { + // Copy the path directory to the buffer + if (SHGetPathFromIDList(pidl, pszBuffer)) { + // Store pszBuffer (and the path) in the outPath + outPath = strcat("", pszBuffer); + } + } + CoUninitialize(); + return outPath; +} + /** * Parse settings and set the game veriables * @param fp file pointer to the settings file