Skip to content

config: add shared openw3d.conf path handling and --ini override#104

Merged
caseychaos1212 merged 4 commits intow3dhub:mainfrom
caseychaos1212:pr/iniconf-followup
Mar 25, 2026
Merged

config: add shared openw3d.conf path handling and --ini override#104
caseychaos1212 merged 4 commits intow3dhub:mainfrom
caseychaos1212:pr/iniconf-followup

Conversation

@caseychaos1212
Copy link
Copy Markdown
Collaborator

This follows up the INI-backed config work by moving openw3d.conf path
resolution into shared wwlib code and by teaching the game and legacy
wwconfig entry points to honor an explicit --ini PATH override.

What this changes:

  • adds a shared config-path resolver in wwlib
  • supports --ini PATH in renegade and wwconfig
  • resolves config in this order:
    1. explicit --ini PATH
    2. OPENW3D_CONFIG_INI / RENEGADE_CONFIG_INI
    3. portable openw3d.conf next to the executable if it already exists
    4. standard per-user config path
  • resolves the --ini path before any --gamedir handling can change the working directory
  • creates parent directories before saving to per-user config locations
  • forwards the explicit config path when renegade launches wwconfig.exe
  • treats POSIX-style absolute paths as absolute in the shared file factory

Comment thread Code/wwlib/openw3d.cpp Outdated
Comment on lines +94 to +104
#ifdef _WIN32
char path[MAX_PATH] = { 0 };
DWORD length = GetCurrentDirectoryA(ARRAY_SIZE(path), path);
if (length > 0 && length < ARRAY_SIZE(path)) {
return std::filesystem::path(path);
}
#else
char path[4096] = { 0 };
if (getcwd(path, sizeof(path)) != NULL) {
return std::filesystem::path(path);
}
Copy link
Copy Markdown

@madebr madebr Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps use the OPENW3D_WIN32 and OPENW3D_SDL3 macros?
There is std::filesystem::current_path to get the working directory so the unix getcwd is not needed.

Comment thread Code/wwlib/openw3d.cpp Outdated
Comment on lines +126 to +139
#ifdef _WIN32
char path[32768] = { 0 };
DWORD length = GetModuleFileNameA(NULL, path, ARRAY_SIZE(path));
if (length > 0 && length < ARRAY_SIZE(path)) {
return std::filesystem::path(path).parent_path();
}
#else
char path[4096] = { 0 };
const ssize_t length = readlink("/proc/self/exe", path, sizeof(path) - 1);
if (length > 0) {
path[length] = '\0';
return std::filesystem::path(path).parent_path();
}
#endif
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also use the OPENW3D_* macros here.
For the SDL3 case, I think SDL_GetBasePath returns what we want.

/proc/self/exe only works on Linux and not on the BSDs, macOS, etc

Comment thread Code/wwlib/openw3d.cpp Outdated
Comment on lines +151 to +170
#ifdef _WIN32
std::filesystem::path appdata_path;
HMODULE shfolder = LoadLibraryA("shfolder.dll");
if (shfolder != NULL) {
typedef HRESULT(__stdcall *SHGetFolderPathAType)(HWND, int, HANDLE, DWORD, LPSTR);
SHGetFolderPathAType get_folder_path =
(SHGetFolderPathAType)GetProcAddress(shfolder, "SHGetFolderPathA");
if (get_folder_path != NULL) {
char path[MAX_PATH] = { 0 };
if (get_folder_path(NULL, CSIDL_APPDATA, NULL, 0, path) == S_OK) {
appdata_path = std::filesystem::path(path);
}
}
FreeLibrary(shfolder);
}

return appdata_path;
#else
return std::filesystem::path();
#endif
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same story about OPENW3D_*. SDL3 has SDL_GetUserFolder which provides what we needs.

Comment thread Code/wwlib/openw3d.cpp Outdated
Comment on lines +190 to +205
#ifdef _WIN32
std::filesystem::path config_dir = Get_Windows_AppData_Directory();
if (!config_dir.empty()) {
return config_dir / "OpenW3D" / W3D_CONF_FILENAME;
}
#else
const char *xdg_config_home = std::getenv("XDG_CONFIG_HOME");
if (xdg_config_home != NULL && xdg_config_home[0] != '\0') {
return Make_Absolute_Path(xdg_config_home) / "OpenW3D" / W3D_CONF_FILENAME;
}

const char *home = std::getenv("HOME");
if (home != NULL && home[0] != '\0') {
return Make_Absolute_Path(home) / ".config" / "OpenW3D" / W3D_CONF_FILENAME;
}
#endif
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OPENW3d_* yada yada.

SDL_GetPrefPath returns a path for storing preferences (=configs).

…ed the Unix-specific getcwd and /proc/self/exe code, and now use SDL_GetBasePath() and SDL_GetPrefPath() for the SDL3 path cases. Get_Current_Directory() now just uses std::filesystem::current_path().
Copy link
Copy Markdown
Collaborator

@rm5248 rm5248 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks pretty reasonable to me, I don't have any concerns currently.

Copy link
Copy Markdown

@madebr madebr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So happy the --gamedir option works again as designed!

I've only a small remark about the default ini location.

Comment thread Code/wwlib/openw3d.cpp Outdated
Comment on lines +148 to +150
return appdata_path.empty() ? std::filesystem::path() : appdata_path / "OpenW3D";
#elif defined(OPENW3D_SDL3)
char *pref_path = SDL_GetPrefPath("OpenW3D", "OpenW3D");
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a difference between the default openw3d.conf path:

OPENRW_WIN32: C:\Users\<user>\AppData\Roaming\OpenW3D\openw3d.conf
OPENRW_SDL3: C:\Users\<user>\AppData\Roaming\OpenW3D\OpenW3D\openw3d.conf

Perhaps it should be W3DHub\OpenW3D\openw3d.conf for all?

@caseychaos1212 caseychaos1212 requested a review from madebr March 23, 2026 20:39
Copy link
Copy Markdown
Collaborator

@OmniBlade OmniBlade left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just style nitpicks from me.

Comment thread Code/wwlib/openw3d.cpp Outdated

namespace
{
constexpr char kConfigOrganization[] = "W3DHub";
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code base uses CAPS_CASE for constants and doesn't use hungarian notation for the most part.

Comment thread Code/wwlib/openw3d.cpp Outdated

std::filesystem::path Get_User_Config_Directory()
{
#if defined(OPENW3D_WIN32)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General style in the code base is not to indent preprocessor directives and infact you didn't earlier in the file.

@caseychaos1212 caseychaos1212 merged commit 29956ea into w3dhub:main Mar 25, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants