Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Script by EVWeb, edited by Anoyomouse & Vas
- # Script checks if the SDK path is set. If not, asks where, and then sets it on the User level.
- # After that, the script reads the project files to figure out how to process the mod data.
- # Set working dir to current script dir
- $path = Split-Path $MyInvocation.MyCommand.Path -Parent
- Clear-Host
- Write-Host "Running compiler for mod: $($path)`n"
- # Make sure SDK is installed
- if([string]::IsNullOrWhiteSpace($env:MAJESTYSDK) -or
- -not (Test-Path $env:MAJESTYSDK) -or
- -not (Test-Path "$env:MAJESTYSDK\gplbcc.exe"))
- {
- Add-Type -AssemblyName System.Windows.Forms
- $FolderBrowser = New-Object System.Windows.Forms.FolderBrowserDialog -Property @{
- ShowNewFolderButton = $false
- Description = 'The Majesty SDK Folder has not been set, please locate it.'
- }
- $result = $FolderBrowser.ShowDialog()
- # See if SDK path was set
- if($result -ne [System.Windows.Forms.DialogResult]::OK)
- {
- Write-Host "ERROR: Unable to find the GPL compiler. Set the MAJESTYSDK environment variable to point to the SDK path." -ForegroundColor Red
- exit 1;
- }
- $env:MAJESTYSDK = $FolderBrowser.SelectedPath
- # Persist the environment variable
- [System.Environment]::SetEnvironmentVariable("MAJESTYSDK", $env:MAJESTYSDK, 'User')
- }
- $sdk = $env:MAJESTYSDK + "\gplbcc.exe"
- If (-not (Test-Path $sdk)) {
- Write-Error "Could not find the gplbcc compiler at ($sdk)";
- Exit(1)
- }
- #Read Main Project and create the GPLProjs
- $mmxmls = Get-ChildItem -Include *.mmxml -Name
- foreach($mmxml in $mmxmls)
- {
- [xml]$xml = Get-Content $mmxml
- foreach($mod in $xml.Majesty.Mod)
- {
- foreach($gpl in $mod.DataConfiguration.Dataset.Load.GPL)
- {
- $target = $gpl.Target
- if(Test-Path $target)
- {
- Write-Host "Removing old $($target)" -ForegroundColor DarkYellow
- Remove-Item $target
- }
- $gplproj = [System.IO.Path]::GetFileNameWithoutExtension($target) + ".gplproj"
- if(Test-Path $gplproj)
- {
- Write-Host "Removing old $($gplproj)" -ForegroundColor DarkYellow
- Remove-Item $gplproj
- }
- $projContent = "";
- foreach($source in $gpl.Source)
- {
- if( $source.EndsWith(".dat") )
- {
- $projContent += 'data="'
- }
- else
- {
- $projContent += 'source="'
- }
- $projContent += $source + "`"`r`n"
- }
- Set-Content $gplproj -NoNewline -Value $projContent
- Write-Host "Compiling '$($gplproj)' to '$($target)'" -ForegroundColor Yellow
- & $sdk '-in' $gplproj '-out' $target '-stderr'
- Remove-Item $gplproj
- }
- }
- }
- # If running in the console, wait for input before closing.
- # Changed to require Space to be pressed, in case you have an error you need to copy.
- if ($Host.Name -eq "ConsoleHost")
- {
- Write-Host "Press space to continue..."
- While (($Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyUp")).Character -ne ' ') { }
- }
Add Comment
Please, Sign In to add comment