Skip to content

Commit

Permalink
Fix post-build events.
Browse files Browse the repository at this point in the history
Fix so post-build event makes links in TargetPath correctly, since Microsoft's mklink arguments are backwards from linux's ln.
Also fix link binaries script due to some Steam change, and optimize so only only checks the appmanifest we know we're looking for.
  • Loading branch information
Gwindalmir committed Oct 10, 2021
1 parent 7e4de01 commit 34c8a02
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 48 deletions.
2 changes: 1 addition & 1 deletion MEWorkshopTool/MEWorkshopTool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
<Import Project="..\WorkshopToolCommon\WorkshopToolCommon.projitems" Label="Shared" />
<Import Project="..\Updater\Updater.projitems" Label="Shared" />
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="set APPID=333950&#xD;&#xA;if NOT exist &quot;$(TargetDir)steam_appid.txt&quot; echo %APPID% &gt; &quot;$(TargetDir)steam_appid.txt&quot;&#xD;&#xA;if NOT exist &quot;$(TargetDir)\Bin64&quot; mklink /j &quot;$(ProjectDir)\Bin64&quot; &quot;$(TargetDir)\Bin64&quot;&#xD;&#xA;powershell.exe -ExecutionPolicy Bypass -NoProfile -NonInteractive -Command &quot;&amp; {Compress-Archive -Force -Path $(TargetDir)$(TargetName).exe, $(TargetDir)$(TargetName).exe.config, $(TargetDir)$(TargetName).pdb, $(TargetDir)CommandLine.dll, $(TargetDir).wtignore -DestinationPath $(TargetDir)$(TargetName)-v$(VersionPrefix).zip}&quot;" />
<Exec Command="set APPID=333950&#xD;&#xA;if NOT exist &quot;$(TargetDir)steam_appid.txt&quot; echo %APPID% &gt; &quot;$(TargetDir)steam_appid.txt&quot;&#xD;&#xA;if NOT exist &quot;$(TargetDir)\Bin64&quot; mklink /j &quot;$(TargetDir)\Bin64&quot; &quot;$(ProjectDir)\Bin64&quot;&#xD;&#xA;powershell.exe -ExecutionPolicy Bypass -NoProfile -NonInteractive -Command &quot;&amp; {Compress-Archive -Force -Path $(TargetDir)$(TargetName).exe, $(TargetDir)$(TargetName).exe.config, $(TargetDir)$(TargetName).pdb, $(TargetDir)CommandLine.dll, $(TargetDir)MEWT.config, $(TargetDir).wtignore -DestinationPath $(TargetDir)$(TargetName)-v$(VersionPrefix).zip}&quot;" />
</Target>
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<Exec Command="powershell.exe -ExecutionPolicy Bypass -NoProfile -NonInteractive -File $(SolutionDir)\Tools\LinkBinaries.ps1 333950 $(ProjectDir)\Bin64" />
Expand Down
2 changes: 1 addition & 1 deletion SEWorkshopTool/SEWorkshopTool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,6 @@
<Exec Command="powershell.exe -ExecutionPolicy Bypass -NoProfile -NonInteractive -File $(SolutionDir)\Tools\LinkBinaries.ps1 244850 $(ProjectDir)\Bin64" />
</Target>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="set APPID=244850&#xD;&#xA;if NOT exist &quot;$(TargetDir)steam_appid.txt&quot; echo %APPID% &gt; &quot;$(TargetDir)steam_appid.txt&quot;&#xD;&#xA;if NOT exist &quot;$(TargetDir)\Bin64&quot; mklink /j &quot;$(ProjectDir)\Bin64&quot; &quot;$(TargetDir)\Bin64&quot;&#xD;&#xA;powershell.exe -ExecutionPolicy Bypass -NoProfile -NonInteractive -Command &quot;&amp; {Compress-Archive -Force -Path $(TargetDir)$(TargetName).exe, $(TargetDir)$(TargetName).exe.config, $(TargetDir)$(TargetName).pdb, $(TargetDir)CommandLine.dll, $(TargetDir).wtignore, $(TargetDir)steam_appid.txt -DestinationPath $(TargetDir)$(TargetName)-v$(VersionPrefix).zip}&quot;" />
<Exec Command="set APPID=244850&#xD;&#xA;if NOT exist &quot;$(TargetDir)steam_appid.txt&quot; echo %APPID% &gt; &quot;$(TargetDir)steam_appid.txt&quot;&#xD;&#xA;if NOT exist &quot;$(TargetDir)\Bin64&quot; mklink /j &quot;$(TargetDir)\Bin64&quot; &quot;$(ProjectDir)\Bin64&quot;&#xD;&#xA;powershell.exe -ExecutionPolicy Bypass -NoProfile -NonInteractive -Command &quot;&amp; {Compress-Archive -Force -Path $(TargetDir)$(TargetName).exe, $(TargetDir)$(TargetName).exe.config, $(TargetDir)$(TargetName).pdb, $(TargetDir)CommandLine.dll, $(TargetDir).wtignore, $(TargetDir)steam_appid.txt -DestinationPath $(TargetDir)$(TargetName)-v$(VersionPrefix).zip}&quot;" />
</Target>
</Project>
92 changes: 46 additions & 46 deletions Tools/LinkBinaries.ps1
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[cmdletBinding(SupportsShouldProcess=$false)]
param(
[Parameter(Mandatory=$true)]
[System.UInt32]$AppId = 244850
[Parameter(Mandatory=$true)]
[System.UInt32]$AppId = 244850
,
[Parameter(Mandatory=$false)]
[System.String]$LinkDestination = $null
[Parameter(Mandatory=$false)]
[System.String]$LinkDestination = $null
,
[switch]$Force = $false
[switch]$Force = $false
)

