Skip to content

Commit

Permalink
Improve GameFileX keys reading for translations (CnCNet#476)
Browse files Browse the repository at this point in the history
* Fix logic for using any number and letters after GameFile keys

* Fix typo

* Fix syntax error and add info to the docs

* Apply suggestions from code review

---------

Co-authored-by: Kerbiter <crabiter@vivaldi.net>
  • Loading branch information
2 people authored and SadPencil committed Oct 4, 2024
1 parent 3fa8e63 commit 845c8ae
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
14 changes: 9 additions & 5 deletions ClientCore/ClientConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -278,23 +278,27 @@ private List<TranslationGameFile> ParseTranslationGameFiles()
{
List<TranslationGameFile> gameFiles = new();

for (int i = 0; clientDefinitionsIni.KeyExists(TRANSLATIONS, $"GameFile{i}"); i++)
foreach (string key in clientDefinitionsIni.GetSectionKeys(TRANSLATIONS))
{
// the syntax is GameFileX=path/to/source.file,path/to/destination.file[,checked]
string value = clientDefinitionsIni.GetStringValue(TRANSLATIONS, $"GameFile{i}", string.Empty);
string[] parts = value.Split(',', StringSplitOptions.RemoveEmptyEntries).Select(s => s.Trim()).ToArray();
// where X can be any text or number
if (!key.StartsWith("GameFile"))
continue;

string value = clientDefinitionsIni.GetStringValue(TRANSLATIONS, key, string.Empty);
string[] parts = value.Split(',');

// fail explicitly if the syntax is wrong
if (parts.Length is < 2 or > 3
|| (parts.Length == 3 && parts[2].ToUpperInvariant() != "CHECKED"))
{
throw new IniParseException($"Invalid syntax for value of GameFile{i}! " +
throw new IniParseException($"Invalid syntax for value of {key}! " +
$"Expected path/to/source.file,path/to/destination.file[,checked], read {value}.");
}

bool isChecked = parts.Length == 3 && parts[2].ToUpperInvariant() == "CHECKED";

gameFiles.Add(new(Source: parts[0], Target: parts[1], isChecked));
gameFiles.Add(new(Source: parts[0].Trim(), Target: parts[1].Trim(), isChecked));
}

return gameFiles;
Expand Down
8 changes: 6 additions & 2 deletions Docs/Translation.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ Each key in the `[Values]` section is composed of a few elements, joined using `
## Ingame translation setup

The translation system's ingame translation support requires the mod/game author(s) to specify the files which translators can provide in order to translate the game. The files are specified in the the syntax is `GameFileX=path/to/source.file,path/to/destination.file[,checked]` INI key in the `[Translations]` section of `ClientDefinitions.ini` (X is an index starting from 0 and going up), with comma-separated parts of the value meaning the following:
The translation system's ingame translation support requires the mod/game author(s) to specify the files which translators can provide in order to translate the game. The files are specified in the the syntax is `GameFileX=path/to/source.file,path/to/destination.file[,checked]` INI key in the `[Translations]` section of `ClientDefinitions.ini` (X is any text you want to add to the key to help sort files), with comma-separated parts of the value meaning the following:
1) the path to the source file relative to currently selected translation directory;
2) the destination to copy to, relative to the game root folder;
3) (optional) `checked` for the file to be checked by file integrity checks (should be on if this file can be used to cheat), if not specified - this file is not checked.
Expand All @@ -124,7 +124,11 @@ The translation system's ingame translation support requires the mod/game author
Example configuration in `ClientDefinitions.ini`:
```ini
[Translations]
GameFile0=translation.mix,expandmo98.mix
GameFileTranslationMix=translation.mix,expandmo98.mix
GameFile_GDI01=Missions/g0.map,Maps/Missions/g0.map
GameFile_NOD01=Missions/n0.map,Maps/Missions/n0.map
GameFile_DLL_SD=Resources/language_800x600.dll, Resources/language_800x600.dll
GameFile_DLL_HD=Resources/language_1024x720.dll,Resources/language_1024x720.dll
```

This will make the `translation.mix` file from current translation folder (say, `Resources/Translations/ru`) copied to game root as `expandmo98.mix` on game start.
Expand Down

0 comments on commit 845c8ae

Please sign in to comment.