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

Commit 41ae437

Browse files
Merge pull request #799 from github-for-unity/fixes/lock-unlock-multiple-files
Assets Window support to lock/unlock multiple files
2 parents a376d78 + 20d4c85 commit 41ae437

File tree

21 files changed

+749
-632
lines changed

21 files changed

+749
-632
lines changed

script

src/GitHub.Api/Application/ApplicationManagerBase.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ abstract class ApplicationManagerBase : IApplicationManager
1616
private Progress progress = new Progress(TaskBase.Default);
1717
protected bool isBusy;
1818
private bool firstRun;
19-
protected bool FirstRun { get { return firstRun; } set { firstRun = value; } }
19+
protected bool FirstRun { get { return firstRun; } set { firstRun = value; } }
2020
private Guid instanceId;
2121
protected Guid InstanceId { get { return instanceId; } set { instanceId = value; } }
2222

@@ -79,7 +79,7 @@ public void Run()
7979
var getEnvPath = new SimpleProcessTask(TaskManager.Token, "bash".ToNPath(), "-c \"/usr/libexec/path_helper\"")
8080
.Configure(ProcessManager, dontSetupGit: true)
8181
.Catch(e => true); // make sure this doesn't throw if the task fails
82-
var path = getEnvPath.RunWithReturn(true);
82+
var path = getEnvPath.RunSynchronously();
8383
if (getEnvPath.Successful)
8484
{
8585
Logger.Trace("Existing Environment Path Original:{0} Updated:{1}", Environment.Path, path);
@@ -199,7 +199,7 @@ public void SetupGit(GitInstaller.GitInstallationState state)
199199
Logger.Error(e, "Error running lfs install");
200200
return true;
201201
})
202-
.RunWithReturn(true);
202+
.RunSynchronously();
203203
}
204204

205205
if (Environment.IsWindows)
@@ -209,7 +209,7 @@ public void SetupGit(GitInstaller.GitInstallationState state)
209209
{
210210
Logger.Error(e, "Error getting the credential helper");
211211
return true;
212-
}).RunWithReturn(true);
212+
}).RunSynchronously();
213213

214214
if (string.IsNullOrEmpty(credentialHelper))
215215
{
@@ -220,7 +220,7 @@ public void SetupGit(GitInstaller.GitInstallationState state)
220220
Logger.Error(e, "Error setting the credential helper");
221221
return true;
222222
})
223-
.RunWithReturn(true);
223+
.RunSynchronously();
224224
}
225225
}
226226
}
@@ -243,21 +243,21 @@ public void InitializeRepository()
243243

244244
var filesForInitialCommit = new List<string> { gitignore, gitAttrs, assetsGitignore };
245245

246-
GitClient.Init().RunWithReturn(true);
246+
GitClient.Init().RunSynchronously();
247247
progress.UpdateProgress(10, 100, "Initializing...");
248248

249249
ConfigureMergeSettings();
250250
progress.UpdateProgress(20, 100, "Initializing...");
251251

252-
GitClient.LfsInstall().RunWithReturn(true);
252+
GitClient.LfsInstall().RunSynchronously();
253253
progress.UpdateProgress(30, 100, "Initializing...");
254254

255255
AssemblyResources.ToFile(ResourceType.Generic, ".gitignore", targetPath, Environment);
256256
AssemblyResources.ToFile(ResourceType.Generic, ".gitattributes", targetPath, Environment);
257257
assetsGitignore.CreateFile();
258-
GitClient.Add(filesForInitialCommit).RunWithReturn(true);
258+
GitClient.Add(filesForInitialCommit).RunSynchronously();
259259
progress.UpdateProgress(60, 100, "Initializing...");
260-
GitClient.Commit("Initial commit", null).RunWithReturn(true);
260+
GitClient.Commit("Initial commit", null).RunSynchronously();
261261
progress.UpdateProgress(70, 100, "Initializing...");
262262
Environment.InitializeRepository();
263263
}
@@ -292,12 +292,12 @@ private void ConfigureMergeSettings()
292292
GitClient.SetConfig("merge.unityyamlmerge.cmd", yamlMergeCommand, GitConfigSource.Local).Catch(e => {
293293
Logger.Error(e, "Error setting merge.unityyamlmerge.cmd");
294294
return true;
295-
}).RunWithReturn(true);
295+
}).RunSynchronously();
296296

