55using System . IO . Packaging ;
66using System . Linq ;
77using System . Net ;
8+ using System . Reflection ;
89using System . Text ;
910using System . Text . RegularExpressions ;
1011using System . Threading ;
@@ -23,26 +24,25 @@ public class UpdateManager : Manager
2324 private Timer _updatePollTimer ;
2425 private string _torchDir = new FileInfo ( typeof ( UpdateManager ) . Assembly . Location ) . DirectoryName ;
2526 private Logger _log = LogManager . GetCurrentClassLogger ( ) ;
26- [ Dependency ]
2727 private FilesystemManager _fsManager ;
28+ private bool _isProcessing = false ;
2829
2930 public UpdateManager ( ITorchBase torchInstance ) : base ( torchInstance )
3031 {
31- //_updatePollTimer = new Timer(TimerElapsed, this, TimeSpan.Zero, TimeSpan.FromMinutes(5));
32+ //fs is only really used here so might as well create it here
33+ _fsManager = new FilesystemManager ( torchInstance ) ;
3234 }
3335
3436 /// <inheritdoc />
3537 public override void Attach ( )
3638 {
37- CheckAndUpdateTorch ( ) ;
3839 }
3940
4041 private void TimerElapsed ( object state )
4142 {
42- CheckAndUpdateTorch ( ) ;
4343 }
4444
45- private async void CheckAndUpdateTorch ( )
45+ public async void CheckAndUpdateTorch ( )
4646 {
4747 if ( Torch . Config . NoUpdate || ! Torch . Config . GetTorchUpdates || ( Torch . Config . BranchName == TorchBranchType . dev ) )
4848 return ;
@@ -53,6 +53,8 @@ private async void CheckAndUpdateTorch()
5353
5454 try
5555 {
56+ _log . Info ( "Checking for Torch Update..." ) ;
57+ _isProcessing = true ;
5658 var job = await JenkinsQuery . Instance . GetLatestVersion ( Torch . Config . BranchName . ToString ( ) ) ;
5759 if ( job == null )
5860 {
@@ -68,21 +70,26 @@ private async void CheckAndUpdateTorch()
6870 if ( ! await JenkinsQuery . Instance . DownloadRelease ( job , updateName ) )
6971 {
7072 _log . Warn ( "Failed to download new release!" ) ;
73+ _isProcessing = false ;
7174 return ;
7275 }
7376 UpdateFromZip ( updateName , _torchDir ) ;
7477 File . Delete ( updateName ) ;
75- _log . Warn ( $ "Torch version { job . Version } has been installed. Please restart to apply update.") ;
78+ _log . Warn ( $ "Torch version { job . Version } has been installed. Restarting...") ;
79+ Torch . Restart ( ) ;
7680 }
7781 else
7882 {
7983 _log . Info ( "Torch is up to date." ) ;
8084 }
85+ _isProcessing = false ;
86+
8187 }
8288 catch ( Exception e )
8389 {
8490 _log . Error ( "An error occured downloading the Torch update." ) ;
8591 _log . Error ( e ) ;
92+ _isProcessing = false ;
8693 }
8794 }
8895
@@ -105,6 +112,15 @@ private void UpdateFromZip(string zipFile, string extractPath)
105112 //zip.ExtractToDirectory(extractPath); //throws exceptions sometimes?
106113 }
107114 }
115+
116+ /// <summary>
117+ /// Returns true if update data is being checked or processed.
118+ /// </summary>
119+ /// <returns></returns>
120+ public bool GetIsUpdating ( )
121+ {
122+ return _isProcessing ;
123+ }
108124
109125 /// <inheritdoc />
110126 public override void Detach ( )
0 commit comments