mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-18 12:05:14 -04:00
Prevent launcher updating if any client instances are open, fixes #200.
This commit is contained in:
parent
d0caf51a90
commit
b3a7df8776
@ -1,5 +1,6 @@
|
||||
// ClassicalSharp copyright 2014-2016 UnknownShadow200 | Licensed under MIT
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using ClassicalSharp;
|
||||
@ -67,7 +68,7 @@ namespace Launcher {
|
||||
|
||||
void SuccessfulUpdateCheck( UpdateCheckTask task ) {
|
||||
if( task.LatestDev == null || task.LatestStable == null ) return;
|
||||
dev = task.LatestDev; view.LastDev = dev.TimeBuilt;
|
||||
dev = task.LatestDev; view.LastDev = dev.TimeBuilt;
|
||||
stable = task.LatestStable; view.LastStable = stable.TimeBuilt;
|
||||
Resize();
|
||||
}
|
||||
@ -82,18 +83,25 @@ namespace Launcher {
|
||||
widgets[view.relIndex + 1].OnClick = (x, y) => UpdateBuild( true, false );
|
||||
|
||||
widgets[view.devIndex].OnClick = (x, y) => UpdateBuild( false, true );
|
||||
widgets[view.devIndex + 1].OnClick = (x, y) => UpdateBuild( false, false );
|
||||
widgets[view.devIndex + 1].OnClick = (x, y) => UpdateBuild( false, false );
|
||||
|
||||
widgets[view.backIndex].OnClick =
|
||||
widgets[view.backIndex].OnClick =
|
||||
(x, y) => game.SetScreen( new MainScreen( game ) );
|
||||
}
|
||||
|
||||
void UpdateBuild( bool release, bool dx ) {
|
||||
DateTime last = release ? view.LastStable : view.LastDev;
|
||||
Build build = release ? stable : dev;
|
||||
if( last == DateTime.MinValue || build.DirectXSize < 50000
|
||||
if( last == DateTime.MinValue || build.DirectXSize < 50000
|
||||
|| build.OpenGLSize < 50000 ) return;
|
||||
|
||||
view.gameOpen = CheckClientInstances();
|
||||
view.SetWarning();
|
||||
LauncherWidget widget = widgets[view.statusIndex];
|
||||
game.ClearArea( widget.X, widget.Y, widget.Width, widget.Height );
|
||||
RedrawWidget( widgets[view.statusIndex] );
|
||||
if( view.gameOpen ) return;
|
||||
|
||||
string path = dx ? build.DirectXPath : build.OpenGLPath;
|
||||
Utils.LogDebug( "Updating to: " + path );
|
||||
Patcher.PatchTime = build.TimeBuilt;
|
||||
@ -102,6 +110,17 @@ namespace Launcher {
|
||||
game.ShouldUpdate = true;
|
||||
}
|
||||
|
||||
bool CheckClientInstances() {
|
||||
Process[] processes = Process.GetProcesses();
|
||||
for( int i = 0; i < processes.Length; i++ ) {
|
||||
string name = processes[i].ProcessName;
|
||||
if( Utils.CaselessEquals( name, "ClassicalSharp" )
|
||||
|| Utils.CaselessEquals( name, "ClassicalSharp.exe" ) )
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void Dispose() {
|
||||
game.Window.Keyboard.KeyDown -= KeyDown;
|
||||
game.Window.Keyboard.KeyUp -= KeyUp;
|
||||
|
@ -11,7 +11,8 @@ namespace Launcher {
|
||||
public sealed class UpdatesView : IView {
|
||||
|
||||
public DateTime LastStable, LastDev;
|
||||
internal int backIndex, relIndex, devIndex;
|
||||
internal int backIndex, relIndex, devIndex, statusIndex;
|
||||
internal bool gameOpen;
|
||||
|
||||
public UpdatesView( LauncherWindow game ) : base( game ) {
|
||||
widgets = new LauncherWidget[13];
|
||||
@ -60,15 +61,22 @@ namespace Launcher {
|
||||
MakeButtonAt( "Direct3D 9", 130, 35, titleFont, Anchor.Centre, -80, 55 );
|
||||
MakeButtonAt( "OpenGL", 130, 35, titleFont, Anchor.Centre, 80, 55 );
|
||||
|
||||
MakeLabelAt( "&eDirect3D 9 is recommended for Windows.",
|
||||
MakeLabelAt( "&eDirect3D 9 is recommended for Windows",
|
||||
inputFont, Anchor.Centre, Anchor.Centre, 0, 105 );
|
||||
MakeLabelAt( "&eThe client must be closed before updating.",
|
||||
inputFont, Anchor.Centre, Anchor.Centre, 0, 130 );
|
||||
statusIndex = widgetIndex;
|
||||
string text = gameOpen ? "&cThe game must be closed before updating" : "";
|
||||
MakeLabelAt( text, inputFont, Anchor.Centre, Anchor.Centre, 0, 130 );
|
||||
|
||||
backIndex = widgetIndex;
|
||||
MakeButtonAt( "Back", 80, 35, titleFont, Anchor.Centre, 0, 170 );
|
||||
}
|
||||
|
||||
internal void SetWarning() {
|
||||
string text = gameOpen ? "&cThe game must be closed before updating" : "";
|
||||
LauncherLabelWidget widget = (LauncherLabelWidget)widgets[statusIndex];
|
||||
widget.SetDrawData( drawer, text, inputFont, Anchor.Centre, Anchor.Centre, 0, 130 );
|
||||
}
|
||||
|
||||
string GetDateString( DateTime last ) {
|
||||
if( last == DateTime.MaxValue ) return "&cCheck failed";
|
||||
if( last == DateTime.MinValue ) return "Checking..";
|
||||
|
Loading…
x
Reference in New Issue
Block a user