@@ -26,13 +26,14 @@ class GitInstallDetails
26
26
27
27
private readonly bool onWindows ;
28
28
29
- public GitInstallDetails ( NPath pluginDataPath , bool onWindows )
29
+ public GitInstallDetails ( NPath baseDataPath , bool onWindows )
30
30
{
31
31
this . onWindows = onWindows ;
32
32
33
- PluginDataPath = pluginDataPath ;
33
+ ZipPath = baseDataPath . Combine ( "downloads" ) ;
34
+ ZipPath . EnsureDirectoryExists ( ) ;
34
35
35
- var gitInstallPath = PluginDataPath . Combine ( PackageNameWithVersion ) ;
36
+ var gitInstallPath = baseDataPath . Combine ( PackageNameWithVersion ) ;
36
37
GitInstallationPath = gitInstallPath ;
37
38
38
39
if ( onWindows )
@@ -60,7 +61,7 @@ public NPath GetGitLfsExecutablePath(NPath gitInstallRoot)
60
61
: gitInstallRoot . Combine ( "libexec" , "git-core" , GitLfsExecutable ) ;
61
62
}
62
63
63
- public NPath PluginDataPath { get ; }
64
+ public NPath ZipPath { get ; }
64
65
public NPath GitInstallationPath { get ; }
65
66
public string GitExecutable { get ; }
66
67
public NPath GitExecutablePath { get ; }
@@ -91,9 +92,8 @@ public GitInstaller(IEnvironment environment, CancellationToken cancellationToke
91
92
92
93
public GitInstaller ( IEnvironment environment , CancellationToken cancellationToken ,
93
94
GitInstallDetails installDetails , NPath gitArchiveFilePath , NPath gitLfsArchivePath )
94
- : this (
95
- environment , ZipHelper . Instance , cancellationToken , installDetails , gitArchiveFilePath ,
96
- gitLfsArchivePath )
95
+ : this ( environment , ZipHelper . Instance , cancellationToken , installDetails ,
96
+ gitArchiveFilePath , gitLfsArchivePath )
97
97
{ }
98
98
99
99
public GitInstaller ( IEnvironment environment , IZipHelper sharpZipLibHelper , CancellationToken cancellationToken ,
@@ -120,7 +120,10 @@ public void SetupGitIfNeeded(ActionTask<NPath> onSuccess, ITask onFailure)
120
120
var isGitExtractedTask = new FuncTask < NPath > ( cancellationToken , ( ) =>
121
121
{
122
122
if ( ! IsGitExtracted ( ) )
123
+ {
124
+ GrabZipFromResources ( ) ;
123
125
return null ;
126
+ }
124
127
Logger . Trace ( "SetupGitIfNeeded: Skipped" ) ;
125
128
return installDetails . GitExecutablePath ;
126
129
} ) ;
@@ -140,6 +143,43 @@ public void SetupGitIfNeeded(ActionTask<NPath> onSuccess, ITask onFailure)
140
143
isGitExtractedTask . Start ( ) ;
141
144
}
142
145
146
+ private void GrabZipFromResources ( )
147
+ {
148
+ if ( gitArchiveFilePath == null || ! gitArchiveFilePath . FileExists ( ) )
149
+ gitArchiveFilePath = AssemblyResources . ToFile ( ResourceType . Platform , "git.zip" , installDetails . ZipPath , environment ) ;
150
+ if ( ! gitArchiveFilePath . FileExists ( ) )
151
+ gitArchiveFilePath = null ;
152
+
153
+ if ( gitLfsArchivePath == null || ! gitLfsArchivePath . FileExists ( ) )
154
+ gitLfsArchivePath = AssemblyResources . ToFile ( ResourceType . Platform , "git-lfs.zip" , installDetails . ZipPath , environment ) ;
155
+ if ( ! gitLfsArchivePath . FileExists ( ) )
156
+ gitLfsArchivePath = null ;
157
+ }
158
+
159
+ private ITask CreateDownloadTask ( )
160
+ {
161
+ gitArchiveFilePath = installDetails . ZipPath . Combine ( "git.zip" ) ;
162
+ gitLfsArchivePath = installDetails . ZipPath . Combine ( "git-lfs.zip" ) ;
163
+
164
+ var downloader = new Downloader ( ) ;
165
+ downloader . QueueDownload ( installDetails . GitZipUrl , installDetails . GitZipMd5Url , installDetails . ZipPath ) ;
166
+ downloader . QueueDownload ( installDetails . GitLfsZipUrl , installDetails . GitLfsZipMd5Url , installDetails . ZipPath ) ;
167
+ return downloader ;
168
+ }
169
+
170
+ private FuncTask < NPath > CreateUnzipTasks ( NPath gitExtractPath , NPath gitLfsExtractPath , NPath tempZipExtractPath )
171
+ {
172
+ var unzipGitTask = new UnzipTask ( cancellationToken , gitArchiveFilePath , gitExtractPath , sharpZipLibHelper ,
173
+ environment . FileSystem , GitInstallDetails . GitExtractedMD5 ) ;
174
+ var unzipGitLfsTask = new UnzipTask ( cancellationToken , gitLfsArchivePath , gitLfsExtractPath , sharpZipLibHelper ,
175
+ environment . FileSystem , GitInstallDetails . GitLfsExtractedMD5 ) ;
176
+
177
+ var moveGitTask = new FuncTask < NPath > ( cancellationToken , ( ) => MoveGitAndLfs ( gitExtractPath , gitLfsExtractPath , tempZipExtractPath ) ) ;
178
+ return unzipGitTask
179
+ . Then ( unzipGitLfsTask )
180
+ . Then ( moveGitTask ) ;
181
+ }
182
+
143
183
private FuncTask < NPath > ExtractPortableGit ( )
144
184
{
145
185
var tempZipExtractPath = NPath . CreateTempDirectory ( "git_zip_extract_zip_paths" ) ;
@@ -157,19 +197,6 @@ private FuncTask<NPath> ExtractPortableGit()
157
197
return unzipTasks ;
158
198
}
159
199
160
- private FuncTask < NPath > CreateUnzipTasks ( NPath gitExtractPath , NPath gitLfsExtractPath , NPath tempZipExtractPath )
161
- {
162
- var unzipGitTask = new UnzipTask ( cancellationToken , gitArchiveFilePath , gitExtractPath , sharpZipLibHelper ,
163
- environment . FileSystem , GitInstallDetails . GitExtractedMD5 ) ;
164
- var unzipGitLfsTask = new UnzipTask ( cancellationToken , gitLfsArchivePath , gitLfsExtractPath , sharpZipLibHelper ,
165
- environment . FileSystem , GitInstallDetails . GitLfsExtractedMD5 ) ;
166
-
167
- var moveGitTask = new FuncTask < NPath > ( cancellationToken , ( ) => MoveGitAndLfs ( gitExtractPath , gitLfsExtractPath , tempZipExtractPath ) ) ;
168
- return unzipGitTask
169
- . Then ( unzipGitLfsTask )
170
- . Then ( moveGitTask ) ;
171
- }
172
-
173
200
private NPath MoveGitAndLfs ( NPath gitExtractPath , NPath gitLfsExtractPath , NPath tempZipExtractPath )
174
201
{
175
202
var targetGitLfsExecPath = installDetails . GetGitLfsExecutablePath ( gitExtractPath ) ;
@@ -193,19 +220,6 @@ private NPath MoveGitAndLfs(NPath gitExtractPath, NPath gitLfsExtractPath, NPath
193
220
return installDetails . GitExecutablePath ;
194
221
}
195
222
196
- private ITask CreateDownloadTask ( )
197
- {
198
- gitArchiveFilePath = installDetails . PluginDataPath . Combine ( "git.zip" ) ;
199
- gitLfsArchivePath = installDetails . PluginDataPath . Combine ( "git-lfs.zip" ) ;
200
-
201
- var downloader = new Downloader ( ) ;
202
-
203
- downloader . QueueDownload ( installDetails . GitZipUrl , installDetails . GitZipMd5Url , installDetails . PluginDataPath ) ;
204
- downloader . QueueDownload ( installDetails . GitLfsZipUrl , installDetails . GitLfsZipMd5Url , installDetails . PluginDataPath ) ;
205
-
206
- return downloader ;
207
- }
208
-
209
223
private bool IsGitExtracted ( )
210
224
{
211
225
if ( ! installDetails . GitInstallationPath . DirectoryExists ( ) )
@@ -214,7 +228,7 @@ private bool IsGitExtracted()
214
228
return false ;
215
229
}
216
230
217
- var gitExecutableMd5 = environment . FileSystem . CalculateFileMD5 ( installDetails . GitExecutablePath ) ;
231
+ var gitExecutableMd5 = installDetails . GitExecutablePath . CalculateMD5 ( ) ;
218
232
var expectedGitExecutableMd5 = environment . IsWindows ? GitInstallDetails . WindowsGitExecutableMD5 : GitInstallDetails . MacGitExecutableMD5 ;
219
233
220
234
if ( ! expectedGitExecutableMd5 . Equals ( gitExecutableMd5 , StringComparison . InvariantCultureIgnoreCase ) )
@@ -223,7 +237,7 @@ private bool IsGitExtracted()
223
237
return false ;
224
238
}
225
239
226
- var gitLfsExecutableMd5 = environment . FileSystem . CalculateFileMD5 ( installDetails . GitLfsExecutablePath ) ;
240
+ var gitLfsExecutableMd5 = installDetails . GitLfsExecutablePath . CalculateMD5 ( ) ;
227
241
var expectedGitLfsExecutableMd5 = environment . IsWindows ? GitInstallDetails . WindowsGitLfsExecutableMD5 : GitInstallDetails . MacGitLfsExecutableMD5 ;
228
242
229
243
if ( ! expectedGitLfsExecutableMd5 . Equals ( gitLfsExecutableMd5 , StringComparison . InvariantCultureIgnoreCase ) )
0 commit comments