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

Commit 33172b9

Browse files
committed
Merge features/octorun-initial-setup into releases/0.30
2 parents ad37aca + bba3d48 commit 33172b9

File tree

8 files changed

+163
-133
lines changed

8 files changed

+163
-133
lines changed

src/GitHub.Api/Application/ApplicationManagerBase.cs

Lines changed: 47 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -54,48 +54,53 @@ public void Run(bool firstRun)
5454
{
5555
Logger.Trace("Run - CurrentDirectory {0}", NPath.CurrentDirectory);
5656

57-
isBusy = true;
57+
var initEnvironmentTask = new ActionTask<NPath>(CancellationToken,
58+
(_, path) => InitializeEnvironment(path))
59+
{ Affinity = TaskAffinity.UI };
5860

59-
var gitExecutablePath = SystemSettings.Get(Constants.GitInstallPathKey)?.ToNPath();
60-
if (gitExecutablePath.HasValue && gitExecutablePath.Value.FileExists()) // we have a git path
61-
{
62-
Logger.Trace("Using git install path from settings: {0}", gitExecutablePath);
63-
InitializeEnvironment(gitExecutablePath.Value);
64-
}
65-
else // we need to go find git
66-
{
67-
Logger.Trace("No git path found in settings");
61+
isBusy = true;
6862

69-
var initEnvironmentTask = new ActionTask<NPath>(CancellationToken,
70-
(b, path) => InitializeEnvironment(path)) { Affinity = TaskAffinity.UI };
71-
var findExecTask = new FindExecTask("git", CancellationToken)
72-
.FinallyInUI((b, ex, path) =>
63+
var octorunInstaller = new OctorunInstaller(Environment, TaskManager);
64+
var setupTask = octorunInstaller
65+
.SetupOctorunIfNeeded()
66+
.Then((s, octorunPath) =>
7367
{
74-
if (b && path.IsInitialized)
75-
{
76-
//Logger.Trace("FindExecTask Success: {0}", path);
77-
InitializeEnvironment(path);
78-
}
79-
else
80-
{
81-
//Logger.Warning("FindExecTask Failure");
82-
Logger.Error("Git not found");
83-
}
68+
Environment.OctorunScriptPath = octorunPath;
8469
});
8570

86-
var gitInstaller = new GitInstaller(Environment, CancellationToken);
71+
var initializeGitTask = new FuncTask<NPath>(CancellationToken, () =>
72+
{
73+
var gitExecutablePath = SystemSettings.Get(Constants.GitInstallPathKey)?.ToNPath();
74+
if (gitExecutablePath.HasValue && gitExecutablePath.Value.FileExists()) // we have a git path
75+
{
76+
Logger.Trace("Using git install path from settings: {0}", gitExecutablePath);
77+
return gitExecutablePath.Value;
78+
}
79+
return NPath.Default;
80+
});
8781

88-
// if successful, continue with environment initialization, otherwise try to find an existing git installation
89-
var setupTask = gitInstaller.SetupGitIfNeeded();
90-
setupTask.Progress(progressReporter.UpdateProgress);
91-
setupTask.OnEnd += (thisTask, result, success, exception) =>
82+
initializeGitTask.OnEnd += (t, path, _, __) =>
9283
{
93-
if (success && result.IsInitialized)
94-
thisTask.Then(initEnvironmentTask);
95-
else
96-
thisTask.Then(findExecTask);
84+
if (path.IsInitialized)
85+
return;
86+
87+
Logger.Trace("No git path found in settings");
88+
89+
var gitInstaller = new GitInstaller(Environment, CancellationToken);
90+
91+
// if successful, continue with environment initialization, otherwise try to find an existing git installation
92+
var task = gitInstaller.SetupGitIfNeeded();
93+
task.Progress(progressReporter.UpdateProgress);
94+
task.OnEnd += (thisTask, result, success, exception) =>
95+
{
96+
thisTask.Then(initEnvironmentTask, taskIsTopOfChain: true);
97+
};
98+
99+
// append installer task to top chain
100+
t.Then(task, taskIsTopOfChain: true);
97101
};
98-
}
102+
103+
setupTask.Then(initializeGitTask).Start();
99104
}
100105

101106
public ITask InitializeRepository()
@@ -195,13 +200,20 @@ protected void SetupMetrics(string unityVersion, bool firstRun)
195200
/// <param name="octorunScriptPath"></param>
196201
private void InitializeEnvironment(NPath gitExecutablePath)
197202
{
203+
SetupMetrics();
204+
205+
if (!gitExecutablePath.IsInitialized)
206+
{
207+
isBusy = false;
208+
return;
209+
}
210+
198211
Environment.GitExecutablePath = gitExecutablePath;
199212
Environment.User.Initialize(GitClient);
200213

201214
var afterGitSetup = new ActionTask(CancellationToken, RestartRepository)
202215
.ThenInUI(InitializeUI);
203216

204-
SetupMetrics();
205217
ITask task = afterGitSetup;
206218
if (Environment.IsWindows)
207219
{

src/GitHub.Api/Installer/GitInstaller.cs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Threading;
3-
using System.Threading.Tasks;
43
using GitHub.Logging;
54

65
namespace GitHub.Unity
@@ -14,6 +13,7 @@ class GitInstaller
1413
private readonly GitInstallDetails installDetails;
1514
private readonly IZipHelper sharpZipLibHelper;
1615

16+
GitInstallationState installationState;
1717
ITask<NPath> installationTask;
1818

1919
public GitInstaller(IEnvironment environment, CancellationToken cancellationToken,
@@ -35,35 +35,35 @@ public ITask<NPath> SetupGitIfNeeded()
3535
installationTask.OnEnd += (thisTask, result, success, exception) => thisTask.UpdateProgress(100, 100);
3636

3737
if (!environment.IsWindows)
38-
return installationTask;
38+
{
39+
return new FindExecTask("git", cancellationToken)
40+
.Then(installationTask, taskIsTopOfChain: true);
41+
}
3942

40-
var startTask = new FuncTask<GitInstallationState>(cancellationToken, () =>
43+
var startTask = new FuncTask<NPath>(cancellationToken, () =>
4144
{
42-
var state = VerifyGitInstallation();
43-
if (!state.GitIsValid && !state.GitLfsIsValid)
44-
state = GrabZipFromResources(state);
45+
installationState = VerifyGitInstallation();
46+
if (!installationState.GitIsValid && !installationState.GitLfsIsValid)
47+
installationState = GrabZipFromResources(installationState);
4548
else
4649
Logger.Trace("SetupGitIfNeeded: Skipped");
47-
return state;
50+
return installDetails.GitExecutablePath;
4851
})
4952
{ Name = "Git Installation - Extract" };
5053

5154

52-
startTask.OnEnd += (thisTask, state, success, exception) =>
55+
startTask.OnEnd += (thisTask, path, success, exception) =>
5356
{
54-
if (!state.GitIsValid && !state.GitLfsIsValid)
57+
if (!installationState.GitIsValid && !installationState.GitLfsIsValid)
5558
{
56-
if (!state.GitZipExists || !state.GitLfsZipExists)
57-
thisTask = thisTask.Then(CreateDownloadTask(state));
58-
thisTask = thisTask.Then(ExtractPortableGit(state));
59+
if (!installationState.GitZipExists || !installationState.GitLfsZipExists)
60+
thisTask = thisTask.Then(CreateDownloadTask(installationState));
61+
thisTask = thisTask.Then(ExtractPortableGit(installationState));
5962
}
6063
thisTask.Then(installationTask);
6164
};
6265

63-
// we want to start the startTask and not the installationTask because the latter only gets
64-
// appended to the task chain when startTask ends, so calling Start() on it wouldn't work
65-
startTask.Start();
66-
return installationTask;
66+
return startTask;
6767
}
6868

6969
private GitInstallationState VerifyGitInstallation()
@@ -123,7 +123,7 @@ private GitInstallationState GrabZipFromResources(GitInstallationState state)
123123
return state;
124124
}
125125

126-
private ITask<GitInstallationState> CreateDownloadTask(GitInstallationState state)
126+
private ITask<NPath> CreateDownloadTask(GitInstallationState state)
127127
{
128128
var downloader = new Downloader();
129129
downloader.QueueDownload(installDetails.GitZipUrl, installDetails.GitZipMd5Url, installDetails.ZipPath);
@@ -133,11 +133,11 @@ private ITask<GitInstallationState> CreateDownloadTask(GitInstallationState stat
133133
state.GitZipExists = installDetails.GitZipPath.FileExists();
134134
state.GitLfsZipExists = installDetails.GitLfsZipPath.FileExists();
135135
installationTask.UpdateProgress(40, 100);
136-
return state;
136+
return installDetails.ZipPath;
137137
});
138138
}
139139

140-
private FuncTask<GitInstallationState> ExtractPortableGit(GitInstallationState state)
140+
private FuncTask<NPath> ExtractPortableGit(GitInstallationState state)
141141
{
142142
ITask<NPath> task = null;
143143
var tempZipExtractPath = NPath.CreateTempDirectory("git_zip_extract_zip_paths");
@@ -187,10 +187,10 @@ private FuncTask<GitInstallationState> ExtractPortableGit(GitInstallationState s
187187
task = task?.Then(unzipTask) ?? unzipTask;
188188
}
189189

190-
return task.Finally(new FuncTask<GitInstallationState>(cancellationToken, (success) =>
190+
return task.Finally(new FuncTask<NPath>(cancellationToken, (success) =>
191191
{
192192
tempZipExtractPath.DeleteIfExists();
193-
return state;
193+
return installDetails.GitInstallationPath;
194194
}));
195195
}
196196

src/GitHub.Api/Installer/IZipHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ namespace GitHub.Unity
66
interface IZipHelper
77
{
88
bool Extract(string archive, string outFolder, CancellationToken cancellationToken,
9-
Func<long, long, bool> onProgress = null);
9+
Func<long, long, bool> onProgress);
1010
}
1111
}

0 commit comments

Comments
 (0)