@@ -71,7 +71,7 @@ public static Patcher Instance
7171 private readonly ManualResetEvent _userDecisionSetEvent = new ManualResetEvent ( false ) ;
7272
7373 private readonly IRequestTimeoutCalculator _requestTimeoutCalculator = new SimpleRequestTimeoutCalculator ( ) ;
74-
74+
7575 private bool _hasAutomaticallyInstalledApp ;
7676
7777 private bool _hasAutomaticallyCheckedForAppUpdate ;
@@ -138,7 +138,7 @@ public IReadOnlyReactiveProperty<PatcherData> Data
138138 {
139139 get { return _data ; }
140140 }
141-
141+
142142 private readonly ReactiveProperty < string > _warning = new ReactiveProperty < string > ( ) ;
143143
144144 public IReadOnlyReactiveProperty < string > Warning
@@ -206,11 +206,11 @@ public void Quit()
206206 private void CloseLockFile ( )
207207 {
208208 try
209- {
209+ {
210210 if ( _lockFileStream != null )
211211 {
212212 _lockFileStream . Close ( ) ;
213-
213+
214214 DebugLogger . Log ( "Deleting the lock file." ) ;
215215 File . Delete ( _data . Value . LockFilePath ) ;
216216 }
@@ -278,7 +278,7 @@ private void OnApplicationQuit()
278278 DebugLogger . Log ( "Cancelling application quit because patcher thread is alive." ) ;
279279
280280 Application . CancelQuit ( ) ;
281-
281+
282282 StartCoroutine ( KillThread ( ) ) ;
283283 }
284284 }
@@ -433,11 +433,11 @@ private void ThreadExecution(CancellationToken cancellationToken)
433433 catch ( ThreadAbortException )
434434 {
435435 DebugLogger . Log ( "Patcher thread finished: thread has been aborted." ) ;
436- }
436+ }
437437 catch ( MultipleInstancesException exception )
438438 {
439439 DebugLogger . LogException ( exception ) ;
440- Quit ( ) ;
440+ Quit ( ) ;
441441 }
442442 catch ( Exception exception )
443443 {
@@ -630,11 +630,11 @@ private void ThreadWaitForUserDecision(CancellationToken cancellationToken)
630630 private void ThreadExecuteUserDecision ( CancellationToken cancellationToken )
631631 {
632632 bool displayWarningInsteadOfError = false ;
633-
633+
634634 try
635635 {
636636 _warning . Value = string . Empty ;
637-
637+
638638 DebugLogger . Log ( string . Format ( "Executing user decision {0}..." , _userDecision ) ) ;
639639
640640 switch ( _userDecision )
@@ -687,7 +687,7 @@ private void ThreadExecuteUserDecision(CancellationToken cancellationToken)
687687 catch ( ApiConnectionException e )
688688 {
689689 DebugLogger . LogException ( e ) ;
690-
690+
691691 if ( displayWarningInsteadOfError )
692692 {
693693 _warning . Value = "Unable to check for updates. Please check your internet connection." ;
@@ -737,6 +737,8 @@ private void ThreadDisplayError(PatcherError error, CancellationToken cancellati
737737 {
738738 try
739739 {
740+ _state . Value = PatcherState . DisplayingError ;
741+
740742 DebugLogger . Log ( string . Format ( "Displaying patcher error {0}..." , error ) ) ;
741743
742744 ErrorDialog . Display ( error , cancellationToken ) ;
@@ -777,7 +779,7 @@ private void ThreadStartApp()
777779
778780 private void ThreadUpdateApp ( bool automatically , CancellationToken cancellationToken )
779781 {
780- _state . Value = PatcherState . UpdatingApp ;
782+ _state . Value = PatcherState . Connecting ;
781783
782784 _appInfo . Value = _app . RemoteMetaData . GetAppInfo ( ! automatically ) ;
783785 _remoteVersionId . Value = _app . GetLatestVersionId ( ! automatically ) ;
@@ -795,10 +797,16 @@ private void ThreadUpdateApp(bool automatically, CancellationToken cancellationT
795797 try
796798 {
797799 _updaterStatus . Value = appUpdater . Status ;
798- appUpdater . Update ( _updateAppCancellationTokenSource . Token ) ;
800+
801+ using ( _updaterStatus . Take ( 1 ) . Subscribe ( ( status ) => _state . Value = PatcherState . UpdatingApp ) )
802+ {
803+ appUpdater . Update ( _updateAppCancellationTokenSource . Token ) ;
804+ }
799805 }
800806 finally
801807 {
808+ _state . Value = PatcherState . None ;
809+
802810 _updaterStatus . Value = null ;
803811 _updateAppCancellationTokenSource = null ;
804812 }
0 commit comments