1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-15 11:03:00 +01:00

Merge pull request #4887 from IntelOrca/use-external-title-sequences

Use external title sequences repository
This commit is contained in:
Ted John
2016-12-20 12:38:52 +00:00
committed by GitHub
14 changed files with 258 additions and 676 deletions

4
.gitignore vendored
View File

@@ -14,11 +14,15 @@ distribution/windows/*.exe
# Build artifacts
artifacts
.cache
.dependencies
#lib
lib
libversion
#sequences
data/title
#################
## Eclipse
#################

View File

@@ -396,6 +396,9 @@ list(APPEND DOC_FILES "${CMAKE_CURRENT_SOURCE_DIR}/contributors.md" "${CMAKE_CUR
# CMake does not allow specifying a dependency chain which includes built-in
# targets, like `install`, so we have to trick it and execute dependency ourselves.
install(CODE "execute_process(COMMAND \"${CMAKE_COMMAND}\" --build \"${CMAKE_CURRENT_BINARY_DIR}\" --target g2)")
install(CODE "file(DOWNLOAD https://github.com/OpenRCT2/title-sequences/releases/download/v0.0.5/title-sequence-v0.0.5.zip ${CMAKE_INSTALL_PREFIX}/share/${PROJECT}/title/title-sequences.zip EXPECTED_HASH_SHA1=79ffb2585d12abcbfce205d7696e3472a504b005 SHOW_PROGRESS)")
install(CODE "execute_process(COMMAND \"${CMAKE_COMMAND}\" -E chdir ${CMAKE_INSTALL_PREFIX}/share/${PROJECT}/title/ \"${CMAKE_COMMAND}\" -E tar xvf title-sequences.zip)")
install(CODE "file(REMOVE ${CMAKE_INSTALL_PREFIX}/share/${PROJECT}/title/title-sequences.zip)")
install(TARGETS ${PROJECT} RUNTIME DESTINATION bin)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/g2.dat" DESTINATION share/${PROJECT})
install(DIRECTORY data/ DESTINATION share/${PROJECT})

View File

@@ -2297,6 +2297,7 @@
buildConfigurationList = D497D0891C20FD53002BF46A /* Build configuration list for PBXNativeTarget "OpenRCT2" */;
buildPhases = (
D4EC48E91C264FC20024B507 /* Download Libraries */,
D4E09E831E049C0600F53CE3 /* Download Title Sequences */,
D4EC012A1C25532B00DAFE69 /* Setup AppIcon */,
D4CA88671D4E962100060C11 /* Get Git Variables */,
D497D0741C20FD52002BF46A /* Sources */,
@@ -2415,6 +2416,20 @@
shellPath = /bin/sh;
shellScript = "echo \"#define\" OPENRCT2_BRANCH \\\"$(git rev-parse --abbrev-ref HEAD)\\\" > \"${DERIVED_FILE_DIR}/gitversion.h\"\necho \"#define\" OPENRCT2_COMMIT_SHA1 \\\"$(git rev-parse HEAD)\\\" >> \"${DERIVED_FILE_DIR}/gitversion.h\"\necho \"#define\" OPENRCT2_COMMIT_SHA1_SHORT \\\"$(git rev-parse --short HEAD)\\\" >> \"${DERIVED_FILE_DIR}/gitversion.h\"\ncp \"${SRCROOT}/distribution/macos/Info.plist\" \"${DERIVED_FILE_DIR}/Info.plist\"\nplutil -replace CFBundleVersion -string \"$(git rev-parse --short HEAD)\" \"${DERIVED_FILE_DIR}/Info.plist\"";
};
D4E09E831E049C0600F53CE3 /* Download Title Sequences */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "Download Title Sequences";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "version=\"0.0.5\"\nzipname=\"title-sequence-v$version.zip\"\nliburl=\"https://github.com/OpenRCT2/title-sequences/releases/download/v$version/$zipname\"\n\n[[ ! -d \"${SRCROOT}/data/title\" || ! -e \"${SRCROOT}/sequencesversion\" || $(head -n 1 \"${SRCROOT}/sequencesversion\") != $version ]]\noutdated=$?\n\nif [[ $outdated -eq 0 ]]; then\nif [[ -d \"${SRCROOT}/data/title\" ]]; then rm -r \"${SRCROOT}/data/title\"; fi\nmkdir -p \"${SRCROOT}/data/title\"\n\ncurl -L -o \"${SRCROOT}/data/title/$zipname\" \"$liburl\"\nunzip -uaq -d \"${SRCROOT}/data/title\" \"${SRCROOT}/data/title/$zipname\"\nrm \"${SRCROOT}/data/title/$zipname\"\n\necho $version > \"${SRCROOT}/sequencesversion\"\nfi";
};
D4EC012A1C25532B00DAFE69 /* Setup AppIcon */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;

