@@ -85,6 +85,11 @@ public static class AutoUpdater
8585 /// </summary>
8686 public static string InstallationPath ;
8787
88+ /// <summary>
89+ /// If you are using a zip file as an update file, then you can set this value to a new executable path relative to the installation directory.
90+ /// </summary>
91+ public static string ExecutablePath ;
92+
8893 /// <summary>
8994 /// Set the Application Title shown in Update dialog. Although AutoUpdater.NET will get it automatically, you can set this property if you like to give custom Title.
9095 /// </summary>
@@ -272,73 +277,71 @@ public static void Start(string appCast, Assembly myAssembly = null)
272277 _remindLaterTimer = null ;
273278 }
274279
275- if ( ! Running && _remindLaterTimer == null )
276- {
277- Running = true ;
280+ if ( Running || _remindLaterTimer != null ) return ;
278281
279- AppCastURL = appCast ;
282+ Running = true ;
280283
281- _isWinFormsApplication = Application . MessageLoop ;
284+ AppCastURL = appCast ;
282285
283- if ( ! _isWinFormsApplication )
284- {
285- Application . EnableVisualStyles ( ) ;
286- }
286+ _isWinFormsApplication = Application . MessageLoop ;
287287
288- Assembly assembly = myAssembly ?? Assembly . GetEntryAssembly ( ) ;
288+ if ( ! _isWinFormsApplication )
289+ {
290+ Application . EnableVisualStyles ( ) ;
291+ }
289292
290- if ( Synchronous )
291- {
292- try
293- {
294- var result = CheckUpdate ( assembly ) ;
293+ Assembly assembly = myAssembly ?? Assembly . GetEntryAssembly ( ) ;
295294
296- if ( StartUpdate ( result ) )
297- {
298- return ;
299- }
295+ if ( Synchronous )
296+ {
297+ try
298+ {
299+ var result = CheckUpdate ( assembly ) ;
300300
301- Running = false ;
302- }
303- catch ( Exception exception )
301+ if ( StartUpdate ( result ) )
304302 {
305- ShowError ( exception ) ;
303+ return ;
306304 }
305+
306+ Running = false ;
307307 }
308- else
308+ catch ( Exception exception )
309309 {
310- using ( var backgroundWorker = new BackgroundWorker ( ) )
311- {
312- backgroundWorker . DoWork += ( _ , args ) =>
313- {
314- Assembly mainAssembly = args . Argument as Assembly ;
310+ ShowError ( exception ) ;
311+ }
312+ }
313+ else
314+ {
315+ using var backgroundWorker = new BackgroundWorker ( ) ;
316+
317+ backgroundWorker . DoWork += ( _ , args ) =>
318+ {
319+ Assembly mainAssembly = args . Argument as Assembly ;
315320
316- args . Result = CheckUpdate ( mainAssembly ) ;
317- } ;
321+ args . Result = CheckUpdate ( mainAssembly ) ;
322+ } ;
318323
319- backgroundWorker . RunWorkerCompleted += ( _ , args ) =>
324+ backgroundWorker . RunWorkerCompleted += ( _ , args ) =>
325+ {
326+ if ( args . Error != null )
327+ {
328+ ShowError ( args . Error ) ;
329+ }
330+ else
331+ {
332+ if ( ! args . Cancelled )
320333 {
321- if ( args . Error != null )
322- {
323- ShowError ( args . Error ) ;
324- }
325- else
334+ if ( StartUpdate ( args . Result ) )
326335 {
327- if ( ! args . Cancelled )
328- {
329- if ( StartUpdate ( args . Result ) )
330- {
331- return ;
332- }
333- }
334-
335- Running = false ;
336+ return ;
336337 }
337- } ;
338+ }
338339
339- backgroundWorker . RunWorkerAsync ( assembly ) ;
340+ Running = false ;
340341 }
341- }
342+ } ;
343+
344+ backgroundWorker . RunWorkerAsync ( assembly ) ;
342345 }
343346 }
344347
@@ -446,47 +449,46 @@ private static bool StartUpdate(object result)
446449 }
447450 else
448451 {
449- if ( result is UpdateInfoEventArgs args )
452+ if ( result is not UpdateInfoEventArgs args ) return false ;
453+
454+ if ( CheckForUpdateEvent != null )
450455 {
451- if ( CheckForUpdateEvent != null )
452- {
453- CheckForUpdateEvent ( args ) ;
454- }
455- else
456+ CheckForUpdateEvent ( args ) ;
457+ }
458+ else
459+ {
460+ if ( args . IsUpdateAvailable )
456461 {
457- if ( args . IsUpdateAvailable )
462+ if ( Mandatory && UpdateMode == Mode . ForcedDownload )
458463 {
459- if ( Mandatory && UpdateMode == Mode . ForcedDownload )
464+ DownloadUpdate ( args ) ;
465+ Exit ( ) ;
466+ }
467+ else
468+ {
469+ if ( Thread . CurrentThread . GetApartmentState ( ) . Equals ( ApartmentState . STA ) )
460470 {
461- DownloadUpdate ( args ) ;
462- Exit ( ) ;
471+ ShowUpdateForm ( args ) ;
463472 }
464473 else
465474 {
466- if ( Thread . CurrentThread . GetApartmentState ( ) . Equals ( ApartmentState . STA ) )
467- {
468- ShowUpdateForm ( args ) ;
469- }
470- else
471- {
472- Thread thread = new Thread ( new ThreadStart ( delegate { ShowUpdateForm ( args ) ; } ) ) ;
473- thread . CurrentCulture =
474- thread . CurrentUICulture = CultureInfo . CurrentCulture ;
475- thread . SetApartmentState ( ApartmentState . STA ) ;
476- thread . Start ( ) ;
477- thread . Join ( ) ;
478- }
475+ Thread thread = new Thread ( new ThreadStart ( delegate { ShowUpdateForm ( args ) ; } ) ) ;
476+ thread . CurrentCulture =
477+ thread . CurrentUICulture = CultureInfo . CurrentCulture ;
478+ thread . SetApartmentState ( ApartmentState . STA ) ;
479+ thread . Start ( ) ;
480+ thread . Join ( ) ;
479481 }
480-
481- return true ;
482482 }
483483
484- if ( ReportErrors )
485- {
486- MessageBox . Show ( Resources . UpdateUnavailableMessage ,
487- Resources . UpdateUnavailableCaption ,
488- MessageBoxButtons . OK , MessageBoxIcon . Information ) ;
489- }
484+ return true ;
485+ }
486+
487+ if ( ReportErrors )
488+ {
489+ MessageBox . Show ( Resources . UpdateUnavailableMessage ,
490+ Resources . UpdateUnavailableCaption ,
491+ MessageBoxButtons . OK , MessageBoxIcon . Information ) ;
490492 }
491493 }
492494 }
@@ -553,7 +555,7 @@ internal static void Exit()
553555
554556 if ( ! process . HasExited )
555557 {
556- process . Kill ( ) ; //TODO show UI message asking user to close program himself instead of silently killing it
558+ process . Kill ( ) ; //TODO: Show UI message asking user to close program himself instead of silently killing it
557559 }
558560 }
559561 }
@@ -637,15 +639,14 @@ internal static void SetTimer(DateTime remindLater)
637639 /// </summary>
638640 public static bool DownloadUpdate ( UpdateInfoEventArgs args )
639641 {
640- using ( var downloadDialog = new DownloadUpdateDialog ( args ) )
642+ using var downloadDialog = new DownloadUpdateDialog ( args ) ;
643+
644+ try
645+ {
646+ return downloadDialog . ShowDialog ( ) . Equals ( DialogResult . OK ) ;
647+ }
648+ catch ( TargetInvocationException )
641649 {
642- try
643- {
644- return downloadDialog . ShowDialog ( ) . Equals ( DialogResult . OK ) ;
645- }
646- catch ( TargetInvocationException )
647- {
648- }
649650 }
650651
651652 return false ;
@@ -656,17 +657,16 @@ public static bool DownloadUpdate(UpdateInfoEventArgs args)
656657 /// </summary>
657658 public static void ShowUpdateForm ( UpdateInfoEventArgs args )
658659 {
659- using ( var updateForm = new UpdateForm ( args ) )
660+ using var updateForm = new UpdateForm ( args ) ;
661+
662+ if ( UpdateFormSize . HasValue )
660663 {
661- if ( UpdateFormSize . HasValue )
662- {
663- updateForm . Size = UpdateFormSize . Value ;
664- }
664+ updateForm . Size = UpdateFormSize . Value ;
665+ }
665666
666- if ( updateForm . ShowDialog ( ) . Equals ( DialogResult . OK ) )
667- {
668- Exit ( ) ;
669- }
667+ if ( updateForm . ShowDialog ( ) . Equals ( DialogResult . OK ) )
668+ {
669+ Exit ( ) ;
670670 }
671671 }
672672
0 commit comments