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

Commit c9784c7

Browse files
Stacking tasks in order to get the desired async forks
1 parent 08719d9 commit c9784c7

File tree

4 files changed

+145
-29
lines changed

4 files changed

+145
-29
lines changed

src/GitHub.Api/Application/ApplicationManagerBase.cs

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,63 @@ public void Run(bool firstRun)
5151
var afterGitSetup = new ActionTask(CancellationToken, RestartRepository)
5252
.ThenInUI(InitializeUI);
5353

54-
// SetupGit()
55-
// .Then(RestartRepository)
56-
// .ThenInUI(InitializeUI)
57-
// .Start();
54+
Logger.Trace("afterGitSetup");
55+
56+
var windowsCredentialSetup = new ActionTask(CancellationToken, () => {
57+
GitClient.GetConfig("credential.helper", GitConfigSource.Global).Then((b, credentialHelper) => {
58+
if (!string.IsNullOrEmpty(credentialHelper))
59+
{
60+
Logger.Trace("Windows CredentialHelper: {0}", credentialHelper);
61+
afterGitSetup.Start();
62+
}
63+
else
64+
{
65+
Logger.Warning("No Windows CredentialHeloper found: Setting to wincred");
66+
67+
GitClient.SetConfig("credential.helper", "wincred", GitConfigSource.Global)
68+
.Then(() => { afterGitSetup.Start(); }).Start();
69+
}
70+
}).Start();
71+
});
72+
73+
Logger.Trace("windowsCredentialSetup");
74+
75+
var afterPathDetermined = new ActionTask<NPath>(CancellationToken, (b1, path) => {
76+
77+
Logger.Trace("Setting Environment git path: {0}", path);
78+
Environment.GitExecutablePath = path;
79+
80+
}).ThenInUI(() => {
81+
82+
Environment.User.Initialize(GitClient);
83+
84+
if (Environment.IsWindows)
85+
{
86+
windowsCredentialSetup.Start();
87+
}
88+
else
89+
{
90+
afterGitSetup.Start();
91+
}
92+
});
93+
94+
Logger.Trace("afterPathDetermined");
95+
96+
var applicationDataPath = Environment.GetSpecialFolder(System.Environment.SpecialFolder.LocalApplicationData).ToNPath();
97+
var installDetails = new PortableGitInstallDetails(applicationDataPath, true);
98+
99+
var gitInstaller = new GitInstaller(Environment, CancellationToken, installDetails);
100+
gitInstaller.SetupGitIfNeeded(new ActionTask<NPath>(CancellationToken, (b, s) => {
101+
102+
Logger.Trace("Success: {0}", s);
103+
104+
new FuncTask<NPath>(CancellationToken, () => s)
105+
.Then(afterPathDetermined)
106+
.Start();
107+
108+
}), new ActionTask(CancellationToken, () => {
109+
Logger.Trace("Failure");
110+
}) );
58111
}
59112

60113
private ITask SetupGit()