Binary file not shown.

Binary file not shown.

View File

@@ -1,84 +0,0 @@
# OpenRCT2 0.0.4 Title Sequence Script
# Arranged by NWSpacek (Kelson Blakewood).
# If you have parks you think would work well in a title sequence (must be NCSO), contact me on reddit at u/spacek_toast
LOAD Ill Paradise.sv6
LOCATION 113 105
WAIT 15
LOCATION 120 102
ROTATE 3
WAIT 10
LOCATION 73 136
ROTATE 1
WAIT 15
LOAD Title Sequence Park 1.sv6
ROTATE 2
LOCATION 120 43
WAIT 15
LOCATION 124 74
WAIT 15
ROTATE 1
LOCATION 120 90
WAIT 10
LOCATION 123 130
WAIT 20
LOCATION 70 85
ROTATE 1
WAIT 15
LOAD Cypress Grove Title.sv6
LOCATION 106 43
ROTATE 3
WAIT 15
LOCATION 60 103
ROTATE 1
WAIT 10
LOCATION 91 83
WAIT 10
ROTATE 1
LOCATION 117 61
WAIT 10
LOCATION 82 95
ROTATE 1
WAIT 20
LOCATION 110 94
ROTATE 3
WAIT 15
LOCATION 79 94
WAIT 10
LOCATION 63 97
ROTATE 1
WAIT 10
LOAD TaCW.sv6
WAIT 15
ROTATE 1
LOCATION 110 95
WAIT 15
LOCATION 57 101
ROTATE 3
WAIT 15
LOCATION 100 63
ROTATE 2
WAIT 15
RESTART
END

View File

@@ -1,98 +0,0 @@
# RollerCoaster Tycoon 1 Title Sequence
##############################
# RollerCoaster Tycoon 1 #
##############################
# SC_DIAMOND_HEIGHTS
LOADRCT1 3
ROTATE 2
LOCATION 47, 99
WAIT 15
ROTATE 2
LOCATION 90, 48
WAIT 15
ROTATE 1
LOCATION 86, 43
WAIT 15
ROTATE 3
LOCATION 57, 50
WAIT 15
ROTATE 2
LOCATION 86, 64
WAIT 15
# SC_KATIES_DREAMLAND
LOADRCT1 7
LOCATION 48, 44
WAIT 15
LOCATION 64, 41
WAIT 15
# SC_POKEY_PARK,
LOADRCT1 8
ROTATE 2
LOCATION 56, 64
WAIT 15
# SC_WHITE_WATER_PARK
LOADRCT1 9
ROTATE 3
LOCATION 96, 88
WAIT 15
LOCATION 84, 95
WAIT 15
# SC_MILLENNIUM_MINES
LOADRCT1 10
ROTATE 1
ROTATE 1
LOCATION 64, 37
WAIT 15
# SC_KARTS_COASTERS
LOADRCT1 11
LOCATION 84, 56
WAIT 15
LOCATION 34, 36
WAIT 15
LOCATION 33, 65
WAIT 15
# SC_MELS_WORLD
LOADRCT1 12
ROTATE 3
LOCATION 50, 50
WAIT 15
LOCATION 35, 39
WAIT 15
ROTATE 3
LOCATION 62, 39
WAIT 15
# SC_CRUMBLY_WOODS
LOADRCT1 15
ROTATE 3
LOCATION 57, 94
WAIT 15
LOCATION 44, 84
WAIT 15
ROTATE 1
LOCATION 76, 59
WAIT 15
LOCATION 76, 48
WAIT 15
# SC_LIGHTNING_PEAKS
LOADRCT1 17
LOCATION 80, 49
WAIT 15
LOCATION 60, 62
WAIT 15
# SC_IVORY_TOWERS
LOADRCT1 18
ROTATE 3
LOCATION 50, 77
WAIT 15
RESTART