function Get-ViaDepotDownloader {
Expand Down Expand Up @@ -49,14 +49,14 @@ function Get-ViaDepotDownloader {
}

if ($LinkDestination -and (Test-Path -Path $LinkDestination)) {
if ($Force) {
# -Force and -Recurse are required to delete a junction. However it won't delete the contents, as expected.
Remove-Item $LinkDestination -Force -Recurse
}
else {
Write-Verbose "Destination '$($LinkDestination)' already exists, skipping"
exit 0
}
if ($Force) {
# -Force and -Recurse are required to delete a junction. However it won't delete the contents, as expected.
Remove-Item $LinkDestination -Force -Recurse
}
else {
Write-Verbose "Destination '$($LinkDestination)' already exists, skipping"
exit 0
}
}

$GamePath = $null
Expand All @@ -72,23 +72,23 @@ try {
$librarys = ConvertFrom-VDF -InputObject (Get-Content "$($steamPath)\steamapps\libraryfolders.vdf")

for ($i = 1; $true; $i++) {
if ($librarys.LibraryFolders."$i" -eq $null) {
break
}
if ($librarys.LibraryFolders."$i" -eq $null) {
break
}

$path = $librarys.LibraryFolders."$i".Replace("\\","\")
Write-Verbose "Additional Steam library found in '$($path)'"
[array]$steamLibraries += $path
$path = $librarys.LibraryFolders."$i".path.Replace("\\","\")
Write-Verbose "Additional Steam library found in '$($path)'"
[array]$steamLibraries += $path
}

ForEach ($library in ($steamLibraries) ) {
Write-Verbose ("Checking library: " + $library)
ForEach ($file in (Get-ChildItem "$($library)\SteamApps\*.acf") ) {
$acf = ConvertFrom-VDF (Get-Content $file -Encoding UTF8)
if ($acf.AppState.appID -eq $AppId) {
$GamePath = "$($library)\SteamApps\common\$($acf.AppState.InstallDir)\Bin64"
}
}
Write-Verbose ("Checking library: " + $library)
$manifest = "$($library)\SteamApps\appmanifest_$($AppId).acf"
if (-not (Test-Path -Path $manifest -PathType Leaf)) { continue }
$acf = ConvertFrom-VDF -InputObject (Get-Content $manifest -Encoding UTF8)
if ($acf.AppState.appID -eq $AppId) {
$GamePath = "$($library)\SteamApps\common\$($acf.AppState.InstallDir)\Bin64"
}
}
if (-not $GamePath) { throw New-Object System.IO.DirectoryNotFoundException }
} catch {
Expand All @@ -101,29 +101,29 @@ try {
}

if ($GamePath) {
if ($LinkDestination) {
Write-Output ("Found Game: $($GamePath)")
New-Item -Path $LinkDestination -ItemType Junction -Value "$($GamePath)" | Out-Null
if ($LinkDestination) {
Write-Output ("Found Game: $($GamePath)")
New-Item -Path $LinkDestination -ItemType Junction -Value "$($GamePath)" | Out-Null
Write-Output ("Created symbolic link: $($LinkDestination) <-> $($GamePath)")
}
else {
Write-Output $GamePath
}
}
else {
Write-Output $GamePath
}
}
else {
if ($AppId -eq 244850) {
$path = Resolve-Path -Path "$($PSScriptRoot)\..\SEWorkshopTool"
$msg = ("`nCould not find Space Engineers installation. Manually create a junction to the Bin64 directory.`n" +
"mklink /j '$($path)\Bin64' '<Location of SpaceEngineers\Bin64>'`n-")
Write-Error $msg
}
elseif ($AppId -eq 333950) {
$path = Resolve-Path -Path "$($PSScriptRoot)\..\MEWorkshopTool"
$msg = ("`nCould not find Medieval Engineers installation. Manually create a junction to the Bin64 directory.`n" +
"mklink /j '$($path)\Bin64' '<Location of MedievalEngineers\Bin64>'`n-")
Write-Error $msg
}
exit 1
if ($AppId -eq 244850) {
$path = Resolve-Path -Path "$($PSScriptRoot)\..\SEWorkshopTool"
$msg = ("`nCould not find Space Engineers installation. Manually create a junction to the Bin64 directory.`n" +
"mklink /j '$($path)\Bin64' '<Location of SpaceEngineers\Bin64>'`n-")
Write-Error $msg
}
elseif ($AppId -eq 333950) {
$path = Resolve-Path -Path "$($PSScriptRoot)\..\MEWorkshopTool"
$msg = ("`nCould not find Medieval Engineers installation. Manually create a junction to the Bin64 directory.`n" +
"mklink /j '$($path)\Bin64' '<Location of MedievalEngineers\Bin64>'`n-")
Write-Error $msg
}
exit 1
}

exit 0

0 comments on commit 34c8a02

Please sign in to comment.