Prevent launcher updating if any client instances are open, fixes #200.

This commit is contained in:
UnknownShadow200 2016-05-12 15:36:34 +10:00
parent d0caf51a90
commit b3a7df8776
2 changed files with 35 additions and 8 deletions

View File

@ -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;
@ -94,6 +95,13 @@ namespace Launcher {
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;

View File

@ -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..";