feat(system): Add -cwd option to keep or override the startup working directory - #3149
feat(system): Add -cwd option to keep or override the startup working directory#3149CryoTheRenegade wants to merge 3 commits into
Conversation
… directory Co-authored-by: Cursor <cursoragent@cursor.com>
PR Summary by QodoAdd -cwd flag to control startup working directory across game and tools
AI Description
Diagram
High-Level Assessment
Files changed (9)
|
Code Review by Qodo
1.
|
Co-authored-by: Cursor <cursoragent@cursor.com>
…Line Co-authored-by: Cursor <cursoragent@cursor.com>
| *pEnd = 0; | ||
| } | ||
| ::SetCurrentDirectory(buffer); | ||
| rts::applyStartupWorkingDirectory(); |
There was a problem hiding this comment.
Instead of using a separate implementation for tools, can we perhaps also call CommandLine::parseCommandLineForStartup(); here and use the same path as WinMain?
| ::SetCurrentDirectory(buffer); | ||
| CommandLine::parseCommandLineForStartup(); | ||
| if (TheGlobalData->m_changeCurrentWorkingDirectoryToExecutablePath) | ||
| rts::setCurrentDirectoryToExecutablePath(); |
There was a problem hiding this comment.
Why is the call delegated to this location through the flag above? To avoid calling it twice after DebugInit?
Can we simplify it and cut the TheGlobalData->m_changeCurrentWorkingDirectoryToExecutablePath middle man?
| return TRUE; | ||
| } | ||
|
|
||
| static char *nextWorkingDirectoryParam(char *newSource, const char *seps) |
There was a problem hiding this comment.
nextWorkingDirectoryParam is identical to nextParam at CommandLine.cpp:1333 Both are in Core in the same library, so this can just use the existing one.
Also -cwd now gets parsed twice by two different paths: the game via parseCwd + m_changeCurrentWorkingDirectoryToExecutablePath, the tools by re-parsing the raw command line here. Any quoting fix would have to land in both. Can these share one entry point?
Summary
-cwdso the game and tools can run with an executable outside the install directoryCommandLine::applyStartupWorkingDirectory()helperThis recreates the abandoned #1445 feature and applies the review feedback from that PR:
-cwdbehavior-cwd <path>is a small step toward a customizable read-only data location without rewriting every relative file loadExample Visual Studio usage: add
-cwdto Command Arguments and set Working Directory to the game install path.Considerations from #1445:
mss32.dllandBINKW32.DLLare not system DLLs, so this is fine. See Win32 DLL search orderLoadImageA,LoadCursorFromFile, ...) search the executable path, then the current working directory, then%PATH%. See OpenFile remarksfopenalways use the current working directoryThis change was drafted with LLM assistance