View File

@@ -1,187 +0,0 @@
# RollerCoaster Tycoon 1 Title Sequence
##############################
# Added Attractions #
##############################
# SC_HAUNTED_HARBOR
LOADRCT1 45
LOCATION 62, 53
WAIT 11
ROTATE 3
LOCATION 78, 45
WAIT 16
# SC_CANARY_MINES
LOADRCT1 42
LOCATION 52, 28
WAIT 15
# SC_GENTLE_GLEN
LOADRCT1 48
LOCATION 68, 45
WAIT 11
# SC_FUNTOPIA
LOADRCT1 44
LOCATION 69, 93
WAIT 17
# SC_SPRIGHTLY_PARK
LOADRCT1 51
ROTATE 3
LOCATION 97, 72
WAIT 12
ROTATE 2
LOCATION 74, 71
WAIT 12
ROTATE 2
LOCATION 67, 90
WAIT 12
# SC_GIGGLE_DOWNS
LOADRCT1 65
LOCATION 94, 64
WAIT 10
# SC_SWAMP_COVE
LOADRCT1 59
LOCATION 96, 22
WAIT 10
ROTATE 3
LOCATION 90, 29
WAIT 10
# SC_FRUIT_FARM
LOADRCT1 53
LOCATION 47, 52
WAIT 12
# SC_FUTURE_WORLD
LOADRCT1 47
LOCATION 67, 59
WAIT 19
# SC_THREE_MONKEYS_PARK
LOADRCT1 41
ROTATE 2
LOCATION 72, 61
WAIT 8
ROTATE 2
LOCATION 68, 70
WAIT 8
LOCATION 58, 56
WAIT 8
ROTATE 1
LOCATION 44, 70
WAIT 8
ROTATE 3
LOCATION 43, 90
WAIT 10
# SC_ROMAN_VILLAGE
LOADRCT1 58
LOCATION 49, 46
WAIT 15
# SC_ADRENALINE_HEIGHTS
LOADRCT1 60
ROTATE 3
LOCATION 38, 57
WAIT 15
##############################
# RollerCoaster Tycoon 1 #
##############################
# SC_DIAMOND_HEIGHTS
LOADRCT1 3
ROTATE 2
LOCATION 47, 99
WAIT 15
ROTATE 2
LOCATION 90, 48
WAIT 15
ROTATE 1
LOCATION 86, 43
WAIT 15
ROTATE 3
LOCATION 57, 50
WAIT 15
ROTATE 2
LOCATION 86, 64
WAIT 15
# SC_KATIES_DREAMLAND
LOADRCT1 7
LOCATION 48, 44
WAIT 15
LOCATION 64, 41
WAIT 15
# SC_POKEY_PARK,
LOADRCT1 8
ROTATE 2
LOCATION 56, 64
WAIT 15
# SC_WHITE_WATER_PARK
LOADRCT1 9
ROTATE 3
LOCATION 96, 88
WAIT 15
LOCATION 84, 95
WAIT 15
# SC_MILLENNIUM_MINES
LOADRCT1 10
ROTATE 1
ROTATE 1
LOCATION 64, 37
WAIT 15
# SC_KARTS_COASTERS
LOADRCT1 11
LOCATION 84, 56
WAIT 15
LOCATION 34, 36
WAIT 15
LOCATION 33, 65
WAIT 15
# SC_MELS_WORLD
LOADRCT1 12
ROTATE 3
LOCATION 50, 50
WAIT 15
LOCATION 35, 39
WAIT 15
ROTATE 3
LOCATION 62, 39
WAIT 15
# SC_CRUMBLY_WOODS
LOADRCT1 15
ROTATE 3
LOCATION 57, 94
WAIT 15
LOCATION 44, 84
WAIT 15
ROTATE 1
LOCATION 76, 59
WAIT 15
LOCATION 76, 48
WAIT 15
# SC_LIGHTNING_PEAKS
LOADRCT1 17
LOCATION 80, 49
WAIT 15
LOCATION 60, 62
WAIT 15
# SC_IVORY_TOWERS
LOADRCT1 18
ROTATE 3
LOCATION 50, 77
WAIT 15
RESTART

View File

