2017-02-26 19:23:31 +00:00
using System ;
using System.Collections.Generic ;
using System.Drawing.IconLib ;
2020-04-23 08:16:16 +00:00
using System.Drawing ;
2017-02-26 19:23:31 +00:00
using System.IO ;
2020-04-23 08:16:16 +00:00
using System.Linq ;
2017-02-26 19:23:31 +00:00
using System.Reflection ;
using System.Runtime.InteropServices ;
using System.Windows.Forms ;
2020-04-23 08:16:16 +00:00
using HeliosPlus.Resources ;
using HeliosPlus.Shared ;
2020-04-27 10:55:44 +00:00
using HeliosPlus.GameLibraries ;
2020-05-01 10:30:27 +00:00
using System.Globalization ;
2020-05-16 05:07:52 +00:00
using Manina.Windows.Forms ;
2020-05-16 11:16:46 +00:00
using System.Windows.Forms.VisualStyles ;
2017-02-26 19:23:31 +00:00
2020-04-23 08:16:16 +00:00
namespace HeliosPlus.UIForms
2017-02-26 19:23:31 +00:00
{
public partial class ShortcutForm : Form
{
2020-04-28 10:38:43 +00:00
List < SteamGame > _allSteamGames ;
2020-05-16 05:07:52 +00:00
private ProfileAdaptor _profileAdaptor ;
private static bool _inDialog = false ;
private List < Profile > _loadedProfiles = new List < Profile > ( ) ;
2020-05-17 09:19:55 +00:00
private Profile _profileToUse = null ;
private Shortcut _shortcutToEdit = null ;
private string _saveOrRenameMode = "save" ;
private bool _isNewShortcut = true ;
2020-05-03 08:39:35 +00:00
2017-02-26 19:23:31 +00:00
public ShortcutForm ( )
{
InitializeComponent ( ) ;
2020-05-17 09:19:55 +00:00
// Set the profileAdaptor we need to load images from Profiles
// into the Profiles ImageListView
2020-05-16 05:07:52 +00:00
_profileAdaptor = new ProfileAdaptor ( ) ;
2020-05-17 09:19:55 +00:00
2017-02-26 19:23:31 +00:00
}
2020-05-17 09:19:55 +00:00
public ShortcutForm ( Shortcut shortcutToEdit ) : this ( )
2017-02-26 19:23:31 +00:00
{
2020-05-17 09:19:55 +00:00
_shortcutToEdit = shortcutToEdit ;
2017-02-26 19:23:31 +00:00
}
2020-04-22 11:46:31 +00:00
public string ProcessNameToMonitor
2017-02-26 19:23:31 +00:00
{
2020-04-22 11:46:31 +00:00
get
{
if ( rb_switch_temp . Checked & & rb_standalone . Checked ) {
if ( rb_wait_executable . Checked )
{
return txt_process_name . Text ;
}
}
return string . Empty ;
}
2017-08-07 16:38:48 +00:00
set
{
2020-04-23 08:16:16 +00:00
// We we're setting this entry, then we want to set it to a particular entry
txt_process_name . Text = value ;
rb_wait_executable . Checked = true ;
2017-08-07 16:38:48 +00:00
}
2017-02-26 19:23:31 +00:00
}
2020-04-22 11:46:31 +00:00
public string ExecutableNameAndPath
2017-02-26 19:23:31 +00:00
{
2020-04-22 11:46:31 +00:00
get = > rb_switch_temp . Checked & & rb_launcher . Checked ? txt_executable . Text : string . Empty ;
2017-02-26 19:23:31 +00:00
set
{
2020-04-22 11:46:31 +00:00
if ( File . Exists ( txt_executable . Text ) )
2017-02-26 19:23:31 +00:00
{
2020-04-22 11:46:31 +00:00
rb_switch_temp . Checked = true ;
rb_launcher . Checked = true ;
2017-02-26 19:23:31 +00:00
txt_executable . Text = value ;
}
}
}
2020-04-22 11:46:31 +00:00
public uint ExecutableTimeout
2018-10-20 00:27:25 +00:00
{
2020-04-22 11:46:31 +00:00
get
{
if ( rb_wait_executable . Checked )
{
return ( uint ) nud_timeout_executable . Value ;
}
return 0 ;
}
set
{
nud_timeout_executable . Value = value ;
}
2018-10-20 00:27:25 +00:00
}
2017-02-26 19:23:31 +00:00
2020-04-22 11:46:31 +00:00
public string ExecutableArguments
2017-02-26 19:23:31 +00:00
{
2020-04-22 11:46:31 +00:00
get = > cb_args_executable . Checked ? txt_args_executable . Text : string . Empty ;
2017-02-26 19:23:31 +00:00
set
{
2020-04-22 11:46:31 +00:00
txt_args_executable . Text = value ;
cb_args_executable . Checked = true ;
2017-02-26 19:23:31 +00:00
}
}
2020-04-22 11:46:31 +00:00
public uint GameAppId
2017-08-07 16:38:48 +00:00
{
2020-04-28 10:38:43 +00:00
get = > rb_switch_temp . Checked & & rb_launcher . Checked ? ( uint ) Convert . ToInt32 ( txt_game_id . Text ) : 0 ;
2020-04-22 11:46:31 +00:00
set
{
rb_switch_temp . Checked = true ;
rb_launcher . Checked = true ;
2020-04-28 10:38:43 +00:00
txt_game_id . Text = value . ToString ( ) ;
2020-04-22 11:46:31 +00:00
}
2017-08-07 16:38:48 +00:00
}
2020-04-22 11:46:31 +00:00
public string GameName
2017-02-26 19:23:31 +00:00
{
2020-04-22 11:46:31 +00:00
get = > rb_switch_temp . Checked & & rb_launcher . Checked ? txt_game_name . Text : string . Empty ;
2017-02-26 19:23:31 +00:00
set
{
2020-04-22 11:46:31 +00:00
rb_switch_temp . Checked = true ;
rb_launcher . Checked = true ;
txt_game_name . Text = value ;
2017-02-26 19:23:31 +00:00
}
}
2020-05-17 09:19:55 +00:00
public Shortcut Shortcut
{
get = > _shortcutToEdit ;
}
2020-04-22 11:46:31 +00:00
public SupportedGameLibrary GameLibrary
2017-02-26 19:23:31 +00:00
{
2020-04-28 10:38:43 +00:00
get
{
if ( rb_switch_temp . Checked & & rb_launcher . Checked )
{
if ( txt_game_launcher . Text . Contains ( "Steam" ) )
{
return SupportedGameLibrary . Steam ;
}
else if ( txt_game_launcher . Text . Contains ( "Uplay" ) )
{
return SupportedGameLibrary . Uplay ;
}
}
return SupportedGameLibrary . Unknown ;
}
2020-04-22 11:46:31 +00:00
set
2017-02-26 19:23:31 +00:00
{
2020-04-22 11:46:31 +00:00
rb_switch_temp . Checked = true ;
rb_launcher . Checked = true ;
switch ( value )
2018-10-20 00:27:25 +00:00
{
2020-04-22 11:46:31 +00:00
case SupportedGameLibrary . Steam :
2020-04-28 10:38:43 +00:00
txt_game_launcher . Text = Enum . GetName ( typeof ( SupportedGameLibrary ) , SupportedGameLibrary . Steam ) ;
2020-04-22 11:46:31 +00:00
break ;
case SupportedGameLibrary . Uplay :
2020-04-28 10:38:43 +00:00
txt_game_launcher . Text = Enum . GetName ( typeof ( SupportedGameLibrary ) , SupportedGameLibrary . Uplay ) ;
2020-04-22 11:46:31 +00:00
break ;
2018-10-20 00:27:25 +00:00
}
2020-04-22 11:46:31 +00:00
// TODO - If SupportedGameLibrary.Unknown; then we need to show an error message.
}
}
2018-10-20 00:27:25 +00:00
2020-04-22 11:46:31 +00:00
public uint GameTimeout
{
get
{
if ( rb_switch_temp . Checked & & rb_launcher . Checked )
2018-10-20 00:27:25 +00:00
{
2020-04-22 11:46:31 +00:00
return ( uint ) nud_timeout_game . Value ;
2018-10-20 00:27:25 +00:00
}
2017-02-26 19:23:31 +00:00
return 0 ;
}
set
{
2020-04-22 11:46:31 +00:00
nud_timeout_game . Value = value ;
2017-02-26 19:23:31 +00:00
}
}
2020-04-22 11:46:31 +00:00
public string GameArguments
{
get = > cb_args_game . Checked ? txt_args_game . Text : string . Empty ;
set
{
txt_args_game . Text = value ;
cb_args_game . Checked = true ;
}
}
2020-05-01 10:30:27 +00:00
private static bool IsLowQuality ( IconImage iconImage )
{
return iconImage . PixelFormat = = System . Drawing . Imaging . PixelFormat . Format1bppIndexed | |
iconImage . PixelFormat = = System . Drawing . Imaging . PixelFormat . Format4bppIndexed | |
iconImage . PixelFormat = = System . Drawing . Imaging . PixelFormat . Format8bppIndexed ;
}
2017-02-26 19:23:31 +00:00
private void btn_app_executable_Click ( object sender , EventArgs e )
{
if ( dialog_open . ShowDialog ( this ) = = DialogResult . OK )
2018-10-20 00:27:25 +00:00
{
if ( File . Exists ( dialog_open . FileName ) & & Path . GetExtension ( dialog_open . FileName ) = = @".exe" )
2017-02-26 19:23:31 +00:00
{
txt_executable . Text = dialog_open . FileName ;
dialog_open . FileName = string . Empty ;
}
else
{
MessageBox . Show (
Language . Selected_file_is_not_a_valid_executable_file ,
Language . Executable ,
MessageBoxButtons . OK ,
MessageBoxIcon . Exclamation ) ;
}
2018-10-20 00:27:25 +00:00
}
2017-02-26 19:23:31 +00:00
}
2017-08-07 16:38:48 +00:00
private void btn_save_Click ( object sender , EventArgs e )
{
2020-05-17 09:19:55 +00:00
// Store all of the information in the Shortcut object based on what's been selected in this form
2018-10-20 00:27:25 +00:00
2020-05-17 09:19:55 +00:00
// Validate the fields are filled as they should be!
// Check the name is valid
if ( String . IsNullOrWhiteSpace ( txt_shortcut_save_name . Text ) & & Program . IsValidFilename ( txt_shortcut_save_name . Text ) )
2017-08-07 16:38:48 +00:00
{
2020-05-17 09:19:55 +00:00
MessageBox . Show (
@"You need to specify a name for this Shortcut before it can be saved." ,
@"Please name this Shortcut." ,
MessageBoxButtons . OK ,
MessageBoxIcon . Exclamation ) ;
return ;
2017-08-07 16:38:48 +00:00
}
2020-04-22 11:46:31 +00:00
2020-05-17 09:19:55 +00:00
// Check the profile is set and that it's still valid
if ( ! ( _profileToUse is Profile ) )
2017-02-26 19:23:31 +00:00
{
2020-05-17 09:19:55 +00:00
MessageBox . Show (
@"You need to select a Display Profile to use with this shortcut. Please select one from the list of Display Profiles on the left of the screen." ,
@"Please choose a Display Profile." ,
MessageBoxButtons . OK ,
MessageBoxIcon . Exclamation ) ;
return ;
}
2018-10-20 00:27:25 +00:00
2020-05-17 09:19:55 +00:00
// Check the permanence requirements
if ( rb_switch_perm . Checked )
{
// Check the Shortcut Category to see if it's application
2017-02-26 19:23:31 +00:00
if ( rb_standalone . Checked )
{
2020-05-17 09:19:55 +00:00
if ( cb_args_executable . Checked & & String . IsNullOrWhiteSpace ( txt_args_executable . Text ) )
2018-10-20 00:27:25 +00:00
{
2020-05-17 09:19:55 +00:00
MessageBox . Show (
@"If you have chosen to pass extra arguments to the executable when it is run, then you need to enter them in the 'Pass arguments to Executable' field. If you didn't want to pass extra arguments then please uncheck the 'Pass arguments to Executable' checkbox." ,
@"Please add Executable arguments." ,
MessageBoxButtons . OK ,
MessageBoxIcon . Exclamation ) ;
return ;
2018-10-20 00:27:25 +00:00
}
2020-05-17 09:19:55 +00:00
if ( ! File . Exists ( txt_executable . Text ) )
2017-02-26 19:23:31 +00:00
{
2020-05-17 09:19:55 +00:00
MessageBox . Show (
@"The executable you have chosen does not exist! Please reselect the executable, or check you have persmissions to view it." ,
@"Executable doesn't exist" ,
MessageBoxButtons . OK ,
MessageBoxIcon . Exclamation ) ;
return ;
2017-02-26 19:23:31 +00:00
}
2018-10-20 00:27:25 +00:00
2020-05-17 09:19:55 +00:00
if ( String . IsNullOrWhiteSpace ( txt_process_name . Text ) )
2020-04-22 11:46:31 +00:00
{
2020-05-17 09:19:55 +00:00
string message = "" ;
2020-04-22 11:46:31 +00:00
2020-05-17 09:19:55 +00:00
// figure out the message we want to give the user
if ( _shortcutToEdit . ProcessNameToMonitorUsesExecutable )
message = @"Cannot work out the process to monitor from the executable. Please reselect the executable (and we'll try again), and if that doesn't work then manually enter the process name into the 'Process to monitor' field." ;
else
message = @"Please manually enter the process name into the 'Process to monitor' field." ;
2020-04-27 10:55:44 +00:00
2020-05-17 09:19:55 +00:00
// show the error message
MessageBox . Show (
message ,
@"Empty process monitor" ,
MessageBoxButtons . OK ,
MessageBoxIcon . Exclamation ) ;
return ;
}
}
else if ( rb_switch_temp . Checked )
{
2018-10-20 00:27:25 +00:00
2020-05-17 09:19:55 +00:00
if ( cb_args_game . Checked & & String . IsNullOrWhiteSpace ( txt_args_game . Text ) )
2017-02-26 19:23:31 +00:00
{
2020-05-17 09:19:55 +00:00
MessageBox . Show (
@"If you have chosen to pass extra arguments to the Game when it is run, then you need to enter them in the 'Pass arguments to Game' field. If you didn't want to pass extra arguments then please uncheck the 'Pass arguments to Game' checkbox." ,
@"Please add Game arguments." ,
MessageBoxButtons . OK ,
MessageBoxIcon . Exclamation ) ;
return ;
2017-02-26 19:23:31 +00:00
}
2020-05-17 09:19:55 +00:00
if ( Convert . ToUInt32 ( txt_game_id . Text ) = = 0 )
2017-02-26 19:23:31 +00:00
{
2020-05-17 09:19:55 +00:00
MessageBox . Show (
@"Please choose a Game by scrolling through the list, selecting the Game that you want, and then clicking the '>>' button to fill the Game fields." ,
@"Please choose a Game." ,
MessageBoxButtons . OK ,
MessageBoxIcon . Exclamation ) ;
return ;
2017-02-26 19:23:31 +00:00
}
}
2020-05-17 09:19:55 +00:00
}
2020-04-22 11:46:31 +00:00
2020-05-17 09:19:55 +00:00
// Fill the Shortcut object with the bits we care about saving
2020-04-22 11:46:31 +00:00
2020-05-17 09:19:55 +00:00
// Update the Executable args
_shortcutToEdit . ExecutableArguments = txt_args_executable . Text ;
2018-10-20 00:27:25 +00:00
2020-05-17 09:19:55 +00:00
// Update if the executable args are needed
_shortcutToEdit . ExecutableArgumentsRequired = cb_args_executable . Checked ;
2020-05-01 10:30:27 +00:00
2020-05-17 09:19:55 +00:00
// Update the Executable name and path
_shortcutToEdit . ExecutableNameAndPath = txt_executable . Text ;
2020-04-27 10:55:44 +00:00
2020-05-17 09:19:55 +00:00
// Update the executable timeout
_shortcutToEdit . ExecutableTimeout = Convert . ToUInt32 ( nud_timeout_executable . Value ) ;
2020-04-27 10:55:44 +00:00
2020-05-17 09:19:55 +00:00
// Update the game app id
_shortcutToEdit . GameAppId = Convert . ToUInt32 ( txt_game_id . Text ) ;
2020-04-27 10:55:44 +00:00
2020-05-17 09:19:55 +00:00
// Update the game args
_shortcutToEdit . GameArguments = txt_args_game . Text ;
2020-04-27 10:55:44 +00:00
2020-05-17 09:19:55 +00:00
// Update if the game args are needed
_shortcutToEdit . GameArgumentsRequired = cb_args_game . Checked ;
2020-04-27 10:55:44 +00:00
2020-05-17 09:19:55 +00:00
// Update what game library it's from
//_shortcutToEdit.GameLibrary = SupportedGameLibrary.Steam;
2020-04-27 10:55:44 +00:00
2020-05-17 09:19:55 +00:00
// Update the Game Name
_shortcutToEdit . GameName = txt_game_name . Text ;
2020-05-01 10:30:27 +00:00
2020-05-17 09:19:55 +00:00
// Update the Game Timeout
_shortcutToEdit . GameTimeout = Convert . ToUInt32 ( nud_timeout_game . Value ) ;
2020-04-27 10:55:44 +00:00
2020-05-17 09:19:55 +00:00
// Update the Shortcut name
_shortcutToEdit . Name = txt_shortcut_save_name . Text ;
2020-04-28 10:38:43 +00:00
2020-05-17 09:19:55 +00:00
// Check the permanence requirements
if ( rb_switch_temp . Checked )
_shortcutToEdit . Permanence = ShortcutPermanence . Temporary ;
2020-04-27 10:55:44 +00:00
2020-05-17 09:19:55 +00:00
if ( rb_switch_perm . Checked )
_shortcutToEdit . Permanence = ShortcutPermanence . Permanent ;
2020-04-27 10:55:44 +00:00
2020-05-17 09:19:55 +00:00
// Update the process name to monitor
if ( ! String . IsNullOrWhiteSpace ( txt_process_name . Text ) ) {
_shortcutToEdit . ProcessNameToMonitor = txt_process_name . Text ;
}
2018-10-20 00:27:25 +00:00
2020-05-17 09:19:55 +00:00
if ( rb_wait_process . Checked & & ! String . IsNullOrWhiteSpace ( txt_process_name . Text ) )
{
_shortcutToEdit . ProcessNameToMonitorUsesExecutable = true ;
_shortcutToEdit . ProcessNameToMonitor = txt_process_name . Text ;
2017-02-26 19:23:31 +00:00
}
else
{
2020-05-17 09:19:55 +00:00
_shortcutToEdit . ProcessNameToMonitorUsesExecutable = false ;
2017-02-26 19:23:31 +00:00
}
2020-05-17 09:19:55 +00:00
// Update the profile to use
_shortcutToEdit . ProfileToUse = _profileToUse ;
2018-10-20 00:27:25 +00:00
2020-05-17 09:19:55 +00:00
// Update the Category as well as the OriginalIconPath
// (as we need the OriginalIconPath to run the SaveShortcutIconToCache method)
if ( rb_launcher . Checked )
_shortcutToEdit . Category = ShortcutCategory . Game ;
if ( txt_game_launcher . Text = = SupportedGameLibrary . Steam . ToString ( ) )
_shortcutToEdit . OriginalIconPath = ( from steamGame in SteamGame . AllGames where steamGame . GameId = = _shortcutToEdit . GameAppId select steamGame . GameIconPath ) . First ( ) ;
else if ( txt_game_launcher . Text = = SupportedGameLibrary . Uplay . ToString ( ) )
_shortcutToEdit . OriginalIconPath = ( from uplayGame in UplayGame . AllGames where uplayGame . GameId = = _shortcutToEdit . GameAppId select uplayGame . GameIconPath ) . First ( ) ;
else if ( rb_standalone . Checked )
_shortcutToEdit . Category = ShortcutCategory . Application ;
// Save the shortcut icon
_shortcutToEdit . SaveShortcutIconToCache ( ) ;
// Add the Shortcut to the list of saved Shortcuts so it gets saved for later
// but only if it's new... if it is an edit then it will already be in the list.
if ( _isNewShortcut )
Shortcut . AllSavedShortcuts . Add ( _shortcutToEdit ) ;
// Save everything is golden and close the form.
DialogResult = DialogResult . OK ;
this . Close ( ) ;
2017-02-26 19:23:31 +00:00
}
2020-05-17 09:19:55 +00:00
2017-02-26 19:23:31 +00:00
private void txt_executable_TextChanged ( object sender , EventArgs e )
{
2020-05-01 10:30:27 +00:00
if ( File . Exists ( txt_executable . Text ) )
2017-02-26 19:23:31 +00:00
{
2020-04-22 11:46:31 +00:00
2020-05-01 10:30:27 +00:00
// Try and discern the process name for this
// if the user hasn't entered anything already
if ( txt_process_name . Text = = String . Empty )
{
try
{
txt_process_name . Text = Path . GetFileNameWithoutExtension ( txt_executable . Text ) ? . ToLower ( ) ? ? txt_process_name . Text ;
}
catch
{
// ignored
}
}
2020-05-17 09:19:55 +00:00
if ( txt_shortcut_save_name . Text . Length > 0 )
{
// Turn on the CreateShortcut Button
btn_save . Enabled = true ;
btn_save . Visible = true ;
}
else
{
btn_save . Enabled = false ;
btn_save . Visible = false ;
}
}
else
2017-02-26 19:23:31 +00:00
{
2020-05-01 10:30:27 +00:00
// Turn off the CreateShortcut Button
btn_save . Enabled = false ;
2020-05-17 09:19:55 +00:00
btn_save . Visible = false ;
2017-02-26 19:23:31 +00:00
}
}
2020-04-19 05:37:29 +00:00
2020-04-22 11:46:31 +00:00
private void rb_switch_perm_CheckedChanged ( object sender , EventArgs e )
{
if ( rb_switch_perm . Checked )
{
// Disable the Temporary Group
g_temporary . Enabled = false ;
}
2020-05-17 09:19:55 +00:00
if ( txt_shortcut_save_name . Text . Length > 0 )
{
// Turn on the CreateShortcut Button
btn_save . Enabled = true ;
btn_save . Visible = true ;
}
else
{
btn_save . Enabled = false ;
btn_save . Visible = false ;
}
2020-04-22 11:46:31 +00:00
}
2020-04-19 05:37:29 +00:00
private void rb_switch_temp_CheckedChanged ( object sender , EventArgs e )
{
2020-04-22 11:46:31 +00:00
if ( rb_switch_temp . Checked )
{
// Enable the Temporary Group
g_temporary . Enabled = true ;
2020-05-01 10:30:27 +00:00
// If it's been set already to a valid gamelauncher, then enable the button
if ( txt_game_launcher . Text . Length > 0 & & txt_game_id . Text . Length > 0 & & txt_game_name . Text . Length > 0 )
{
// Turn on the CreateShortcut Button
btn_save . Enabled = true ;
2020-05-17 09:19:55 +00:00
btn_save . Visible = true ;
2020-05-01 10:30:27 +00:00
}
// else if it's a valid executable
2020-05-17 09:19:55 +00:00
else if ( txt_executable . Text . Length > 0 & & File . Exists ( txt_executable . Text ) & & txt_shortcut_save_name . Text . Length > 0 )
2020-05-01 10:30:27 +00:00
{
// Turn on the CreateShortcut Button
btn_save . Enabled = true ;
2020-05-17 09:19:55 +00:00
btn_save . Visible = true ;
2020-05-01 10:30:27 +00:00
}
else
{
// Turn on the CreateShortcut Button
btn_save . Enabled = false ;
2020-05-17 09:19:55 +00:00
btn_save . Visible = false ;
2020-05-01 10:30:27 +00:00
}
}
2020-04-19 05:37:29 +00:00
}
2020-04-22 11:46:31 +00:00
private void rb_standalone_CheckedChanged ( object sender , EventArgs e )
{
if ( rb_standalone . Checked )
{
// Enable the Standalone Panel
p_standalone . Enabled = true ;
// Disable the Game Panel
p_game . Enabled = false ;
2020-05-01 10:30:27 +00:00
2020-05-17 09:19:55 +00:00
if ( txt_executable . Text . Length > 0 & & File . Exists ( txt_executable . Text ) & & txt_shortcut_save_name . Text . Length > 0 )
2020-05-01 10:30:27 +00:00
{
// Turn on the CreateShortcut Button
btn_save . Enabled = true ;
2020-05-17 09:19:55 +00:00
btn_save . Visible = true ;
2020-05-01 10:30:27 +00:00
}
else
{
// Turn on the CreateShortcut Button
btn_save . Enabled = false ;
2020-05-17 09:19:55 +00:00
btn_save . Visible = false ;
2020-05-01 10:30:27 +00:00
}
2020-04-22 11:46:31 +00:00
}
2020-05-01 10:30:27 +00:00
2020-04-22 11:46:31 +00:00
}
private void rb_launcher_CheckedChanged ( object sender , EventArgs e )
{
if ( rb_launcher . Checked )
{
// Enable the Game Panel
p_game . Enabled = true ;
// Disable the Standalone Panel
p_standalone . Enabled = false ;
2020-05-01 10:30:27 +00:00
// If it's been set already to a valid gamelauncher, then enable the button
2020-05-17 09:19:55 +00:00
if ( txt_game_launcher . Text . Length > 0 & & txt_game_id . Text . Length > 0 & & txt_game_name . Text . Length > 0 & & txt_shortcut_save_name . Text . Length > 0 )
2020-05-01 10:30:27 +00:00
{
// Turn on the CreateShortcut Button
btn_save . Enabled = true ;
2020-05-17 09:19:55 +00:00
btn_save . Visible = true ;
2020-05-01 10:30:27 +00:00
}
else
{
// Turn on the CreateShortcut Button
btn_save . Enabled = false ;
2020-05-17 09:19:55 +00:00
btn_save . Visible = false ;
2020-05-01 10:30:27 +00:00
}
2020-04-22 11:46:31 +00:00
}
}
2020-04-19 05:37:29 +00:00
private void cb_args_executable_CheckedChanged ( object sender , EventArgs e )
{
2020-04-22 11:46:31 +00:00
// Disable the Process Name Text field
if ( cb_args_executable . Checked )
{
// Enable the Executable Arguments Text field
txt_args_executable . Enabled = true ;
}
else
{
// Disable the Executable Arguments Text field
txt_args_executable . Enabled = false ;
}
}
2020-05-16 05:07:52 +00:00
private void RefreshImageListView ( Profile profile )
{
ilv_saved_profiles . ClearSelection ( ) ;
IEnumerable < ImageListViewItem > matchingImageListViewItems = ( from item in ilv_saved_profiles . Items where item . Text = = profile . Name select item ) ;
if ( matchingImageListViewItems . Any ( ) )
{
matchingImageListViewItems . First ( ) . Selected = true ;
matchingImageListViewItems . First ( ) . Focused = true ;
}
}
2020-04-23 08:16:16 +00:00
private async void ShortcutForm_Load ( object sender , EventArgs e )
2020-04-22 11:46:31 +00:00
{
2020-05-17 09:19:55 +00:00
// Create a new SHortcut if we are creating a new one
// And set up the page.
if ( _shortcutToEdit = = null )
{
_shortcutToEdit = new Shortcut ( ) ;
_isNewShortcut = true ;
_saveOrRenameMode = "save" ;
btn_save_or_rename . Text = "Save As" ;
}
else
{
_isNewShortcut = false ;
_saveOrRenameMode = "rename" ;
btn_save_or_rename . Text = "Rename To" ;
}
2020-05-16 05:07:52 +00:00
// Load all the profiles to prepare things
_loadedProfiles = ( List < Profile > ) Profile . LoadAllProfiles ( ) ;
2020-04-23 08:16:16 +00:00
2020-05-16 05:07:52 +00:00
bool foundCurrentProfileInLoadedProfiles = false ;
foreach ( Profile loadedProfile in _loadedProfiles )
2020-05-03 08:39:35 +00:00
{
2020-05-16 05:07:52 +00:00
if ( Profile . CurrentProfile . Equals ( loadedProfile ) )
{
// We have already saved the selected profile!
// so we need to show the selected profile
ChangeSelectedProfile ( loadedProfile ) ;
foundCurrentProfileInLoadedProfiles = true ;
}
2020-05-03 08:39:35 +00:00
}
2020-05-16 05:07:52 +00:00
// If we get to the end of the loaded profiles and haven't
// found a matching profile, then we need to show the current
// Profile
if ( ! foundCurrentProfileInLoadedProfiles )
ChangeSelectedProfile ( Profile . CurrentProfile ) ;
2020-05-17 09:19:55 +00:00
// Refresh the Shortcut UI
RefreshShortcutUI ( ) ;
2020-05-16 05:07:52 +00:00
2020-04-27 10:55:44 +00:00
// Start finding the games and loading the Games ListView
List < SteamGame > allSteamGames = SteamGame . GetAllInstalledGames ( ) ;
2020-04-28 10:38:43 +00:00
_allSteamGames = allSteamGames ;
2020-04-27 10:55:44 +00:00
foreach ( var game in allSteamGames . OrderBy ( game = > game . GameName ) )
2020-05-01 10:30:27 +00:00
{
if ( File . Exists ( game . GameIconPath ) )
{
try
{
if ( game . GameIconPath . EndsWith ( ".ico" ) )
{
// if it's an icon try to load it as a bitmap
il_games . Images . Add ( Image . FromFile ( game . GameIconPath ) ) ;
}
else if ( game . GameIconPath . EndsWith ( ".exe" , StringComparison . InvariantCultureIgnoreCase ) | | game . GameIconPath . EndsWith ( ".dll" , StringComparison . InvariantCultureIgnoreCase ) )
{
// otherwise use IconExtractor
/ * IconExtractor IconEx = new IconExtractor ( game . GameIconPath ) ;
Icon icoAppIcon = IconEx . GetIcon ( 0 ) ; // Because standard System.Drawing.Icon.ExtractAssociatedIcon() returns ONLY 32x32.*/
Icon icoAppIcon = Icon . ExtractAssociatedIcon ( game . GameIconPath ) ;
// We first try high quality icons
2020-05-16 11:16:46 +00:00
Bitmap extractedBitmap = Shortcut . ExtractVistaIcon ( icoAppIcon ) ;
2020-05-01 10:30:27 +00:00
if ( extractedBitmap = = null )
extractedBitmap = icoAppIcon . ToBitmap ( ) ;
il_games . Images . Add ( extractedBitmap ) ;
}
}
catch ( Exception )
{
il_games . Images . Add ( Image . FromFile ( "Resources/Steam.ico" ) ) ;
}
} else
{
//(Icon)global::Calculate.Properties.Resources.ResourceManager.GetObject("Steam.ico");
il_games . Images . Add ( Image . FromFile ( "Resources/Steam.ico" ) ) ;
}
2020-04-22 11:46:31 +00:00
if ( ! Visible )
{
return ;
}
lv_games . Items . Add ( new ListViewItem
{
2020-04-27 10:55:44 +00:00
Text = game . GameName ,
2020-04-22 11:46:31 +00:00
Tag = game ,
ImageIndex = il_games . Images . Count - 1
} ) ;
2020-04-23 08:16:16 +00:00
}
2020-04-22 11:46:31 +00:00
}
private void rb_wait_process_CheckedChanged ( object sender , EventArgs e )
{
if ( rb_wait_process . Checked )
{
// Enable the Process Name Text field
txt_process_name . Enabled = true ;
2020-04-23 08:16:16 +00:00
} else
{
txt_process_name . Enabled = false ;
2020-04-22 11:46:31 +00:00
}
}
private void rb_wait_executable_CheckedChanged ( object sender , EventArgs e )
{
if ( rb_wait_executable . Checked )
{
// Disable the Process Name Text field
txt_process_name . Enabled = false ;
2020-04-23 08:16:16 +00:00
} else
{
txt_process_name . Enabled = true ;
2020-04-22 11:46:31 +00:00
}
}
private void btn_app_process_Click ( object sender , EventArgs e )
{
if ( dialog_open . ShowDialog ( this ) = = DialogResult . OK )
{
if ( File . Exists ( dialog_open . FileName ) & & Path . GetExtension ( dialog_open . FileName ) = = @".exe" )
{
txt_process_name . Text = dialog_open . FileName ;
dialog_open . FileName = string . Empty ;
}
else
{
MessageBox . Show (
Language . Selected_file_is_not_a_valid_executable_file ,
Language . Executable ,
MessageBoxButtons . OK ,
MessageBoxIcon . Exclamation ) ;
}
}
2020-04-19 05:37:29 +00:00
}
2020-04-23 08:16:16 +00:00
private void cb_args_game_CheckedChanged ( object sender , EventArgs e )
{
if ( cb_args_game . Checked )
{
txt_args_game . Enabled = true ;
} else
{
txt_args_game . Enabled = false ;
}
}
2020-04-28 10:38:43 +00:00
private void btn_choose_game_Click ( object sender , EventArgs e )
{
if ( lv_games . SelectedItems . Count > 0 )
{
txt_game_name . Text = lv_games . SelectedItems [ 0 ] . Text ;
foreach ( SteamGame game in _allSteamGames )
{
if ( game . GameName = = txt_game_name . Text )
{
2020-05-01 10:30:27 +00:00
txt_game_launcher . Text = SteamGame . GameLibrary . ToString ( ) ;
2020-04-28 10:38:43 +00:00
txt_game_id . Text = game . GameId . ToString ( ) ;
}
}
2020-05-01 10:30:27 +00:00
2020-05-17 09:19:55 +00:00
if ( txt_shortcut_save_name . Text . Length > 0 )
{
// Turn on the CreateShortcut Button
btn_save . Enabled = true ;
btn_save . Visible = true ;
}
2020-04-28 10:38:43 +00:00
}
}
2020-05-03 08:39:35 +00:00
2020-05-16 05:07:52 +00:00
private void ilv_saved_profiles_ItemClick ( object sender , ItemClickEventArgs e )
2020-05-03 08:39:35 +00:00
{
2020-05-16 05:07:52 +00:00
foreach ( Profile loadedProfile in _loadedProfiles )
{
if ( loadedProfile . Name = = e . Item . Text )
{
ChangeSelectedProfile ( loadedProfile ) ;
}
}
2020-05-03 08:39:35 +00:00
}
2020-05-16 05:07:52 +00:00
private void ChangeSelectedProfile ( Profile profile )
2020-05-03 08:39:35 +00:00
{
2020-05-17 09:19:55 +00:00
// If the profile is null then return
// (this happens when a new blank shortcut is created
if ( profile = = null )
return ;
2020-05-03 08:39:35 +00:00
2020-05-16 05:07:52 +00:00
// And we need to update the actual selected profile too!
2020-05-17 09:19:55 +00:00
_profileToUse = profile ;
2020-05-16 05:07:52 +00:00
// We also need to load the saved profile name to show the user
2020-05-17 09:19:55 +00:00
lbl_profile_shown . Text = _profileToUse . Name ;
2020-05-16 05:07:52 +00:00
2020-05-17 09:19:55 +00:00
if ( _profileToUse . Equals ( Profile . CurrentProfile ) )
2020-05-03 08:39:35 +00:00
{
2020-05-16 05:07:52 +00:00
lbl_profile_shown_subtitle . Text = "(Current Display Profile in use)" ;
btn_save . Visible = false ;
2020-05-03 08:39:35 +00:00
}
2020-05-16 05:07:52 +00:00
else
2020-05-03 08:39:35 +00:00
{
2020-05-17 09:19:55 +00:00
if ( ! _profileToUse . IsPossible )
2020-05-16 05:07:52 +00:00
{
lbl_profile_shown_subtitle . Text = "(Display Profile is not valid so cannot be used)" ;
btn_save . Visible = false ;
}
else
{
lbl_profile_shown_subtitle . Text = "" ;
btn_save . Visible = true ;
}
2020-05-03 08:39:35 +00:00
}
2020-05-16 05:07:52 +00:00
// Refresh the image list view
RefreshImageListView ( profile ) ;
// And finally show the profile in the display view
dv_profile . Profile = profile ;
dv_profile . Refresh ( ) ;
2020-05-03 08:39:35 +00:00
}
2020-05-16 05:07:52 +00:00
2020-05-17 09:19:55 +00:00
private void RefreshShortcutUI ( )
2020-05-03 08:39:35 +00:00
{
2020-05-16 05:07:52 +00:00
if ( ! _inDialog )
2020-05-03 08:39:35 +00:00
{
2020-05-16 05:07:52 +00:00
if ( _loadedProfiles . Count > 0 )
2020-05-03 08:39:35 +00:00
{
2020-05-16 05:07:52 +00:00
// Temporarily stop updating the saved_profiles listview
ilv_saved_profiles . SuspendLayout ( ) ;
ImageListViewItem newItem = null ;
bool foundCurrentProfileInLoadedProfiles = false ;
foreach ( Profile loadedProfile in _loadedProfiles )
{
bool thisLoadedProfileIsAlreadyHere = ( from item in ilv_saved_profiles . Items where item . Text = = loadedProfile . Name select item . Text ) . Any ( ) ;
if ( ! thisLoadedProfileIsAlreadyHere )
{
//loadedProfile.SaveProfileImageToCache();
//newItem = new ImageListViewItem(loadedProfile.SavedProfileCacheFilename, loadedProfile.Name);
//newItem = new ImageListViewItem(loadedProfile, loadedProfile.Name);
newItem = new ImageListViewItem ( loadedProfile , loadedProfile . Name ) ;
//ilv_saved_profiles.Items.Add(newItem);
ilv_saved_profiles . Items . Add ( newItem , _profileAdaptor ) ;
}
}
// If we get to the end of the loaded profiles and haven't
// found a matching profile, then we need to show the current
// Profile
if ( ! foundCurrentProfileInLoadedProfiles )
ChangeSelectedProfile ( Profile . CurrentProfile ) ;
// Check if we were loading a profile to edit
// If so, select that instead of all that other stuff above!
2020-05-17 09:19:55 +00:00
if ( _shortcutToEdit ! = null )
ChangeSelectedProfile ( _shortcutToEdit . ProfileToUse ) ;
2020-05-16 05:07:52 +00:00
// Restart updating the saved_profiles listview
ilv_saved_profiles . ResumeLayout ( ) ;
2020-05-03 08:39:35 +00:00
}
2020-05-16 05:07:52 +00:00
2020-05-03 08:39:35 +00:00
}
2020-05-16 05:07:52 +00:00
else
// Otherwise turn off the dialog mode we were just in
_inDialog = false ;
}
private void btn_back_Click ( object sender , EventArgs e )
{
2020-05-17 09:19:55 +00:00
DialogResult = DialogResult . Cancel ;
2020-05-16 05:07:52 +00:00
this . Close ( ) ;
2020-05-03 08:39:35 +00:00
}
2020-05-16 11:16:46 +00:00
private void radiobutton_Paint ( object sender , PaintEventArgs e )
{
base . OnPaint ( e ) ;
RadioButton radiobutton = sender as RadioButton ;
if ( ! radiobutton . Enabled )
{
int x = ClientRectangle . X + CheckBoxRenderer . GetGlyphSize (
e . Graphics , CheckBoxState . UncheckedNormal ) . Width + 1 ;
int y = ClientRectangle . Y + 2 ;
TextRenderer . DrawText ( e . Graphics , radiobutton . Text ,
radiobutton . Font , new Point ( x , y ) , Color . Gray ,
TextFormatFlags . LeftAndRightPadding ) ;
}
}
private void checkbox_Paint ( object sender , PaintEventArgs e )
{
base . OnPaint ( e ) ;
CheckBox checkbox = sender as CheckBox ;
if ( ! checkbox . Enabled )
{
int x = ClientRectangle . X + CheckBoxRenderer . GetGlyphSize (
e . Graphics , CheckBoxState . UncheckedNormal ) . Width + 1 ;
int y = ClientRectangle . Y + 1 ;
TextRenderer . DrawText ( e . Graphics , checkbox . Text ,
checkbox . Font , new Point ( x , y ) , Color . Gray ,
TextFormatFlags . LeftAndRightPadding ) ;
}
}
private void label_Paint ( object sender , PaintEventArgs e )
{
base . OnPaint ( e ) ;
Label label = sender as Label ;
if ( ! label . Enabled )
{
int x = ClientRectangle . X - 2 ;
int y = ClientRectangle . Y ;
TextRenderer . DrawText ( e . Graphics , label . Text ,
label . Font , new Point ( x , y ) , Color . Gray ,
TextFormatFlags . LeftAndRightPadding ) ;
}
}
2017-02-26 19:23:31 +00:00
}
}