From 9eaf30bbf9d5e69844d85b131038610b9d82d952 Mon Sep 17 00:00:00 2001 From: Alex Berry Date: Wed, 4 Mar 2020 19:34:46 +0000 Subject: [PATCH] Updating readme, adding compile.ps1 --- README.md | 17 ++++++++++++++++- compile.ps1 | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 compile.ps1 diff --git a/README.md b/README.md index 0590f86..727bca0 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,18 @@ # pwn-compile -Compile.ps1 repositor \ No newline at end of file +Compile.ps1 repository. + +## Usage + +### All-Cores mode +To run this script with all available cores, copy it to your maps directory, open a powershell terminal, cd to this directory and run: + +```powershell +.\compile.ps1 +``` + +### X Cores mode +To override the number of cores used to compile, set the Cores param when calling the script: +```powershell +.\compile.ps1 -Cores 2 +``` diff --git a/compile.ps1 b/compile.ps1 new file mode 100644 index 0000000..edd2d32 --- /dev/null +++ b/compile.ps1 @@ -0,0 +1,39 @@ +Param( + [Int]$Cores = 0 +) + +if ($Cores-ne 0) { + Write-Host "Overriding core count with $Cores." + $MaxThreads = $Cores +} +else { + $MaxThreads = (Get-WmiObject -Class Win32_Processor).NumberOfLogicalProcessors + Write-Host "Running with $MaxThreads" Cores by default. +} + + +$files = (ls *.pwn).Name +$workdir = (pwd) +$Block = { + Param([string] $file, [string] $workdir) + & cd $workdir; .\pawncc.exe $file +} +#Remove all jobs +Get-Job | Remove-Job +#Start the jobs. Max 4 jobs running simultaneously. +foreach($file in $files){ + While ($(Get-Job -state running).count -ge $MaxThreads){ + Start-Sleep -Milliseconds 3 + } + Start-Job -Scriptblock $Block -ArgumentList $file, $workdir +} +#Wait for all jobs to finish. +While ($(Get-Job -State Running).count -gt 0){ + start-sleep 1 +} +#Get information from each job. +foreach($job in Get-Job){ + $info= Receive-Job -Id ($job.Id) +} +#Remove all jobs created. +Get-Job | Remove-Job \ No newline at end of file