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

Commit 1439048

Browse files
committed
Put paths in environment
1 parent cc6dacf commit 1439048

File tree

3 files changed

+50
-54
lines changed

3 files changed

+50
-54
lines changed

src/GitHub.Api/Application/ApplicationManagerBase.cs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,27 +46,23 @@ public void Run(bool firstRun)
4646
{
4747
Logger.Trace("Run - CurrentDirectory {0}", NPath.CurrentDirectory);
4848

49-
var octorunPath = Environment.UserCachePath.Combine("octorun");
50-
var octorunScriptPath = octorunPath.Combine("src", "bin", "app.js");
51-
Logger.Trace("Using octorunScriptPath: {0}", octorunScriptPath);
52-
53-
var gitExecutablePath = SystemSettings.Get(Constants.GitInstallPathKey)?.ToNPath();
49+
var gitExecutablePath = SystemSettings.Get(Constants.GitInstallPathKey)?.ToNPath();
5450
if (gitExecutablePath.HasValue && gitExecutablePath.Value.FileExists()) // we have a git path
5551
{
5652
Logger.Trace("Using git install path from settings: {0}", gitExecutablePath);
57-
InitializeEnvironment(gitExecutablePath.Value, octorunScriptPath);
53+
InitializeEnvironment(gitExecutablePath.Value);
5854
}
5955
else // we need to go find git
6056
{
6157
Logger.Trace("No git path found in settings");
6258

63-
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 };
6460
var findExecTask = new FindExecTask("git", CancellationToken)
6561
.FinallyInUI((b, ex, path) => {
6662
if (b && path.IsInitialized)
6763
{
6864
Logger.Trace("FindExecTask Success: {0}", path);
69-
InitializeEnvironment(path, octorunScriptPath);
65+
InitializeEnvironment(path);
7066
}
7167
else
7268
{
@@ -177,13 +173,12 @@ protected void SetupMetrics(string unityVersion, bool firstRun)
177173
/// </summary>
178174
/// <param name="gitExecutablePath"></param>
179175
/// <param name="octorunScriptPath"></param>
180-
private void InitializeEnvironment(NPath gitExecutablePath, NPath octorunScriptPath)
176+
private void InitializeEnvironment(NPath gitExecutablePath)
181177
{
182178
var afterGitSetup = new ActionTask(CancellationToken, RestartRepository)
183179
.ThenInUI(InitializeUI);
184180

185181
Environment.GitExecutablePath = gitExecutablePath;
186-
Environment.OctorunScriptPath = octorunScriptPath;
187182
Environment.User.Initialize(GitClient);
188183
SetupMetrics();
189184

src/GitHub.Api/Installer/OctorunInstaller.cs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,18 @@ class OctorunInstaller
1010
private const string OctorunExtractedMD5 = "b7341015bc701a9f5bf83f51b1b596b7";
1111

1212
private static readonly ILogging Logger = LogHelper.GetLogger<OctorunInstaller>();
13-
private readonly CancellationToken cancellationToken;
1413

15-
private readonly IEnvironment environment;
14+
private readonly IFileSystem fileSystem;
15+
private readonly ITaskManager taskManager;
1616
private readonly IZipHelper sharpZipLibHelper;
1717
private readonly NPath octorunArchivePath;
1818
private NPath octorunPath;
1919

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))
20+
public OctorunInstaller(IFileSystem fileSystem, ITaskManager taskManager,
21+
NPath octorunPath, IZipHelper sharpZipLibHelper, NPath octorunArchivePath)
2622
{
27-
this.environment = environment;
28-
this.cancellationToken = cancellationToken;
23+
this.fileSystem = fileSystem;
24+
this.taskManager = taskManager;
2925
this.octorunPath = octorunPath;
3026
this.sharpZipLibHelper = sharpZipLibHelper;
3127
this.octorunArchivePath = octorunArchivePath;
@@ -54,8 +50,8 @@ private void ExtractOctorun(ActionTask<NPath> onSuccess, ITask onFailure)
5450
Logger.Trace("ExtractOctorun");
5551

5652
var tempZipExtractPath = NPath.CreateTempDirectory("octorun_extract_archive_path");
57-
var resultTask = new UnzipTask(cancellationToken, octorunArchivePath, tempZipExtractPath, sharpZipLibHelper,
58-
environment.FileSystem, OctorunExtractedMD5)
53+
var resultTask = new UnzipTask(taskManager.Token, octorunArchivePath, tempZipExtractPath, sharpZipLibHelper,
54+
fileSystem, OctorunExtractedMD5)
5955
.Then(s => MoveOctorun(tempZipExtractPath));
6056

6157
resultTask.Then(onFailure, TaskRunOptions.OnFailure);

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
}

0 commit comments

Comments
 (0)