297297
GitClient.SetConfig("merge.unityyamlmerge.trustExitCode", "false", GitConfigSource.Local).Catch(e => {
298298
Logger.Error(e, "Error setting merge.unityyamlmerge.trustExitCode");
299299
return true;
300-
}).RunWithReturn(true);
300+
}).RunSynchronously();
301301
}
302302

303303
private void CaptureRepoSize()

src/GitHub.Api/Authentication/LoginManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public ITask Logout(UriString hostAddress)
138138
{
139139
Guard.ArgumentNotNull(hostAddress, nameof(hostAddress));
140140

141-
return new ActionTask(keychain.Clear(hostAddress, true)) { Message = "Signing out" }.Start();
141+
return new TPLTask(keychain.Clear(hostAddress, true)) { Message = "Signing out" }.Start();
142142
}
143143

144144
private async Task<LoginResultData> TryLogin(

src/GitHub.Api/Git/RepositoryManager.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ private ITask HookupHandlers(ITask task, bool filesystemChangesExpected)
460460
}
461461
};
462462

463-
task.Finally(success =>
463+
task.OnEnd += (_, __, ___) =>
464464
{
465465
if (filesystemChangesExpected)
466466
{
@@ -473,6 +473,21 @@ private ITask HookupHandlers(ITask task, bool filesystemChangesExpected)
473473
//Logger.Trace("Ended Operation - Clearing Busy Flag");
474474
IsBusy = false;
475475
}
476+
};
477+
task.Catch(_ =>
478+
{
479+
if (filesystemChangesExpected)
480+
{
481+
//Logger.Trace("Ended Operation - Enable Watcher");
482+
watcher.Start();
483+
}
484+
485+
if (isExclusive)
486+
{
487+
//Logger.Trace("Ended Operation - Clearing Busy Flag");
488+
IsBusy = false;
489+
}
490+
476491
});
477492
return task;
478493
}

src/GitHub.Api/Installer/GitInstaller.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ private GitInstallationState FindGit(GitInstallationState state)
106106
var gitPath = new FindExecTask("git", cancellationToken)
107107
.Configure(processManager, dontSetupGit: true)
108108
.Catch(e => true)
109-
.RunWithReturn(true);
109+
.RunSynchronously();
110110
state.GitExecutablePath = gitPath;
111111
state = ValidateGitVersion(state);
112112
if (state.GitIsValid)
@@ -122,7 +122,7 @@ private GitInstallationState FindGitLfs(GitInstallationState state)
122122
var gitLfsPath = new FindExecTask("git-lfs", cancellationToken)
123123
.Configure(processManager, dontSetupGit: true)
124124
.Catch(e => true)
125-
.RunWithReturn(true);
125+
.RunSynchronously();
126126
state.GitLfsExecutablePath = gitLfsPath;
127127
state = ValidateGitLfsVersion(state);
128128
if (state.GitLfsIsValid)
@@ -159,7 +159,7 @@ public GitInstallationState ValidateGitVersion(GitInstallationState state)
159159
var version = new GitVersionTask(cancellationToken)
160160
.Configure(processManager, state.GitExecutablePath, dontSetupGit: true)
161161
.Catch(e => true)
162-
.RunWithReturn(true);
162+
.RunSynchronously();
163163
state.GitIsValid = version >= Constants.MinimumGitVersion;
164164
state.GitVersion = version;
165165
return state;
@@ -175,7 +175,7 @@ public GitInstallationState ValidateGitLfsVersion(GitInstallationState state)
175175
var version = new ProcessTask<TheVersion>(cancellationToken, "version", new LfsVersionOutputProcessor())
176176
.Configure(processManager, state.GitLfsExecutablePath, dontSetupGit: true)
177177
.Catch(e => true)
178-
.RunWithReturn(true);
178+
.RunSynchronously();
179179
state.GitLfsIsValid = version >= Constants.MinimumGitLfsVersion;
180180
state.GitLfsVersion = version;
181181
return state;
@@ -244,7 +244,7 @@ private GitInstallationState GetZipsIfNeeded(GitInstallationState state)
244244
if (state.GitZipExists && state.GitLfsZipExists)
245245
return state;
246246