@@ -1,233 +0,0 @@
# RollerCoaster Tycoon 1 Title Sequence
##############################
# Added Attractions (part 1) #
##############################
# SC_HAUNTED_HARBOR
LOADRCT1 45
LOCATION 62, 53
WAIT 11
ROTATE 3
LOCATION 78, 45
WAIT 16
# SC_CANARY_MINES
LOADRCT1 42
LOCATION 52, 28
WAIT 15
# SC_GENTLE_GLEN
LOADRCT1 48
LOCATION 68, 45
WAIT 11
# SC_FUNTOPIA
LOADRCT1 44
LOCATION 69, 93
WAIT 17
##############################
# Loopy Landscapes #
##############################
# SC_FRIGHTMARE_HILLS
LOADRCT1 86
LOCATION 46, 47
WAIT 5
# SC_GOOD_KNIGHT_PARK
LOADRCT1 30
ROTATE 2
LOCATION 60, 62
WAIT 5
# SC_ICEBERG_ISLANDS
LOADRCT1 22
ROTATE 3
LOCATION 36, 52
WAIT 4
# SC_SOUTHERN_SANDS
LOADRCT1 91
ROTATE 2
LOCATION 51, 47
WAIT 4
# SC_SUNNY_SWAMPS
LOADRCT1 85
ROTATE 3
LOCATION 77, 82
WAIT 4
# SC_VERTIGO_VIEWS
LOADRCT1 27
LOCATION 22, 56
WAIT 3
# SC_WACKY_WARREN
LOADRCT1 31
ROTATE 3
LOCATION 72, 80
WAIT 4
##############################
# Added Attractions (part 2) #
##############################
# SC_SPRIGHTLY_PARK
LOADRCT1 51
ROTATE 3
LOCATION 97, 72
WAIT 12
ROTATE 2
LOCATION 74, 71
WAIT 12
ROTATE 2
LOCATION 67, 90
WAIT 12
# SC_GIGGLE_DOWNS
LOADRCT1 65
LOCATION 94, 64
WAIT 10
# SC_SWAMP_COVE
LOADRCT1 59
LOCATION 96, 22
WAIT 10
ROTATE 3
LOCATION 90, 29
WAIT 10
# SC_FRUIT_FARM
LOADRCT1 53
LOCATION 47, 52
WAIT 12
# SC_FUTURE_WORLD
LOADRCT1 47
LOCATION 67, 59
WAIT 19
# SC_THREE_MONKEYS_PARK
LOADRCT1 41
ROTATE 2
LOCATION 72, 61
WAIT 8
ROTATE 2
LOCATION 68, 70
WAIT 8
LOCATION 58, 56
WAIT 8
ROTATE 1
LOCATION 44, 70
WAIT 8
ROTATE 3
LOCATION 43, 90
WAIT 10
# SC_ROMAN_VILLAGE
LOADRCT1 58
LOCATION 49, 46
WAIT 15
# SC_ADRENALINE_HEIGHTS
LOADRCT1 60
ROTATE 3
LOCATION 38, 57
WAIT 15
##############################
# RollerCoaster Tycoon 1 #
##############################
# SC_DIAMOND_HEIGHTS
LOADRCT1 3
ROTATE 2
LOCATION 47, 99
WAIT 15
ROTATE 2
LOCATION 90, 48
WAIT 15
ROTATE 1
LOCATION 86, 43
WAIT 15
ROTATE 3
LOCATION 57, 50
WAIT 15
ROTATE 2
LOCATION 86, 64
WAIT 15
# SC_KATIES_DREAMLAND
LOADRCT1 7
LOCATION 48, 44
WAIT 15
LOCATION 64, 41
WAIT 15
# SC_POKEY_PARK,
LOADRCT1 8
ROTATE 2
LOCATION 56, 64
WAIT 15
# SC_WHITE_WATER_PARK
LOADRCT1 9
ROTATE 3
LOCATION 96, 88
WAIT 15
LOCATION 84, 95
WAIT 15
# SC_MILLENNIUM_MINES
LOADRCT1 10
ROTATE 1
ROTATE 1
LOCATION 64, 37
WAIT 15
# SC_KARTS_COASTERS
LOADRCT1 11
LOCATION 84, 56
WAIT 15
LOCATION 34, 36
WAIT 15
LOCATION 33, 65
WAIT 15
# SC_MELS_WORLD
LOADRCT1 12
ROTATE 3
LOCATION 50, 50
WAIT 15
LOCATION 35, 39
WAIT 15
ROTATE 3
LOCATION 62, 39
WAIT 15
# SC_CRUMBLY_WOODS
LOADRCT1 15
ROTATE 3
LOCATION 57, 94
WAIT 15
LOCATION 44, 84
WAIT 15
ROTATE 1
LOCATION 76, 59
WAIT 15
LOCATION 76, 48
WAIT 15
# SC_LIGHTNING_PEAKS
LOADRCT1 17
LOCATION 80, 49
WAIT 15
LOCATION 60, 62
WAIT 15
# SC_IVORY_TOWERS
LOADRCT1 18
ROTATE 3
LOCATION 50, 77
WAIT 15
RESTART

