Skip to content
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

Translation system config reading fix #476

Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions ClientCore/ClientConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@

public string StatisticsLogFileName => clientDefinitionsIni.GetStringValue(SETTINGS, "StatisticsLogFileName", "DTA.LOG");

public (string Name, string Path) GetThemeInfoFromIndex(int themeIndex) => clientDefinitionsIni.GetStringValue("Themes", themeIndex.ToString(), ",").Split(',').AsTuple2();

Check warning on line 239 in ClientCore/ClientConfiguration.cs

View workflow job for this annotation

GitHub Actions / build-clients (Ares)

The behavior of 'int.ToString()' could vary based on the current user's locale settings. Replace this call in 'ClientConfiguration.GetThemeInfoFromIndex(int)' with a call to 'int.ToString(IFormatProvider)'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1305)

Check warning on line 239 in ClientCore/ClientConfiguration.cs

View workflow job for this annotation

GitHub Actions / build-clients (TS)

The behavior of 'int.ToString()' could vary based on the current user's locale settings. Replace this call in 'ClientConfiguration.GetThemeInfoFromIndex(int)' with a call to 'int.ToString(IFormatProvider)'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1305)

Check warning on line 239 in ClientCore/ClientConfiguration.cs

View workflow job for this annotation

GitHub Actions / build-clients (YR)

The behavior of 'int.ToString()' could vary based on the current user's locale settings. Replace this call in 'ClientConfiguration.GetThemeInfoFromIndex(int)' with a call to 'int.ToString(IFormatProvider)'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1305)

/// <summary>
/// Returns the directory path for a theme, or null if the specified
Expand Down Expand Up @@ -278,23 +278,26 @@
{
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();
// syntax must bet GameFileX=..., where X - any text.
Metadorius marked this conversation as resolved.
Show resolved Hide resolved
if (!key.StartsWith("GameFile"))

Check warning on line 284 in ClientCore/ClientConfiguration.cs

View workflow job for this annotation

GitHub Actions / build-clients (Ares)

The behavior of 'string.StartsWith(string)' could vary based on the current user's locale settings. Replace this call in 'ClientCore.ClientConfiguration.ParseTranslationGameFiles()' with a call to 'string.StartsWith(string, System.StringComparison)'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1310)

Check warning on line 284 in ClientCore/ClientConfiguration.cs

View workflow job for this annotation

GitHub Actions / build-clients (TS)

The behavior of 'string.StartsWith(string)' could vary based on the current user's locale settings. Replace this call in 'ClientCore.ClientConfiguration.ParseTranslationGameFiles()' with a call to 'string.StartsWith(string, System.StringComparison)'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1310)

Check warning on line 284 in ClientCore/ClientConfiguration.cs

View workflow job for this annotation

GitHub Actions / build-clients (YR)

The behavior of 'string.StartsWith(string)' could vary based on the current user's locale settings. Replace this call in 'ClientCore.ClientConfiguration.ParseTranslationGameFiles()' with a call to 'string.StartsWith(string, System.StringComparison)'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1310)
continue;

string value = clientDefinitionsIni.GetStringValue(TRANSLATIONS, key, string.Empty);
string[] parts = value.Split(',');
Metadorius marked this conversation as resolved.
Show resolved Hide resolved

// fail explicitly if the syntax is wrong
if (parts.Length is < 2 or > 3
|| (parts.Length == 3 && parts[2].ToUpperInvariant() != "CHECKED"))

Check warning on line 292 in ClientCore/ClientConfiguration.cs

View workflow job for this annotation

GitHub Actions / build-clients (Ares)

Prefer using 'string.Equals(string, StringComparison)' to perform a case-insensitive comparison, but keep in mind that this might cause subtle changes in behavior, so make sure to conduct thorough testing after applying the suggestion, or if culturally sensitive comparison is not required, consider using 'StringComparison.OrdinalIgnoreCase' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1862)

Check warning on line 292 in ClientCore/ClientConfiguration.cs

View workflow job for this annotation

GitHub Actions / build-clients (TS)

Prefer using 'string.Equals(string, StringComparison)' to perform a case-insensitive comparison, but keep in mind that this might cause subtle changes in behavior, so make sure to conduct thorough testing after applying the suggestion, or if culturally sensitive comparison is not required, consider using 'StringComparison.OrdinalIgnoreCase' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1862)

Check warning on line 292 in ClientCore/ClientConfiguration.cs

View workflow job for this annotation

GitHub Actions / build-clients (YR)

Prefer using 'string.Equals(string, StringComparison)' to perform a case-insensitive comparison, but keep in mind that this might cause subtle changes in behavior, so make sure to conduct thorough testing after applying the suggestion, or if culturally sensitive comparison is not required, consider using 'StringComparison.OrdinalIgnoreCase' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1862)
{
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";

Check warning on line 298 in ClientCore/ClientConfiguration.cs

View workflow job for this annotation

GitHub Actions / build-clients (Ares)

Prefer using 'string.Equals(string, StringComparison)' to perform a case-insensitive comparison, but keep in mind that this might cause subtle changes in behavior, so make sure to conduct thorough testing after applying the suggestion, or if culturally sensitive comparison is not required, consider using 'StringComparison.OrdinalIgnoreCase' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1862)

Check warning on line 298 in ClientCore/ClientConfiguration.cs

View workflow job for this annotation

GitHub Actions / build-clients (TS)

Prefer using 'string.Equals(string, StringComparison)' to perform a case-insensitive comparison, but keep in mind that this might cause subtle changes in behavior, so make sure to conduct thorough testing after applying the suggestion, or if culturally sensitive comparison is not required, consider using 'StringComparison.OrdinalIgnoreCase' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1862)

Check warning on line 298 in ClientCore/ClientConfiguration.cs

View workflow job for this annotation

GitHub Actions / build-clients (YR)

Prefer using 'string.Equals(string, StringComparison)' to perform a case-insensitive comparison, but keep in mind that this might cause subtle changes in behavior, so make sure to conduct thorough testing after applying the suggestion, or if culturally sensitive comparison is not required, consider using 'StringComparison.OrdinalIgnoreCase' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1862)

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 Expand Up @@ -379,7 +382,7 @@

#endregion

public OSVersion GetOperatingSystemVersion()

Check warning on line 385 in ClientCore/ClientConfiguration.cs

View workflow job for this annotation

GitHub Actions / build-clients (Ares)

Member 'GetOperatingSystemVersion' does not access instance data and can be marked as static (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1822)

Check warning on line 385 in ClientCore/ClientConfiguration.cs

View workflow job for this annotation

GitHub Actions / build-clients (TS)

Member 'GetOperatingSystemVersion' does not access instance data and can be marked as static (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1822)
{
#if NETFRAMEWORK
// OperatingSystem.IsWindowsVersionAtLeast() is the preferred API but is not supported on earlier .NET versions
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
Loading