forked from electronicarts/CnC_Generals_Zero_Hour
-
Notifications
You must be signed in to change notification settings - Fork 248
feat(system): Add startup working directory options #3149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
CryoTheRenegade
wants to merge
11
commits into
TheSuperHackers:main
Choose a base branch
from
CryoTheRenegade:feat/startup-working-directory
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
adae3f0
feat(system): Add -cwd option to keep or override the startup working…
CryoTheRenegade d92c83e
fix(system): Restore WorldBuilder buf and harden -cwd directory changes
CryoTheRenegade 04d6eaa
refactor(system): Move startup working directory logic out of Command…
CryoTheRenegade 1dbd691
refactor(system): Parse -cwd once in CommandLine startup
CryoTheRenegade a45c8dd
fix(system): Initialize WorldBuilder -cwd skip flag in a constructor
CryoTheRenegade cadc529
fix(system): Make cwd overrides explicit
CryoTheRenegade 13925e7
refactor(system): Split working directory options
CryoTheRenegade 5ff2f5c
refactor(system): Record parsed startup arguments
CryoTheRenegade 377032f
fix(system): Preserve startup argument parsing state
CryoTheRenegade 1602ff0
fix(system): Use CRT command-line arguments
CryoTheRenegade 56d5044
refactor(system): Clean up command-line state
CryoTheRenegade File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| /* | ||
| ** Command & Conquer Generals Zero Hour(tm) | ||
| ** Copyright 2025 TheSuperHackers | ||
| ** | ||
| ** This program is free software: you can redistribute it and/or modify | ||
| ** it under the terms of the GNU General Public License as published by | ||
| ** the Free Software Foundation, either version 3 of the License, or | ||
| ** (at your option) any later version. | ||
| ** | ||
| ** This program is distributed in the hope that it will be useful, | ||
| ** but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| ** GNU General Public License for more details. | ||
| ** | ||
| ** You should have received a copy of the GNU General Public License | ||
| ** along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "Lib/BaseType.h" | ||
|
|
||
| namespace rts | ||
| { | ||
|
|
||
| // TheSuperHackers @feature 14/08/2026 | ||
| // Process working directory helpers. CommandLine::parseCommandLineForStartup() | ||
| // applies these: default is the executable directory, -useCwd keeps the OS | ||
| // directory, and -setCwd <path> uses that path. | ||
|
|
||
| Bool setCurrentDirectoryToExecutablePath(); | ||
| Bool setCurrentDirectoryToPath(const char *path); | ||
| void keepCurrentDirectory(); | ||
| void setCurrentDirectoryToExecutablePathIfNotSet(); | ||
|
|
||
| } // namespace rts |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| /* | ||
| ** Command & Conquer Generals Zero Hour(tm) | ||
| ** Copyright 2025 TheSuperHackers | ||
| ** | ||
| ** This program is free software: you can redistribute it and/or modify | ||
| ** it under the terms of the GNU General Public License as published by | ||
| ** the Free Software Foundation, either version 3 of the License, or | ||
| ** (at your option) any later version. | ||
| ** | ||
| ** This program is distributed in the hope that it will be useful, | ||
| ** but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| ** GNU General Public License for more details. | ||
| ** | ||
| ** You should have received a copy of the GNU General Public License | ||
| ** along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| #include "PreRTS.h" // This must go first in EVERY cpp file in the GameEngine | ||
|
|
||
| #include "Common/WorkingDirectory.h" | ||
|
|
||
| namespace rts | ||
| { | ||
|
|
||
| static Bool s_workingDirectorySet = FALSE; | ||
|
|
||
| Bool setCurrentDirectoryToExecutablePath() | ||
| { | ||
| Char buffer[_MAX_PATH]; | ||
| const DWORD len = GetModuleFileName(nullptr, buffer, ARRAY_SIZE(buffer)); | ||
| if (len == 0 || len >= ARRAY_SIZE(buffer)) | ||
| { | ||
| DEBUG_LOG(("Failed to get executable path for working directory (error %d)", GetLastError())); | ||
| return FALSE; | ||
| } | ||
|
|
||
| if (Char *pEnd = strrchr(buffer, '\\')) | ||
| { | ||
| *pEnd = 0; | ||
| } | ||
|
|
||
| if (::SetCurrentDirectory(buffer) == 0) | ||
| { | ||
| DEBUG_LOG(("Failed to set working directory to executable path '%s' (error %d)", buffer, GetLastError())); | ||
| return FALSE; | ||
| } | ||
|
|
||
| s_workingDirectorySet = TRUE; | ||
| return TRUE; | ||
| } | ||
|
|
||
| Bool setCurrentDirectoryToPath(const char *path) | ||
| { | ||
| if (path == nullptr || path[0] == '\0') | ||
| return FALSE; | ||
|
|
||
| if (::SetCurrentDirectory(path) == 0) | ||
| { | ||
| DEBUG_LOG(("Failed to set working directory to '%s' (error %d)", path, GetLastError())); | ||
| return FALSE; | ||
| } | ||
|
|
||
| s_workingDirectorySet = TRUE; | ||
| return TRUE; | ||
| } | ||
|
|
||
| void keepCurrentDirectory() | ||
| { | ||
| s_workingDirectorySet = TRUE; | ||
| } | ||
|
|
||
| void setCurrentDirectoryToExecutablePathIfNotSet() | ||
| { | ||
| if (!s_workingDirectorySet) | ||
| setCurrentDirectoryToExecutablePath(); | ||
| } | ||
|
|
||
| } // namespace rts |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is correct.
Picture setting command line
-setCwd Path -useCwd, this then uses Path instead of Current Directory.We would expect the last command line argument to win the race.