Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit cc6dacf

Browse files
Initial OctorunInstaller based off GitInstaller
1 parent 8008bf3 commit cc6dacf

File tree

6 files changed

+116
-1
lines changed

6 files changed

+116
-1
lines changed

octorun/version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
8008bf3da68428f50368cf2fe3fe290df4acad54

src/GitHub.Api/Application/ApplicationManagerBase.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ public void Run(bool firstRun)
4646
{
4747
Logger.Trace("Run - CurrentDirectory {0}", NPath.CurrentDirectory);
4848

49-
var octorunScriptPath = Environment.UserCachePath.Combine("octorun", "src", "bin", "app.js");
49+
var octorunPath = Environment.UserCachePath.Combine("octorun");
50+
var octorunScriptPath = octorunPath.Combine("src", "bin", "app.js");
5051
Logger.Trace("Using octorunScriptPath: {0}", octorunScriptPath);
5152

5253
var gitExecutablePath = SystemSettings.Get(Constants.GitInstallPathKey)?.ToNPath();

src/GitHub.Api/GitHub.Api.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@
116116
<Compile Include="Helpers\Constants.cs" />
117117
<Compile Include="Helpers\Validation.cs" />
118118
<Compile Include="Installer\GitInstaller.cs" />
119+
<Compile Include="Installer\OctorunInstaller.cs" />
119120
<Compile Include="Installer\UnzipTask.cs" />
120121
<Compile Include="IO\FileSystem.cs" />
121122
<Compile Include="OutputProcessors\GitAheadBehindStatusOutputProcessor.cs" />
@@ -281,6 +282,7 @@
281282
<ItemGroup>
282283
<EmbeddedResource Include="Resources\.gitattributes" />
283284
<EmbeddedResource Include="Resources\.gitignore" />
285+
<EmbeddedResource Include="Resources\octorun.zip" />
284286
</ItemGroup>
285287
<ItemGroup>
286288
<EmbeddedResource Include="Localization.resx">

src/GitHub.Api/Installer/GitInstaller.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ private NPath MoveGitAndLfs(NPath gitExtractPath, NPath gitLfsExtractPath, NPath
168168

169169
Logger.Trace($"Moving tempDirectory:'{gitExtractPath}' to extractTarget:'{installDetails.GitInstallationPath}'");
170170

171+
installDetails.GitInstallationPath.DeleteIfExists();
171172
installDetails.GitInstallationPath.EnsureParentDirectoryExists();
172173
gitExtractPath.Move(installDetails.GitInstallationPath);
173174

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
using System;
2+
using System.Threading;
3+
using GitHub.Logging;
4+
5+
namespace GitHub.Unity
6+
{
7+
class OctorunInstaller
8+
{
9+
private const string ExpectedOctorunVersion = "8008bf3da68428f50368cf2fe3fe290df4acad54";
10+
private const string OctorunExtractedMD5 = "b7341015bc701a9f5bf83f51b1b596b7";
11+
12+
private static readonly ILogging Logger = LogHelper.GetLogger<OctorunInstaller>();
13+
private readonly CancellationToken cancellationToken;
14+
15+
private readonly IEnvironment environment;
16+
private readonly IZipHelper sharpZipLibHelper;
17+
private readonly NPath octorunArchivePath;
18+
private NPath octorunPath;
19+
20+
public OctorunInstaller(IEnvironment environment, CancellationToken cancellationToken, NPath octorunPath,
21+
NPath octorunArchivePath = default(NPath)) : this(environment, cancellationToken, octorunPath, ZipHelper.Instance,
22+
octorunArchivePath)
23+
{ }
24+
25+
public OctorunInstaller(IEnvironment environment, CancellationToken cancellationToken, NPath octorunPath, IZipHelper sharpZipLibHelper, NPath octorunArchivePath = default (NPath))
26+
{
27+
this.environment = environment;
28+
this.cancellationToken = cancellationToken;
29+
this.octorunPath = octorunPath;
30+
this.sharpZipLibHelper = sharpZipLibHelper;
31+
this.octorunArchivePath = octorunArchivePath;
32+
}
33+
34+
public void SetupOctorunIfNeeded(ActionTask<NPath> onSuccess, ITask onFailure)
35+
{
36+
Logger.Trace("SetupOctorunIfNeeded");
37+
38+
var isOctorunExtracted = IsOctorunExtracted();
39+
Logger.Trace("isOctorunExtracted: {0}", isOctorunExtracted);
40+
41+
if (!isOctorunExtracted)
42+
{
43+
ExtractOctorun(onSuccess, onFailure);
44+
}
45+
else
46+
{
47+
onSuccess.PreviousResult = octorunPath;
48+
onSuccess.Start();
49+
}
50+
}
51+
52+
private void ExtractOctorun(ActionTask<NPath> onSuccess, ITask onFailure)
53+
{
54+
Logger.Trace("ExtractOctorun");
55+
56+
var tempZipExtractPath = NPath.CreateTempDirectory("octorun_extract_archive_path");
57+
var resultTask = new UnzipTask(cancellationToken, octorunArchivePath, tempZipExtractPath, sharpZipLibHelper,
58+
environment.FileSystem, OctorunExtractedMD5)
59+
.Then(s => MoveOctorun(tempZipExtractPath));
60+
61+
resultTask.Then(onFailure, TaskRunOptions.OnFailure);
62+
resultTask.Then(onSuccess, TaskRunOptions.OnSuccess);
63+
64+
resultTask.Start();
65+
}
66+
67+
private NPath MoveOctorun(NPath octorunExtractPath)
68+
{
69+
Logger.Trace($"Moving tempDirectory:'{octorunExtractPath}' to extractTarget:'{octorunPath}'");
70+
71+
octorunPath.DeleteIfExists();
72+
octorunPath.EnsureParentDirectoryExists();
73+
octorunExtractPath.Move(octorunPath);
74+
75+
Logger.Trace($"Deleting targetGitLfsExecPath:'{octorunExtractPath}'");
76+
octorunExtractPath.DeleteIfExists();
77+
78+
return octorunPath;
79+
}
80+
81+
private bool IsOctorunExtracted()
82+
{
83+
if (!octorunPath.DirectoryExists())
84+
{
85+
Logger.Warning($"{octorunPath} does not exist");
86+
return false;
87+
}
88+
89+
var versionFilePath = octorunPath.Combine("version");
90+
91+
if (!versionFilePath.FileExists())
92+
{
93+
Logger.Warning($"{versionFilePath} does not exist");
94+
return false;
95+
}
96+
97+
var octorunVersion = versionFilePath.ReadAllText();
98+
if (!ExpectedOctorunVersion.Equals(octorunVersion))
99+
{
100+
Logger.Warning("Current version {0} does not match expected {1}", octorunVersion, ExpectedOctorunVersion);
101+
return false;
102+
}
103+
104+
return true;
105+
}
106+
}
107+
}

src/GitHub.Api/Resources/octorun.zip

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:0c48d9a98049a3fafcebc107ab2bd2a6c79825ce00131c75fa3d8fd22fabddce
3+
size 217909

0 commit comments

Comments
 (0)