Refactor calculating file hashes
This PR reworks the file hash calculator to:
-
Fix a bug introduced in https://github.com/CnCNet/xna-cncnet-client/pull/341/ (codes here, diff here), where all files in "Map Code" and "Game Options" folders are not included. This bug should be a threat for anti-cheating detection.
TLDR: the bug is introduced because:
string folderName = @"E:\SteamLibrary"; string fileName1 = Directory.GetFiles(folderName).First().Dump(); // "E:\SteamLibrary\libraryfolder.vdf" string fileName2 = new DirectoryInfo(folderName).EnumerateFiles("*").First().Name.Dump(); // "libraryfolder.vdf" -
Fix a potential bug introduced in implementing multi-language support. Files in
ClientConfiguration.Instance.TranslationGameFiles.Where(tgf => tgf.Checked)(these files should be checked) are not sorted, leaving the file order as uncertain, especially in cross-platform scenarios. Now, all enumerated files will be sorted with path separators normalized. -
For known text file extensions like
.ini, when computing hashes, the client will try to normalize the difference between Windows (\r\nin the end of every line except for the last) and UNIX (\nin the end of every line). -
Remove redundancy parameter in
CalculateHashes(List<GameMode> gameModes)that has been unused since 801bee2b39a55640055fee01cf9e86622748d102
Nightly build for this pull request:
- artifacts-YR.zip
- artifacts-Ares.zip
- artifacts-TS.zip This comment is automatic and is meant to allow guests to get latest automatic builds without registering. It is updated on every successful build.
- Fix a potential bug introduced in implementing multi-language support. Files in
ClientConfiguration.Instance.TranslationGameFiles.Where(tgf => tgf.Checked)(these files should be checked) are not sorted, leaving the file order as uncertain, especially in cross-platform scenarios. Now, all enumerated files will be sorted with path separators normalized.
I am not sure, IIRC they are order-independent?
- Fix a potential bug introduced in implementing multi-language support. Files in
ClientConfiguration.Instance.TranslationGameFiles.Where(tgf => tgf.Checked)(these files should be checked) are not sorted, leaving the file order as uncertain, especially in cross-platform scenarios. Now, all enumerated files will be sorted with path separators normalized.I am not sure, IIRC they are order-independent?
No. They are order-dependent.
https://github.com/CnCNet/xna-cncnet-client/blob/6dc4a6dd284d7cc5e12715a6832bb225d7f0697a/DXMainClient/Online/FileHashCalculator.cs#L131
fh.INIHashes = AddToStringIfFileExists(fh.INIHashes, filePath);
string AddToStringIfFileExists(string str, string path)
{
if (File.Exists(path))
return str + Utilities.CalculateSHA1ForFile(SafePath.CombineFilePath(ProgramConstants.GamePath, path));
return str;
}