X2CommunityCore / xcom2-launcher

The Alternative Mod Launcher (AML) is a replacement for the default game launchers from XCOM 2 and XCOM Chimera Squad.
GNU General Public License v3.0
347 stars 51 forks source link

settings.json/steam_appid.txt/etc placed in working directory instead of the application folder #223

Closed antiz closed 2 years ago

antiz commented 4 years ago

Hi!

Expected Behavior

The instance-specific configuration (everything except GlobalSettings) is tied to that copy/extracted directory of AML without being affected by how AML is started.

Current Behavior

AML searches for its configuration in the current working dir of the calling environment.

Possible Solution

During startup, set the working dir to the directory containing the executable: XCOM2 Launcher.exe

(Or use appropriate paths when opening settings.json/etc, but I reckon that is more effort.)

Steps to Reproduce

  1. cd C:\
  2. .\path\to\XCOM2 Launcher.exe

Details / Context

Some application launchers behave differently than Windows Shell/Explorer.

For example: PowerToys Run uses its own installation directory as the working dir for applications it starts (which I admit is questionable). As a result, AML tries to write to C:\Program Files\PowerToys\steam_appid.txt, which is neither sensible, nor likely to succeed, unless elevated.

Possible Implementation

Directory.SetCurrentDirectory(Path.GetDirectoryName(Application.ExecutablePath)); on startup

I'm not too knowledgeable on C#/WinForms so there might be a more fitting API to use, but this does do the trick; tested locally.

Behaviour when double-clicking the executable or using Run (win+r) is unchanged, as this change simply forces a behaviour that was already present in those scenarios. Behaviour when using a Shortcut to launch AML is unchanged as well, unless the user manually changed the Start in attribute of the shortcut.

All this is under the assumption that keeping the settings in the application dir is indeed the intended behaviour. Please correct me if I'm wrong on this.

I can do a pull request for this, but given that it's a one-liner, it might be easier for a contributor to make the change directly.

Greetings, antiz

RevZero commented 4 years ago

Thanks for the detailed report. I will probably have time to verify and accept this tomorrow.