99using Intersect . Client . MonoGame . Input ;
1010using Intersect . Client . MonoGame . Network ;
1111using Intersect . Configuration ;
12- using Intersect . Updater ;
1312using Microsoft . Xna . Framework ;
1413using Microsoft . Xna . Framework . Graphics ;
1514using System . Diagnostics ;
1615using System . Reflection ;
1716using Intersect . Client . Framework . Database ;
1817using Intersect . Client . Framework . Graphics ;
1918using Intersect . Client . ThirdParty ;
20- using Intersect . Utilities ;
2119using MainMenu = Intersect . Client . Interface . Menu . MainMenu ;
2220using Intersect . Client . Interface . Shared ;
2321using Intersect . Client . MonoGame . NativeInterop ;
2422using Intersect . Client . MonoGame . NativeInterop . OpenGL ;
2523using Intersect . Core ;
2624using Intersect . Framework . Core ;
25+ using Intersect . Framework . Core . AssetManagement ;
2726using Intersect . Framework . SystemInformation ;
27+ using Intersect . Framework . Utilities ;
2828using Microsoft . Extensions . Logging ;
2929using Exception = System . Exception ;
3030
@@ -45,17 +45,17 @@ internal partial class IntersectGame : Game
4545
4646 #region "Autoupdate Variables"
4747
48- private Updater . Updater mUpdater ;
48+ private Updater ? _updater ;
4949
50- private Texture2D updaterBackground ;
50+ private Texture2D ? updaterBackground ;
5151
52- private SpriteFont updaterFont ;
52+ private SpriteFont ? updaterFont ;
5353
54- private SpriteFont updaterFontSmall ;
54+ private SpriteFont ? updaterFontSmall ;
5555
56- private Texture2D updaterProgressBar ;
56+ private Texture2D ? updaterProgressBar ;
5757
58- private SpriteBatch updateBatch ;
58+ private SpriteBatch ? updateBatch ;
5959
6060 private bool updaterGraphicsReset ;
6161
@@ -138,12 +138,8 @@ private IntersectGame(IClientContext context, Action postStartupAction)
138138 // Reuse Updater object instead of creating a new one each time.
139139 if ( ! string . IsNullOrWhiteSpace ( updateUrl ) )
140140 {
141- mUpdater = new Updater . Updater (
142- updateUrl ,
143- Path . Combine ( "version.json" ) ,
144- true ,
145- 5
146- ) ;
141+ _updater ??= new Updater ( updateUrl , "client/update.json" , "version.client.json" , 7 ) ;
142+ _updater . Start ( ) ;
147143 }
148144 }
149145
@@ -159,7 +155,7 @@ protected override void Initialize()
159155
160156 PlatformStatistics . GPUStatisticsProvider = GL . CreateGPUStatisticsProvider ( ) ;
161157
162- if ( mUpdater != null )
158+ if ( _updater != null )
163159 {
164160 //Set the size of the updater screen before applying graphic changes.
165161 //We need to do this here instead of in the constructor for the size change to apply to Linux
@@ -222,67 +218,63 @@ protected override void Update(GameTime gameTime)
222218 PlatformStatistics . Refresh ( ) ;
223219 }
224220
225- if ( mUpdater ! = null )
221+ if ( _updater = = null )
226222 {
227- if ( mUpdater . CheckUpdaterContentLoaded ( ) )
228- {
229- LoadUpdaterContent ( ) ;
230- }
231-
232- if ( mUpdater . Status == UpdateStatus . Done || mUpdater . Status == UpdateStatus . None )
223+ if ( _updater == null )
233224 {
234- if ( updaterGraphicsReset == true )
225+ if ( ! mInitialized )
235226 {
236- //Drew a frame, now let's initialize the engine
237227 IntersectInit ( ) ;
238- mUpdater = null ;
239228 }
240- }
241- else if ( mUpdater . Status == UpdateStatus . Restart )
242- {
243- //Auto relaunch on Windows
244- switch ( Environment . OSVersion . Platform )
229+
230+ if ( Globals . IsRunning )
231+ {
232+ if ( mLastUpdateTime < gameTime . TotalGameTime . TotalMilliseconds )
233+ {
234+ lock ( Globals . GameLock )
235+ {
236+ Main . Update ( gameTime . ElapsedGameTime ) ;
237+ }
238+
239+ ///mLastUpdateTime = gameTime.TotalGameTime.TotalMilliseconds + (1000/60f);
240+ }
241+ }
242+ else
245243 {
246- case PlatformID . Win32NT :
247- case PlatformID . Win32S :
248- case PlatformID . Win32Windows :
249- case PlatformID . WinCE :
250- Process . Start (
251- Environment . GetCommandLineArgs ( ) [ 0 ] ,
252- Environment . GetCommandLineArgs ( ) . Length > 1
253- ? string . Join ( " " , Environment . GetCommandLineArgs ( ) . Skip ( 1 ) )
254- : null
255- ) ;
256-
257- Exit ( ) ;
258- break ;
244+ Main . DestroyGame ( ) ;
245+ Exit ( ) ;
259246 }
260247 }
261248 }
262-
263- if ( mUpdater == null )
249+ else
264250 {
265- if ( ! mInitialized )
251+ if ( _updater . CheckUpdaterContentLoaded ( ) )
266252 {
267- IntersectInit ( ) ;
253+ LoadUpdaterContent ( ) ;
268254 }
269255
270- if ( Globals . IsRunning )
256+ switch ( _updater . Status )
271257 {
272- if ( mLastUpdateTime < gameTime . TotalGameTime . TotalMilliseconds )
258+ case UpdateStatus . UpdateCompleted or UpdateStatus . None :
273259 {
274- lock ( Globals . GameLock )
260+ if ( updaterGraphicsReset )
275261 {
276- Main . Update ( gameTime . ElapsedGameTime ) ;
262+ // Drew a frame, now let's initialize the engine
263+ IntersectInit ( ) ;
264+ _updater = null ;
277265 }
278266
279- ///mLastUpdateTime = gameTime.TotalGameTime.TotalMilliseconds + (1000/60f);
267+ break ;
268+ }
269+ case UpdateStatus . Restart :
270+ {
271+ if ( ! ProcessHelper . TryRelaunch ( ) )
272+ {
273+ ApplicationContext . CurrentContext . Logger . LogWarning ( "Failed to restart automatically" ) ;
274+ }
275+
276+ break ;
280277 }
281- }
282- else
283- {
284- Main . DestroyGame ( ) ;
285- Exit ( ) ;
286278 }
287279 }
288280
@@ -293,7 +285,7 @@ protected override void LoadContent()
293285 {
294286 base . LoadContent ( ) ;
295287
296- if ( mUpdater != null )
288+ if ( _updater != null )
297289 {
298290 LoadUpdaterContent ( ) ;
299291 }
@@ -309,22 +301,26 @@ protected override void Draw(GameTime gameTime)
309301
310302 GraphicsDevice . Clear ( Microsoft . Xna . Framework . Color . Black ) ;
311303
312- if ( mUpdater != null )
304+ if ( _updater is { } updater )
313305 {
314- if ( mUpdater . Status == UpdateStatus . Done || mUpdater . Status == UpdateStatus . None )
306+ if ( updater . Status is UpdateStatus . UpdateCompleted or UpdateStatus . None )
315307 {
316308 if ( updaterGraphicsReset == false )
317309 {
318- ( Core . Graphics . Renderer as MonoRenderer ) ? . Init ( GraphicsDevice ) ;
319- ( Core . Graphics . Renderer as MonoRenderer ) ? . Init ( ) ;
320- ( Core . Graphics . Renderer as MonoRenderer ) ? . Begin ( ) ;
321- ( Core . Graphics . Renderer as MonoRenderer ) ? . End ( ) ;
310+ if ( Core . Graphics . Renderer is MonoRenderer renderer )
311+ {
312+ renderer . Init ( GraphicsDevice ) ;
313+ renderer . Init ( ) ;
314+ renderer . Begin ( ) ;
315+ renderer . End ( ) ;
316+ }
317+
322318 updaterGraphicsReset = true ;
323319 }
324320 }
325321 else
326322 {
327- DrawUpdater ( ) ;
323+ DrawUpdater ( updater ) ;
328324 }
329325 }
330326 else
@@ -392,7 +388,7 @@ protected override void OnExiting(object sender, ExitingEventArgs args)
392388
393389 try
394390 {
395- mUpdater ? . Stop ( ) ;
391+ _updater ? . Stop ( ) ;
396392 }
397393 catch ( Exception exception )
398394 {
@@ -429,7 +425,7 @@ protected override void OnExiting(object sender, ExitingEventArgs args)
429425 base . OnExiting ( sender , args ) ;
430426 }
431427
432- private void DrawUpdater ( )
428+ private void DrawUpdater ( Updater updater )
433429 {
434430 //Draw updating text and show progress bar...
435431
@@ -456,18 +452,18 @@ private void DrawUpdater()
456452 var filesRemaining = string . Empty ;
457453 var sizeRemaining = string . Empty ;
458454
459- switch ( mUpdater . Status )
455+ switch ( updater . Status )
460456 {
461- case UpdateStatus . Checking :
457+ case UpdateStatus . DownloadingManifest :
462458 status = Strings . Update . Checking ;
463459 break ;
464460
465- case UpdateStatus . Updating :
461+ case UpdateStatus . UpdateInProgress :
466462 status = Strings . Update . Updating ;
467- progressPercent = mUpdater . Progress / 100f ;
468- progress = Strings . Update . PercentComplete . ToString ( ( int ) mUpdater . Progress ) ;
469- filesRemaining = Strings . Update . FilesRemaining . ToString ( mUpdater . FilesRemaining ) ;
470- sizeRemaining = Strings . Update . RemainingSize . ToString ( mUpdater . GetHumanReadableFileSize ( mUpdater . SizeRemaining ) ) ;
463+ progressPercent = updater . Progress / 100f ;
464+ progress = Strings . Update . PercentComplete . ToString ( ( int ) updater . Progress ) ;
465+ filesRemaining = Strings . Update . FilesRemaining . ToString ( updater . FilesRemaining ) ;
466+ sizeRemaining = Strings . Update . RemainingSize . ToString ( Updater . GetHumanReadableFileSize ( updater . SizeRemaining ) ) ;
471467 break ;
472468
473469 case UpdateStatus . Restart :
@@ -476,15 +472,15 @@ private void DrawUpdater()
476472 progress = Strings . Update . PercentComplete . ToString ( 100 ) ;
477473 break ;
478474
479- case UpdateStatus . Done :
475+ case UpdateStatus . UpdateCompleted :
480476 status = Strings . Update . Done ;
481477 progressPercent = 100 ;
482478 progress = Strings . Update . PercentComplete . ToString ( 100 ) ;
483479 break ;
484480
485481 case UpdateStatus . Error :
486482 status = Strings . Update . Error ;
487- progress = mUpdater . Exception ? . Message ?? "" ;
483+ progress = updater . Exception ? . Message ?? "" ;
488484 progressPercent = 100 ;
489485 break ;
490486
0 commit comments