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

Commit 6dc4d73

Browse files
authored
Merge pull request #629 from github-for-unity/features/octorun-installer
Initial OctorunInstaller based off GitInstaller
2 parents 8008bf3 + 1439048 commit 6dc4d73

File tree

7 files changed

+152
-41
lines changed

7 files changed

+152
-41
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: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,26 +46,23 @@ 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");
50-
Logger.Trace("Using octorunScriptPath: {0}", octorunScriptPath);
51-
52-
var gitExecutablePath = SystemSettings.Get(Constants.GitInstallPathKey)?.ToNPath();
49+
var gitExecutablePath = SystemSettings.Get(Constants.GitInstallPathKey)?.ToNPath();
5350
if (gitExecutablePath.HasValue && gitExecutablePath.Value.FileExists()) // we have a git path
5451
{
5552
Logger.Trace("Using git install path from settings: {0}", gitExecutablePath);
56-
InitializeEnvironment(gitExecutablePath.Value, octorunScriptPath);
53+
InitializeEnvironment(gitExecutablePath.Value);
5754
}
5855
else // we need to go find git
5956
{
6057
Logger.Trace("No git path found in settings");
6158

62-
var initEnvironmentTask = new ActionTask<NPath>(CancellationToken, (_, path) => InitializeEnvironment(path, octorunScriptPath)) { Affinity = TaskAffinity.UI };
59+
var initEnvironmentTask = new ActionTask<NPath>(CancellationToken, (_, path) => InitializeEnvironment(path)) { Affinity = TaskAffinity.UI };
6360
var findExecTask = new FindExecTask("git", CancellationToken)
6461
.FinallyInUI((b, ex, path) => {
6562
if (b && path.IsInitialized)
6663
{
6764
Logger.Trace("FindExecTask Success: {0}", path);
68-
InitializeEnvironment(path, octorunScriptPath);
65+
InitializeEnvironment(path);
6966
}
7067
else
7168
{
@@ -176,13 +173,12 @@ protected void SetupMetrics(string unityVersion, bool firstRun)
176173
/// </summary>
177174
/// <param name="gitExecutablePath"></param>
178175
/// <param name="octorunScriptPath"></param>
179-
private void InitializeEnvironment(NPath gitExecutablePath, NPath octorunScriptPath)
176+
private void InitializeEnvironment(NPath gitExecutablePath)
180177
{
181178
var afterGitSetup = new ActionTask(CancellationToken, RestartRepository)
182179
.ThenInUI(InitializeUI);
183180

184181
Environment.GitExecutablePath = gitExecutablePath;
185-
Environment.OctorunScriptPath = octorunScriptPath;
186182
Environment.User.Initialize(GitClient);
187183
SetupMetrics();
188184

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: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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+
14+
private readonly IFileSystem fileSystem;
15+
private readonly ITaskManager taskManager;
16+
private readonly IZipHelper sharpZipLibHelper;
17+
private readonly NPath octorunArchivePath;
18+
private NPath octorunPath;
19+
20+
public OctorunInstaller(IFileSystem fileSystem, ITaskManager taskManager,
21+
NPath octorunPath, IZipHelper sharpZipLibHelper, NPath octorunArchivePath)
22+
{
23+
this.fileSystem = fileSystem;
24+
this.taskManager = taskManager;
25+
this.octorunPath = octorunPath;
26+
this.sharpZipLibHelper = sharpZipLibHelper;
27+
this.octorunArchivePath = octorunArchivePath;
28+
}
29+
30+
public void SetupOctorunIfNeeded(ActionTask<NPath> onSuccess, ITask onFailure)
31+
{
32+
Logger.Trace("SetupOctorunIfNeeded");
33+
34+
var isOctorunExtracted = IsOctorunExtracted();
35+
Logger.Trace("isOctorunExtracted: {0}", isOctorunExtracted);
36+
37+
if (!isOctorunExtracted)
38+
{
39+
ExtractOctorun(onSuccess, onFailure);
40+
}
41+
else
42+
{
43+
onSuccess.PreviousResult = octorunPath;
44+
onSuccess.Start();
45+
}
46+
}
47+
48+
private void ExtractOctorun(ActionTask<NPath> onSuccess, ITask onFailure)
49+
{
50+
Logger.Trace("ExtractOctorun");
51+
52+
var tempZipExtractPath = NPath.CreateTempDirectory("octorun_extract_archive_path");
53+
var resultTask = new UnzipTask(taskManager.Token, octorunArchivePath, tempZipExtractPath, sharpZipLibHelper,
54+
fileSystem, OctorunExtractedMD5)
55+
.Then(s => MoveOctorun(tempZipExtractPath));
56+
57+
resultTask.Then(onFailure, TaskRunOptions.OnFailure);
58+
resultTask.Then(onSuccess, TaskRunOptions.OnSuccess);
59+
60+
resultTask.Start();
61+
}
62+
63+
private NPath MoveOctorun(NPath octorunExtractPath)
64+
{
65+
Logger.Trace($"Moving tempDirectory:'{octorunExtractPath}' to extractTarget:'{octorunPath}'");
66+
67+
octorunPath.DeleteIfExists();
68+
octorunPath.EnsureParentDirectoryExists();
69+
octorunExtractPath.Move(octorunPath);
70+
71+
Logger.Trace($"Deleting targetGitLfsExecPath:'{octorunExtractPath}'");
72+
octorunExtractPath.DeleteIfExists();
73+
74+
return octorunPath;
75+
}
76+
77+
private bool IsOctorunExtracted()
78+
{
79+
if (!octorunPath.DirectoryExists())
80+
{
81+
Logger.Warning($"{octorunPath} does not exist");
82+
return false;
83+
}
84+
85+
var versionFilePath = octorunPath.Combine("version");
86+
87+
if (!versionFilePath.FileExists())
88+
{
89+
Logger.Warning($"{versionFilePath} does not exist");
90+
return false;
91+
}
92+
93+
var octorunVersion = versionFilePath.ReadAllText();
94+
if (!ExpectedOctorunVersion.Equals(octorunVersion))
95+
{
96+
Logger.Warning("Current version {0} does not match expected {1}", octorunVersion, ExpectedOctorunVersion);
97+
return false;
98+
}
99+
100+
return true;
101+
}
102+
}
103+
}

src/GitHub.Api/Platform/DefaultEnvironment.cs

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,14 @@ namespace GitHub.Unity
88
public class DefaultEnvironment : IEnvironment
99
{
1010
private const string logFile = "github-unity.log";
11+
private static bool? onWindows;
12+
private static bool? onLinux;
13+
private static bool? onMac;
14+
15+
private NPath gitExecutablePath;
16+
private NPath nodeJsExecutablePath;
17+
private NPath octorunScriptPath;
1118

12-
public NPath LogPath { get; }
1319
public DefaultEnvironment()
1420
{
1521
NPath localAppData;
@@ -36,12 +42,21 @@ public DefaultEnvironment()
3642
LogPath = UserCachePath.Combine(logFile);
3743
}
3844

39-
public DefaultEnvironment(ICacheContainer cacheContainer)
40-
: this()
45+
public DefaultEnvironment(ICacheContainer cacheContainer) : this()
4146
{
4247
this.CacheContainer = cacheContainer;
4348
}
4449

50+
/// <summary>
51+
/// This is for tests to reset the static OS flags
52+
/// </summary>
53+
public static void Reset()
54+
{
55+
onWindows = null;
56+
onLinux = null;
57+
onMac = null;
58+
}
59+
4560
public void Initialize(string unityVersion, NPath extensionInstallPath, NPath unityApplicationPath, NPath unityApplicationContentsPath, NPath assetsPath)
4661
{
4762
ExtensionInstallPath = extensionInstallPath;
@@ -107,6 +122,7 @@ public string GetEnvironmentVariable(string variable)
107122
return Environment.GetEnvironmentVariable(variable);
108123
}
109124

125+
public NPath LogPath { get; }
110126
public IFileSystem FileSystem { get { return NPath.FileSystem; } set { NPath.FileSystem = value; } }
111127
public string UnityVersion { get; set; }
112128
public NPath UnityApplication { get; set; }
@@ -116,42 +132,43 @@ public string GetEnvironmentVariable(string variable)
116132
public NPath ExtensionInstallPath { get; set; }
117133
public NPath UserCachePath { get; set; }
118134
public NPath SystemCachePath { get; set; }
119-
public NPath Path { get { return Environment.GetEnvironmentVariable("PATH").ToNPath(); } }
120-
public string NewLine { get { return Environment.NewLine; } }
121-
public NPath OctorunScriptPath { get; set; }
122-
123-
private NPath gitExecutablePath;
135+
public NPath Path => Environment.GetEnvironmentVariable("PATH").ToNPath();
136+
public string NewLine => Environment.NewLine;
137+
public NPath OctorunScriptPath
138+
{
139+
get
140+
{
141+
if (!octorunScriptPath.IsInitialized)
142+
octorunScriptPath = UserCachePath.Combine("octorun", "src", "bin", "app.js");
143+
return octorunScriptPath;
144+
}
145+
set
146+
{
147+
octorunScriptPath = value;
148+
}
149+
}
124150
public NPath GitExecutablePath
125151
{
126152
get { return gitExecutablePath; }
127153
set
128154
{
129155
gitExecutablePath = value;
130-
if (String.IsNullOrEmpty(gitExecutablePath))
156+
if (!gitExecutablePath.IsInitialized)
131157
GitInstallPath = NPath.Default;
132158
else
133159
GitInstallPath = GitExecutablePath.Resolve().Parent.Parent;
134160
}
135161
}
136-
137-
private NPath nodeJsExecutablePath;
138-
139162
public NPath NodeJsExecutablePath
140163
{
141164
get
142165
{
143166
if (!nodeJsExecutablePath.IsInitialized)
144-
{
145-
nodeJsExecutablePath =
146-
UnityApplicationContents.Combine("Tools", "nodejs", "node" + ExecutableExtension);
147-
}
148-
167+
nodeJsExecutablePath = UnityApplicationContents.Combine("Tools", "nodejs", "node" + ExecutableExtension);
149168
return nodeJsExecutablePath;
150169
}
151170
}
152-
153171
public NPath GitInstallPath { get; private set; }
154-
155172
public NPath RepositoryPath { get; private set; }
156173
public ICacheContainer CacheContainer { get; private set; }
157174
public IRepository Repository { get; set; }
@@ -161,17 +178,6 @@ public NPath NodeJsExecutablePath
161178
public bool IsLinux { get { return OnLinux; } }
162179
public bool IsMac { get { return OnMac; } }
163180

164-
/// <summary>
165-
/// This is for tests to reset the static OS flags
166-
/// </summary>
167-
public static void Reset()
168-
{
169-
onWindows = null;
170-
onLinux = null;
171-
onMac = null;
172-
}
173-
174-
private static bool? onWindows;
175181
public static bool OnWindows
176182
{
177183
get
@@ -183,7 +189,6 @@ public static bool OnWindows
183189
set { onWindows = value; }
184190
}
185191

186-
private static bool? onLinux;
187192
public static bool OnLinux
188193
{
189194
get
@@ -195,7 +200,6 @@ public static bool OnLinux
195200
set { onLinux = value; }
196201
}
197202

198-
private static bool? onMac;
199203
public static bool OnMac
200204
{
201205
get
@@ -208,6 +212,7 @@ public static bool OnMac
208212
}
209213
set { onMac = value; }
210214
}
215+
211216
public string ExecutableExtension { get { return IsWindows ? ".exe" : string.Empty; } }
212217
protected static ILogging Logger { get; } = LogHelper.GetLogger<DefaultEnvironment>();
213218
}

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)