Skip to content

Commit

Permalink
Now game process get killed properly
Browse files Browse the repository at this point in the history
Updated icon
UI improvements
  • Loading branch information
UAVXP committed Apr 18, 2017
1 parent 5b9b330 commit 084a5c9
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 532 deletions.
68 changes: 39 additions & 29 deletions MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ protected override CreateParams CreateParams
}
}



public MainForm()
{
InitializeComponent();
Expand All @@ -48,8 +50,6 @@ public MainForm()
private void close_Click(object sender, EventArgs e)
{
SaveAdditionalParameters();

// logout();
this.Close();
}

Expand Down Expand Up @@ -84,8 +84,8 @@ public static bool isModDirectory(string path)
string shortDir = path.Substring(path.LastIndexOf('\\') + 1);
foreach (string dir in ignoredirs)
{
// if (dir == shortDir)
if( shortDir.Contains(dir) )
if (dir == shortDir)
// if( shortDir.Contains(dir) )
return false;
}

Expand Down Expand Up @@ -114,10 +114,8 @@ public static bool isModDirectory(string path)
count++;
}
}
if (count <= 0)
return false;

return true;
return (count > 0);
}
public static string getRegistryMainPath()
{
Expand Down Expand Up @@ -184,8 +182,6 @@ public static bool setRegistryValue(string subkey, string value)
return true;
}

// public static string gamePath = Directory.GetCurrentDirectory();

#if DEBUG
public static string gamePath = @"D:\AHL2_R";
#else
Expand All @@ -202,17 +198,6 @@ public static string getModDirectory()
return regValue;
}

private static void removeProc(Process[] proc, int count)
{
if (count > 0)
{
for (int i = 0; i < count; i++)
{
proc[i].Kill();
}
}
}

#if TRANSLATION
private void TranslateModDirectory(ref string dir)
{
Expand All @@ -237,12 +222,11 @@ private void TranslateModDirectory(ref string dir)
}
}
#endif

private void MainForm_Load(object sender, EventArgs e)
public void RefreshModList()
{
modList.Items.Clear();
List<string> listOfMods = new List<string>();
// foreach (string dir in Directory.GetDirectories(Directory.GetCurrentDirectory()))

foreach (string dir in Directory.GetDirectories(gamePath))
{
if (isModDirectory(dir))
Expand Down Expand Up @@ -293,9 +277,14 @@ private void MainForm_Load(object sender, EventArgs e)
#endif
}

private void MainForm_Load(object sender, EventArgs e)
{
RefreshModList();
}

private void SaveAdditionalParameters()
{
setRegistryValue("GameParameters", gameParametersText.Text);
setRegistryValue("GameParameters", gameParametersText.Text); // TODO: Do a separate parameters for every mod
setRegistryValue("ServerParameters", srvParametersText.Text);
}

Expand Down Expand Up @@ -341,10 +330,6 @@ private void parametersText_Leave(object sender, EventArgs e)
private void startProcess(string name)
{
string choosedMod = modList.SelectedItem.ToString();
setRegistryValue("LNGameMod", choosedMod);

// Saving parameters into registry
SaveAdditionalParameters();

// Environment.SetEnvironmentVariable("VPROJECT", gamePath + "\\" + getModDirectory());
Environment.SetEnvironmentVariable("VPROJECT", gamePath + "\\" + choosedMod);
Expand All @@ -368,7 +353,18 @@ private void closeProcess(string name)
{
Process[] processes = Process.GetProcessesByName(name);
int procCount = processes.Length;
removeProc(processes, procCount);
if (procCount > 0)
{
for (int i = 0; i < procCount; i++)
{
// Close only process that exists aside program
bool bSamePath = Path.GetDirectoryName(processes[0].Modules[0].FileName).Equals(gamePath);
if (bSamePath)
{
processes[i].Kill();
}
}
}
}

private void gameStartButton_Click(object sender, EventArgs e)
Expand Down Expand Up @@ -406,5 +402,19 @@ private void srvStopButton_Click(object sender, EventArgs e)
{
closeProcess( "hlds" );
}

private void btnRefresh_Click(object sender, EventArgs e)
{
RefreshModList();
}

private void modList_TextChanged(object sender, EventArgs e)
{
string choosedMod = (sender as ComboBox).SelectedItem.ToString();
setRegistryValue("LNGameMod", choosedMod);

// Saving parameters into registry
SaveAdditionalParameters();
}
}
}
23 changes: 20 additions & 3 deletions MainForm.designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 084a5c9

Please sign in to comment.