Minor Cleanup

This commit is contained in:
s_falahati 2017-08-07 21:08:48 +04:30
parent 50f1fe9cde
commit 7087bc8695

View File

@ -23,10 +23,14 @@ namespace HeliosDisplayManagement.UIForms
Profile = profile; Profile = profile;
} }
public Profile Profile public string Arguments
{ {
get { return dv_profile.Profile; } get { return cb_args.Checked ? txt_args.Text : string.Empty; }
set { dv_profile.Profile = value; } set
{
txt_args.Text = value;
cb_args.Checked = !string.IsNullOrWhiteSpace(txt_args.Text);
}
} }
public string FileName public string FileName
@ -43,15 +47,10 @@ namespace HeliosDisplayManagement.UIForms
} }
} }
public string Arguments public static string IconCache
{ =>
get { return cb_args.Checked ? txt_args.Text : string.Empty; } Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
set Assembly.GetExecutingAssembly().GetName().Name, @"IconCache");
{
txt_args.Text = value;
cb_args.Checked = !string.IsNullOrWhiteSpace(txt_args.Text);
}
}
public string ProcessName public string ProcessName
{ {
@ -66,6 +65,12 @@ namespace HeliosDisplayManagement.UIForms
} }
} }
public Profile Profile
{
get { return dv_profile.Profile; }
set { dv_profile.Profile = value; }
}
public uint SteamAppId public uint SteamAppId
{ {
get { return cb_temp.Checked && rb_steam.Checked ? (uint) nud_steamappid.Value : 0; } get { return cb_temp.Checked && rb_steam.Checked ? (uint) nud_steamappid.Value : 0; }
@ -102,34 +107,6 @@ namespace HeliosDisplayManagement.UIForms
} }
} }
private void Controls_CheckedChanged(object sender, EventArgs e)
{
g_temp.Enabled = cb_temp.Checked;
p_standalone.Enabled = rb_standalone.Checked;
txt_process.Enabled = cb_process.Checked;
nud_timeout.Enabled = cb_process.Checked;
p_steam.Enabled = rb_steam.Checked;
txt_args.Enabled = cb_args.Checked;
if (rb_steam.Checked)
nud_steamappid_ValueChanged(rb_steam, e);
}
private void nud_steamappid_ValueChanged(object sender, EventArgs e)
{
lbl_steamname.Text = new SteamGame((uint) nud_steamappid.Value).ToString();
}
private void nud_steamapps_Click(object sender, EventArgs e)
{
var steamGamesForm = new SteamGamesForm();
if ((steamGamesForm.ShowDialog(this) == DialogResult.OK) && (steamGamesForm.SteamGame != null))
nud_steamappid.Value = steamGamesForm.SteamGame.AppId;
}
private void btn_app_executable_Click(object sender, EventArgs e) private void btn_app_executable_Click(object sender, EventArgs e)
{ {
if (dialog_open.ShowDialog(this) == DialogResult.OK) if (dialog_open.ShowDialog(this) == DialogResult.OK)
@ -148,12 +125,53 @@ namespace HeliosDisplayManagement.UIForms
} }
} }
public static string IconCache private void btn_save_Click(object sender, EventArgs e)
=> {
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), DialogResult = DialogResult.None;
Assembly.GetExecutingAssembly().GetName().Name, @"IconCache"); try
{
if (dialog_save.ShowDialog(this) == DialogResult.OK)
{
if (CreateShortcut(dialog_save.FileName))
MessageBox.Show(
Language.Shortcut_place_successfully,
Language.Shortcut,
MessageBoxButtons.OK,
MessageBoxIcon.Information);
else
MessageBox.Show(
Language.Failed_to_create_the_shortcut_Unexpected_exception_occurred,
Language.Shortcut,
MessageBoxButtons.OK,
MessageBoxIcon.Exclamation);
dialog_save.FileName = string.Empty;
DialogResult = DialogResult.OK;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, Language.Shortcut, MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
private void Controls_CheckedChanged(object sender, EventArgs e)
{
g_temp.Enabled = cb_temp.Checked;
p_standalone.Enabled = rb_standalone.Checked;
txt_process.Enabled = cb_process.Checked;
nud_timeout.Enabled = cb_process.Checked;
p_steam.Enabled = rb_steam.Checked;
txt_args.Enabled = cb_args.Checked;
if (rb_steam.Checked)
nud_steamappid_ValueChanged(rb_steam, e);
}
// ReSharper disable once FunctionComplexityOverflow // ReSharper disable once FunctionComplexityOverflow
// ReSharper disable once CyclomaticComplexity
private bool CreateShortcut(string fileName) private bool CreateShortcut(string fileName)
{ {
var programName = Path.GetFileNameWithoutExtension(txt_executable.Text); var programName = Path.GetFileNameWithoutExtension(txt_executable.Text);
@ -186,7 +204,7 @@ namespace HeliosDisplayManagement.UIForms
new ProfileIcon(Profile).ToIconOverly(txt_executable.Text) new ProfileIcon(Profile).ToIconOverly(txt_executable.Text)
.Save(icon, MultiIconFormat.ICO); .Save(icon, MultiIconFormat.ICO);
} }
catch (Exception ex) catch (Exception)
{ {
icon = $"{txt_executable.Text.Trim()},0"; icon = $"{txt_executable.Text.Trim()},0";
} }
@ -194,9 +212,7 @@ namespace HeliosDisplayManagement.UIForms
else if (rb_steam.Checked) else if (rb_steam.Checked)
{ {
if (!SteamGame.SteamInstalled) if (!SteamGame.SteamInstalled)
{
throw new Exception(Language.Steam_is_not_installed); throw new Exception(Language.Steam_is_not_installed);
}
var steamGame = new SteamGame((uint) nud_steamappid.Value); var steamGame = new SteamGame((uint) nud_steamappid.Value);
args.Add($"-s {(int) nud_steamappid.Value}"); args.Add($"-s {(int) nud_steamappid.Value}");
args.Add($"-t {(int) nud_steamtimeout.Value}"); args.Add($"-t {(int) nud_steamtimeout.Value}");
@ -204,22 +220,18 @@ namespace HeliosDisplayManagement.UIForms
Profile.Name); Profile.Name);
var steamIcon = steamGame.GetIcon().Result; var steamIcon = steamGame.GetIcon().Result;
if (!string.IsNullOrWhiteSpace(steamIcon)) if (!string.IsNullOrWhiteSpace(steamIcon))
{
try try
{ {
icon = Path.Combine(IconCache, Guid.NewGuid() + ".ico"); icon = Path.Combine(IconCache, Guid.NewGuid() + ".ico");
new ProfileIcon(Profile).ToIconOverly(steamIcon) new ProfileIcon(Profile).ToIconOverly(steamIcon)
.Save(icon, MultiIconFormat.ICO); .Save(icon, MultiIconFormat.ICO);
} }
catch (Exception ex) catch (Exception)
{ {
icon = steamIcon; icon = steamIcon;
} }
}
else else
{
icon = $"{SteamGame.SteamAddress},0"; icon = $"{SteamGame.SteamAddress},0";
}
} }
if (cb_args.Checked && !string.IsNullOrWhiteSpace(txt_args.Text)) if (cb_args.Checked && !string.IsNullOrWhiteSpace(txt_args.Text))
args.Add($"--arguments \"{txt_args.Text.Trim()}\""); args.Add($"--arguments \"{txt_args.Text.Trim()}\"");
@ -259,9 +271,7 @@ namespace HeliosDisplayManagement.UIForms
shortcut.WorkingDirectory = Path.GetDirectoryName(Application.ExecutablePath) ?? shortcut.WorkingDirectory = Path.GetDirectoryName(Application.ExecutablePath) ??
string.Empty; string.Empty;
if (!string.IsNullOrWhiteSpace(icon)) if (!string.IsNullOrWhiteSpace(icon))
{
shortcut.IconLocation = icon; shortcut.IconLocation = icon;
}
shortcut.Save(); shortcut.Save();
} }
finally finally
@ -283,33 +293,16 @@ namespace HeliosDisplayManagement.UIForms
return (fileName != null) && File.Exists(fileName); return (fileName != null) && File.Exists(fileName);
} }
private void btn_save_Click(object sender, EventArgs e) private void nud_steamappid_ValueChanged(object sender, EventArgs e)
{ {
DialogResult = DialogResult.None; lbl_steamname.Text = new SteamGame((uint) nud_steamappid.Value).ToString();
try }
{
if (dialog_save.ShowDialog(this) == DialogResult.OK) private void nud_steamapps_Click(object sender, EventArgs e)
{ {
if (CreateShortcut(dialog_save.FileName)) var steamGamesForm = new SteamGamesForm();
MessageBox.Show( if ((steamGamesForm.ShowDialog(this) == DialogResult.OK) && (steamGamesForm.SteamGame != null))
Language.Shortcut_place_successfully, nud_steamappid.Value = steamGamesForm.SteamGame.AppId;
Language.Shortcut,
MessageBoxButtons.OK,
MessageBoxIcon.Information);
else
MessageBox.Show(
Language.Failed_to_create_the_shortcut_Unexpected_exception_occurred,
Language.Shortcut,
MessageBoxButtons.OK,
MessageBoxIcon.Exclamation);
dialog_save.FileName = string.Empty;
DialogResult = DialogResult.OK;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, Language.Shortcut, MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
} }
private void txt_executable_TextChanged(object sender, EventArgs e) private void txt_executable_TextChanged(object sender, EventArgs e)