@@ -12,9 +12,17 @@ abstract class ApplicationManagerBase : IApplicationManager
1212 protected static ILogging Logger { get ; } = LogHelper . GetLogger < IApplicationManager > ( ) ;
1313
1414 private RepositoryManager repositoryManager ;
15+ private Progress progressReporter ;
16+ protected bool isBusy ;
17+ public event Action < IProgress > OnProgress
18+ {
19+ add { progressReporter . OnProgress += value ; }
20+ remove { progressReporter . OnProgress -= value ; }
21+ }
1522
1623 public ApplicationManagerBase ( SynchronizationContext synchronizationContext )
1724 {
25+ progressReporter = new Progress ( ) ;
1826 SynchronizationContext = synchronizationContext ;
1927 SynchronizationContext . SetSynchronizationContext ( SynchronizationContext ) ;
2028 ThreadingHelper . SetUIThread ( ) ;
@@ -46,6 +54,8 @@ public void Run(bool firstRun)
4654 {
4755 Logger . Trace ( "Run - CurrentDirectory {0}" , NPath . CurrentDirectory ) ;
4856
57+ isBusy = true ;
58+
4959 var gitExecutablePath = SystemSettings . Get ( Constants . GitInstallPathKey ) ? . ToNPath ( ) ;
5060 if ( gitExecutablePath . HasValue && gitExecutablePath . Value . FileExists ( ) ) // we have a git path
5161 {
@@ -56,32 +66,41 @@ public void Run(bool firstRun)
5666 {
5767 Logger . Trace ( "No git path found in settings" ) ;
5868
59- var initEnvironmentTask = new ActionTask < NPath > ( CancellationToken , ( _ , path ) => InitializeEnvironment ( path ) ) { Affinity = TaskAffinity . UI } ;
69+ var initEnvironmentTask = new ActionTask < NPath > ( CancellationToken ,
70+ ( b , path ) => InitializeEnvironment ( path ) ) { Affinity = TaskAffinity . UI } ;
6071 var findExecTask = new FindExecTask ( "git" , CancellationToken )
61- . FinallyInUI ( ( b , ex , path ) => {
72+ . FinallyInUI ( ( b , ex , path ) =>
73+ {
6274 if ( b && path . IsInitialized )
6375 {
64- Logger . Trace ( "FindExecTask Success: {0}" , path ) ;
76+ // Logger.Trace("FindExecTask Success: {0}", path);
6577 InitializeEnvironment ( path ) ;
6678 }
6779 else
6880 {
69- Logger . Warning ( "FindExecTask Failure" ) ;
81+ // Logger.Warning("FindExecTask Failure");
7082 Logger . Error ( "Git not found" ) ;
7183 }
7284 } ) ;
7385
74- var installDetails = new GitInstallDetails ( Environment . UserCachePath , true ) ;
75- var gitInstaller = new GitInstaller ( Environment , CancellationToken , installDetails ) ;
86+ var gitInstaller = new GitInstaller ( Environment , CancellationToken ) ;
7687
7788 // if successful, continue with environment initialization, otherwise try to find an existing git installation
78- gitInstaller . SetupGitIfNeeded ( initEnvironmentTask , findExecTask ) ;
89+ var setupTask = gitInstaller . SetupGitIfNeeded ( ) ;
90+ setupTask . Progress ( progressReporter . UpdateProgress ) ;
91+ setupTask . OnEnd += ( thisTask , result , success , exception ) =>
92+ {
93+ if ( success && result . IsInitialized )
94+ thisTask . Then ( initEnvironmentTask ) ;
95+ else
96+ thisTask . Then ( findExecTask ) ;
97+ } ;
7998 }
8099 }
81100
82101 public ITask InitializeRepository ( )
83102 {
84- Logger . Trace ( "Running Repository Initialize" ) ;
103+ // Logger.Trace("Running Repository Initialize");
85104
86105 var targetPath = NPath . CurrentDirectory ;
87106
@@ -124,17 +143,18 @@ public void RestartRepository()
124143 {
125144 if ( Environment . RepositoryPath . IsInitialized )
126145 {
127- repositoryManager = Unity . RepositoryManager . CreateInstance ( Platform , TaskManager , GitClient , ProcessManager , Environment . FileSystem , Environment . RepositoryPath ) ;
146+ repositoryManager = Unity . RepositoryManager . CreateInstance ( Platform , TaskManager , GitClient , Environment . FileSystem , Environment . RepositoryPath ) ;
128147 repositoryManager . Initialize ( ) ;
129- Environment . Repository . Initialize ( repositoryManager ) ;
148+ Environment . Repository . Initialize ( repositoryManager , TaskManager ) ;
130149 repositoryManager . Start ( ) ;
131- Logger . Trace ( $ "Got a repository? { Environment . Repository } ") ;
150+ Environment . Repository . Start ( ) ;
151+ Logger . Trace ( $ "Got a repository? { ( Environment . Repository != null ? Environment . Repository . LocalPath : "null" ) } ") ;
132152 }
133153 }
134154
135155 protected void SetupMetrics ( string unityVersion , bool firstRun )
136156 {
137- Logger . Trace ( "Setup metrics" ) ;
157+ // Logger.Trace("Setup metrics");
138158
139159 var usagePath = Environment . UserCachePath . Combine ( Constants . UsageFile ) ;
140160
@@ -175,40 +195,35 @@ protected void SetupMetrics(string unityVersion, bool firstRun)
175195 /// <param name="octorunScriptPath"></param>
176196 private void InitializeEnvironment ( NPath gitExecutablePath )
177197 {
198+ Environment . GitExecutablePath = gitExecutablePath ;
199+ Environment . User . Initialize ( GitClient ) ;
200+
178201 var afterGitSetup = new ActionTask ( CancellationToken , RestartRepository )
179202 . ThenInUI ( InitializeUI ) ;
180203
181- Environment . GitExecutablePath = gitExecutablePath ;
182- Environment . User . Initialize ( GitClient ) ;
183204 SetupMetrics ( ) ;
184-
205+ ITask task = afterGitSetup ;
185206 if ( Environment . IsWindows )
186207 {
187- GitClient
188- . GetConfig ( "credential.helper" , GitConfigSource . Global )
189- . Then ( ( b , credentialHelper ) => {
190- if ( ! string . IsNullOrEmpty ( credentialHelper ) )
191- {
192- Logger . Trace ( "Windows CredentialHelper: {0}" , credentialHelper ) ;
193- afterGitSetup . Start ( ) ;
194- }
195- else
208+ var credHelperTask = GitClient . GetConfig ( "credential.helper" , GitConfigSource . Global ) ;
209+ credHelperTask . OnEnd += ( thisTask , credentialHelper , success , exception ) =>
210+ {
211+ if ( ! success || string . IsNullOrEmpty ( credentialHelper ) )
196212 {
197213 Logger . Warning ( "No Windows CredentialHelper found: Setting to wincred" ) ;
198-
199- GitClient . SetConfig ( "credential.helper" , "wincred" , GitConfigSource . Global )
200- . Then ( afterGitSetup )
201- . Start ( ) ;
214+ thisTask
215+ . Then ( GitClient . SetConfig ( "credential.helper" , "wincred" , GitConfigSource . Global ) )
216+ . Then ( afterGitSetup ) ;
202217 }
203- } )
204- . Start ( ) ;
205- }
206- else
207- {
208- afterGitSetup . Start ( ) ;
218+ else
219+ thisTask . Then ( afterGitSetup ) ;
220+ } ;
221+ task = credHelperTask ;
209222 }
223+ task . Start ( ) ;
210224 }
211225
226+
212227 private bool disposed = false ;
213228 protected virtual void Dispose ( bool disposing )
214229 {
@@ -238,6 +253,7 @@ public void Dispose()
238253 public ISettings SystemSettings { get ; protected set ; }
239254 public ISettings UserSettings { get ; protected set ; }
240255 public IUsageTracker UsageTracker { get ; protected set ; }
256+ public bool IsBusy { get { return isBusy ; } }
241257 protected TaskScheduler UIScheduler { get ; private set ; }
242258 protected SynchronizationContext SynchronizationContext { get ; private set ; }
243259 protected IRepositoryManager RepositoryManager { get { return repositoryManager ; } }
0 commit comments