1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-10 01:22:25 +01:00
Files
OpenRCT2/openrct2.deps.targets
Aaron van Geffen ec0f4126b0 Let security guards alternate between slow and fast walking (#24730)
* Let security guards alternate between slow and fast walking

* Alternate based on amount of nearby guests instead

* Optimise loop to exit early once threshold has been reached

* Only count walking guests for security crowdedness

* Update replay bundle to v0.0.89

* Update NetworkBase.cpp
2025-07-15 10:02:37 +00:00

299 lines
12 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- DownloadDependency task -->
<UsingTask TaskName="DownloadDependency"
TaskFactory="CodeTaskFactory"
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
<ParameterGroup>
<Name Required="true" ParameterType="System.String" />
<Url Required="true" ParameterType="System.String" />
<Sha1 Required="true" ParameterType="System.String" />
<CheckFile Required="false" ParameterType="System.String" />
<OutputDirectory Required="true" ParameterType="System.String" />
</ParameterGroup>
<Task>
<Reference Include="System.IO.Compression, Version=4.0.0.0" />
<Reference Include="System.IO.Compression.FileSystem" />
<Using Namespace="System"/>
<Using Namespace="System.IO"/>
<Using Namespace="System.IO.Compression"/>
<Using Namespace="System.Net"/>
<Using Namespace="System.Text"/>
<Using Namespace="Microsoft.Build.Framework"/>
<Using Namespace="Microsoft.Build.Utilities"/>
<Code Type="Method" Language="cs">
<![CDATA[
public override bool Execute()
{
if (!String.IsNullOrEmpty(CheckFile))
{
string checkSha1 = GetSha1FromCheckFile(CheckFile, Name);
if (String.Equals(checkSha1, Sha1, StringComparison.OrdinalIgnoreCase) && Directory.Exists(OutputDirectory))
{
Log.LogMessage(MessageImportance.Normal, String.Format("{0} up to date", Name));
return true;
}
}
string tempFile = Path.GetTempFileName();
try
{
// Download the file
Log.LogMessage(MessageImportance.High, String.Format("Downloading '{0}'.", Url));
var client = new WebClient();
client.DownloadFile(Url, tempFile);
// Check the file matches
string actualSha1;
if (!CheckFileSha1(tempFile, Sha1, out actualSha1))
{
Log.LogError("Download file did not match expected SHA1\n expected: {0}\n actual: {1}", Sha1, actualSha1);
return false;
}
// Extract contents
Log.LogMessage(MessageImportance.High, String.Format("Extracting to '{0}'.", OutputDirectory));
if (!Directory.Exists(OutputDirectory))
{
Directory.CreateDirectory(OutputDirectory);
}
ExtractZip(tempFile, OutputDirectory, overwrite: true);
SetSha1InCheckFile(CheckFile, Name, Sha1);
}
catch (Exception ex)
{
Log.LogErrorFromException(ex, showStackTrace: false);
}
finally
{
try
{
File.Delete(tempFile);
}
catch
{
}
}
return true;
}
private string GetSha1FromCheckFile(string checkFile, string name)
{
string result = null;
try
{
if (File.Exists(checkFile))
{
string[] lines = File.ReadAllLines(checkFile);
string sha1;
GetCheckFileLineIndexSha1(lines, name, out sha1);
return sha1;
}
}
catch (Exception ex)
{
Log.LogWarningFromException(ex, showStackTrace: false);
}
return result;
}
private void SetSha1InCheckFile(string checkFile, string name, string sha1)
{
try
{
string newLine = String.Format("{0} = {1}", name, sha1.ToLower());
string[] lines = new string[0];
int lineIndex = -1;
if (File.Exists(checkFile))
{
lines = File.ReadAllLines(checkFile);
string oldsha1;
lineIndex = GetCheckFileLineIndexSha1(lines, name, out oldsha1);
}
if (lineIndex == -1)
{
if (lines.Length == 0 || lines[lines.Length - 1].Trim().Length > 0)
{
Array.Resize(ref lines, lines.Length + 1);
}
lineIndex = lines.Length - 1;
// End with new line
Array.Resize(ref lines, lines.Length + 1);
}
lines[lineIndex] = newLine;
File.WriteAllLines(checkFile, lines);
}
catch (Exception ex)
{
Log.LogWarningFromException(ex, showStackTrace: false);
}
}
private int GetCheckFileLineIndexSha1(string[] lines, string name, out string sha1)
{
for (int i = 0; i < lines.Length; i++)
{
string line = lines[i];
string[] lineParts = line.Split('=');
if (lineParts.Length == 2)
{
string lineTag = lineParts[0].Trim();
string lineSha1 = lineParts[1].Trim();
if (lineTag == name)
{
sha1 = lineSha1;
return i;
}
}
}
sha1 = null;
return -1;
}
private bool CheckFileSha1(string file, string expectedSha1, out string actualSha1)
{
using (var fs = new FileStream(file, FileMode.Open))
{
var hasher = System.Security.Cryptography.SHA1.Create();
byte[] hash = hasher.ComputeHash(fs);
actualSha1 = BytesToHexString(hash);
if (String.Equals(actualSha1, expectedSha1, StringComparison.OrdinalIgnoreCase))
{
return true;
}
}
return false;
}
private string BytesToHexString(byte[] data)
{
var sb = new StringBuilder();
foreach (byte b in data)
{
sb.Append(b.ToString("x2"));
}
return sb.ToString();
}
private static void ExtractZip(string zipPath, string destinationDirectory, bool overwrite)
{
var archive = ZipFile.OpenRead(zipPath);
if (!overwrite)
{
archive.ExtractToDirectory(destinationDirectory);
return;
}
foreach (ZipArchiveEntry file in archive.Entries)
{
string fileName = Path.Combine(destinationDirectory, file.FullName);
string directory = Path.GetDirectoryName(fileName);
if (!Directory.Exists(directory))
{
Directory.CreateDirectory(directory);
}
if (file.Name != String.Empty)
{
file.ExtractToFile(fileName, true);
}
}
}
]]>
</Code>
</Task>
</UsingTask>
<!-- 3rd party libraries / dependencies -->
<PropertyGroup>
<RootDir>$(MsBuildThisFileDirectory)</RootDir>
<DependenciesCheckFile>$(RootDir).dependencies</DependenciesCheckFile>
<LibsUrl Condition="'$(Platform)'=='ARM64'">https://github.com/OpenRCT2/Dependencies/releases/download/v37/openrct2-libs-v37-arm64-windows-static.zip</LibsUrl>
<LibsSha1 Condition="'$(Platform)'=='ARM64'">508bbd39b9be3d746ed8e17b6c0e7a79f6fa13c8</LibsSha1>
<LibsUrl Condition="'$(Platform)'=='x64'">https://github.com/OpenRCT2/Dependencies/releases/download/v37/openrct2-libs-v37-x64-windows-static.zip</LibsUrl>
<LibsSha1 Condition="'$(Platform)'=='x64'">28fabdb3fe8ddb7c73cd1c5e57ec8df5bd6232e5</LibsSha1>
<LibsUrl Condition="'$(Platform)'=='Win32'">https://github.com/OpenRCT2/Dependencies/releases/download/v37/openrct2-libs-v37-x86-windows-static.zip</LibsUrl>
<LibsSha1 Condition="'$(Platform)'=='Win32'">9984c1e317dcfb3aaf8e17f1db2ebb0f771e2373</LibsSha1>
<TitleSequencesUrl>https://github.com/OpenRCT2/title-sequences/releases/download/v0.4.14/title-sequences.zip</TitleSequencesUrl>
<TitleSequencesSha1>6c04781b959b468e1f65ec2d2f21f5aaa5e5724d</TitleSequencesSha1>
<ObjectsUrl>https://github.com/OpenRCT2/objects/releases/download/v1.7.1/objects.zip</ObjectsUrl>
<ObjectsSha1>6bfcb5f8dbd87b049071088baba029d8215f969c</ObjectsSha1>
<OpenSFXUrl>https://github.com/OpenRCT2/OpenSoundEffects/releases/download/v1.0.5/opensound.zip</OpenSFXUrl>
<OpenSFXSha1>b1b1f1b241d2cbff63a1889c4dc5a09bdf769bfb</OpenSFXSha1>
<OpenMSXUrl>https://github.com/OpenRCT2/OpenMusic/releases/download/v1.6/openmusic.zip</OpenMSXUrl>
<OpenMSXSha1>ba170fa6d777b309c15420f4b6eb3fa25082a9d1</OpenMSXSha1>
<ReplaysUrl>https://github.com/OpenRCT2/replays/releases/download/v0.0.89/replays.zip</ReplaysUrl>
<ReplaysSha1>089CB8EEA76A98028367FDDE72675E9309AB9036</ReplaysSha1>
</PropertyGroup>
<!-- Unified Dependency Target -->
<Target Name="DownloadAllDependencies"
BeforeTargets="PrepareForBuild"
DependsOnTargets="DownloadLibs;DownloadTitleSequences;DownloadObjects;DownloadOpenSFX;DownloadOpenMSX;DownloadReplays">
<!-- Add completion marker -->
<Touch Files="$(DependenciesCheckFile)" AlwaysCreate="true" />
</Target>
<!-- Target Implementations -->
<Target Name="DownloadLibs">
<!-- libs -->
<DownloadDependency Name="Libs"
Url="$(LibsUrl)"
Sha1="$(LibsSha1)"
CheckFile="$(DependenciesCheckFile)"
OutputDirectory="$(RootDir)lib\$(Platform)" />
</Target>
<!-- Target to download the title sequences -->
<Target Name="DownloadTitleSequences">
<DownloadDependency Name="TitleSequences"
Url="$(TitleSequencesUrl)"
Sha1="$(TitleSequencesSha1)"
CheckFile="$(DependenciesCheckFile)"
OutputDirectory="$(TargetDir)data\sequence" />
</Target>
<!-- Target to download the objects -->
<Target Name="DownloadObjects">
<DownloadDependency Name="Objects"
Url="$(ObjectsUrl)"
Sha1="$(ObjectsSha1)"
CheckFile="$(DependenciesCheckFile)"
OutputDirectory="$(TargetDir)data\object" />
</Target>
<!-- Target to download OpenSFX -->
<Target Name="DownloadOpenSFX">
<DownloadDependency Name="OpenSFX"
Url="$(OpenSFXUrl)"
Sha1="$(OpenSFXSha1)"
CheckFile="$(DependenciesCheckFile)"
OutputDirectory="$(TargetDir)data" />
</Target>
<!-- Target to download OpenMSX -->
<Target Name="DownloadOpenMSX">
<DownloadDependency Name="OpenMSX"
Url="$(OpenMSXUrl)"
Sha1="$(OpenMSXSha1)"
CheckFile="$(DependenciesCheckFile)"
OutputDirectory="$(TargetDir)data" />
</Target>
<!-- Target to download replays -->
<Target Name="DownloadReplays">
<DownloadDependency Name="Replays"
Url="$(ReplaysUrl)"
Sha1="$(ReplaysSha1)"
CheckFile="$(DependenciesCheckFile)"
OutputDirectory="$(TargetDir)testdata\replays" />
</Target>
</Project>