247-
var downloader = new Downloader();
247+
var downloader = new Downloader(environment.FileSystem);
248248
downloader.Catch(e =>
249249
{
250250
LogHelper.Trace(e, "Failed to download");
@@ -255,7 +255,7 @@ private GitInstallationState GetZipsIfNeeded(GitInstallationState state)
255255
downloader.QueueDownload(state.GitPackage.Uri, installDetails.ZipPath);
256256
if (!state.GitLfsZipExists && !state.GitLfsIsValid && state.GitLfsPackage != null)
257257
downloader.QueueDownload(state.GitLfsPackage.Uri, installDetails.ZipPath);
258-
downloader.RunWithReturn(true);
258+
downloader.RunSynchronously();
259259

260260
state.GitZipExists = installDetails.GitZipPath.FileExists();
261261
state.GitLfsZipExists = installDetails.GitLfsZipPath.FileExists();
@@ -295,7 +295,7 @@ private GitInstallationState ExtractGit(GitInstallationState state)
295295
return true;
296296
});
297297
unzipTask.Progress(p => Progress.UpdateProgress(40 + (long)(20 * p.Percentage), 100, unzipTask.Message));
298-
var path = unzipTask.RunWithReturn(true);
298+
var path = unzipTask.RunSynchronously();
299299
var target = state.GitInstallationPath;
300300
if (unzipTask.Successful)
301301
{
@@ -320,7 +320,7 @@ private GitInstallationState ExtractGit(GitInstallationState state)
320320
return true;
321321
});
322322
unzipTask.Progress(p => Progress.UpdateProgress(60 + (long)(20 * p.Percentage), 100, unzipTask.Message));
323-
var path = unzipTask.RunWithReturn(true);
323+
var path = unzipTask.RunSynchronously();
324324
var target = state.GitLfsInstallationPath;
325325
if (unzipTask.Successful)
326326
{

src/GitHub.Api/Installer/OctorunInstaller.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public NPath SetupOctorunIfNeeded()
3838
tempZipExtractPath, sharpZipLibHelper,
3939
fileSystem)
4040
.Catch(e => { Logger.Error(e, "Error extracting octorun"); return true; });
41-
var extractPath = unzipTask.RunWithReturn(true);
41+
var extractPath = unzipTask.RunSynchronously();
4242
if (unzipTask.Successful)
4343
path = MoveOctorun(extractPath.Combine("octorun"));
4444
return path;
@@ -112,4 +112,4 @@ public OctorunInstallDetails(NPath baseDataPath)
112112
public NPath VersionFile => InstallationPath.Combine("version");
113113
}
114114
}
115-
}
115+
}

src/GitHub.Api/Installer/UnzipTask.cs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,17 @@ protected NPath BaseRun(bool success)
2626
return base.RunWithReturn(success);
2727
}
2828

29-
public override NPath RunWithReturn(bool success)
29+
protected override NPath RunWithReturn(bool success)
3030
{
3131
var ret = BaseRun(success);
32-
33-
RaiseOnStart();
34-
3532
try
3633
{
3734
ret = RunUnzip(success);
3835
}
3936
catch (Exception ex)
4037
{
41-
Errors = ex.Message;
4238
if (!RaiseFaultHandlers(ex))
43-
throw;
44-
}
45-
finally
46-
{
47-
RaiseOnEnd(ret);
39+
throw exception;
4840
}
4941
return ret;
5042
}

src/GitHub.Api/Managers/Downloader.cs

Lines changed: 24 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
using System;
2-
using System.Collections.Generic;
32
using System.IO;
43
using System.Net;
5-
using System.Threading;
6-
using System.Threading.Tasks;
74
using GitHub.Logging;
8-
using System.Linq;
95

106
namespace GitHub.Unity
117
{
@@ -20,111 +16,39 @@ public DownloadData(UriString url, NPath file)
2016
}
2117
}
2218

