Skip to content

Instantly share code, notes, and snippets.

@Pysis868
Last active December 18, 2024 17:49
Show Gist options
  • Save Pysis868/1d5a91e1c1930e79807d71c361136c32 to your computer and use it in GitHub Desktop.
Save Pysis868/1d5a91e1c1930e79807d71c361136c32 to your computer and use it in GitHub Desktop.
Handle game file data, most likely hash mismatches, and handle fixing them ourselves using data from Frontier, to help the installer continue, or just direct installing.
#!/usr/bin/env fish
# Author: Pysis
# License: MIT
# Link: https://gist.github.com/Pysis868/1d5a91e1c1930e79807d71c361136c32
# Handle game file data,
# most likely hash mismatches,
# and handle fixing them ourselves using data from Frontier,
# to help the installer continue, or just direct installing.
# Notes:
# - Files are checksummed/hashed using SHA1.
# - Preferring to exit on errors to help detect and fix procedural errors,
# minimizing/preventing continued, large, erroneous process executions.
function edDownloadFiles
while read jsonLine
## Load and check file paths and names.
set remoteFile (
echo "$jsonLine" \
| jq -r '.RemoteFile'
);
set remoteFileName (
basename "$remoteFile"
);
set localFilePath (
echo "$jsonLine" \
| jq -r '.LocalFile'
);
set localFileName (
basename "$localFilePath"
);
if test -z "$remoteFile" -o -z "$remoteFileName" -o -z "$localFilePath"
echo 'remoteFileName or localFilePath empty; noting and continuing...';
echo "remoteFileName or localFilePath empty." >> 'errors.json';
echo "$jsonLine" >> 'errors.json';
else
# echo 'File paths and names determined successfully.';
end
set expSha1 (
echo "$jsonLine" \
| jq -r '.Expected'
);
## Branch for extra hash check if file exists.
## Remove if it does, but corrupted.
## Skip if completely valid.
if test -e "$localFilePath"
echo "Remote file \"$remoteFileName\" already exists";
echo "as \"$localFileName\".";
set actSha1 (
sha1sum "$localFilePath" \
| awk '{ print $1 }' \
| sed -r 's/^\\\\//'
);
if test -z "$expSha1" -o -z "$actSha1"
echo 'File SHA1 hashes could not be determined or generated; noting and continuing...';
echo "File SHA1 hashes could not be determined or generated." >> 'errors.json';
echo "$jsonLine" >> 'errors.json';
else
# echo 'File SHA1 hashes determined and generated successfully.';
end
if test "$expSha1" != "$actSha1"
errorPrint 'SHA1 of local file does not match expected; removing local file to redownload...';
rm "$localFilePath";
else
# echo 'File SHA1 hash matches expected; skipping...';
echo;
continue;
end
end
# echo "Processing remote file \"$remoteFileName\"...";
## If file not cached, download for installation.
if test ! -e "$remoteFileName"
if wget "$remoteFile" -O "$localFilePath"
# echo 'File downloaded successfully; continuing...';
else
echo 'File download failed; noting and continuing...';
echo "File download failed." >> 'errors.json';
echo "$jsonLine" >> 'errors.json';
end
else
# echo 'File already exists; continuing...';
end
set actSha1 (
sha1sum "$localFilePath" \
| awk '{ print $1 }' \
| sed -r 's/^\\\\//'
);
## Check downloaded file's hash to avoid corruption.
if test -z "$expSha1" -o -z "$actSha1"
echo 'File SHA1 hashes could not be determined or generated; noting and continuing...';
echo "File SHA1 hashes could not be determined or generated." >> 'errors.json';
echo "$jsonLine" >> 'errors.json';
else
# echo 'File SHA1 hashes determined and generated successfully.';
end
if test "$expSha1" != "$actSha1"
echo 'SHA1 of downloaded file does not match expected; noting and continuing...';
echo "SHA1 of downloaded file does not match expected." >> 'errors.json';
echo "$jsonLine" >> 'errors.json';
else
# echo 'File SHA1 hash match expected.';
end
echo;
end
end
#!/usr/bin/env fish
# Author: Pysis
# License: MIT
# Link: https://gist.github.com/Pysis868/1d5a91e1c1930e79807d71c361136c32
# Process the client.log file for problems,
# only outputting file metadata blocks.
# Download files:
# cat "$fileClientLog" \
# | edParseClientLog \
# | edDownloadFiles \
# ;
function edParseClientLog
while read line
## Load JSON Data.
set json (
echo "$line" \
| dos2unix \
| sed -r \
-e 's/^[^:]+: //' \
-e 's/;$//' \
-e 's/\\\\/\\\\\\\\/g'
);
if test "$status" -gt '0' -o -z "$json"
errorPrint 'JSON manipulation failed, or data is empty; exiting...';
errorPrint "line : $line" ;
errorPrint "json : $json" ;
popd;
return 1;
else
# echo 'JSON manipulation completed successfully.';
end
## Load and check action.
set action (
echo "$json" \
| jq -r '.action'
);
if test \
"$action" != 'DownloadedDataMismatch'
# -o "$action" != 'ValidationOfDownloadedFileFailed'
# errorPrint 'Action not \'DownloadedDataMismatch\'; exiting...';
# errorPrint "json : $json" ;
# errorPrint "action : $action" ;
# errorPrint "remoteFileName: $remoteFileName" ;
# errorPrint "localFilePath : $localFilePath" ;
# return 2;
# echo 'Action not \'DownloadedDataMismatch\'; skipping...';
continue;
else
# echo 'Correct redownload action type.';
end
## Output
# string join \n $json;
echo "$json";
end
end
#!/usr/bin/env fish
# Author: Pysis
# License: MIT
# Link: https://gist.github.com/Pysis868/1d5a91e1c1930e79807d71c361136c32
# Process the install manifest file to match
# the JSON format client.log uses.
# Convert manifest file to JSON:
# zcat "$fileManifest" \
# | xq | gzip - > (
# cygpath "$fileManifest" \
# | sed -r 's/\.xml\.gz//'
# )'.json.gz';
# Download files:
# zcat "$fileManifestJSON" \
# | edParseManifest \
# | edDownloadFiles \
# ;
function edParseManifest
test -z "$pathLocalBase";
and set pathLocalBase "$argv[1]";
if test -z "$pathLocalBase"
errorPrint 'pathLocalBase not provided; exiting...';
return 1;
end
if test ! -e "$pathLocalBase"
errorPrint 'pathLocalBase does not exist; exiting...';
return 2;
end
jq -c -r --arg pathLocalBase "$pathLocalBase" '
.Manifest.File[]
| {
Expected: .Hash,
LocalFile: ("\\($pathLocalBase)\\\\\(.Path)"),
RemoteFile: .Download,
Size: .Size
}
';
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment