2020-03-09 17:49:36 +09:00
|
|
|
$ErrorActionPreference = "Stop";
|
|
|
|
|
|
|
|
# Retrieve commit hash from latest archive update
|
2020-03-09 23:35:43 +09:00
|
|
|
Write-Host -ForegroundColor Blue "Retrieving last update commit..";
|
2020-06-28 12:55:28 +09:00
|
|
|
$LastGCMUpdate = (git log -1 --pretty=format:"%H" ./docs/.vuepress/public/files/GCMCodes.zip);
|
2020-03-09 17:49:36 +09:00
|
|
|
|
|
|
|
if ([string]::IsNullOrWhiteSpace($LastGCMUpdate)) {
|
|
|
|
Write-Host -ForegroundColor Red "Failed to retrieve the latest update commit";
|
|
|
|
exit -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
Write-Host -ForegroundColor Green "Last GCM Archive Update:" $LastGCMUpdate;
|
|
|
|
|
|
|
|
# Check whether any one of the code files chnged
|
|
|
|
Write-Host -ForegroundColor Blue "Scanning for code changes.."
|
|
|
|
|
2020-06-28 12:55:28 +09:00
|
|
|
$CodeUpdates = (git diff --name-only $LastGCMUpdate HEAD -- './docs/.vuepress/public/codes/*.xml')
|
2020-03-09 17:49:36 +09:00
|
|
|
|
|
|
|
if ([string]::IsNullOrWhiteSpace($CodeUpdates)) {
|
|
|
|
Write-Host -ForegroundColor Green "No code changes detected";
|
2020-03-09 23:35:43 +09:00
|
|
|
exit 0;
|
2020-03-09 17:49:36 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
Write-Host "Changed files since last archive Update:" $CodeUpdates;
|
|
|
|
|
|
|
|
# Start build
|
|
|
|
Write-Host -ForegroundColor Blue "Packing new archive...";
|
|
|
|
|
|
|
|
# Setup workspace
|
2020-03-09 23:35:43 +09:00
|
|
|
New-Item -ItemType directory -Path "./.build";
|
2020-06-28 12:55:28 +09:00
|
|
|
Copy-Item "./docs/.vuepress/public/codes/*.xml" "./.build/";
|
2020-03-09 23:35:43 +09:00
|
|
|
Set-Location "./.build";
|
2020-03-09 17:49:36 +09:00
|
|
|
|
|
|
|
# Helper function to convert the XML files to the GCM txt format
|
|
|
|
function XmlToGcm($source, $destination, $versionname) {
|
|
|
|
[xml]$xml = Get-Content $source;
|
|
|
|
|
|
|
|
Add-Content $destination $versionname;
|
|
|
|
Add-Content $destination "Super Mario Sunshine" -NoNewline;
|
|
|
|
|
|
|
|
foreach ($code in $xml.codes.code) {
|
|
|
|
Add-Content $destination "";
|
|
|
|
Add-Content $destination "";
|
|
|
|
Add-Content $destination "$($code.title."#text") ($($code.date)) [$($code.author)]";
|
|
|
|
$codeSource = $code.source -replace " +$", "" -replace "^? [^a-zA-Z0-9]", "";
|
|
|
|
Add-Content $destination $codeSource.Trim() -NoNewline;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-03-09 23:35:43 +09:00
|
|
|
# Helper function to convert the XML files to the Dolphin INI format
|
|
|
|
function XmlToIni($source, $destination, $versionname) {
|
|
|
|
[xml]$xml = Get-Content $source;
|
|
|
|
|
|
|
|
Add-Content $destination "Paste the following on top of your games .ini file:"
|
|
|
|
Add-Content $destination "[Gecko]" -NoNewline
|
|
|
|
|
|
|
|
foreach ($code in $xml.codes.code) {
|
|
|
|
Add-Content $destination "";
|
|
|
|
Add-Content $destination "`$$($code.title."#text") ($($code.date)) [$($code.author)]";
|
|
|
|
$codeSource = $code.source -replace " +$", "" -replace "^? [^a-zA-Z0-9]", "";
|
|
|
|
Add-Content $destination $codeSource.Trim() -NoNewline;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
# Convert files to GCM format
|
|
|
|
Write-Host "Converting XML files to GCM format..";
|
2020-03-09 17:49:36 +09:00
|
|
|
XmlToGcm "GMSE01.xml" "GMSE01.txt" "GMSE01";
|
|
|
|
XmlToGcm "GMSP01.xml" "GMSP01.txt" "GMSP01";
|
|
|
|
XmlToGcm "GMSJ01.xml" "GMSJ01.txt" "GMSJ01";
|
|
|
|
XmlToGcm "GMSJ0A.xml" "GMSJ01 (A).txt" "GMSJ01";
|
|
|
|
|
|
|
|
# Replace zip file
|
2020-03-09 23:35:43 +09:00
|
|
|
Write-Host "Compressing and replacing GCM archive..";
|
2020-06-28 12:55:28 +09:00
|
|
|
Compress-Archive "./*.txt" "../docs/.vuepress/public/files/GCMCodes.zip" -Force;
|
2020-03-09 23:35:43 +09:00
|
|
|
|
|
|
|
Write-Host -ForegroundColor Green "GCM Archive rebuilt";
|
|
|
|
|
|
|
|
# Convert files to Dolphin format
|
|
|
|
Remove-Item *.txt;
|
|
|
|
|
|
|
|
Write-Host "Converting XML files to Dolphin INI format..";
|
|
|
|
XmlToIni "GMSE01.xml" "GMSE01.txt" "GMSE01";
|
|
|
|
XmlToIni "GMSP01.xml" "GMSP01.txt" "GMSP01";
|
|
|
|
XmlToIni "GMSJ01.xml" "GMSJ01.txt" "GMSJ01";
|
|
|
|
XmlToIni "GMSJ0A.xml" "GMSJ01 (A).txt" "GMSJ01";
|
|
|
|
|
|
|
|
Write-Host "Compressing and replacing Dolphin archive..";
|
2020-06-28 12:55:28 +09:00
|
|
|
Compress-Archive "./*.txt" "../docs/.vuepress/public/files/DolphinCodes.zip" -Force;
|
2020-03-09 23:35:43 +09:00
|
|
|
|
|
|
|
Write-Host -ForegroundColor Green "Dolphin Archive rebuilt";
|
|
|
|
|
|
|
|
# Cleanup
|
|
|
|
Write-Host "Cleaning up..";
|
2020-03-09 17:49:36 +09:00
|
|
|
Set-Location ..;
|
2020-03-09 23:35:43 +09:00
|
|
|
Remove-Item "./.build" -Recurse;
|
2020-06-28 13:30:10 +09:00
|
|
|
Write-Host -ForegroundColor Green "Done";
|