How to know which config file has been read (solved)

Started by Manu, Tue 08/06/2021 08:15:40

Previous topic - Next topic

Manu

Hello
I read in the documentation that the engine supports three configuration files, read in the following order:

1) Default config file
2) Current user's global config file
3) Current user's game config file

Is it possible to know what is the file that the game has read? In other words, I'd like to know if the game is using the default config or the user game config. Something more advanced than just testing if "%USERPROFILE%/Saved Games/GAMENAME/acsetup.cfg" exists, since this changes between Mac, Windows, and Linux.

The idea is to avoid asking for some preferences (for example translation) if the user has already chosen it and saved it in the game config.

Thanks!



Crimson Wizard

#1
Quote from: emabolo on Tue 08/06/2021 08:15:40
The idea is to avoid asking for some preferences (for example translation) if the user has already chosen it and saved it in the game config.

I might mention that player may as well edit default config by hand to change the language and other settings. I know that Linux users often do that, because there's no builtin setup program available on Linux and it's simply easier to edit a file in the game dir.


But if you really must do this, the latest version of AGS (3.5.1) provides direct means to access user config regardless of its location using new tag $CONFIGFILE$.
For example:
Code: ags

if (File.Exists("$CONFIGFILE$")) {
  // do something
} else {
  // do something else
}


You may also open it for reading or writing
Code: ags

File* f = File.Open("$CONFIGFILE$", eFileRead);

if returned "f" is null this means there's no user config yet.

For parsing config, there's a good module called IniFile that may be easily used to both read and write a config file:
https://www.adventuregamestudio.co.uk/forums/index.php?topic=46631.0

Manu

Quote from: Crimson Wizard on Tue 08/06/2021 08:30:13
But if you really must do this, the latest version of AGS (3.5.1) provides direct means to access user config regardless of its location using new tag $CONFIGFILE$.

Fantastic! Exactly what I wanted. Thanks a lot!

SMF spam blocked by CleanTalk