feat(system): Add startup working directory options - #3149
feat(system): Add startup working directory options#3149CryoTheRenegade wants to merge 17 commits into
Conversation
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.
|
|
| Filename | Overview |
|---|---|
| Core/GameEngine/Source/Common/WorkingDirectory.cpp | Implements cached startup-directory capture and executable, inherited, and custom working-directory selection. |
| Core/GameEngine/Source/Common/CommandLine.cpp | Adds startup working-directory options and records arguments consumed across parsing phases. |
| Core/Tools/MapCacheBuilder/Source/WinMain.cpp | Adopts shared startup parsing and filters consumed arguments before tool-specific processing. |
| Generals/Code/Tools/WorldBuilder/src/WorldBuilder.cpp | Integrates startup parsing and prevents MFC from treating consumed option values as filenames. |
| GeneralsMD/Code/Tools/WorldBuilder/src/WorldBuilder.cpp | Mirrors WorldBuilder startup parsing and consumed-argument filtering for Zero Hour. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Process starts] --> B[Capture inherited working directory]
B --> C[parseCommandLineForStartup]
C --> D{Startup option}
D -->|useCwd| E[Restore inherited directory]
D -->|setCwd path| F[Set explicit directory]
D -->|Neither| G[Set executable directory]
E --> H[Record consumed arguments]
F --> H
G --> H
H --> I[Continue game or tool initialization]
I --> J[Tool-specific parser skips consumed arguments]
Reviews (14): Last reviewed commit: "refactor(system): Remove startup initial..." | Re-trigger Greptile
xezon
left a comment
There was a problem hiding this comment.
Becomes better, but it is still sloppy.
… directory Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
…Line Co-authored-by: Cursor <cursoragent@cursor.com>
Have the game and tools share parseCommandLineForStartup so the working directory is applied in one place, without a GlobalData flag or a second tokenizer. Co-authored-by: Cursor <cursoragent@cursor.com>
VC6 does not support in-class member initializers, which broke the WorldBuilder command-line parser on CI. Co-authored-by: Cursor <cursoragent@cursor.com>
3f8d8d9 to
6f4fce1
Compare
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: abdddd99ad
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| { | ||
| // TheSuperHackers @bugfix CryoTheRenegade 29/08/2026 | ||
| // -setCwd <path> overrides the working directory. | ||
| if (num <= 1 || args[1][0] == '-' || args[1][0] == '/') |
There was a problem hiding this comment.
Accept valid paths beginning with option characters
When the requested working directory is a valid relative directory whose name starts with - (for example, -setCwd -install), this check treats the path as a missing argument and silently falls back to the executable directory; quoting the path does not help because the CRT removes the quotes. Root-relative paths beginning with / are rejected similarly. The parser should distinguish recognized options from path values or provide an escaping mechanism rather than rejecting paths solely by their first character.
Useful? React with 👍 / 👎.
|
|
||
| #include "Common/WorkingDirectory.h" | ||
|
|
||
| // Capture before static constructors can reach startup parsing through DebugInit. |
There was a problem hiding this comment.
Hmm ok this is unfortunate. So there is some racing for initialization. Can we do it some way without these pragmas?
Summary
-useCwdto keep the inherited working directory and-setCwd <path>to select an explicit startup directoryCommandLine::parseCommandLineForStartup()for the games, GUIEdit, WorldBuilder, and MapCacheBuilderFor Visual Studio, add
-useCwdto Command Arguments and set Working Directory to the game install path.To select an explicit directory, pass its path after
-setCwd. Quote paths that contain spaces:This recreates the abandoned #1445 feature and applies the review feedback from that PR:
GlobalDatamiddleman flagWorkingDirectoryConsiderations from #1445:
mss32.dllandBINKW32.DLLare not system DLLs. See Win32 DLL search order.LoadImageAandLoadCursorFromFilesearch the executable path, then the current working directory, then%PATH%. See OpenFile remarks.fopenuse the current working directory.This change was drafted with LLM assistance.