From b04b25d01332a079e00473f2d627596e97ccb3a4 Mon Sep 17 00:00:00 2001 From: "Miso Zmiric (Mike Squinter)" Date: Thu, 8 May 2014 07:10:26 +0100 Subject: [PATCH 1/2] Add directory_browser to config_create_default partially resolves #42 [https://github.com/IntelOrca/OpenRCT2/issues/42] --- projects/openrct2.sln | 12 +++++++++- src/config.c | 55 +++++++++++++++++++++++++++++++++++++++++-- src/config.h | 1 + src/rct2.c | 2 +- 4 files changed, 66 insertions(+), 4 deletions(-) diff --git a/projects/openrct2.sln b/projects/openrct2.sln index f176b7813f..4bdb4ac96e 100644 --- a/projects/openrct2.sln +++ b/projects/openrct2.sln @@ -1,18 +1,28 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 2013 -VisualStudioVersion = 12.0.30110.0 +VisualStudioVersion = 12.0.21005.1 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "openrct2", "openrct2.vcxproj", "{D24D94F6-2A74-480C-B512-629C306CE92F}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|Mixed Platforms = Debug|Mixed Platforms Debug|Win32 = Debug|Win32 + Release|Any CPU = Release|Any CPU + Release|Mixed Platforms = Release|Mixed Platforms Release|Win32 = Release|Win32 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D24D94F6-2A74-480C-B512-629C306CE92F}.Debug|Any CPU.ActiveCfg = Debug|Win32 + {D24D94F6-2A74-480C-B512-629C306CE92F}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 + {D24D94F6-2A74-480C-B512-629C306CE92F}.Debug|Mixed Platforms.Build.0 = Debug|Win32 {D24D94F6-2A74-480C-B512-629C306CE92F}.Debug|Win32.ActiveCfg = Debug|Win32 {D24D94F6-2A74-480C-B512-629C306CE92F}.Debug|Win32.Build.0 = Debug|Win32 + {D24D94F6-2A74-480C-B512-629C306CE92F}.Release|Any CPU.ActiveCfg = Release|Win32 + {D24D94F6-2A74-480C-B512-629C306CE92F}.Release|Mixed Platforms.ActiveCfg = Release|Win32 + {D24D94F6-2A74-480C-B512-629C306CE92F}.Release|Mixed Platforms.Build.0 = Release|Win32 {D24D94F6-2A74-480C-B512-629C306CE92F}.Release|Win32.ActiveCfg = Release|Win32 {D24D94F6-2A74-480C-B512-629C306CE92F}.Release|Win32.Build.0 = Release|Win32 EndGlobalSection diff --git a/src/config.c b/src/config.c index ff256fcfc0..b907cfd77b 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]; @@ -220,8 +221,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 RTC2!", "OpenRCT2", MB_OK); + char *res = directory_browser(); + strcpy(gConfig.game_path, res); } fp = fopen(path, "w"); @@ -232,6 +234,55 @@ static void config_create_default(char *path) fclose(fp); } +//A directory browser allowing for semi-automatic config.ini for non standard installs +char* 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 diff --git a/src/config.h b/src/config.h index 2ed8b08dff..4d00474a91 100644 --- a/src/config.h +++ b/src/config.h @@ -76,6 +76,7 @@ extern uint16 gShortcutKeys[SHORTCUT_COUNT]; void config_reset_shortcut_keys(); void config_load(); void config_save(); +char* directory_browser(); // New config format diff --git a/src/rct2.c b/src/rct2.c index be54cd7306..696769cc63 100644 --- a/src/rct2.c +++ b/src/rct2.c @@ -151,7 +151,7 @@ void rct2_init_directories() // check install directory DWORD dwAttrib = GetFileAttributes(gConfig.game_path); if (dwAttrib == INVALID_FILE_ATTRIBUTES || !(dwAttrib & FILE_ATTRIBUTE_DIRECTORY)) { - MessageBox(NULL, "Invalid RCT2 installation path. Please correct in config.ini.", "OpenRCT2", MB_OK); + MessageBox(NULL, "Invalid RCT2 installation path. Please delete config.ini and run OpenRTC2 again.", "OpenRCT2", MB_OK); exit(-1); } From b1017a839f0ec50dfb6fef801bd146630b76311d Mon Sep 17 00:00:00 2001 From: "Miso Zmiric (Mike Squinter)" Date: Thu, 8 May 2014 13:06:36 +0100 Subject: [PATCH 2/2] fix late night typo --- src/config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config.c b/src/config.c index b907cfd77b..125aa5123e 100644 --- a/src/config.c +++ b/src/config.c @@ -221,7 +221,7 @@ 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 select the directoy where you installed RTC2!", "OpenRCT2", MB_OK); + MessageBox(NULL, "Unable to find RCT2 installation directory. Please select the directoy where you installed RCT2!", "OpenRCT2", MB_OK); char *res = directory_browser(); strcpy(gConfig.game_path, res); }