View File

@@ -1,34 +0,0 @@
# RollerCoaster Tycoon 2 Title Sequence
LOADMM
LOCATION 210 112
WAIT 13
ROTATE 1
LOCATION 210 112
WAIT 14
ROTATE 3
LOCATION 167 180
WAIT 12
ROTATE 1
LOCATION 155 189
WAIT 12
LOCATION 106 39
WAIT 12
LOCATION 182 50
WAIT 12
ROTATE 3
LOCATION 209 47
WAIT 12
ROTATE 1
LOCATION 159 93
WAIT 12
RESTART

View File

@@ -62,11 +62,14 @@
<!-- 3rd party libraries / dependencies -->
<PropertyGroup>
<DependenciesCheckFile>$(RootDir).dependencies</DependenciesCheckFile>
<LibsUrl>https://github.com/OpenRCT2/Dependencies/releases/download/v$(TargetLibsVersion)/openrct2-libs-vs2015.zip</LibsUrl>
<LibsPath>$(RootDir)lib\</LibsPath>
<LibsVersionPath>$(LibsPath)libversion</LibsVersionPath>
<LibsSha1>f088adcd12450c2672f78679ea5d1fbffc28fd22</LibsSha1>
<GtestVersion>1.8.0</GtestVersion>
<GtestUrl>https://github.com/google/googletest/archive/release-$(GtestVersion).zip</GtestUrl>
<GtestUrl>https://github.com/google/googletest/archive/release-1.8.0.zip</GtestUrl>
<GtestSha1>667f873ab7a4d246062565fad32fb6d8e203ee73</GtestSha1>
<TitleSequencesUrl>https://github.com/OpenRCT2/title-sequences/releases/download/v0.0.5/title-sequence-v0.0.5.zip</TitleSequencesUrl>
<TitleSequencesSha1>79ffb2585d12abcbfce205d7696e3472a504b005</TitleSequencesSha1>
</PropertyGroup>
<ItemGroup>
@@ -107,45 +110,25 @@
</UploadArtifacts>
</ItemGroup>
<Target Name="CheckLibs">
<!-- Get libversion file and check version -->
<Message Text="Checking if libraries need updating..." Importance="high" />
<PropertyGroup>
<CurrentLibsVersion>0</CurrentLibsVersion>
<CurrentLibsVersion Condition="Exists($(LibsVersionPath))">$([System.IO.File]::ReadAllText($(LibsVersionPath)).Trim())</CurrentLibsVersion>
<UpdateLibs Condition="$(TargetLibsVersion) &gt; $(CurrentLibsVersion)">true</UpdateLibs>
</PropertyGroup>
<Message Condition="'$(UpdateLibs)'!='true'" Text="Libraries up to date" Importance="high" />
<Message Condition="'$(UpdateLibs)'=='true'" Text="Libraries out of date, updating..." Importance="high" />
<CallTarget Condition="'$(UpdateLibs)'=='true'" Targets="DownloadLibs" />
</Target>
<Target Name="DownloadLibs">
<PropertyGroup>
<LibsZipPath>$(LibsPath)openrct2-libs-vs2015.zip</LibsZipPath>
<GtestZipPath>$(LibsPath)gtest.zip</GtestZipPath>
</PropertyGroup>
<!-- Clean libs directory -->
<RemoveDir Directories="$(LibsPath)" />
<MakeDir Directories="$(LibsPath)" />
<Message Text="Downloading libraries..." Importance="normal" />
<!-- prebuilt libs -->
<Exec Command="powershell -ExecutionPolicy Unrestricted -Command &quot;Invoke-WebRequest '$(LibsUrl)' -OutFile '$(LibsZipPath)'&quot;" StandardOutputImportance="low" />
<Unzip Input="$(LibsZipPath)" OutputDirectory="$(LibsPath)" />
<Delete Files="$(LibsZipPath)" ContinueOnError="true" />
<!-- libs -->
<DownloadDependency Name="Libs"
Url="$(LibsUrl)"
Sha1="$(LibsSha1)"
CheckFile="$(DependenciesCheckFile)"
OutputDirectory="$(RootDir)lib" />
<!-- googletest -->
<Message Text="Downloading googletest..." Importance="normal" />
<Exec Command="powershell -ExecutionPolicy Unrestricted -Command &quot;Invoke-WebRequest '$(GtestUrl)' -OutFile '$(GtestZipPath)'&quot;" StandardOutputImportance="low" />
<Unzip Input="$(GtestZipPath)" OutputDirectory="$(LibsPath)" />
<Delete Files="$(GtestZipPath)" ContinueOnError="true" />
<Exec Command="cmd /c move &quot;$(LibsPath)googletest-release-$(GtestVersion)&quot; &quot;$(LibsPath)googletest&quot;" />
<!-- Update libversion file -->
<WriteLinesToFile Lines="$(TargetLibsVersion)" File="$(LibsVersionPath)" Overwrite="true" />
<DownloadDependency Name="googletest"
Url="$(GtestUrl)"
Sha1="$(GtestSha1)"
CheckFile="$(DependenciesCheckFile)"
OutputDirectory="$(RootDir)lib" />
<PropertyGroup>
<GtestSrc>$(RootDir)lib\googletest-release-$(GtestVersion)</GtestSrc>
<GtestDst>$(RootDir)lib\googletest</GtestDst>
</PropertyGroup>
<Exec Command="cmd /c &quot;if exist &quot;$(GtestSrc)&quot; ( rmdir /S /Q &quot;$(GtestDst)&quot; 2> nul &amp; move &quot;$(GtestSrc)&quot; &quot;$(GtestDst)&quot; )&quot;" />
</Target>
<Target Name="Clean">
@@ -165,7 +148,7 @@
<MSBuild Projects="openrct2.sln" Targets="Clean" Properties="$(SlnProperties)" />
</Target>
<Target Name="BeforeBuild" BeforeTargets="Build;Rebuild" DependsOnTargets="CheckLibs">
<Target Name="BeforeBuild" BeforeTargets="Build;Rebuild" DependsOnTargets="DownloadLibs">
<PropertyGroup>
<BuildString Condition="'$(GIT_COMMIT_SHA1_SHORT)'!=''">$(GIT_COMMIT_SHA1_SHORT)</BuildString>
<BuildString Condition="'$(GIT_BRANCH)'!=''">$(BuildString) ($(GIT_BRANCH))</BuildString>
@@ -221,6 +204,15 @@
StandardOutputImportance="low" />
</Target>
<!-- Target to download the title sequences -->
<Target Name="DownloadTitleSequences" AfterTargets="Build">
<DownloadDependency Name="TitleSequences"
Url="$(TitleSequencesUrl)"
Sha1="$(TitleSequencesSha1)"
CheckFile="$(DependenciesCheckFile)"
OutputDirectory="$(TargetDir)data\title" />
</Target>
<!-- Target to sign OpenRCT2
This requires the project parameter SIGN_PASSWORD to be set -->
<Target Name="Sign" AfterTargets="Build" Inputs="@(SignItems)" Outputs="%(SignItems.Identity).signed"

View File

@@ -106,6 +106,7 @@
</Task>
</UsingTask>
<!-- Unzip task -->
<UsingTask TaskName="Unzip"
TaskFactory="CodeTaskFactory"
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
@@ -123,4 +124,207 @@
</Code>
</Task>
</UsingTask>
<!-- 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))
{
Log.LogMessage(MessageImportance.Normal, String.Format("{0} up to date", Name));
return true;
}
}
string tempFile = Path.GetTempFileName();
try
{
// Download the file
Log.LogMessage(MessageImportance.Normal, 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.Normal, 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);
if (file.Name == String.Empty)
{
string directory = Path.GetDirectoryName(fileName);
Directory.CreateDirectory(directory);
continue;
}
file.ExtractToFile(fileName, true);
}
}
]]>
</Code>
</Task>
</UsingTask>
</Project>