Skip to content

feat(system): Add command line option to skip force set of cwd #1445

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
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

CoChiefResident
Copy link

@CoChiefResident CoChiefResident commented Aug 11, 2025

This PR introduces the possiblity to put the game executable outside of the Generals/ZeroHour installation path.

Considerations regarding:

  • DLLs: The current working directory is simply also part of the DLL search path order. But now not before the system folders but afterwards. Since there are no system DLLs using mss32.dll and BINKW32.DLL, this is fine. See Win32 Docu - DLL Standard search order
  • Win32 File Access: I am not able to find any documentation on that. But debugging it with Process Monitor will show when using a Win32 file access function like LoadImageA or LoadCursorFromFile with a relative path, first the executable path, then current working directory, then all paths in %PATH% are searched. See https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-openfile#remarks
  • C runtime functions like fopen: Will always work based on current working directory.

Example usage with VS:

grafik

(Sorry for German version, I added "-cwd" to "Command Arguments" and the install path to "Working Directory")

@CoChiefResident CoChiefResident marked this pull request as ready for review August 11, 2025 20:19
Copy link

@xezon xezon left a comment

Choose a reason for hiding this comment

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

Ah this is nice. I have not thought of that and always enabled the INSTALL build target to test.

Can you please also look over all the tools and do the same there? At a quick glance, GUIEdit, MapCacheBuilder, WorldBuilder also do this. Also can move the common code to a single place to not repeat the same logic in many places.

@xezon xezon added Enhancement Is new feature or request Minor Severity: Minor < Major < Critical < Blocker Gen Relates to Generals ZH Relates to Zero Hour labels Aug 11, 2025
@xezon xezon added this to the Code foundation build up milestone Aug 11, 2025
@xezon xezon changed the title feature: Add command line option to skip force set of cwd feat(system): Add command line option to skip force set of cwd Aug 11, 2025
@CoChiefResident
Copy link
Author

Can you please also look over all the tools and do the same there? At a quick glance, GUIEdit, MapCacheBuilder, WorldBuilder also do this.

I did not build or use any tool until just now :). I can have a look, but I would put this into another pull request. For developer tools the solution might be different, like a select directory dialog when it detects that the current working directory is not ok.

Also can move the common code to a single place to not repeat the same logic in many places.

What do you mean exactly? I am not that familiar with the code that much. I see that CommandLine.cpp and .h are the same in Generals and ZeroHour, but would it not make sense to move it to Core in a different PR?

@xezon
Copy link

xezon commented Aug 12, 2025

I did not build or use any tool until just now :). I can have a look, but I would put this into another pull request. For developer tools the solution might be different, like a select directory dialog when it detects that the current working directory is not ok.

From what I saw the tools use the exact same logic on their startup function. If we can make them behave the same, then that would be nice.

What do you mean exactly? I am not that familiar with the code that much. I see that CommandLine.cpp and .h are the same in Generals and ZeroHour, but would it not make sense to move it to Core in a different PR?

I mean refactor the code in a way that the code duplication for changing the working directory is eliminated.

@OmniBlade
Copy link

In my opinion, the correct fix here is to make the game entirely location agnostic so we don't care what the working directory is. Have both a read only data location and read/write user data location being customisable via either command line, ini file or both.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Is new feature or request Gen Relates to Generals Minor Severity: Minor < Major < Critical < Blocker ZH Relates to Zero Hour
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants