@@ -14,8 +14,10 @@ abstract class ApplicationManagerBase : IApplicationManager
14
14
private RepositoryManager repositoryManager ;
15
15
private Progress progressReporter ;
16
16
protected bool isBusy ;
17
- protected bool firstRun ;
18
- protected Guid instanceId ;
17
+ private bool firstRun ;
18
+ protected bool FirstRun { get { return firstRun ; } set { firstRun = value ; } }
19
+ private Guid instanceId ;
20
+ protected Guid InstanceId { get { return instanceId ; } set { instanceId = value ; } }
19
21
20
22
public event Action < IProgress > OnProgress
21
23
{
@@ -49,52 +51,76 @@ public void Run()
49
51
{
50
52
isBusy = true ;
51
53
52
- var thread = new Thread ( obj =>
54
+ var thread = new Thread ( ( ) =>
53
55
{
54
- CancellationToken token = ( CancellationToken ) obj ;
55
- SetupMetrics ( Environment . UnityVersion , firstRun , instanceId ) ;
56
-
57
- if ( Environment . IsMac )
56
+ GitInstallationState state = new GitInstallationState ( ) ;
57
+ try
58
58
{
59
- var getEnvPath = new SimpleProcessTask ( token , "bash" . ToNPath ( ) , "-c \" /usr/libexec/path_helper\" " )
60
- . Configure ( ProcessManager , dontSetupGit : true )
61
- . Catch ( e => true ) ; // make sure this doesn't throw if the task fails
62
- var path = getEnvPath . RunWithReturn ( true ) ;
63
- if ( getEnvPath . Successful )
59
+ SetupMetrics ( Environment . UnityVersion , instanceId ) ;
60
+
61
+ if ( Environment . IsMac )
64
62
{
65
- Logger . Trace ( "Existing Environment Path Original:{0} Updated:{1}" , Environment . Path , path ) ;
66
- Environment . Path = path ? . Split ( new [ ] { "\" " } , StringSplitOptions . None ) [ 1 ] ;
63
+ var getEnvPath = new SimpleProcessTask ( CancellationToken , "bash" . ToNPath ( ) , "-c \" /usr/libexec/path_helper\" " )
64
+ . Configure ( ProcessManager , dontSetupGit : true )
65
+ . Catch ( e => true ) ; // make sure this doesn't throw if the task fails
66
+ var path = getEnvPath . RunWithReturn ( true ) ;
67
+ if ( getEnvPath . Successful )
68
+ {
69
+ Logger . Trace ( "Existing Environment Path Original:{0} Updated:{1}" , Environment . Path , path ) ;
70
+ Environment . Path = path ? . Split ( new [ ] { "\" " } , StringSplitOptions . None ) [ 1 ] ;
71
+ }
67
72
}
68
- }
69
73
70
- GitInstallationState state = new GitInstallationState ( ) ;
71
- var runInstallers = firstRun ;
74
+ var installer = new GitInstaller ( Environment , ProcessManager , CancellationToken )
75
+ { Progress = progressReporter } ;
76
+ state = Environment . GitInstallationState ;
77
+ if ( ! state . GitIsValid && ! state . GitLfsIsValid && FirstRun )
78
+ {
79
+ // importing old settings
80
+ NPath gitExecutablePath = Environment . SystemSettings . Get ( Constants . GitInstallPathKey , NPath . Default ) ;
81
+ if ( gitExecutablePath . IsInitialized )
82
+ {
83
+ Environment . SystemSettings . Unset ( Constants . GitInstallPathKey ) ;
84
+ state . GitExecutablePath = gitExecutablePath ;
85
+ state . GitInstallationPath = gitExecutablePath . Parent . Parent ;
86
+ Environment . GitInstallationState = state ;
87
+ }
88
+ }
72
89
73
- if ( ! runInstallers )
74
- {
75
- state = SystemSettings . Get < GitInstallationState > ( Constants . GitInstallationState ) ?? state ;
76
- var now = DateTimeOffset . Now ;
77
- runInstallers = now . Date != state . GitLastCheckTime . Date || ( ! ( state . GitIsValid && state . GitLfsIsValid ) ) ;
78
- }
90
+ if ( state . GitIsValid && state . GitLfsIsValid )
91
+ {
92
+ if ( firstRun )
93
+ {
94
+ installer . ValidateGitVersion ( state ) ;
95
+ if ( state . GitIsValid )
96
+ {
97
+ installer . ValidateGitLfsVersion ( state ) ;
98
+ }
99
+ }
100
+ }
79
101
80
- if ( runInstallers )
81
- {
82
102
Environment . OctorunScriptPath = new OctorunInstaller ( Environment , TaskManager )
83
103
. SetupOctorunIfNeeded ( ) ;
84
104
85
- state = new GitInstaller ( Environment , ProcessManager , TaskManager , SystemSettings )
86
- { Progress = progressReporter }
87
- . SetupGitIfNeeded ( ) ;
88
- }
105
+ if ( ! state . GitIsValid || ! state . GitLfsIsValid )
106
+ {
107
+ state = installer . SetupGitIfNeeded ( ) ;
108
+ }
109
+
110
+ SetupGit ( state ) ;
89
111
90
- SetupGit ( state ) ;
112
+ if ( state . GitIsValid && state . GitLfsIsValid )
113
+ {
114
+ RestartRepository ( ) ;
115
+ }
91
116
92
- if ( state . GitIsValid && state . GitLfsIsValid )
117
+ }
118
+ catch ( Exception ex )
93
119
{
94
- RestartRepository ( ) ;
120
+ Logger . Error ( ex , "A problem ocurred setting up Git" ) ;
95
121
}
96
122
97
- new ActionTask < bool > ( token , ( s , gitIsValid ) =>
123
+ new ActionTask < bool > ( CancellationToken , ( s , gitIsValid ) =>
98
124
{
99
125
InitializationComplete ( ) ;
100
126
if ( gitIsValid )
@@ -106,17 +132,33 @@ public void Run()
106
132
{ Affinity = TaskAffinity . UI }
107
133
. Start ( ) ;
108
134
} ) ;
109
- thread . Start ( CancellationToken ) ;
135
+ thread . Start ( ) ;
110
136
}
111
137
112
- private void SetupGit ( GitInstaller . GitInstallationState state )
138
+ public void SetupGit ( GitInstaller . GitInstallationState state )
113
139
{
114
- if ( ! ( state . GitIsValid && state . GitLfsIsValid ) )
140
+ if ( ! state . GitIsValid || ! state . GitLfsIsValid )
141
+ {
142
+ if ( ! state . GitExecutablePath . IsInitialized )
143
+ {
144
+ Logger . Warning ( Localization . GitNotFound ) ;
145
+ }
146
+ else if ( ! state . GitLfsExecutablePath . IsInitialized )
147
+ {
148
+ Logger . Warning ( Localization . GitLFSNotFound ) ;
149
+ }
150
+ else if ( state . GitVersion < Constants . MinimumGitVersion )
151
+ {
152
+ Logger . Warning ( String . Format ( Localization . GitVersionTooLow , state . GitExecutablePath , state . GitVersion , Constants . MinimumGitVersion ) ) ;
153
+ }
154
+ else if ( state . GitLfsVersion < Constants . MinimumGitLfsVersion )
155
+ {
156
+ Logger . Warning ( String . Format ( Localization . GitLfsVersionTooLow , state . GitLfsExecutablePath , state . GitLfsVersion , Constants . MinimumGitLfsVersion ) ) ;
157
+ }
115
158
return ;
159
+ }
116
160
117
- Environment . GitExecutablePath = state . GitExecutablePath ;
118
- Environment . GitLfsExecutablePath = state . GitLfsExecutablePath ;
119
- Environment . IsCustomGitExecutable = state . IsCustomGitPath ;
161
+ Environment . GitInstallationState = state ;
120
162
Environment . User . Initialize ( GitClient ) ;
121
163
122
164
if ( firstRun )
@@ -142,7 +184,13 @@ private void SetupGit(GitInstaller.GitInstallationState state)
142
184
} )
143
185
. RunWithReturn ( true ) ;
144
186
145
- GitClient . LfsInstall ( ) . RunWithReturn ( true ) ;
187
+ GitClient . LfsInstall ( )
188
+ . Catch ( e =>
189
+ {
190
+ Logger . Error ( e , "Error running lfs install" ) ;
191
+ return true ;
192
+ } )
193
+ . RunWithReturn ( true ) ;
146
194
147
195
if ( Environment . IsWindows )
148
196
{
@@ -170,37 +218,53 @@ private void SetupGit(GitInstaller.GitInstallationState state)
170
218
171
219
public void InitializeRepository ( )
172
220
{
173
- var thread = new Thread ( obj =>
221
+ isBusy = true ;
222
+ var thread = new Thread ( ( ) =>
174
223
{
175
- CancellationToken token = ( CancellationToken ) obj ;
176
- var targetPath = NPath . CurrentDirectory ;
177
-
178
- var gitignore = targetPath . Combine ( ".gitignore" ) ;
179
- var gitAttrs = targetPath . Combine ( ".gitattributes" ) ;
180
- var assetsGitignore = targetPath . Combine ( "Assets" , ".gitignore" ) ;
181
-
182
- var filesForInitialCommit = new List < string > { gitignore , gitAttrs , assetsGitignore } ;
183
-
184
- GitClient . Init ( ) . RunWithReturn ( true ) ;
185
- GitClient . LfsInstall ( ) . RunWithReturn ( true ) ;
186
- AssemblyResources . ToFile ( ResourceType . Generic , ".gitignore" , targetPath , Environment ) ;
187
- AssemblyResources . ToFile ( ResourceType . Generic , ".gitattributes" , targetPath , Environment ) ;
188
- assetsGitignore . CreateFile ( ) ;
189
- GitClient . Add ( filesForInitialCommit ) . RunWithReturn ( true ) ;
190
- GitClient . Commit ( "Initial commit" , null ) . RunWithReturn ( true ) ;
191
- Environment . InitializeRepository ( ) ;
192
- RestartRepository ( ) ;
193
- UsageTracker . IncrementProjectsInitialized ( ) ;
194
- TaskManager . RunInUI ( InitializeUI ) ;
224
+ var success = true ;
225
+ try
226
+ {
227
+ var targetPath = NPath . CurrentDirectory ;
228
+
229
+ var gitignore = targetPath . Combine ( ".gitignore" ) ;
230
+ var gitAttrs = targetPath . Combine ( ".gitattributes" ) ;
231
+ var assetsGitignore = targetPath . Combine ( "Assets" , ".gitignore" ) ;
232
+
233
+ var filesForInitialCommit = new List < string > { gitignore , gitAttrs , assetsGitignore } ;
234
+
235
+ GitClient . Init ( ) . RunWithReturn ( true ) ;
236
+ GitClient . LfsInstall ( ) . RunWithReturn ( true ) ;
237
+ AssemblyResources . ToFile ( ResourceType . Generic , ".gitignore" , targetPath , Environment ) ;
238
+ AssemblyResources . ToFile ( ResourceType . Generic , ".gitattributes" , targetPath , Environment ) ;
239
+ assetsGitignore . CreateFile ( ) ;
240
+ GitClient . Add ( filesForInitialCommit ) . RunWithReturn ( true ) ;
241
+ GitClient . Commit ( "Initial commit" , null ) . RunWithReturn ( true ) ;
242
+ Environment . InitializeRepository ( ) ;
243
+ UsageTracker . IncrementProjectsInitialized ( ) ;
244
+ }
245
+ catch ( Exception ex )
246
+ {
247
+ Logger . Error ( ex , "A problem ocurred initializing the repository" ) ;
248
+ success = false ;
249
+ }
250
+
251
+ if ( success )
252
+ {
253
+ RestartRepository ( ) ;
254
+ TaskManager . RunInUI ( InitializeUI ) ;
255
+ }
256
+ isBusy = false ;
195
257
} ) ;
196
- thread . Start ( CancellationToken ) ;
258
+ thread . Start ( ) ;
197
259
}
198
260
199
261
public void RestartRepository ( )
200
262
{
201
263
if ( ! Environment . RepositoryPath . IsInitialized )
202
264
return ;
203
265
266
+ repositoryManager ? . Dispose ( ) ;
267
+
204
268
repositoryManager = Unity . RepositoryManager . CreateInstance ( Platform , TaskManager , GitClient , Environment . FileSystem , Environment . RepositoryPath ) ;
205
269
repositoryManager . Initialize ( ) ;
206
270
Environment . Repository . Initialize ( repositoryManager , TaskManager ) ;
@@ -209,7 +273,7 @@ public void RestartRepository()
209
273
Logger . Trace ( $ "Got a repository? { ( Environment . Repository != null ? Environment . Repository . LocalPath : "null" ) } ") ;
210
274
}
211
275
212
- protected void SetupMetrics ( string unityVersion , bool firstRun , Guid instanceId )
276
+ protected void SetupMetrics ( string unityVersion , Guid instanceId )
213
277
{
214
278
string userId = null ;
215
279
if ( UserSettings . Exists ( Constants . GuidKey ) )
0 commit comments