From 5e16c4710026478a433c3024dc053afc9fa3cd00 Mon Sep 17 00:00:00 2001 From: Frank Skare Date: Sun, 26 May 2019 05:32:23 +0200 Subject: [PATCH] - --- README.md | 1 + setup.ps1 | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/README.md b/README.md index 6e2dd09..58c6a24 100644 --- a/README.md +++ b/README.md @@ -209,6 +209,7 @@ mpv.net bugs and requests: - new options osd-font-size, sub-font, sub-font-size, sub-color, sub-border-color, sub-back-color - the config editor no longer shows the command line switches - the github start page was greatly improved +- the setup.ps1 PowerShell script was greatly improved in regard of error handling and readability ### 3.7 diff --git a/setup.ps1 b/setup.ps1 index 24d12fa..e0c7c90 100644 --- a/setup.ps1 +++ b/setup.ps1 @@ -1,3 +1,6 @@ +using namespace System.IO; + +# exit the script if the exit code is greater than 0 function CheckExitCode { if ($LastExitCode -gt 0) { Write-Host "`nExit code $LastExitCode was returned.`n" -ForegroundColor Red @@ -5,16 +8,30 @@ function CheckExitCode { } } +# exit the script if the file don't exist +function CheckFileExist($path) { + if (![File]::Exists($path)) { + Write-Host "`nFile is missing:`n`n$path`n" -ForegroundColor Red + exit + } +} + $msbuild = "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe" $innoSetup = "C:\Program Files (x86)\Inno Setup 6\ISCC.exe" $sevenZip = "C:\Program Files\7-Zip\7z.exe" +# exit the script if one of the executables don't exist +CheckFileExist($msbuild); CheckFileExist($innoSetup); CheckFileExist($sevenZip); + +# build the projects using msbuild & $msbuild mpv.net.sln /p:Configuration=Debug /p:Platform=x64; CheckExitCode & $msbuild mpv.net.sln /p:Configuration=Debug /p:Platform=x86; CheckExitCode +# build the setups using inno setup & $innoSetup /Darch="x64" setup.iss; CheckExitCode & $innoSetup /Darch="x86" setup.iss; CheckExitCode +# create the x64 portable archives $scriptDir = Split-Path -Path $PSCommandPath -Parent $desktopDir = [Environment]::GetFolderPath("Desktop") $exePath = $scriptDir + "\mpv.net\bin\x64\mpvnet.exe" @@ -24,6 +41,7 @@ Copy-Item $scriptDir\mpv.net\bin\x64 $targetDir -Recurse -Exclude System.Managem & $sevenZip a -t7z -mx9 "$targetDir.7z" -r "$targetDir\*"; CheckExitCode & $sevenZip a -tzip -mx9 "$targetDir.zip" -r "$targetDir\*"; CheckExitCode +# create the x86 portable archives $exePath = $scriptDir + "\mpv.net\bin\x86\mpvnet.exe" $version = [Diagnostics.FileVersionInfo]::GetVersionInfo($exePath).FileVersion $targetDir = $desktopDir + "\mpv.net-portable-x86-" + $version