@@ -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
@@ -47,7 +47,7 @@ protected void Initialize()
4747 ApplicationConfiguration . WebTimeout = UserSettings . Get ( Constants . WebTimeoutKey , ApplicationConfiguration . WebTimeout ) ;
4848 Platform . Initialize ( ProcessManager , TaskManager ) ;
4949 progress . OnProgress += progressReporter . UpdateProgress ;
50- UsageTracker = new UsageTracker ( UserSettings , Environment , InstanceId . ToString ( ) ) ;
50+ UsageTracker = new UsageTracker ( TaskManager , UserSettings , Environment , InstanceId . ToString ( ) ) ;
5151
5252#if ENABLE_METRICS
5353 var metricsService = new MetricsService ( ProcessManager ,
@@ -64,18 +64,22 @@ public void Run()
6464 isBusy = true ;
6565 progress . UpdateProgress ( 0 , 100 , "Initializing..." ) ;
6666
67+ if ( firstRun )
68+ {
69+ UsageTracker . IncrementNumberOfStartups ( ) ;
70+ }
71+
6772 var thread = new Thread ( ( ) =>
6873 {
6974 GitInstallationState state = new GitInstallationState ( ) ;
7075 try
7176 {
72- SetupMetrics ( ) ;
7377 if ( Environment . IsMac )
7478 {
7579 var getEnvPath = new SimpleProcessTask ( TaskManager . Token , "bash" . ToNPath ( ) , "-c \" /usr/libexec/path_helper\" " )
7680 . Configure ( ProcessManager , dontSetupGit : true )
7781 . Catch ( e => true ) ; // make sure this doesn't throw if the task fails
78- var path = getEnvPath . RunWithReturn ( true ) ;
82+ var path = getEnvPath . RunSynchronously ( ) ;
7983 if ( getEnvPath . Successful )
8084 {
8185 Logger . Trace ( "Existing Environment Path Original:{0} Updated:{1}" , Environment . Path , path ) ;
@@ -187,14 +191,15 @@ public void SetupGit(GitInstaller.GitInstallationState state)
187191 if ( Environment . RepositoryPath . IsInitialized )
188192 {
189193 ConfigureMergeSettings ( ) ;
194+ CaptureRepoSize ( ) ;
190195
191196 GitClient . LfsInstall ( )
192197 . Catch ( e =>
193198 {
194199 Logger . Error ( e , "Error running lfs install" ) ;
195200 return true ;
196201 } )
197- . RunWithReturn ( true ) ;
202+ . RunSynchronously ( ) ;
198203 }
199204
200205 if ( Environment . IsWindows )
@@ -204,7 +209,7 @@ public void SetupGit(GitInstaller.GitInstallationState state)
204209 {
205210 Logger . Error ( e , "Error getting the credential helper" ) ;
206211 return true ;
207- } ) . RunWithReturn ( true ) ;
212+ } ) . RunSynchronously ( ) ;
208213
209214 if ( string . IsNullOrEmpty ( credentialHelper ) )
210215 {
@@ -215,7 +220,7 @@ public void SetupGit(GitInstaller.GitInstallationState state)
215220 Logger . Error ( e , "Error setting the credential helper" ) ;
216221 return true ;
217222 } )
218- . RunWithReturn ( true ) ;
223+ . RunSynchronously ( ) ;
219224 }
220225 }
221226 }
@@ -238,24 +243,23 @@ public void InitializeRepository()
238243
239244 var filesForInitialCommit = new List < string > { gitignore , gitAttrs , assetsGitignore } ;
240245
241- GitClient . Init ( ) . RunWithReturn ( true ) ;
246+ GitClient . Init ( ) . RunSynchronously ( ) ;
242247 progress . UpdateProgress ( 10 , 100 , "Initializing..." ) ;
243248
244249 ConfigureMergeSettings ( ) ;
245250 progress . UpdateProgress ( 20 , 100 , "Initializing..." ) ;
246251
247- GitClient . LfsInstall ( ) . RunWithReturn ( true ) ;
252+ GitClient . LfsInstall ( ) . RunSynchronously ( ) ;
248253 progress . UpdateProgress ( 30 , 100 , "Initializing..." ) ;
249254
250255 AssemblyResources . ToFile ( ResourceType . Generic , ".gitignore" , targetPath , Environment ) ;
251256 AssemblyResources . ToFile ( ResourceType . Generic , ".gitattributes" , targetPath , Environment ) ;
252257 assetsGitignore . CreateFile ( ) ;
253- GitClient . Add ( filesForInitialCommit ) . RunWithReturn ( true ) ;
258+ GitClient . Add ( filesForInitialCommit ) . RunSynchronously ( ) ;
254259 progress . UpdateProgress ( 60 , 100 , "Initializing..." ) ;
255- GitClient . Commit ( "Initial commit" , null ) . RunWithReturn ( true ) ;
260+ GitClient . Commit ( "Initial commit" , null ) . RunSynchronously ( ) ;
256261 progress . UpdateProgress ( 70 , 100 , "Initializing..." ) ;
257262 Environment . InitializeRepository ( ) ;
258- UsageTracker . IncrementProjectsInitialized ( ) ;
259263 }
260264 catch ( Exception ex )
261265 {
@@ -269,6 +273,7 @@ public void InitializeRepository()
269273 progress . UpdateProgress ( 90 , 100 , "Initializing..." ) ;
270274 RestartRepository ( ) ;
271275 TaskManager . RunInUI ( InitializeUI ) ;
276+ UsageTracker . IncrementProjectsInitialized ( ) ;
272277 progress . UpdateProgress ( 100 , 100 , "Initialized" ) ;
273278 }
274279 isBusy = false ;
@@ -287,12 +292,43 @@ private void ConfigureMergeSettings()
287292 GitClient . SetConfig ( "merge.unityyamlmerge.cmd" , yamlMergeCommand , GitConfigSource . Local ) . Catch ( e => {
288293 Logger . Error ( e , "Error setting merge.unityyamlmerge.cmd" ) ;
289294 return true ;
290- } ) . RunWithReturn ( true ) ;
295+ } ) . RunSynchronously ( ) ;
291296
292297 GitClient . SetConfig ( "merge.unityyamlmerge.trustExitCode" , "false" , GitConfigSource . Local ) . Catch ( e => {
293298 Logger . Error ( e , "Error setting merge.unityyamlmerge.trustExitCode" ) ;
294299 return true ;
295- } ) . RunWithReturn ( true ) ;
300+ } ) . RunSynchronously ( ) ;
301+ }
302+
303+ private void CaptureRepoSize ( )
304+ {
305+ GitClient . CountObjects ( )
306+ . Finally ( ( success , gitObjects ) =>
307+ {
308+ if ( success )
309+ {
310+ UsageTracker . UpdateRepoSize ( gitObjects . kilobytes ) ;
311+ }
312+ } )
313+ . Start ( ) ;
314+
315+ var gitLfsDataPath = Environment . RepositoryPath . Combine ( ".git" , "lfs" ) ;
316+ if ( gitLfsDataPath . Exists ( ) )
317+ {
318+ var diskUsageTask = Environment . IsWindows
319+ ? ( IProcessTask < int > ) new WindowsDiskUsageTask ( gitLfsDataPath , TaskManager . Token )
320+ : new LinuxDiskUsageTask ( gitLfsDataPath , TaskManager . Token ) ;
321+
322+ diskUsageTask
323+ . Configure ( ProcessManager )
324+ . Finally ( ( success , kilobytes ) =>
325+ {
326+ if ( success )
327+ {
328+ UsageTracker . UpdateLfsDiskUsage ( kilobytes ) ;
329+ }
330+ } ) . Start ( ) ;
331+ }
296332 }
297333
298334 public void RestartRepository ( )
@@ -310,14 +346,6 @@ public void RestartRepository()
310346 Logger . Trace ( $ "Got a repository? { ( Environment . Repository != null ? Environment . Repository . LocalPath : "null" ) } ") ;
311347 }
312348
313- protected void SetupMetrics ( )
314- {
315- if ( firstRun )
316- {
317- UsageTracker . IncrementNumberOfStartups ( ) ;
318- }
319- }
320-
321349 protected abstract void InitializeUI ( ) ;
322350 protected abstract void InitializationComplete ( ) ;
323351
0 commit comments