Permalink
Browse files

Fix executable directory path function

  • Loading branch information...
RadWolfie committed Jan 18, 2019
1 parent 318d017 commit 4edfebb3024d8bf540fed101380ba4d4f27b5c3b
Showing with 26 additions and 21 deletions.
  1. +1 −1 resource/Cxbx.rc
  2. +12 −11 src/common/Settings.cpp
  3. +4 −2 src/common/Settings.hpp
  4. +1 −1 src/gui/ResCxbx.h
  5. +2 −0 src/gui/WinMain.cpp
  6. +6 −6 src/gui/WndMain.cpp
@@ -576,7 +576,7 @@ BEGIN
POPUP "Config &Data Location...", 65535,MFT_STRING,MFS_ENABLED
BEGIN
MENUITEM "Store in AppData", ID_SETTINGS_CONFIG_DLOCAPPDATA,MFT_STRING,MFS_ENABLED
MENUITEM "Store with Executable", ID_SETTINGS_CONFIG_DLOCCURDIR,MFT_STRING,MFS_ENABLED
MENUITEM "Store with Executable", ID_SETTINGS_CONFIG_DLOCEXECDIR,MFT_STRING,MFS_ENABLED
MENUITEM "Custom", ID_SETTINGS_CONFIG_DLOCCUSTOM,MFT_STRING,MFS_ENABLED
END
POPUP "&Symbol Cache", 65535,MFT_STRING,MFS_ENABLED
@@ -49,7 +49,9 @@ static_assert(false, "Please implement support for cross-platform's user profile
#include <QDir> // for create directory
#include <QFile> // for check file existance
#include <QStandardPaths> // for cross-platform's user profile support
#endif
#endif

std::string g_exec_filepath;

// NOTE: Update settings_version when add/edit/delete setting's structure.
const uint settings_version = 3;
@@ -127,10 +129,9 @@ static struct {
const char* DirectHostBackBufferAccess = "DirectHostBackBufferAccess";
} sect_hack_keys;

std::string GenerateCurrentDirectoryStr()
{
// NOTE: There is no cross-platform support for getting file's current directory.
return std::experimental::filesystem::current_path().generic_string();
std::string GenerateExecDirectoryStr()
{
return g_exec_filepath.substr(0, g_exec_filepath.find_last_of("\\/"));
}

// NOTE: This function will be only have Qt support, std::experimental::filesystem doesn't have generic support.
@@ -192,13 +193,13 @@ bool Settings::Init()
std::string saveFile;
#ifdef RETRO_API_VERSION // TODO: Change me to #ifndef QT_VERSION
// Can only have one option without Qt.
saveFile = GenerateCurrentDirectoryStr();
saveFile = GenerateExecDirectoryStr();

#else // Only support for Qt compile build.
int iRet = MessageBox(nullptr, szSettings_save_user_option_message, "Cxbx-Reloaded", MB_YESNOCANCEL | MB_ICONQUESTION);

if (iRet == IDYES) {
saveFile = GenerateCurrentDirectoryStr();
saveFile = GenerateExecDirectoryStr();
}
else if (iRet == IDNO){
saveFile = GenerateUserProfileDirectoryStr();
@@ -238,7 +239,7 @@ bool Settings::Init()

bool Settings::LoadUserConfig()
{
std::string fileSearch = GenerateCurrentDirectoryStr();
std::string fileSearch = GenerateExecDirectoryStr();

fileSearch.append(szSettings_settings_file);

@@ -727,7 +728,7 @@ std::string Settings::GetDataLocation()
default:
#ifdef RETRO_API_VERSION // TODO: Change me to #ifndef QT_VERSION

m_gui.DataStorageToggle = CXBX_DATA_CURDIR;
m_gui.DataStorageToggle = CXBX_DATA_EXECDIR;

#else // Only support for Qt compile build.

@@ -739,8 +740,8 @@ std::string Settings::GetDataLocation()
break;
#endif

case CXBX_DATA_CURDIR:
m_current_data_location = GenerateCurrentDirectoryStr();
case CXBX_DATA_EXECDIR:
m_current_data_location = GenerateExecDirectoryStr();
break;

case CXBX_DATA_CUSTOM:
@@ -37,14 +37,16 @@
#include "Cxbx.h"

#include "SimpleIni.h"
#include <string>
#include <string>

extern std::string g_exec_filepath;

#define szSettings_alloc_error "ERROR: Unable to allocate Settings class."

// Cxbx-Reloaded's data storage location.
typedef enum _CXBX_DATA {
CXBX_DATA_APPDATA = 0,
CXBX_DATA_CURDIR = 1,
CXBX_DATA_EXECDIR = 1,
CXBX_DATA_CUSTOM = 2,
} CXBX_DATA;

@@ -351,7 +351,7 @@
#define ID_HACKS_SPEEDHACKS 40103
#define ID_SETTINGS_CONFIG_DLOCCUSTOM 40104
#define ID_SETTINGS_CONFIG_DLOCAPPDATA 40105
#define ID_SETTINGS_CONFIG_DLOCCURDIR 40106
#define ID_SETTINGS_CONFIG_DLOCEXECDIR 40106
#define ID_SETTINGS_ALLOWADMINPRIVILEGE 40107
#define ID_SETTINGS_CONFIG_LOGGING 40108
#define ID_SYNC_CONFIG_LOGGING 40109
@@ -80,6 +80,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
HWND hWnd = nullptr;
DWORD guiProcessID = 0;

// TODO: Convert ALL __argc & __argv to use main(int argc, char** argv) method.
if (__argc >= 2 && std::strcmp(__argv[1], "/load") == 0 && std::strlen(__argv[2]) > 0) {
bKernel = true;

@@ -98,6 +99,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
bKernel = false;
guiProcessID = GetCurrentProcessId();
}
g_exec_filepath = __argv[0]; // NOTE: Workaround solution until simulated "main" function is made.

/*! initialize shared memory */
EmuShared::Init(guiProcessID);
@@ -1040,9 +1040,9 @@ LRESULT CALLBACK WndMain::WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lP
}
break;

case ID_SETTINGS_CONFIG_DLOCCURDIR:
case ID_SETTINGS_CONFIG_DLOCEXECDIR:
{
g_Settings->m_gui.DataStorageToggle = CXBX_DATA_CURDIR;
g_Settings->m_gui.DataStorageToggle = CXBX_DATA_EXECDIR;
RefreshMenus();
}
break;
@@ -1734,19 +1734,19 @@ void WndMain::RefreshMenus()
switch (g_Settings->m_gui.DataStorageToggle) {
case CXBX_DATA_APPDATA:
CheckMenuItem(settings_menu, ID_SETTINGS_CONFIG_DLOCAPPDATA, MF_CHECKED);
CheckMenuItem(settings_menu, ID_SETTINGS_CONFIG_DLOCCURDIR, MF_UNCHECKED);
CheckMenuItem(settings_menu, ID_SETTINGS_CONFIG_DLOCEXECDIR, MF_UNCHECKED);
CheckMenuItem(settings_menu, ID_SETTINGS_CONFIG_DLOCCUSTOM, MF_UNCHECKED);
break;

case CXBX_DATA_CURDIR:
case CXBX_DATA_EXECDIR:
CheckMenuItem(settings_menu, ID_SETTINGS_CONFIG_DLOCAPPDATA, MF_UNCHECKED);
CheckMenuItem(settings_menu, ID_SETTINGS_CONFIG_DLOCCURDIR, MF_CHECKED);
CheckMenuItem(settings_menu, ID_SETTINGS_CONFIG_DLOCEXECDIR, MF_CHECKED);
CheckMenuItem(settings_menu, ID_SETTINGS_CONFIG_DLOCCUSTOM, MF_UNCHECKED);
break;

case CXBX_DATA_CUSTOM:
CheckMenuItem(settings_menu, ID_SETTINGS_CONFIG_DLOCAPPDATA, MF_UNCHECKED);
CheckMenuItem(settings_menu, ID_SETTINGS_CONFIG_DLOCCURDIR, MF_UNCHECKED);
CheckMenuItem(settings_menu, ID_SETTINGS_CONFIG_DLOCEXECDIR, MF_UNCHECKED);
CheckMenuItem(settings_menu, ID_SETTINGS_CONFIG_DLOCCUSTOM, MF_CHECKED);
break;
}

0 comments on commit 4edfebb

Please sign in to comment.