src/GitHub.Api/GitHub.Api.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@
117117
<Compile Include="Application\ApplicationManagerBase.cs" />
118118
<Compile Include="Helpers\Constants.cs" />
119119
<Compile Include="Helpers\Validation.cs" />
120+
<Compile Include="Installer\GitInstaller.cs" />
120121
<Compile Include="Installer\PortableGitInstallTask.cs" />
121122
<Compile Include="Installer\ShortCircuitTask.cs" />
122123
<Compile Include="Installer\UnzipTask.cs" />
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
using System;
2+
using System.Threading;
3+
4+
namespace GitHub.Unity
5+
{
6+
class GitInstaller
7+
{
8+
private static ILogging Logger = Logging.GetLogger<GitInstaller>();
9+
10+
private readonly IEnvironment environment;
11+
private readonly IZipHelper sharpZipLibHelper;
12+
private readonly CancellationToken cancellationToken;
13+
private readonly PortableGitInstallDetails installDetails;
14+
15+
public GitInstaller(IEnvironment environment, CancellationToken cancellationToken, PortableGitInstallDetails installDetails)
16+
: this(environment, null, cancellationToken, installDetails)
17+
{
18+
}
19+
20+
public GitInstaller(IEnvironment environment, IZipHelper sharpZipLibHelper, CancellationToken cancellationToken, PortableGitInstallDetails installDetails)
21+
{
22+
this.environment = environment;
23+
this.sharpZipLibHelper = sharpZipLibHelper;
24+
this.cancellationToken = cancellationToken;
25+
this.installDetails = installDetails;
26+
}
27+
28+
public void SetupGitIfNeeded(ActionTask<NPath> onSuccess, ITask onFailure)
29+
{
30+
Logger.Trace("SetupGitIfNeeded");
31+
32+
if (!environment.IsWindows)
33+
{
34+
onFailure.Start();
35+
}
36+
37+
new FuncTask<bool>(cancellationToken, IsPortableGitExtracted)
38+
.Then((success, isPortableGitExtracted) => {
39+
40+
Logger.Trace("IsPortableGitExtracted: {0}", isPortableGitExtracted);
41+
42+
if (isPortableGitExtracted)
43+
{
44+
new FuncTask<NPath>(cancellationToken, () => installDetails.GitExecPath)
45+
.Then(onSuccess)
46+
.Start();
47+
}
48+
else
49+
{
50+
new PortableGitInstallTask(cancellationToken, environment, installDetails).Then((b, path) => {
51+
if (b && path != null)
52+
{
53+
new FuncTask<NPath>(cancellationToken, () => path)
54+
.Then(onSuccess)
55+
.Start();
56+
}
57+
else
58+
{
59+
onFailure.Start();
60+
}
61+
}).Start();
62+
63+
}
64+
65+
}).Start();
66+
}
67+
68+
private bool IsPortableGitExtracted()
69+
{
70+
if (!installDetails.GitInstallPath.DirectoryExists())
71+
{
72+
Logger.Trace("{0} does not exist", installDetails.GitInstallPath);
73+
return false;
74+
}
75+
76+
var fileListMD5 = environment.FileSystem.CalculateFolderMD5(installDetails.GitInstallPath, false);
77+
if (!fileListMD5.Equals(PortableGitInstallDetails.FileListMD5, StringComparison.InvariantCultureIgnoreCase))
78+
{
79+
Logger.Trace("MD5 {0} does not match expected {1}", fileListMD5, PortableGitInstallDetails.FileListMD5);
80+
return false;
81+
}
82+
83+
Logger.Trace("Git Present");
84+
return true;
85+
}
86+
}
87+
}

src/GitHub.Api/Installer/PortableGitInstallTask.cs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,6 @@ protected override NPath RunWithReturn(bool success)
6969

7070
Logger.Trace("Starting PortableGitInstallTask");
7171

72-
if (IsPortableGitExtracted())
73-
{
74-
Logger.Trace("Completed PortableGitInstallTask");
75-
return installDetails.GitExecPath;
76-
}
77-
7872
Token.ThrowIfCancellationRequested();
7973

8074
installDetails.GitInstallPath.DeleteIfExists();
@@ -145,25 +139,6 @@ private bool MoveExtractTarget(NPath extractTarget)
145139
return true;
146140
}
147141

148-
private bool IsPortableGitExtracted()
149-
{
150-
if (!installDetails.GitInstallPath.DirectoryExists())
151-
{
152-
Logger.Trace("{0} does not exist", installDetails.GitInstallPath);
153-
return false;
154-
}
155-
156-
var fileListMD5 = environment.FileSystem.CalculateFolderMD5(installDetails.GitInstallPath, false);
157-
if (!fileListMD5.Equals(PortableGitInstallDetails.FileListMD5, StringComparison.InvariantCultureIgnoreCase))
158-
{
159-
Logger.Trace("MD5 {0} does not match expected {1}", fileListMD5, PortableGitInstallDetails.FileListMD5);
160-
return false;
161-
}
162-
163-
Logger.Trace("Git Present");
164-
return true;
165-
}
166-
167142
private bool InstallGit(NPath targetPath)
168143
{
169144
Logger.Trace("InstallGit");

0 commit comments

Comments
 (0)