@@ -14,8 +14,10 @@ abstract class ApplicationManagerBase : IApplicationManager
1414 private RepositoryManager repositoryManager ;
1515 private Progress progressReporter ;
1616 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 ; } }
1921
2022 public event Action < IProgress > OnProgress
2123 {
@@ -49,52 +51,76 @@ public void Run()
4951 {
5052 isBusy = true ;
5153
52- var thread = new Thread ( obj =>
54+ var thread = new Thread ( ( ) =>
5355 {
54- CancellationToken token = ( CancellationToken ) obj ;
55- SetupMetrics ( Environment . UnityVersion , firstRun , instanceId ) ;
56-
57- if ( Environment . IsMac )
56+ GitInstallationState state = new GitInstallationState ( ) ;
57+ try
5858 {
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 )
6462 {
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+ }
6772 }
68- }
6973
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+ }
7289
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+ }
79101
80- if ( runInstallers )
81- {
82102 Environment . OctorunScriptPath = new OctorunInstaller ( Environment , TaskManager )
83103 . SetupOctorunIfNeeded ( ) ;
84104
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 ) ;
89111
90- SetupGit ( state ) ;
112+ if ( state . GitIsValid && state . GitLfsIsValid )
113+ {
114+ RestartRepository ( ) ;
115+ }
91116
92- if ( state . GitIsValid && state . GitLfsIsValid )
117+ }
118+ catch ( Exception ex )
93119 {
94- RestartRepository ( ) ;
120+ Logger . Error ( ex , "A problem ocurred setting up Git" ) ;
95121 }
96122
97- new ActionTask < bool > ( token , ( s , gitIsValid ) =>
123+ new ActionTask < bool > ( CancellationToken , ( s , gitIsValid ) =>
98124 {
99125 InitializationComplete ( ) ;
100126 if ( gitIsValid )
@@ -106,17 +132,33 @@ public void Run()
106132 { Affinity = TaskAffinity . UI }
107133 . Start ( ) ;
108134 } ) ;
109- thread . Start ( CancellationToken ) ;
135+ thread . Start ( ) ;
110136 }
111137
112- private void SetupGit ( GitInstaller . GitInstallationState state )
138+ public void SetupGit ( GitInstaller . GitInstallationState state )
113139 {
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+ }
115158 return ;
159+ }
116160
117- Environment . GitExecutablePath = state . GitExecutablePath ;
118- Environment . GitLfsExecutablePath = state . GitLfsExecutablePath ;
119- Environment . IsCustomGitExecutable = state . IsCustomGitPath ;
161+ Environment . GitInstallationState = state ;
120162 Environment . User . Initialize ( GitClient ) ;
121163
122164 if ( firstRun )
@@ -142,7 +184,13 @@ private void SetupGit(GitInstaller.GitInstallationState state)
142184 } )
143185 . RunWithReturn ( true ) ;
144186
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 ) ;
146194
147195 if ( Environment . IsWindows )
148196 {
@@ -170,37 +218,53 @@ private void SetupGit(GitInstaller.GitInstallationState state)
170218
171219 public void InitializeRepository ( )
172220 {
173- var thread = new Thread ( obj =>
221+ isBusy = true ;
222+ var thread = new Thread ( ( ) =>
174223 {
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 ;
195257 } ) ;
196- thread . Start ( CancellationToken ) ;
258+ thread . Start ( ) ;
197259 }
198260
199261 public void RestartRepository ( )
200262 {
201263 if ( ! Environment . RepositoryPath . IsInitialized )
202264 return ;
203265
266+ repositoryManager ? . Dispose ( ) ;
267+
204268 repositoryManager = Unity . RepositoryManager . CreateInstance ( Platform , TaskManager , GitClient , Environment . FileSystem , Environment . RepositoryPath ) ;
205269 repositoryManager . Initialize ( ) ;
206270 Environment . Repository . Initialize ( repositoryManager , TaskManager ) ;
@@ -209,7 +273,7 @@ public void RestartRepository()
209273 Logger . Trace ( $ "Got a repository? { ( Environment . Repository != null ? Environment . Repository . LocalPath : "null" ) } ") ;
210274 }
211275
212- protected void SetupMetrics ( string unityVersion , bool firstRun , Guid instanceId )
276+ protected void SetupMetrics ( string unityVersion , Guid instanceId )
213277 {
214278 string userId = null ;
215279 if ( UserSettings . Exists ( Constants . GuidKey ) )
0 commit comments