forked from Reloaded-Project/Reloaded-II
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Publish.ps1
140 lines (115 loc) · 6.91 KB
/
Publish.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
[cmdletbinding()]
param (
## => User Config <= ##
$Version = "1.0.0"
)
# .NET 6 Has Issues with Handles and Files Already in use when building
# single file applications, we have to try work around it here.
function New-TemporaryDirectory
{
$parent = [System.IO.Path]::GetTempPath()
[string] $name = [System.Guid]::NewGuid()
$returnValue = Join-Path "$parent" "$name"
Write-Host "Location: $returnValue"
return "$returnValue"
}
# Set Working Directory
Split-Path $MyInvocation.MyCommand.Path | Push-Location
[Environment]::CurrentDirectory = $PWD
Write-Host "New Current Directory: $(Get-Location)"
# Build Locations
$buildPath = New-TemporaryDirectory
$outputPath = "$buildPath/Publish"
$outputPath32 = "$buildPath/Publish/x86"
$toolsPath = "$buildPath/Tools/"
$loaderOutputPath = "$outputPath/Loader/"
$loader32OutputPath = "$outputPath/Loader/x86"
$loader64OutputPath = "$outputPath/Loader/x64"
$chocoPath = "./Chocolatey"
$chocoToolsPath = "$chocoPath/tools"
# Project Paths
$bootstrapperPath = "Reloaded.Mod.Loader.Bootstrapper/Reloaded.Mod.Bootstrapper.vcxproj"
$installerProjectPath = "./Reloaded.Mod.Installer/Reloaded.Mod.Installer.csproj"
$launcherProjectPath = "Reloaded.Mod.Launcher/Reloaded.Mod.Launcher.csproj"
$loaderProjectPath = "Reloaded.Mod.Loader/Reloaded.Mod.Loader.csproj"
$addressDumperProjectPath = "Reloaded.Mod.Launcher.Kernel32AddressDumper/Reloaded.Mod.Launcher.Kernel32AddressDumper.csproj"
$templateProjectPath = "Reloaded.Mod.Template/Reloaded.Mod.Template.NuGet.csproj"
$communityProjectPath = "Tools/Reloaded.Community.Tool/Reloaded.Community.Tool.csproj"
$nugetConverterProjectPath = "Tools/NugetConverter/NugetConverter.csproj"
$publisherProjectPath = "Tools/Reloaded.Publisher/Reloaded.Publisher.csproj"
# Outputs
$publishDirectory = "Publish"
$chocoPublishDirectory = "$publishDirectory/Chocolatey"
$installerPublishDirectory = "$publishDirectory/Installer"
$templatePublishDirectory = "$publishDirectory/ModTemplate"
$releaseFolder = "/Release"
$toolsReleaseFileName = "/Tools.zip"
$cleanupPaths = ("$buildPath", "$toolsPath", "$publishDirectory", "$chocoToolsPath")
# Clean output directories
foreach ($cleanupPath in $cleanupPaths) {
Get-ChildItem "$cleanupPath" -Include * -Recurse -ErrorAction SilentlyContinue | Remove-Item -Force -Recurse -ErrorAction SilentlyContinue
}
Get-ChildItem "$chocoPath" -Include *.nupkg -Recurse -ErrorAction SilentlyContinue | Remove-Item -Force -Recurse
# Build using Visual Studio
msbuild $bootstrapperPath /p:Configuration=Release /p:Platform=x64 /p:OutDir="$loaderOutputPath"
dotnet publish "$addressDumperProjectPath" -c Release -r win-x86 --self-contained false -o "$loaderOutputPath"
# Build AnyCPU, and then copy 32-bit AppHost.
dotnet publish "$launcherProjectPath" -c Release --self-contained false -o "$outputPath"
dotnet publish "$launcherProjectPath" -c Release -r win-x86 --self-contained false -o "$outputPath32"
# Build Loader
dotnet publish "$loaderProjectPath" -c Release -r win-x64 --self-contained false -o "$loader64OutputPath" /p:PublishReadyToRun=true
dotnet publish "$loaderProjectPath" -c Release -r win-x86 --self-contained false -o "$loader32OutputPath" /p:PublishReadyToRun=true
# Build Tools
dotnet publish "$nugetConverterProjectPath" -c Release -r win-x64 --self-contained false -o "$toolsPath" /p:PublishSingleFile=true
dotnet publish "$publisherProjectPath" -c Release -r win-x64 --self-contained false -o "$toolsPath" /p:PublishSingleFile=true
dotnet publish "$communityProjectPath" -c Release -r win-x64 --self-contained false -o "$toolsPath" /p:PublishSingleFile=true
# Build Installer
dotnet publish "$installerProjectPath" -o "$installerPublishDirectory"
# Build Templates
dotnet pack "$templateProjectPath" -o "$templatePublishDirectory"
# Copy 32-bit EXE and cleanup folders.
Move-Item -Path "$outputPath32/Reloaded-II.exe" -Destination "$outputPath/Reloaded-II32.exe"
Remove-Item "$outputPath32" -Recurse -ErrorAction SilentlyContinue
Remove-Item "$loaderOutputPath/win-x86" -Recurse -ErrorAction SilentlyContinue
Remove-Item "$outputPath/win-x86" -Recurse -ErrorAction SilentlyContinue
Remove-Item "$outputPath/win-x64" -Recurse -ErrorAction SilentlyContinue
Remove-Item "$outputPath/ref" -Recurse -ErrorAction SilentlyContinue
Remove-Item "$outputPath/Theme/Halogen/Images/IconTemplate.7z" -Recurse -ErrorAction SilentlyContinue
Remove-Item "$outputPath/Theme/Default/R-II/Images/Templates.zip" -Recurse -ErrorAction SilentlyContinue
# Remove non-windows native stuff
$excludePatterns=@('win-x86*','win-x64*','win*')
$includePatterns=@('win-arm*')
Get-ChildItem "$outputPath/runtimes" -Exclude $excludePatterns | Remove-Item -Force -Recurse
Get-ChildItem "$outputPath/runtimes" -Include $includePatterns -Recurse | Remove-Item -Force -Recurse
# Remove debug/compile leftovers.
Get-ChildItem "$loader32OutputPath" -Include *.exe -Recurse -ErrorAction SilentlyContinue | Remove-Item -Force -Recurse
Get-ChildItem "$loader64OutputPath" -Include *.exe -Recurse -ErrorAction SilentlyContinue | Remove-Item -Force -Recurse
foreach ($cleanupPath in $cleanupPaths) {
Get-ChildItem "$cleanupPath" -Include *.config -Recurse -ErrorAction SilentlyContinue | Remove-Item -Force -Recurse
Get-ChildItem "$cleanupPath" -Include *.pdb -Recurse -ErrorAction SilentlyContinue | Remove-Item -Force -Recurse
Get-ChildItem "$cleanupPath" -Include *.xml -Recurse -ErrorAction SilentlyContinue | Remove-Item -Force -Recurse
Get-ChildItem "$cleanupPath" -Include *.exp -Recurse -ErrorAction SilentlyContinue | Remove-Item -Force -Recurse
Get-ChildItem "$cleanupPath" -Include *.lib -Recurse -ErrorAction SilentlyContinue | Remove-Item -Force -Recurse
Get-ChildItem "$cleanupPath" -Include *.iobj -Recurse -ErrorAction SilentlyContinue | Remove-Item -Force -Recurse
Get-ChildItem "$cleanupPath" -Include *.ipdb -Recurse -ErrorAction SilentlyContinue | Remove-Item -Force -Recurse
}
# Make directories for storing results.
New-Item "$chocoPublishDirectory" -ItemType Directory -ErrorAction SilentlyContinue
# Compress result.
Add-Type -A System.IO.Compression.FileSystem
[IO.Compression.ZipFile]::CreateFromDirectory("$toolsPath", "$publishDirectory" + "$toolsReleaseFileName")
# Publish Mod
Get-ChildItem -Path "$outputPath" -Recurse -Force -ErrorAction SilentlyContinue
New-Item "$publishDirectory/$releaseFolder" -ItemType Directory -ErrorAction SilentlyContinue
./Publish.Reloaded.Release.ps1 -Version "$Version" -CurrentVersionPath "$outputPath" -ReleasePath "$publishDirectory/$releaseFolder"
Remove-Item "$chocoToolsPath" -Recurse -ErrorAction SilentlyContinue
New-Item "$chocoToolsPath" -ItemType Directory -ErrorAction SilentlyContinue
Copy-Item "$toolsPath/*" -Destination "$chocoToolsPath"
choco pack ./Chocolatey/reloaded-ii-tools.nuspec --out "$chocoPublishDirectory"
# Cleanup build items
Remove-Item "$buildPath" -Recurse
# Show Publish Items
Write-Host "Publish Items"
Get-ChildItem -Path $publishDirectory -Recurse -Force -ErrorAction SilentlyContinue
# Restore Working Directory
Pop-Location