From 45f78eded4bef89acba56eaf5f0ab5698d7c2936 Mon Sep 17 00:00:00 2001 From: atmaxinger Date: Fri, 9 May 2014 11:40:06 +0200 Subject: [PATCH] Moved platform specific UI code (MessageBox, DirectoryChooser) into osinterface.c --- src/config.c | 52 +++++------------------------------------------ src/osinterface.c | 49 +++++++++++++++++++++++++++++++++++++++++++- src/osinterface.h | 2 ++ src/rct2.c | 2 +- 4 files changed, 56 insertions(+), 49 deletions(-) diff --git a/src/config.c b/src/config.c index af8ac6ca44..c29c7ff622 100644 --- a/src/config.c +++ b/src/config.c @@ -27,6 +27,8 @@ #include "rct2.h" #include +#include "osinterface.h" + // Current keyboard shortcuts uint16 gShortcutKeys[SHORTCUT_COUNT]; @@ -230,8 +232,8 @@ 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 RCT2!", "OpenRCT2", MB_OK); - char *res = config_show_directory_browser(); + osinterface_show_messagebox("Unable to find RCT2 installation directory. Please select the directoy where you installed RCT2!"); + char *res = osinterface_open_directory_browser("Please select your RCT2 directory"); strcpy(gConfig.game_path, res); } @@ -243,50 +245,6 @@ 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 @@ -505,7 +463,7 @@ static int config_parse_section(FILE *fp, char *setting, char *value){ * @param msg Message to print in message box */ static void config_error(char *msg){ - MessageBox(NULL, msg, "OpenRCT2", MB_OK); + osinterface_show_messagebox(msg); //TODO:SHUT DOWN EVERYTHING! } diff --git a/src/osinterface.c b/src/osinterface.c index 3e97491e5b..760f73bf63 100644 --- a/src/osinterface.c +++ b/src/osinterface.c @@ -19,6 +19,8 @@ *****************************************************************************/ #include +#include +#include #include #include #include @@ -348,4 +350,49 @@ int osinterface_open_common_file_dialog(int type, char *title, char *filename, c RCT2_GLOBAL(0x009E2C74, uint32) = tmp; return result; -} \ No newline at end of file +} + +void osinterface_show_messagebox(char* message){ + MessageBox(NULL, message, "OpenRCT2", MB_OK); +} + +char* osinterface_open_directory_browser(char *title) { + 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(title); + 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; +} diff --git a/src/osinterface.h b/src/osinterface.h index 9ec682fea2..a42da3c6d3 100644 --- a/src/osinterface.h +++ b/src/osinterface.h @@ -47,5 +47,7 @@ void osinterface_draw(); void osinterface_free(); int osinterface_open_common_file_dialog(int type, char *title, char *filename, char *filterPattern, char *filterName); +void osinterface_show_messagebox(char* message); +char* osinterface_open_directory_browser(char *title); #endif diff --git a/src/rct2.c b/src/rct2.c index a16180c282..f586b16230 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); + osinterface_show_messagebox("Invalid RCT2 installation path. Please correct in config.ini."); exit(-1); }