mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-18 20:15:35 -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
|
// ClassicalSharp copyright 2014-2016 UnknownShadow200 | Licensed under MIT
|
||||||
using System;
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using ClassicalSharp;
|
using ClassicalSharp;
|
||||||
@ -94,6 +95,13 @@ namespace Launcher {
|
|||||||
if( last == DateTime.MinValue || build.DirectXSize < 50000
|
if( last == DateTime.MinValue || build.DirectXSize < 50000
|
||||||
|| build.OpenGLSize < 50000 ) return;
|
|| 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;
|
string path = dx ? build.DirectXPath : build.OpenGLPath;
|
||||||
Utils.LogDebug( "Updating to: " + path );
|
Utils.LogDebug( "Updating to: " + path );
|
||||||
Patcher.PatchTime = build.TimeBuilt;
|
Patcher.PatchTime = build.TimeBuilt;
|
||||||
@ -102,6 +110,17 @@ namespace Launcher {
|
|||||||
game.ShouldUpdate = true;
|
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() {
|
public override void Dispose() {
|
||||||
game.Window.Keyboard.KeyDown -= KeyDown;
|
game.Window.Keyboard.KeyDown -= KeyDown;
|
||||||
game.Window.Keyboard.KeyUp -= KeyUp;
|
game.Window.Keyboard.KeyUp -= KeyUp;
|
||||||
|
@ -11,7 +11,8 @@ namespace Launcher {
|
|||||||
public sealed class UpdatesView : IView {
|
public sealed class UpdatesView : IView {
|
||||||
|
|
||||||
public DateTime LastStable, LastDev;
|
public DateTime LastStable, LastDev;
|
||||||
internal int backIndex, relIndex, devIndex;
|
internal int backIndex, relIndex, devIndex, statusIndex;
|
||||||
|
internal bool gameOpen;
|
||||||
|
|
||||||
public UpdatesView( LauncherWindow game ) : base( game ) {
|
public UpdatesView( LauncherWindow game ) : base( game ) {
|
||||||
widgets = new LauncherWidget[13];
|
widgets = new LauncherWidget[13];
|
||||||
@ -60,15 +61,22 @@ namespace Launcher {
|
|||||||
MakeButtonAt( "Direct3D 9", 130, 35, titleFont, Anchor.Centre, -80, 55 );
|
MakeButtonAt( "Direct3D 9", 130, 35, titleFont, Anchor.Centre, -80, 55 );
|
||||||
MakeButtonAt( "OpenGL", 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 );
|
inputFont, Anchor.Centre, Anchor.Centre, 0, 105 );
|
||||||
MakeLabelAt( "&eThe client must be closed before updating.",
|
statusIndex = widgetIndex;
|
||||||
inputFont, Anchor.Centre, Anchor.Centre, 0, 130 );
|
string text = gameOpen ? "&cThe game must be closed before updating" : "";
|
||||||
|
MakeLabelAt( text, inputFont, Anchor.Centre, Anchor.Centre, 0, 130 );
|
||||||
|
|
||||||
backIndex = widgetIndex;
|
backIndex = widgetIndex;
|
||||||
MakeButtonAt( "Back", 80, 35, titleFont, Anchor.Centre, 0, 170 );
|
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 ) {
|
string GetDateString( DateTime last ) {
|
||||||
if( last == DateTime.MaxValue ) return "&cCheck failed";
|
if( last == DateTime.MaxValue ) return "&cCheck failed";
|
||||||
if( last == DateTime.MinValue ) return "Checking..";
|
if( last == DateTime.MinValue ) return "Checking..";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user