@@ -65,18 +65,27 @@ class GitInstaller
65
65
private readonly IZipHelper sharpZipLibHelper ;
66
66
private readonly CancellationToken cancellationToken ;
67
67
private readonly GitInstallDetails installDetails ;
68
+ private NPath gitArchiveFilePath ;
69
+ private NPath gitLfsArchivePath ;
68
70
69
71
public GitInstaller ( IEnvironment environment , CancellationToken cancellationToken , GitInstallDetails installDetails )
70
- : this ( environment , ZipHelper . Instance , cancellationToken , installDetails )
72
+ : this ( environment , ZipHelper . Instance , cancellationToken , installDetails , null , null )
71
73
{
72
74
}
73
75
74
- public GitInstaller ( IEnvironment environment , IZipHelper sharpZipLibHelper , CancellationToken cancellationToken , GitInstallDetails installDetails )
76
+ public GitInstaller ( IEnvironment environment , CancellationToken cancellationToken , GitInstallDetails installDetails , NPath gitArchiveFilePath , NPath gitLfsArchivePath )
77
+ : this ( environment , ZipHelper . Instance , cancellationToken , installDetails , gitArchiveFilePath , gitLfsArchivePath )
78
+ {
79
+ }
80
+
81
+ public GitInstaller ( IEnvironment environment , IZipHelper sharpZipLibHelper , CancellationToken cancellationToken , GitInstallDetails installDetails , NPath gitArchiveFilePath , NPath gitLfsArchivePath )
75
82
{
76
83
this . environment = environment ;
77
84
this . sharpZipLibHelper = sharpZipLibHelper ;
78
85
this . cancellationToken = cancellationToken ;
79
86
this . installDetails = installDetails ;
87
+ this . gitArchiveFilePath = gitArchiveFilePath ;
88
+ this . gitLfsArchivePath = gitLfsArchivePath ;
80
89
}
81
90
82
91
public void SetupGitIfNeeded ( ActionTask < NPath > onSuccess , ITask onFailure )
@@ -90,8 +99,7 @@ public void SetupGitIfNeeded(ActionTask<NPath> onSuccess, ITask onFailure)
90
99
}
91
100
92
101
new FuncTask < bool > ( cancellationToken , IsGitExtracted )
93
- . Then ( ( success , isPortableGitExtracted ) => {
94
-
102
+ . Finally ( ( success , ex , isPortableGitExtracted ) => {
95
103
Logger . Trace ( "IsPortableGitExtracted: {0}" , isPortableGitExtracted ) ;
96
104
97
105
if ( isPortableGitExtracted )
@@ -104,18 +112,25 @@ public void SetupGitIfNeeded(ActionTask<NPath> onSuccess, ITask onFailure)
104
112
}
105
113
else
106
114
{
107
- var tempZipPath = NPath . CreateTempDirectory ( "git_zip_paths" ) ;
108
- var gitArchivePath = AssemblyResources . ToFile ( ResourceType . Platform , "git.zip" , tempZipPath , environment ) ;
109
- var gitLfsArchivePath = AssemblyResources . ToFile ( ResourceType . Platform , "git-lfs.zip" , tempZipPath , environment ) ;
110
-
111
- var gitExtractPath = tempZipPath . Combine ( "git" ) . CreateDirectory ( ) ;
112
- var gitLfsExtractPath = tempZipPath . Combine ( "git-lfs" ) . CreateDirectory ( ) ;
113
-
114
- new UnzipTask ( cancellationToken , gitArchivePath , gitExtractPath , sharpZipLibHelper , environment . FileSystem , GitInstallDetails . GitExtractedMD5 )
115
+ ITask downloadFilesTask = null ;
116
+ if ( gitArchiveFilePath == null || gitLfsArchivePath == null )
117
+ {
118
+ downloadFilesTask = CreateDownloadTask ( ) ;
119
+ }
120
+
121
+ var tempZipExtractPath = NPath . CreateTempDirectory ( "git_zip_extract_zip_paths" ) ;
122
+ var gitExtractPath = tempZipExtractPath . Combine ( "git" ) . CreateDirectory ( ) ;
123
+ var gitLfsExtractPath = tempZipExtractPath . Combine ( "git-lfs" ) . CreateDirectory ( ) ;
124
+
125
+ var resultTask = new UnzipTask ( cancellationToken , gitArchiveFilePath , gitExtractPath , sharpZipLibHelper , environment . FileSystem , GitInstallDetails . GitExtractedMD5 )
115
126
. Then ( new UnzipTask ( cancellationToken , gitLfsArchivePath , gitLfsExtractPath , sharpZipLibHelper , environment . FileSystem , GitInstallDetails . GitLfsExtractedMD5 ) )
116
127
. Then ( ( ) => {
117
128
var targetGitLfsExecPath = installDetails . GetGitLfsExecPath ( gitExtractPath ) ;
118
129
var extractGitLfsExePath = gitLfsExtractPath . Combine ( installDetails . GitLfsExec ) ;
130
+
131
+ Logger . Trace ( "Moving Git LFS Exe:\" {0}\" to target in tempDirectory:\" {1}\" " , extractGitLfsExePath ,
132
+ targetGitLfsExecPath ) ;
133
+
119
134
extractGitLfsExePath . Move ( targetGitLfsExecPath ) ;
120
135
121
136
Logger . Trace ( "Moving tempDirectory:\" {0}\" to extractTarget:\" {1}\" " , gitExtractPath ,
@@ -127,10 +142,10 @@ public void SetupGitIfNeeded(ActionTask<NPath> onSuccess, ITask onFailure)
127
142
Logger . Trace ( "Deleting targetGitLfsExecPath:\" {0}\" " , targetGitLfsExecPath ) ;
128
143
targetGitLfsExecPath . DeleteIfExists ( ) ;
129
144
130
- Logger . Trace ( "Deleting tempZipPath:\" {0}\" " , tempZipPath ) ;
131
- tempZipPath . DeleteIfExists ( ) ;
132
-
133
- } ) . Finally ( ( b , exception ) => {
145
+ Logger . Trace ( "Deleting tempZipPath:\" {0}\" " , tempZipExtractPath ) ;
146
+ tempZipExtractPath . DeleteIfExists ( ) ;
147
+ } )
148
+ . Finally ( ( b , exception ) => {
134
149
if ( b )
135
150
{
136
151
Logger . Trace ( "SetupGitIfNeeded: Success" ) ;
@@ -145,11 +160,47 @@ public void SetupGitIfNeeded(ActionTask<NPath> onSuccess, ITask onFailure)
145
160
146
161
onFailure . Start ( ) ;
147
162
}
148
- } ) . Start ( ) ;
163
+ } ) ;
164
+
165
+ if ( downloadFilesTask != null )
166
+ {
167
+ resultTask = downloadFilesTask . Then ( resultTask ) ;
168
+ }
169
+
170
+ resultTask . Start ( ) ;
149
171
}
150
172
} ) . Start ( ) ;
151
173
}
152
174
175
+ private ITask CreateDownloadTask ( )
176
+ {
177
+ var tempZipPath = NPath . CreateTempDirectory ( "git_zip_paths" ) ;
178
+ gitArchiveFilePath = tempZipPath . Combine ( "git.zip" ) ;
179
+ gitLfsArchivePath = tempZipPath . Combine ( "git-lfs.zip" ) ;
180
+
181
+ var downloadGitMd5Task = new DownloadTextTask ( CancellationToken . None ,
182
+ "https://ghfvs-installer.github.com/unity/portable_git/git.zip.MD5.txt" ) ;
183
+
184
+ var downloadGitTask = new DownloadTask ( CancellationToken . None , environment . FileSystem ,
185
+ "https://ghfvs-installer.github.com/unity/portable_git/git.zip" , gitArchiveFilePath , retryCount : 1 ) ;
186
+
187
+ var downloadGitLfsMd5Task = new DownloadTextTask ( CancellationToken . None ,
188
+ "https://ghfvs-installer.github.com/unity/portable_git/git-lfs.zip.MD5.txt" ) ;
189
+
190
+ var downloadGitLfsTask = new DownloadTask ( CancellationToken . None , environment . FileSystem ,
191
+ "https://ghfvs-installer.github.com/unity/portable_git/git-lfs.zip" , gitLfsArchivePath , retryCount : 1 ) ;
192
+
193
+ return downloadGitMd5Task . Then ( ( b , s ) => {
194
+ downloadGitTask . ValidationHash = s ;
195
+ } )
196
+ . Then ( downloadGitTask )
197
+ . Then ( downloadGitLfsMd5Task )
198
+ . Then ( ( b , s ) => {
199
+ downloadGitLfsTask . ValidationHash = s ;
200
+ } )
201
+ . Then ( downloadGitLfsTask ) ;
202
+ }
203
+
153
204
private bool IsGitExtracted ( )
154
205
{
155
206
if ( ! installDetails . GitInstallPath . DirectoryExists ( ) )
0 commit comments