wrye-bash / wrye-bash

A swiss army knife for modding Bethesda games.
https://wrye-bash.github.io
GNU General Public License v3.0
455 stars 79 forks source link

Generating the bash_default.ini #657

Open Infernio opened 1 year ago

Infernio commented 1 year ago

Right now, we package bash_default.ini so that changes to the default INI don't affect the user's settings. We also bundle a second default INI, in Russian. This part clearly won't scale to other languages - we can't clutter the Mopy folder with ten different default INIs.

So what I'm proposing is to get rid of the packaged bash_default.ini and to instead generate it on boot. Consider this:

default_bash_ini = f"""; Fancy 311 header goes here...

; Introduction goes here...

{wrap_ini_comment(_(
    "sOblivionMods is an alternate root directory for Bash Installers and "
    "other Bash data. Putting it under the game's install directory can cause "
    "performance problems during gameplay, so by default it is placed at the "
    "same level as the game folder. Here are the Oblivion and Skyrim "
    "defaults, and two other examples."))}
;sOblivionMods=..\Oblivion Mods
;sOblivionMods=..\Skyrim Mods
;sOblivionMods=C:\Games\Oblivion Mods
;sOblivionMods=C:\Steam\SteamApps\common\Skyrim Mods

; etc.

"""

default_ini_crc = crc32(default_bash_ini)

wrap_ini_comment would wrap the translated string to a fixed width (e.g. 100 chars) and add comments at the start of each line. The result would be identical to bash_default.ini today:

;--sOblivionMods is an alternate root directory for Bash Installers and other
;    Bash data.  Putting it under the game's install directory can cause
;    performance problems during gameplay, so by default it is placed at the
;    same level as the game folder.  Here are the Oblivion and Skyrim defaults,
;    and two other examples.

But the upside is that this is in Python, meaning we've got access to our translations - so now the INI can be seamlessly translated via the same translation system we're already using.

For checking if we need to regenerate the INI, we can simply compare the CRC computed above to the one on disk. That will catch both outdated INIs and cases when we've switched WB's language.

When doing this, we should obviously put the still-valid translations from the Russian INI into the Russian .po translation file to preserve them.

lojack5 commented 1 year ago

Only potential problem I could see with this is if the user can't even launch WB, but there's a workaround by setting something in the bash.ini, how will they know? Probably pester us on discord.

Infernio commented 1 year ago

I would assume the step for generating the bash_default.ini would be right before the bash.ini parsing step. So if WB doesn't get to the point of generating the default INI, it also won't get to the point of trying to read a bash.ini (which de facto means something is seriously bugged and they should report it so we can fix it).

We could also make the build script generate an initial bash_default.ini, just in case.