Skip to content
This repository has been archived by the owner on Nov 12, 2023. It is now read-only.

Commit

Permalink
Code clean-up.
Browse files Browse the repository at this point in the history
  • Loading branch information
n0tic committed Mar 19, 2021
1 parent 93e3bb2 commit a224ca1
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 62 deletions.
4 changes: 2 additions & 2 deletions SteamServerCreationTool/App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2"/>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
</configuration>
</configuration>
18 changes: 6 additions & 12 deletions SteamServerCreationTool/Forms/CreateServerForm.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
using SteamServerCreationTool.Data;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SteamServerCreationTool.Forms
{
public partial class CreateServerForm : Form
{
public bool ok = false;
MainForm main;
Data.App app;
private MainForm main;
private Data.App app;

public CreateServerForm(MainForm main, Data.App app)
{
Expand All @@ -29,7 +23,7 @@ public CreateServerForm(MainForm main, Data.App app)

private void CreateServerForm_Load(object sender, EventArgs e)
{
if(app != null)
if (app != null)
{
NameTextbox.Text = app.Name;
app_name.Text = app.Name;
Expand Down Expand Up @@ -72,7 +66,7 @@ private void InstallButton_Click(object sender, EventArgs e)
bool unique = true;
foreach (var installed in main.settings.installedServer)
{
if(installed.name == NameTextbox.Text)
if (installed.name == NameTextbox.Text)
{
unique = false;
break;
Expand Down Expand Up @@ -113,7 +107,7 @@ private void CancelButton_Click(object sender, EventArgs e)
Close();
}

void StartSteamCMDServerDownload(Data.App app, bool skip = false)
private void StartSteamCMDServerDownload(Data.App app, bool skip = false)
{
//Keep track of success
bool install = true;
Expand Down Expand Up @@ -172,4 +166,4 @@ void StartSteamCMDServerDownload(Data.App app, bool skip = false)
}).Start();
}
}
}
}
20 changes: 7 additions & 13 deletions SteamServerCreationTool/Forms/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using System.Windows.Forms;

namespace SteamServerCreationTool.Forms
Expand All @@ -20,10 +19,11 @@ public partial class MainForm : Form
{
//Stored Information
internal Settings settings;

public SteamApps apps = null; // All apps from api (Only "server" and excludes "linux")

//Forms
ManageInstallsForm mif;
private ManageInstallsForm mif;

//Temporary information
private App selectedApp = null;
Expand Down Expand Up @@ -488,7 +488,7 @@ private void MainForm_Load(object sender, EventArgs e)
{
settings = new Settings(); // New settings file
MessageBox.Show("WARNING: This is an Alpha build. Not all features have been polished or tested 100%. Report any problems on the Github project issues page.", "Alpha Release", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}

//Do we have an ethernet connection?
if (!Core.CheckNetwork())
Expand Down Expand Up @@ -529,23 +529,18 @@ private void InstallServerButton_Click(object sender, EventArgs e)
using (CreateServerForm csf = new CreateServerForm(this, selectedApp))
{
DialogResult res = csf.ShowDialog();
if(res == DialogResult.OK && csf.ok)
if (res == DialogResult.OK && csf.ok)
{

}
}

return;



InstallServerButton.Enabled = false; // Disable button untill features are done.

//If button text is set to "Move Server"
if (InstallServerButton.Text == "Move Server")
{


}
else // Fresh install
{
Expand All @@ -570,7 +565,6 @@ private void RefreshSelectedServerList()
/// <param name="e"></param>
private void DeleteServerButton_Click(object sender, EventArgs e)
{

}

/// <summary>
Expand Down Expand Up @@ -612,23 +606,23 @@ private void OpenServerButton_Click(object sender, EventArgs e)
/// <param name="e"></param>
private void WindowExpander_Click(object sender, EventArgs e)
{
using(AboutForm af = new AboutForm())
using (AboutForm af = new AboutForm())
{
af.ShowDialog();
}
}

private void SearchButton_Click(object sender, EventArgs e)
{
using(ServerListSearchForm form = new ServerListSearchForm(this))
using (ServerListSearchForm form = new ServerListSearchForm(this))
{
form.ShowDialog();
}
}

private void InstalledServersButton_Click(object sender, EventArgs e)
{
if(mif == null || mif.IsDisposed) mif = new ManageInstallsForm(this);
if (mif == null || mif.IsDisposed) mif = new ManageInstallsForm(this);

mif.Show();
}
Expand Down
50 changes: 24 additions & 26 deletions SteamServerCreationTool/Forms/ManageInstallsForm.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SteamServerCreationTool.Forms
{
public partial class ManageInstallsForm : Form
{
MainForm main;
private MainForm main;

Data.InstalledServer app = null;
private Data.InstalledServer app = null;

public ManageInstallsForm(MainForm main)
{
Expand All @@ -41,14 +36,14 @@ private void InstalledServerList_SelectedIndexChanged(object sender, EventArgs e
app = null;
foreach (var item in main.settings.installedServer)
{
if(InstalledServerList.Items[InstalledServerList.SelectedIndex].ToString() == item.name)
if (InstalledServerList.Items[InstalledServerList.SelectedIndex].ToString() == item.name)
{
app = item;
break;
}
}

if(app != null)
if (app != null)
{
textBox1.Text = app.name;
app_id_label.Text = app.app.Appid.ToString();
Expand All @@ -61,10 +56,10 @@ private void InstalledServerList_SelectedIndexChanged(object sender, EventArgs e
InstallDirButton.Enabled = true;
OpenServerButton.Enabled = true;

if(!Directory.Exists(app.installPath))
if (!Directory.Exists(app.installPath))
{
DialogResult test = MessageBox.Show("The installation folder was not found!\n\rDo you want to remove this database entry?", "Directory Error!", MessageBoxButtons.YesNo, MessageBoxIcon.Error);
switch(test)
switch (test)
{
case DialogResult.Yes:
DeleteServer(app);
Expand All @@ -81,6 +76,7 @@ private void InstalledServerList_SelectedIndexChanged(object sender, EventArgs e
UpdateServerNameButton.Enabled = false;

break;

case DialogResult.No: return;
}
}
Expand Down Expand Up @@ -199,7 +195,6 @@ private void UpdateAllServersButton_Click(object sender, EventArgs e)
ProgressBarInfo.Enabled = false;
ProgressBarInfo.Visible = false;
}));
}).Start();
}
else
Expand Down Expand Up @@ -291,11 +286,11 @@ private void ClearDatabaseSaveServerData_Click(object sender, EventArgs e)

private void InstallDirButton_Click(object sender, EventArgs e)
{
if(MessageBox.Show("Make sure the server is offline before proceeding. Otherwise, this may result in server corruption.", "Directory Warning!", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.Cancel)
if (MessageBox.Show("Make sure the server is offline before proceeding. Otherwise, this may result in server corruption.", "Directory Warning!", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.Cancel)
{
return;
}

//Initialize FolderBrowserDialog
using (FolderBrowserDialog fbd = new FolderBrowserDialog())
{
Expand All @@ -306,16 +301,16 @@ private void InstallDirButton_Click(object sender, EventArgs e)
// Show FolderBrowserDialog dialogue and check if selection is valid
if (fbd.ShowDialog() == DialogResult.OK && Directory.Exists(fbd.SelectedPath))
{

if(app!= null && app.installPath != fbd.SelectedPath)
if (app != null && app.installPath != fbd.SelectedPath)
{
if (MessageBox.Show("Are you sure you want to move the install directory of this server?", "Directory Warning!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
{
//Initiate new Thread to async the move of server files.
new Thread(() =>
{
//Start progressbar
Invoke(new Action(() => {
Invoke(new Action(() =>
{
InstalledServerList.Enabled = false;
UpdateAllServersButton.Enabled = false;
Expand All @@ -335,7 +330,8 @@ private void InstallDirButton_Click(object sender, EventArgs e)
app.installPath = fbd.SelectedPath;
//Stop progressbar, modify button, save new settings and lastly, refresh list.
Invoke(new Action(() => {
Invoke(new Action(() =>
{
InstalledServerList.Enabled = true;
UpdateAllServersButton.Enabled = true;
Expand Down Expand Up @@ -366,9 +362,9 @@ private void OpenServerButton_Click(object sender, EventArgs e)

private void UpdateServerNameButton_Click(object sender, EventArgs e)
{
if(app != null)
if (app != null)
{
if(!string.IsNullOrWhiteSpace(textBox1.Text))
if (!string.IsNullOrWhiteSpace(textBox1.Text))
{
bool unique = true;
foreach (var installed in main.settings.installedServer)
Expand All @@ -380,7 +376,7 @@ private void UpdateServerNameButton_Click(object sender, EventArgs e)
}
}

if(unique)
if (unique)
{
app.name = textBox1.Text;
PopulateDataField();
Expand All @@ -405,7 +401,8 @@ private void DeleteSelectedButton_Click(object sender, EventArgs e)
new Thread(() =>
{
//Start progressbar
Invoke(new Action(() => {
Invoke(new Action(() =>
{
InstalledServerList.Enabled = false;
UpdateAllServersButton.Enabled = false;
DeleteAllServersButton.Enabled = false;
Expand Down Expand Up @@ -443,7 +440,8 @@ private void DeleteSelectedButton_Click(object sender, EventArgs e)
catch (ArgumentException x) { MessageBox.Show(x.Message); }
//Stop progressbar, modify button, save new settings and lastly, refresh list.
Invoke(new Action(() => {
Invoke(new Action(() =>
{
InstalledServerList.Enabled = true;
UpdateAllServersButton.Enabled = true;
Expand All @@ -468,7 +466,7 @@ private void DeleteSelectedButton_Click(object sender, EventArgs e)

private void UpdateSelectedButton_Click(object sender, EventArgs e)
{
if(app != null)
if (app != null)
{
if (MessageBox.Show("Make sure the server is offline before proceeding. Otherwise, this may result in server corruption.", "Server Warning!", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.Cancel)
{
Expand All @@ -479,7 +477,7 @@ private void UpdateSelectedButton_Click(object sender, EventArgs e)
}
}

void StartSteamCMDServerDownload(Data.InstalledServer app, bool skip = false)
private void StartSteamCMDServerDownload(Data.InstalledServer app, bool skip = false)
{
//Keep track of success
bool install = true;
Expand Down Expand Up @@ -533,4 +531,4 @@ void StartSteamCMDServerDownload(Data.InstalledServer app, bool skip = false)
}).Start();
}
}
}
}
12 changes: 3 additions & 9 deletions SteamServerCreationTool/Forms/ServerListSearchForm.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SteamServerCreationTool.Forms
{
public partial class ServerListSearchForm : Form
{
MainForm main;
private MainForm main;

public ServerListSearchForm(MainForm main)
{
Expand Down Expand Up @@ -47,7 +41,7 @@ private void SearchField_TextChanged(object sender, EventArgs e)

private void ResultsList_SelectedIndexChanged(object sender, EventArgs e)
{
if(ResultsList.SelectedIndex != -1)
if (ResultsList.SelectedIndex != -1)
{
main.SteamServerList.SelectedIndex = main.SteamServerList.FindStringExact(ResultsList.Items[ResultsList.SelectedIndex].ToString());
}
Expand All @@ -62,4 +56,4 @@ private void ResultsList_DoubleClick(object sender, EventArgs e)
}
}
}
}
}

0 comments on commit a224ca1

Please sign in to comment.