forked from SignatureBeef/Open-Terraria-API
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prebuild.ps1
87 lines (72 loc) · 2.82 KB
/
prebuild.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
#Use this script to prepare your OTAPI solution for building when you have a fresh clone
#To execute, run the following line in the Package Manager Console window in Visual Studio (View->Other Windows->Package Manager Console)
# Invoke-Expression .\prebuild.ps1
#OTAPI expected paths
$serverSaveFile = [IO.Path]::Combine("wrap", "TerrariaServer", "TerrariaServer.exe");
$zipSavePath = [IO.Path]::Combine("wrap", "TerrariaServer", "TerrariaServer.zip");
$clientSaveFile = "wrap\Terraria\Terraria.exe"
$clientSourcePath = "$((Get-ItemProperty HKLM:\SOFTWARE\WOW6432Node\re-logic\terraria\).exe_path)".Replace('/','\')
#Gets the working path for the current script being executed
Try
{
$workingDirectory = Split-Path -parent $PSCommandPath;
}
Catch
{
#Pash doesnt like here apparently, so since i'm using terminal for pash anyway
#i don't actually need the above.
$workingDirectory = [Environment]::CurrentDirectory;
}
#Generate the full paths
$serverSaveFile = [System.IO.Path]::Combine($workingDirectory, $serverSaveFile)
$zipSavePath = [System.IO.Path]::Combine($workingDirectory, $zipSavePath)
$clientSaveFile = [System.IO.Path]::Combine($workingDirectory, $clientSaveFile)
$clientSourcePath = [System.IO.Path]::Combine([Environment]::GetFolderPath([Environment+SpecialFolder]::ProgramFilesX86), $clientSourcePath);
#Remove any existing TerrariaServer.exe
If(Test-Path $serverSaveFile)
{
#Remove-Item $serverSaveFile
}
#Remove any existing client Terraria.exe
If(Test-Path $clientSaveFile)
{
Remove-Item $clientSaveFile
}
#Remove any existing temp zips
If(Test-Path $zipSavePath)
{
Remove-Item $zipSavePath
}
$downloadUrl = "https://terraria.org/api/download/pc-dedicated-server/terraria-server-1432.zip";
#Download the latest zip
Write-Host "Downloading $downloadUrl";
Try
{
Invoke-WebRequest -Uri $downloadUrl -OutFile $zipSavePath
}
Catch
{
(New-Object System.Net.WebClient).DownloadFile($downloadUrl, $zipSavePath)
}
#Import zip namespaces
[System.Reflection.Assembly]::LoadWithPartialName("System.IO.Compression");
[System.Reflection.Assembly]::LoadWithPartialName("System.IO.Compression.FileSystem");
Write-Host "Extracting TerrariaServer.exe from $zipSavePath";
#Open the zip archive
$zip = [System.IO.Compression.ZipFile]::OpenRead($zipSavePath); #not working on PASH yet :c
#Get the particular .exe we are after
$entry = $zip.GetEntry("1432/Windows/TerrariaServer.exe");
#Write the new zip to disk
$output = New-Object IO.StreamWriter $serverSaveFile;
$input = $entry.Open();
$input.CopyTo($output.BaseStream);
$input.Dispose();
$output.Dispose();
#Cleanup zips
Write-Host "Cleaning up"
$zip.Dispose();
Remove-Item $zipSavePath;
#Process the client. No fancy web update here as people must have paid for it anyway.
Write-Host "Copying client exe"
[System.IO.File]::Copy($clientSourcePath, $clientSaveFile);
Write-Host "Setup complete"