diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 32f48ea..ce1ada6 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -11,10 +11,10 @@ variables: steps: - task: PowerShell@2 - displayName: 'Update GCM Archive' + displayName: 'Update archives' inputs: targetType: 'filePath' - filePath: './update_gcm_archive.azure.ps1' + filePath: './update_archives.azure.ps1' failOnStderr: true workingDirectory: '.' - task: PowerShell@2 @@ -26,7 +26,8 @@ steps: git config --local user.name "BotPatty"; git config --local user.email "ci@zint.ch"; git add ./files/GCMCodes.zip; - git commit -m "Update GCM Archive [skip ci]";' + git add ./files/DolphinCodes.zip; + git commit -m "update archives [skip ci]";' failOnStderr: true workingDirectory: '.' - task: PowerShell@2 diff --git a/files/DolphinCodes.zip b/files/DolphinCodes.zip new file mode 100644 index 0000000..a9aa913 Binary files /dev/null and b/files/DolphinCodes.zip differ diff --git a/files/GCMCodes.zip b/files/GCMCodes.zip index b06e096..8f3cf67 100644 Binary files a/files/GCMCodes.zip and b/files/GCMCodes.zip differ diff --git a/update_gcm_archive.azure.ps1 b/update_archives.azure.ps1 similarity index 57% rename from update_gcm_archive.azure.ps1 rename to update_archives.azure.ps1 index ace347c..f14b830 100644 --- a/update_gcm_archive.azure.ps1 +++ b/update_archives.azure.ps1 @@ -1,7 +1,7 @@ $ErrorActionPreference = "Stop"; # Retrieve commit hash from latest archive update -Write-Host -ForegroundColor Blue "Retrieving last update commit.." +Write-Host -ForegroundColor Blue "Retrieving last update commit.."; $LastGCMUpdate = (git log -1 --pretty=format:"%H" ./files/GCMCodes.zip); if ([string]::IsNullOrWhiteSpace($LastGCMUpdate)) { @@ -18,7 +18,7 @@ $CodeUpdates = (git diff --name-only $LastGCMUpdate HEAD -- './codes/*.xml') if ([string]::IsNullOrWhiteSpace($CodeUpdates)) { Write-Host -ForegroundColor Green "No code changes detected"; - exit 0; + exit 0; } Write-Host "Changed files since last archive Update:" $CodeUpdates; @@ -27,9 +27,9 @@ Write-Host "Changed files since last archive Update:" $CodeUpdates; Write-Host -ForegroundColor Blue "Packing new archive..."; # Setup workspace -New-Item -ItemType directory -Path "./.gcmbuild"; -Copy-Item "./codes/*.xml" "./.gcmbuild/"; -Set-Location "./.gcmbuild"; +New-Item -ItemType directory -Path "./.build"; +Copy-Item "./codes/*.xml" "./.build/"; +Set-Location "./.build"; # Helper function to convert the XML files to the GCM txt format function XmlToGcm($source, $destination, $versionname) { @@ -47,18 +47,52 @@ function XmlToGcm($source, $destination, $versionname) { }; }; -# Convert files -Write-Host "Converting XML files.."; +# 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.."; 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 -Write-Host "Compressing and replacing archive.."; +Write-Host "Compressing and replacing GCM archive.."; Compress-Archive "./*.txt" "../files/GCMCodes.zip" -Force; + +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.."; +Compress-Archive "./*.txt" "../files/DolphinCodes.zip" -Force; + +Write-Host -ForegroundColor Green "Dolphin Archive rebuilt"; + +# Cleanup +Write-Host "Cleaning up.."; Set-Location ..; -Remove-Item "./.gcmbuild" -Recurse; +Remove-Item "./.build" -Recurse; Write-Host -ForegroundColor Green "Done"; # Set Azure variable to commit and push changes