23-
class Downloader : FuncListTask<DownloadData>
19+
class Downloader : TaskQueue<NPath, DownloadData>
2420
{
25-
public event Action<DownloadData> DownloadStart;
26-
public event Action<DownloadData> DownloadComplete;
27-
public event Action<DownloadData, Exception> DownloadFailed;
21+
public event Action<UriString> OnDownloadStart;
22+
public event Action<UriString, NPath> OnDownloadComplete;
23+
public event Action<UriString, Exception> OnDownloadFailed;
2824

29-
private readonly List<DownloaderTask> downloaders = new List<DownloaderTask>();
30-
31-
public override string Message { get; set; } = "Downloading...";
32-
33-
public Downloader() : base(TaskManager.Instance.Token, RunDownloaders)
25+
private readonly IFileSystem fileSystem;
26+
public Downloader(IFileSystem fileSystem)
27+
: base(t =>
28+
{
29+
var dt = t as DownloadTask;
30+
var destinationFile = dt.TargetDirectory.Combine(dt.Url.Filename);
31+
return new DownloadData(dt.Url, destinationFile);
32+
})
3433
{
34+
this.fileSystem = fileSystem;
3535
Name = "Downloader";
36+
Message = "Downloading...";
3637
}
3738

3839
public void QueueDownload(UriString url, NPath targetDirectory)
3940
{
40-
var downloaderTask = new DownloaderTask();
41-
downloaderTask.QueueDownload(url, targetDirectory);
42-
downloaders.Add(downloaderTask);
43-
}
44-
45-
private static List<DownloadData> RunDownloaders(bool success, FuncListTask<DownloadData> source)
46-
{
47-
Downloader self = (Downloader)source;
48-
List<DownloadData> result = null;
49-
var listOfTasks = new List<Task<DownloadData>>();
50-
foreach (var downloader in self.downloaders)
51-
{
52-
downloader.DownloadStart += self.DownloadStart;
53-
downloader.DownloadComplete += self.DownloadComplete;
54-
downloader.DownloadFailed += self.DownloadFailed;
55-
listOfTasks.Add(downloader.Run());
56-
}
57-
var res = TaskEx.WhenAll(listOfTasks).Result;
58-
if (res != null)
59-
result = new List<DownloadData>(res);
60-
return result;
61-
}
62-
63-
class DownloaderTask
64-
{
65-
public event Action<DownloadData> DownloadStart;
66-
public event Action<DownloadData> DownloadComplete;
67-
public event Action<DownloadData, Exception> DownloadFailed;
68-
69-
private readonly List<ITask<NPath>> queuedTasks = new List<ITask<NPath>>();
70-
private readonly TaskCompletionSource<DownloadData> aggregateDownloads = new TaskCompletionSource<DownloadData>();
71-
private readonly IFileSystem fs;
72-
private readonly CancellationToken cancellationToken;
73-
74-
private volatile bool isSuccessful = true;
75-
private volatile Exception exception;
76-
private DownloadData result;
77-
78-
public DownloaderTask()
79-
{
80-
fs = NPath.FileSystem;
81-
cancellationToken = TaskManager.Instance.Token;
82-
DownloadComplete += d => aggregateDownloads.TrySetResult(d);
83-
DownloadFailed += (_, e) => aggregateDownloads.TrySetException(e);
84-
}
85-
86-
public Task<DownloadData> Run()
87-
{
88-
foreach (var task in queuedTasks)
89-
task.Start();
90-
if (queuedTasks.Count == 0)
91-
DownloadComplete(result);
92-
return aggregateDownloads.Task;
93-
}
94-
95-
public Task<DownloadData> QueueDownload(UriString url, NPath targetDirectory)
41+
var download = new DownloadTask(Token, fileSystem, url, targetDirectory);
42+
download.OnStart += t => OnDownloadStart?.Invoke(((DownloadTask)t).Url);
43+
download.OnEnd += (t, res, s, ex) =>
9644
{
97-
var destinationFile = targetDirectory.Combine(url.Filename);
98-
result = new DownloadData(url, destinationFile);
99-
100-
Action<ITask<NPath>, NPath, bool, Exception> verifyDownload = (t, res, success, ex) =>
101-
{
102-
isSuccessful &= success;
103-
if (!success)
104-
exception = ex;
105-
if (!isSuccessful)
106-
{
107-
DownloadFailed(result, exception);
108-
}
109-
else
110-
{
111-
DownloadComplete(result);
112-
}
113-
};
114-
115-
var fileDownload = DownloadFile(url, targetDirectory, result, verifyDownload);
116-
fileDownload.OnStart += _ => DownloadStart?.Invoke(result);
117-
queuedTasks.Add(fileDownload);
118-
return aggregateDownloads.Task;
119-
}
120-
121-
private ITask<NPath> DownloadFile(UriString url, NPath targetDirectory, DownloadData res, Action<ITask<NPath>, NPath, bool, Exception> verifyDownload)
122-
{
123-
var download = new DownloadTask(cancellationToken, fs, url, targetDirectory)
124-
.Catch(e => { DownloadFailed(res, e); return true; });
125-
download.OnEnd += verifyDownload;
126-
return download;
127-
}
45+
if (s)
46+
OnDownloadComplete?.Invoke(((DownloadTask)t).Url, res);
47+
else
48+
OnDownloadFailed?.Invoke(((DownloadTask)t).Url, ex);
49+
};
50+
// queue after hooking up events so OnDownload* gets called first
51+
Queue(download);
12852
}
12953

13054
public static bool Download(ILogging logger, UriString url,

0 commit comments

Comments
 (0)