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
2020-05-16 05:07:52 +00:00
private ProfileAdaptor _profileAdaptor ;
2020-06-15 09:57:46 +00:00
//private List<ProfileItem> _loadedProfiles = new List<ProfileItem>();
2020-06-07 08:48:45 +00:00
private ProfileItem _profileToUse = null ;
2020-10-18 08:17:21 +00:00
private GameStruct _gameToUse ;
private Executable _executableToUse ;
private ShortcutPermanence _permanence = ShortcutPermanence . Temporary ;
List < StartProgram > _startPrograms = new List < StartProgram > ( ) ;
2020-06-07 08:48:45 +00:00
private ShortcutItem _shortcutToEdit = null ;
2020-10-18 08:17:21 +00:00
private bool _isNewShortcut = true ;
2020-10-18 10:04:08 +00:00
private bool _isUnsaved = true ;
2020-07-13 07:53:25 +00:00
private bool _loadedShortcut = false ;
2020-10-18 08:17:21 +00:00
private bool _autoName = true ;
2020-05-31 02:56:22 +00:00
private uint _gameId = 0 ;
2020-06-15 09:57:46 +00:00
private string _uuid = "" ;
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
2020-05-31 10:09:43 +00:00
// Create a new SHortcut if we are creating a new one
// And set up the page (otherwise this is all set when we load an
// existing Shortcut)
2020-10-18 08:17:21 +00:00
/ * if ( _shortcutToEdit = = null )
2020-05-31 10:09:43 +00:00
{
2020-10-20 08:22:07 +00:00
shortcutToEdit = new ShortcutItem ( ) ;
isNewShortcut = true ;
} * /
2017-02-26 19:23:31 +00:00
}
2020-06-07 08:48:45 +00:00
public ShortcutForm ( ShortcutItem shortcutToEdit ) : this ( )
2017-02-26 19:23:31 +00:00
{
2020-05-17 09:19:55 +00:00
_shortcutToEdit = shortcutToEdit ;
2020-05-31 10:09:43 +00:00
_isNewShortcut = false ;
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 )
{
2020-05-31 10:09:43 +00:00
return txt_alternative_executable . Text ;
2020-04-22 11:46:31 +00:00
}
}
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
2020-05-31 10:09:43 +00:00
txt_alternative_executable . Text = value ;
2020-04-23 08:16:16 +00:00
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-05-31 02:56:22 +00:00
get = > rb_switch_temp . Checked & & rb_launcher . Checked ? _gameId : 0 ;
2020-04-22 11:46:31 +00:00
set
{
rb_switch_temp . Checked = true ;
rb_launcher . Checked = true ;
2020-05-31 02:56:22 +00:00
_gameId = value ;
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-06-07 08:48:45 +00:00
public ShortcutItem Shortcut
2020-05-17 09:19:55 +00:00
{
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!
2020-05-19 09:41:26 +00:00
// Check the name is valid to save
if ( String . IsNullOrWhiteSpace ( 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-05-19 09:41:26 +00:00
// Please use a plain name that can be
2020-06-01 10:25:52 +00:00
if ( _isNewShortcut & & ShortcutRepository . ContainsShortcut ( txt_shortcut_save_name . Text ) )
2020-05-19 09:41:26 +00:00
{
MessageBox . Show (
2020-05-31 02:56:22 +00:00
@"A shortcut has already been created with this name. Please enter a different name for this shortcut." ,
2020-05-19 09:41:26 +00:00
@"Please rename this Shortcut." ,
MessageBoxButtons . OK ,
MessageBoxIcon . Exclamation ) ;
return ;
}
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
2020-06-07 08:48:45 +00:00
if ( ! ( _profileToUse is ProfileItem ) )
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-31 10:09:43 +00:00
// Check the Shortcut Category to see if it's application
if ( rb_standalone . Checked )
{
if ( cb_args_executable . Checked & & String . IsNullOrWhiteSpace ( txt_args_executable . Text ) )
2017-02-26 19:23:31 +00:00
{
2020-05-31 10:09:43 +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-31 10:09:43 +00:00
}
2018-10-20 00:27:25 +00:00
2020-05-31 10:09:43 +00:00
if ( ! File . Exists ( txt_executable . Text ) )
{
MessageBox . Show (
@"The executable you have chosen does not exist! Please reselect the executable, or check you have permissions to view it." ,
@"Executable doesn't exist" ,
MessageBoxButtons . OK ,
MessageBoxIcon . Exclamation ) ;
return ;
}
2018-10-20 00:27:25 +00:00
2020-05-31 10:09:43 +00:00
if ( rb_wait_alternative_executable . Checked & & String . IsNullOrWhiteSpace ( txt_alternative_executable . Text ) )
{
MessageBox . Show (
$"If you want to wait for an alternative executable then you need to choose it! Click the 'Choose' button next to the different executable field." ,
@"Need to choose the different executable" ,
MessageBoxButtons . OK ,
MessageBoxIcon . Exclamation ) ;
return ;
2020-05-17 09:19:55 +00:00
}
2020-05-31 10:09:43 +00:00
if ( rb_wait_alternative_executable . Checked & & ! File . Exists ( txt_alternative_executable . Text ) )
2020-05-17 09:19:55 +00:00
{
2020-05-31 10:09:43 +00:00
MessageBox . Show (
@"The alternative executable you have chosen does not exist! Please reselect the alternative executable, or check you have permissions to view it." ,
@"Alternative executable doesn't exist" ,
MessageBoxButtons . OK ,
MessageBoxIcon . Exclamation ) ;
return ;
}
2018-10-20 00:27:25 +00:00
2020-05-31 10:09:43 +00:00
}
else if ( rb_launcher . Checked )
{
2020-05-17 09:19:55 +00:00
2020-05-31 10:09:43 +00:00
if ( cb_args_game . Checked & & String . IsNullOrWhiteSpace ( txt_args_game . Text ) )
{
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 ;
}
if ( _gameId = = 0 )
{
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 ;
}
bool gameStillInstalled = false ;
foreach ( ListViewItem gameItem in lv_games . Items )
{
if ( gameItem . Text . Equals ( txt_game_name . Text ) )
gameStillInstalled = true ;
}
if ( ! gameStillInstalled )
{
DialogResult result = MessageBox . Show (
$"This shortcut refers to the '{txt_game_name.Text}' game that was installed in your {txt_game_launcher.Text} library. This game is no longer installed, so the shortcut won't work. Do you still want to save the shortcut?" ,
@"Game no longer exists" ,
MessageBoxButtons . YesNo ,
MessageBoxIcon . Exclamation ) ;
if ( result = = DialogResult . No )
2020-05-17 09:19:55 +00:00
return ;
2017-02-26 19:23:31 +00:00
}
2020-05-31 10:09:43 +00:00
2020-05-17 09:19:55 +00:00
}
2020-04-22 11:46:31 +00:00
2020-04-28 10:38:43 +00:00
2020-10-20 08:22:07 +00:00
2020-05-17 09:19:55 +00:00
// Check the permanence requirements
if ( rb_switch_temp . Checked )
2020-10-18 08:17:21 +00:00
_permanence = ShortcutPermanence . Temporary ;
2020-04-27 10:55:44 +00:00
2020-05-31 02:56:22 +00:00
if ( rb_switch_permanent . Checked )
2020-10-18 08:17:21 +00:00
_permanence = ShortcutPermanence . Permanent ;
2020-10-11 07:14:22 +00:00
// Save the start program 1
StartProgram myStartProgram = new StartProgram ( ) ;
myStartProgram . Priority = 1 ;
myStartProgram . Enabled = cb_start_program1 . Checked ;
myStartProgram . Executable = txt_start_program1 . Text ;
myStartProgram . ExecutableArgumentsRequired = cb_start_program_pass_args1 . Checked ;
myStartProgram . Arguments = txt_start_program_args1 . Text ;
myStartProgram . CloseOnFinish = cb_start_program_close1 . Checked ;
2020-10-18 08:17:21 +00:00
_startPrograms . Add ( myStartProgram ) ;
2020-10-11 07:14:22 +00:00
myStartProgram = new StartProgram ( ) ;
myStartProgram . Priority = 2 ;
myStartProgram . Executable = txt_start_program2 . Text ;
myStartProgram . Enabled = cb_start_program2 . Checked ;
myStartProgram . ExecutableArgumentsRequired = cb_start_program_pass_args2 . Checked ;
myStartProgram . Arguments = txt_start_program_args2 . Text ;
myStartProgram . CloseOnFinish = cb_start_program_close2 . Checked ;
2020-10-18 08:17:21 +00:00
_startPrograms . Add ( myStartProgram ) ;
2020-10-11 07:14:22 +00:00
myStartProgram = new StartProgram ( ) ;
myStartProgram . Priority = 3 ;
myStartProgram . Executable = txt_start_program3 . Text ;
myStartProgram . Enabled = cb_start_program3 . Checked ;
myStartProgram . ExecutableArgumentsRequired = cb_start_program_pass_args3 . Checked ;
myStartProgram . Arguments = txt_start_program_args3 . Text ;
myStartProgram . CloseOnFinish = cb_start_program_close3 . Checked ;
2020-10-18 08:17:21 +00:00
_startPrograms . Add ( myStartProgram ) ;
2020-10-11 07:14:22 +00:00
myStartProgram = new StartProgram ( ) ;
myStartProgram . Priority = 4 ;
myStartProgram . Executable = txt_start_program4 . Text ;
myStartProgram . Enabled = cb_start_program4 . Checked ;
myStartProgram . ExecutableArgumentsRequired = cb_start_program_pass_args4 . Checked ;
myStartProgram . Arguments = txt_start_program_args4 . Text ;
myStartProgram . CloseOnFinish = cb_start_program_close4 . Checked ;
2020-10-18 08:17:21 +00:00
_startPrograms . Add ( myStartProgram ) ;
2020-10-11 05:11:08 +00:00
2020-10-18 08:17:21 +00:00
// Now we create the Shortcut Object ready to save
// If we're launching a game
2020-05-17 09:19:55 +00:00
if ( rb_launcher . Checked )
2020-10-18 08:15:19 +00:00
{
2020-10-18 08:17:21 +00:00
// If the game is a SteamGame
if ( txt_game_launcher . Text = = SupportedGameLibrary . Steam . ToString ( ) )
{
// Find the SteamGame
_gameToUse = new GameStruct ( ) ;
_gameToUse . GameToPlay = ( from steamGame in SteamLibrary . AllInstalledGames where steamGame . Id = = _gameId select steamGame ) . First ( ) ;
_gameToUse . StartTimeout = Convert . ToUInt32 ( nud_timeout_game . Value ) ;
_gameToUse . GameArguments = txt_args_game . Text ;
_gameToUse . GameArgumentsRequired = cb_args_game . Checked ;
_shortcutToEdit = new ShortcutItem (
2020-10-20 08:22:07 +00:00
txt_shortcut_save_name . Text ,
2020-10-18 08:17:21 +00:00
_profileToUse ,
_gameToUse ,
_permanence ,
_gameToUse . GameToPlay . IconPath ,
_startPrograms ,
2020-10-18 10:04:08 +00:00
_autoName ,
_uuid
2020-10-18 08:17:21 +00:00
) ;
2020-10-20 08:22:07 +00:00
/ * _shortcutToEdit . UpdateGameShortcut (
Name ,
_profileToUse ,
_gameToUse ,
_permanence ,
_gameToUse . GameToPlay . IconPath ,
_startPrograms ,
_autoName ,
_uuid
) ; * /
2020-10-18 08:17:21 +00:00
}
// If the game is a SteamGame
/ * else if ( txt_game_launcher . Text = = SupportedGameLibrary . Uplay . ToString ( ) )
{
// Find the UplayGame
_steamGameToUse = ( from UplayGame in SteamLibrary . AllInstalledGames where UplayGame . GameId = = _shortcutToEdit . GameAppId ) . First ( ) ;
2020-10-20 08:22:07 +00:00
_shortcutToEdit . UpdateGameShortcut (
2020-10-18 08:17:21 +00:00
Name ,
_profileToUse ,
_steamGameToUse ,
_permanence ,
_steamGameToUse . GameIconPath ,
_startPrograms ,
_autoName
) ;
} * /
2020-10-20 08:22:07 +00:00
}
2020-05-17 09:19:55 +00:00
else if ( rb_standalone . Checked )
2020-10-13 09:32:41 +00:00
{
2020-10-18 08:17:21 +00:00
_executableToUse = new Executable ( ) ;
_executableToUse . ExecutableArguments = txt_args_executable . Text ;
_executableToUse . ExecutableArgumentsRequired = cb_args_executable . Checked ;
_executableToUse . ExecutableNameAndPath = txt_executable . Text ;
_executableToUse . ExecutableTimeout = Convert . ToUInt32 ( nud_timeout_executable . Value ) ;
2020-10-18 08:15:19 +00:00
2020-10-18 08:17:21 +00:00
if ( rb_wait_alternative_executable . Checked & & ! String . IsNullOrWhiteSpace ( txt_alternative_executable . Text ) )
{
_executableToUse . ProcessNameToMonitorUsesExecutable = true ;
_executableToUse . DifferentExecutableToMonitor = txt_alternative_executable . Text ;
}
else
{
_executableToUse . ProcessNameToMonitorUsesExecutable = false ;
}
2020-10-20 08:22:07 +00:00
2020-10-18 08:17:21 +00:00
_shortcutToEdit = new ShortcutItem (
2020-10-20 08:22:07 +00:00
txt_shortcut_save_name . Text ,
_profileToUse ,
_executableToUse ,
_permanence ,
_executableToUse . ExecutableNameAndPath ,
_startPrograms ,
_autoName
) ;
/ * _shortcutToEdit . UpdateExecutableShortcut (
2020-10-18 08:17:21 +00:00
Name ,
_profileToUse ,
_executableToUse ,
_permanence ,
_executableToUse . ExecutableNameAndPath ,
_startPrograms ,
_autoName
) ;
2020-10-20 08:22:07 +00:00
* /
}
else
{
_shortcutToEdit = new ShortcutItem (
txt_shortcut_save_name . Text ,
_profileToUse ,
_permanence ,
_executableToUse . ExecutableNameAndPath ,
_startPrograms ,
_autoName
) ;
/ * _shortcutToEdit . UpdateNoGameShortcut (
Name ,
_profileToUse ,
_permanence ,
_executableToUse . ExecutableNameAndPath ,
_startPrograms ,
_autoName
) ;
* /
2020-10-18 08:17:21 +00:00
}
2020-10-19 09:58:23 +00:00
// Generate the Shortcut Icon ready to be used
_shortcutToEdit . SaveShortcutIconToCache ( ) ;
2020-05-17 09:19:55 +00:00
// 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.
2020-10-18 10:04:08 +00:00
2020-05-31 02:56:22 +00:00
// We've saved, so mark it as so
_isUnsaved = false ;
2020-05-17 09:19:55 +00:00
// Save everything is golden and close the form.
DialogResult = DialogResult . OK ;
this . Close ( ) ;
2017-02-26 19:23:31 +00:00
}
2020-05-31 10:09:43 +00:00
private void txt_different_executable_TextChanged ( object sender , EventArgs e )
{
2020-07-13 07:53:25 +00:00
if ( _loadedShortcut )
_isUnsaved = true ;
2020-05-31 10:09:43 +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-07-13 07:53:25 +00:00
if ( _loadedShortcut )
_isUnsaved = true ;
2020-05-31 10:09:43 +00:00
suggestShortcutName ( ) ;
2020-05-31 02:56:22 +00:00
enableSaveButtonIfValid ( ) ;
}
private bool canEnableSaveButton ( )
{
if ( ( txt_shortcut_save_name . Text . Length > 0 ) & &
2020-06-07 08:48:45 +00:00
_profileToUse is ProfileItem & &
2020-05-31 02:56:22 +00:00
( rb_no_game . Checked | |
rb_launcher . Checked & & _gameId > 0 | |
2020-05-31 10:09:43 +00:00
rb_standalone . Checked & & txt_executable . Text . Length > 0 ) )
2020-05-31 02:56:22 +00:00
return true ;
2020-05-17 09:19:55 +00:00
else
2020-05-31 02:56:22 +00:00
return false ;
2017-02-26 19:23:31 +00:00
}
2020-04-19 05:37:29 +00:00
2020-05-31 02:56:22 +00:00
private void enableSaveButtonIfValid ( )
2020-04-22 11:46:31 +00:00
{
2020-05-31 02:56:22 +00:00
if ( canEnableSaveButton ( ) )
2020-05-17 09:19:55 +00:00
btn_save . Enabled = true ;
else
btn_save . Enabled = false ;
2020-05-31 10:09:43 +00:00
}
private void suggestShortcutName ( )
{
2020-10-18 08:17:21 +00:00
if ( _autoName & & _profileToUse is ProfileItem )
2020-05-31 10:09:43 +00:00
{
if ( rb_no_game . Checked )
{
if ( rb_switch_permanent . Checked )
txt_shortcut_save_name . Text = $"{_profileToUse.Name}" ;
else if ( rb_switch_temp . Checked )
txt_shortcut_save_name . Text = $"{_profileToUse.Name} (Temporary)" ;
}
else if ( rb_launcher . Checked & & txt_game_name . Text . Length > 0 )
{
txt_shortcut_save_name . Text = $"{txt_game_name.Text} ({_profileToUse.Name})" ;
}
else if ( rb_standalone . Checked & & txt_executable . Text . Length > 0 )
{
string baseName = Path . GetFileNameWithoutExtension ( txt_executable . Text ) ;
txt_shortcut_save_name . Text = $"{baseName} ({_profileToUse.Name})" ;
}
}
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 )
{
2020-07-13 07:53:25 +00:00
if ( _loadedShortcut )
_isUnsaved = true ;
2020-05-31 02:56:22 +00:00
rb_no_game . Checked = false ;
rb_launcher . Checked = false ;
2020-04-22 11:46:31 +00:00
// 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-31 10:09:43 +00:00
suggestShortcutName ( ) ;
2020-05-31 02:56:22 +00:00
enableSaveButtonIfValid ( ) ;
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 )
{
2020-07-13 07:53:25 +00:00
if ( _loadedShortcut )
_isUnsaved = true ;
2020-05-31 02:56:22 +00:00
rb_no_game . Checked = false ;
rb_standalone . Checked = false ;
2020-04-22 11:46:31 +00:00
// Enable the Game Panel
p_game . Enabled = true ;
// Disable the Standalone Panel
p_standalone . Enabled = false ;
2020-05-01 10:30:27 +00:00
2020-05-31 10:09:43 +00:00
suggestShortcutName ( ) ;
2020-05-31 02:56:22 +00:00
enableSaveButtonIfValid ( ) ;
2020-05-01 10:30:27 +00:00
2020-04-22 11:46:31 +00:00
}
}
2020-05-31 02:56:22 +00:00
private void rb_no_game_CheckedChanged ( object sender , EventArgs e )
{
if ( rb_no_game . Checked )
{
2020-07-13 07:53:25 +00:00
if ( _loadedShortcut )
_isUnsaved = true ;
2020-05-31 02:56:22 +00:00
rb_launcher . Checked = false ;
rb_standalone . Checked = false ;
// Disable the Standalone Panel
p_standalone . Enabled = false ;
// Disable the Game Panel
p_game . Enabled = false ;
2020-05-31 10:09:43 +00:00
suggestShortcutName ( ) ;
2020-05-31 02:56:22 +00:00
enableSaveButtonIfValid ( ) ;
}
}
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-07-13 07:53:25 +00:00
if ( _loadedShortcut )
_isUnsaved = true ;
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-06-07 08:48:45 +00:00
private void RefreshImageListView ( ProfileItem profile )
2020-05-16 05:07:52 +00:00
{
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-10-11 04:04:36 +00:00
matchingImageListViewItems . First ( ) . Enabled = true ;
2020-05-16 05:07:52 +00:00
}
}
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-16 05:07:52 +00:00
// Load all the profiles to prepare things
2020-10-11 04:04:36 +00:00
bool foundChosenProfileInLoadedProfiles = false ;
ProfileItem chosenProfile = null ;
2020-10-18 08:17:21 +00:00
// Load the Games ListView
foreach ( var game in SteamLibrary . AllInstalledGames . OrderBy ( game = > game . Name ) )
{
2020-10-19 09:58:23 +00:00
// Get the bitmap out of the IconPath
// IconPath can be an ICO, or an EXE
2020-10-19 08:50:42 +00:00
Bitmap bm = null ;
try
2020-10-18 08:17:21 +00:00
{
2020-10-19 09:58:23 +00:00
bm = ShortcutItem . ToSmallBitmap ( game . IconPath ) ;
2020-10-19 08:50:42 +00:00
}
2020-10-19 09:58:23 +00:00
catch ( Exception innerEx )
2020-10-19 08:50:42 +00:00
{
2020-10-19 09:58:23 +00:00
Console . WriteLine ( $"ShortcutForm exception: {innerEx.Message}: {innerEx.StackTrace} - {innerEx.InnerException}" ) ;
2020-10-19 08:50:42 +00:00
bm = Properties . Resources . Steam . ToBitmap ( ) ;
}
2020-10-19 09:58:23 +00:00
2020-10-19 08:50:42 +00:00
// Add the images to the images array
il_games . Images . Add ( bm ) ;
2020-10-18 08:17:21 +00:00
if ( ! Visible )
{
return ;
}
2020-10-19 08:50:42 +00:00
// ADd the game to the game array
2020-10-18 08:17:21 +00:00
lv_games . Items . Add ( new ListViewItem
{
Text = game . Name ,
Tag = game ,
ImageIndex = il_games . Images . Count - 1
} ) ;
}
// If it is a new Shortcut then we don't have to load anything!
if ( _isNewShortcut )
2020-10-18 10:04:08 +00:00
{
RefreshShortcutUI ( ) ;
ChangeSelectedProfile ( ProfileRepository . CurrentProfile ) ;
_isUnsaved = true ;
2020-10-18 08:17:21 +00:00
return ;
2020-10-18 10:04:08 +00:00
}
2020-10-18 08:17:21 +00:00
2020-10-18 10:04:08 +00:00
// We only get down here if the form has loaded a shortcut to edit
2020-10-11 04:04:36 +00:00
if ( _shortcutToEdit is ShortcutItem & & _shortcutToEdit . ProfileToUse is ProfileItem )
2020-05-03 08:39:35 +00:00
{
2020-10-11 04:04:36 +00:00
foreach ( ProfileItem loadedProfile in ProfileRepository . AllProfiles )
2020-05-16 05:07:52 +00:00
{
2020-10-11 04:04:36 +00:00
if ( _shortcutToEdit . ProfileToUse . Equals ( loadedProfile ) )
2020-06-15 09:57:46 +00:00
{
2020-10-11 04:04:36 +00:00
// We have loaded the profile used last time
// so we need to show the selected profile in the UI
chosenProfile = loadedProfile ;
foundChosenProfileInLoadedProfiles = true ;
// If the profile is the same, but the user has renamed the profile
// since the shortcut was last created, then we need to tell the user
if ( ! loadedProfile . Name . Equals ( _shortcutToEdit . ProfileToUse . Name ) )
{
MessageBox . Show (
@"The Display Profile used by this Shortcut still exists, but it's changed it's name. We've updated the shortcut's name to reflect this change." ,
@"Display Profile name changed" ,
MessageBoxButtons . OK ,
MessageBoxIcon . Exclamation ) ;
2020-10-20 08:22:07 +00:00
break ;
2020-10-11 04:04:36 +00:00
}
2020-10-20 08:22:07 +00:00
2020-06-15 09:57:46 +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
// If we get to the end of the loaded profiles and haven't
2020-10-11 04:04:36 +00:00
// found a matching profile, then we need to show the current profile
// that we're running now
if ( ! foundChosenProfileInLoadedProfiles & & ProfileRepository . ProfileCount > 0 )
{
foreach ( ProfileItem loadedProfile in ProfileRepository . AllProfiles )
{
if ( ProfileRepository . CurrentProfile . Equals ( loadedProfile ) )
{
// We have loaded the profile used last time
// so we need to show the selected profile in the UI
chosenProfile = loadedProfile ;
foundChosenProfileInLoadedProfiles = true ;
// If the profile is the same, but the user has renamed the profile
// since the shortcut was last created, then we need to tell the user
if ( ! loadedProfile . Name . Equals ( ProfileRepository . CurrentProfile . Name ) )
{
MessageBox . Show (
@"The Display Profile used by this Shortcut still exists, but it's changed it's name. We've updated the shortcut's name to reflect this change." ,
@"Display Profile name changed" ,
MessageBoxButtons . OK ,
MessageBoxIcon . Exclamation ) ;
}
2020-05-16 05:07:52 +00:00
2020-10-11 04:04:36 +00:00
}
}
}
2020-05-16 05:07:52 +00:00
2020-10-20 08:22:07 +00:00
2020-05-31 10:09:43 +00:00
// Now start populating the other fields
2020-06-15 09:57:46 +00:00
_uuid = _shortcutToEdit . UUID ;
2020-10-20 08:22:07 +00:00
2020-05-31 10:09:43 +00:00
// Set if we launch App/Game/NoGame
switch ( _shortcutToEdit . Category )
{
case ShortcutCategory . NoGame :
rb_no_game . Checked = true ;
break ;
case ShortcutCategory . Game :
rb_launcher . Checked = true ;
break ;
case ShortcutCategory . Application :
rb_standalone . Checked = true ;
break ;
}
// Set the launcher items if we have them
txt_game_launcher . Text = _shortcutToEdit . GameLibrary . ToString ( ) ;
txt_game_name . Text = _shortcutToEdit . GameName ;
_gameId = _shortcutToEdit . GameAppId ;
2020-10-18 08:17:21 +00:00
nud_timeout_game . Value = _shortcutToEdit . StartTimeout ;
2020-05-31 10:09:43 +00:00
txt_args_game . Text = _shortcutToEdit . GameArguments ;
if ( _shortcutToEdit . GameArgumentsRequired )
{
cb_args_game . Checked = true ;
}
2020-06-15 09:57:46 +00:00
cb_autosuggest . Checked = _shortcutToEdit . AutoName ;
2020-05-31 10:09:43 +00:00
//select the loaded Game item if it is there
foreach ( ListViewItem gameItem in lv_games . Items )
{
if ( gameItem . Text . Equals ( _shortcutToEdit . GameName ) )
{
gameItem . Selected = true ;
2020-10-20 08:22:07 +00:00
break ;
2020-05-31 10:09:43 +00:00
}
}
// Set the executable items if we have them
txt_executable . Text = _shortcutToEdit . ExecutableNameAndPath ;
2020-10-18 08:17:21 +00:00
nud_timeout_executable . Value = _shortcutToEdit . StartTimeout ;
2020-05-31 10:09:43 +00:00
txt_args_executable . Text = _shortcutToEdit . ExecutableArguments ;
if ( _shortcutToEdit . ExecutableArgumentsRequired )
{
cb_args_executable . Checked = true ;
}
if ( _shortcutToEdit . ProcessNameToMonitorUsesExecutable )
{
rb_wait_executable . Checked = true ;
rb_wait_alternative_executable . Checked = false ;
}
else
{
rb_wait_executable . Checked = false ;
rb_wait_alternative_executable . Checked = true ;
}
txt_alternative_executable . Text = _shortcutToEdit . DifferentExecutableToMonitor ;
// Set the shortcut name
txt_shortcut_save_name . Text = _shortcutToEdit . Name ;
2020-10-11 05:21:06 +00:00
// Set up the start programs
2020-10-11 07:14:22 +00:00
if ( _shortcutToEdit . StartPrograms is List < StartProgram > & & _shortcutToEdit . StartPrograms . Count > 0 )
2020-10-11 05:21:06 +00:00
{
foreach ( StartProgram myStartProgram in _shortcutToEdit . StartPrograms )
{
// Update the 4 programs to start
switch ( myStartProgram . Priority )
{
case 1 :
txt_start_program1 . Text = myStartProgram . Executable ;
cb_start_program1 . Checked = myStartProgram . Enabled ;
cb_start_program_pass_args1 . Checked = myStartProgram . ExecutableArgumentsRequired ;
txt_start_program_args1 . Text = myStartProgram . Arguments ;
cb_start_program_close1 . Checked = myStartProgram . CloseOnFinish ;
break ;
case 2 :
txt_start_program2 . Text = myStartProgram . Executable ;
cb_start_program2 . Checked = myStartProgram . Enabled ;
cb_start_program_pass_args2 . Checked = myStartProgram . ExecutableArgumentsRequired ;
txt_start_program_args2 . Text = myStartProgram . Arguments ;
cb_start_program_close2 . Checked = myStartProgram . CloseOnFinish ;
break ;
case 3 :
txt_start_program3 . Text = myStartProgram . Executable ;
cb_start_program3 . Checked = myStartProgram . Enabled ;
cb_start_program_pass_args3 . Checked = myStartProgram . ExecutableArgumentsRequired ;
txt_start_program_args3 . Text = myStartProgram . Arguments ;
cb_start_program_close3 . Checked = myStartProgram . CloseOnFinish ;
break ;
case 4 :
txt_start_program4 . Text = myStartProgram . Executable ;
cb_start_program4 . Checked = myStartProgram . Enabled ;
cb_start_program_pass_args4 . Checked = myStartProgram . ExecutableArgumentsRequired ;
txt_start_program_args4 . Text = myStartProgram . Arguments ;
cb_start_program_close4 . Checked = myStartProgram . CloseOnFinish ;
break ;
}
}
}
2020-05-31 10:09:43 +00:00
// Refresh the Shortcut UI
RefreshShortcutUI ( ) ;
2020-10-11 04:04:36 +00:00
ChangeSelectedProfile ( chosenProfile ) ;
RefreshImageListView ( chosenProfile ) ;
2020-05-31 10:09:43 +00:00
2020-07-13 07:53:25 +00:00
_loadedShortcut = true ;
2020-10-18 10:04:08 +00:00
_isUnsaved = false ;
2020-05-31 10:09:43 +00:00
2020-10-11 04:26:11 +00:00
// Finally enable the save button if it's still valid
enableSaveButtonIfValid ( ) ;
2020-04-22 11:46:31 +00:00
}
private void rb_wait_process_CheckedChanged ( object sender , EventArgs e )
{
2020-05-31 10:09:43 +00:00
if ( rb_wait_alternative_executable . Checked )
2020-04-22 11:46:31 +00:00
{
2020-07-13 07:53:25 +00:00
if ( _loadedShortcut )
_isUnsaved = true ;
2020-05-31 02:56:22 +00:00
rb_wait_executable . Checked = false ;
2020-05-31 10:09:43 +00:00
txt_alternative_executable . Enabled = true ;
2020-04-22 11:46:31 +00:00
}
}
private void rb_wait_executable_CheckedChanged ( object sender , EventArgs e )
{
if ( rb_wait_executable . Checked )
{
2020-07-13 07:53:25 +00:00
if ( _loadedShortcut )
_isUnsaved = true ;
2020-05-31 10:09:43 +00:00
rb_wait_alternative_executable . Checked = false ;
txt_alternative_executable . Enabled = false ;
2020-04-22 11:46:31 +00:00
}
}
2020-05-31 10:09:43 +00:00
private void btn_app_different_executable_Click ( object sender , EventArgs e )
2020-04-22 11:46:31 +00:00
{
if ( dialog_open . ShowDialog ( this ) = = DialogResult . OK )
{
2020-07-13 07:53:25 +00:00
if ( _loadedShortcut )
_isUnsaved = true ;
2020-04-22 11:46:31 +00:00
if ( File . Exists ( dialog_open . FileName ) & & Path . GetExtension ( dialog_open . FileName ) = = @".exe" )
{
2020-05-31 10:09:43 +00:00
txt_alternative_executable . Text = dialog_open . FileName ;
2020-04-22 11:46:31 +00:00
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 )
{
2020-07-13 07:53:25 +00:00
if ( _loadedShortcut )
_isUnsaved = true ;
2020-04-23 08:16:16 +00:00
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 ;
2020-07-24 01:11:42 +00:00
foreach ( SteamGame game in SteamLibrary . AllInstalledGames )
2020-04-28 10:38:43 +00:00
{
2020-10-18 08:17:21 +00:00
if ( game . Name = = txt_game_name . Text )
2020-04-28 10:38:43 +00:00
{
2020-07-13 07:53:25 +00:00
if ( _loadedShortcut )
_isUnsaved = true ;
2020-07-21 11:40:33 +00:00
txt_game_launcher . Text = game . GameLibrary . ToString ( ) ;
2020-10-18 08:17:21 +00:00
_gameId = game . Id ;
2020-04-28 10:38:43 +00:00
}
}
}
2020-05-31 02:56:22 +00:00
2020-05-31 10:09:43 +00:00
suggestShortcutName ( ) ;
2020-05-31 02:56:22 +00:00
enableSaveButtonIfValid ( ) ;
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-10-11 04:04:36 +00:00
foreach ( ProfileItem savedProfile in ProfileRepository . AllProfiles )
2020-05-16 05:07:52 +00:00
{
2020-10-11 04:04:36 +00:00
if ( savedProfile . Name = = e . Item . Text )
2020-05-16 05:07:52 +00:00
{
2020-10-11 04:04:36 +00:00
ChangeSelectedProfile ( savedProfile ) ;
2020-10-20 08:22:07 +00:00
break ;
2020-05-16 05:07:52 +00:00
}
}
2020-10-11 04:04:36 +00:00
suggestShortcutName ( ) ;
enableSaveButtonIfValid ( ) ;
2020-05-03 08:39:35 +00:00
}
2020-06-07 08:48:45 +00:00
private void ChangeSelectedProfile ( ProfileItem 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-06-14 04:20:52 +00:00
if ( _profileToUse . Equals ( ProfileRepository . CurrentProfile ) )
2020-10-11 04:26:11 +00:00
lbl_profile_shown_subtitle . Text = "This is the Display Profile currently in use." ;
2020-05-16 05:07:52 +00:00
else
2020-10-11 04:04:36 +00:00
lbl_profile_shown_subtitle . Text = "" ;
2020-05-31 02:56:22 +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
2020-05-31 10:09:43 +00:00
2020-06-15 09:57:46 +00:00
if ( ProfileRepository . ProfileCount > 0 )
2020-05-03 08:39:35 +00:00
{
2020-05-16 05:07:52 +00:00
2020-05-31 10:09:43 +00:00
// Temporarily stop updating the saved_profiles listview
ilv_saved_profiles . SuspendLayout ( ) ;
2020-05-16 05:07:52 +00:00
2020-05-31 10:09:43 +00:00
ImageListViewItem newItem = null ;
2020-06-15 09:57:46 +00:00
foreach ( ProfileItem loadedProfile in ProfileRepository . AllProfiles )
2020-05-31 10:09:43 +00:00
{
2020-10-20 08:22:07 +00:00
bool thisLoadedProfileIsAlreadyHere = ( from item in ilv_saved_profiles . Items where item . Text = = loadedProfile . Name orderby item . Text select item . Text ) . Any ( ) ;
2020-05-31 10:09:43 +00:00
if ( ! thisLoadedProfileIsAlreadyHere )
2020-05-16 05:07:52 +00:00
{
2020-05-31 10:09:43 +00:00
//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 ) ;
2020-05-16 05:07:52 +00:00
}
2020-05-31 10:09:43 +00:00
}
2020-05-16 05:07:52 +00:00
2020-05-31 10:09:43 +00:00
// Restart updating the saved_profiles listview
ilv_saved_profiles . ResumeLayout ( ) ;
}
2020-05-31 02:56:22 +00:00
enableSaveButtonIfValid ( ) ;
2020-05-16 05:07:52 +00:00
}
private void btn_back_Click ( object sender , EventArgs e )
{
2020-05-31 10:09:43 +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 ) ;
}
}
2020-05-31 02:56:22 +00:00
private void rb_switch_temp_CheckedChanged ( object sender , EventArgs e )
{
if ( rb_switch_temp . Checked )
{
2020-07-13 07:53:25 +00:00
if ( _loadedShortcut )
_isUnsaved = true ;
2020-05-31 02:56:22 +00:00
rb_switch_permanent . Checked = false ;
2020-05-31 10:09:43 +00:00
suggestShortcutName ( ) ;
2020-05-31 02:56:22 +00:00
}
}
private void rb_switch_permanent_CheckedChanged ( object sender , EventArgs e )
{
if ( rb_switch_permanent . Checked )
{
2020-07-13 07:53:25 +00:00
if ( _loadedShortcut )
_isUnsaved = true ;
2020-05-31 02:56:22 +00:00
rb_switch_temp . Checked = false ;
2020-05-31 10:09:43 +00:00
suggestShortcutName ( ) ;
2020-05-31 02:56:22 +00:00
}
}
private void txt_shortcut_save_name_TextChanged ( object sender , EventArgs e )
{
2020-07-13 07:53:25 +00:00
if ( _loadedShortcut )
_isUnsaved = true ;
2020-05-31 02:56:22 +00:00
enableSaveButtonIfValid ( ) ;
}
2020-05-31 10:09:43 +00:00
private void ShortcutForm_FormClosing ( object sender , FormClosingEventArgs e )
{
2020-07-15 08:11:38 +00:00
if ( _isUnsaved & & _loadedShortcut )
2020-05-31 10:09:43 +00:00
{
// If the user doesn't want to close this window without saving, then don't close the window.
DialogResult result = MessageBox . Show (
@"You have unsaved changes! Do you want to close this window without saving your changes?" ,
@"You have unsaved changes." ,
MessageBoxButtons . YesNo ,
MessageBoxIcon . Exclamation ) ;
e . Cancel = ( result = = DialogResult . No ) ;
}
2020-10-18 10:04:08 +00:00
2020-05-31 10:09:43 +00:00
}
private void btn_exe_to_start_Click ( object sender , EventArgs e )
{
2020-10-11 00:52:28 +00:00
txt_executable . Text = get_exe_file ( ) ;
}
private void txt_shortcut_save_name_Click ( object sender , EventArgs e )
{
if ( _loadedShortcut )
_isUnsaved = true ;
2020-10-18 08:17:21 +00:00
_autoName = false ;
2020-10-11 00:52:28 +00:00
cb_autosuggest . Checked = false ;
}
private void cb_autosuggest_CheckedChanged ( object sender , EventArgs e )
{
if ( _loadedShortcut )
_isUnsaved = true ;
if ( cb_autosuggest . Checked )
2020-10-11 04:04:36 +00:00
{
2020-10-18 08:17:21 +00:00
_autoName = true ;
2020-10-11 04:04:36 +00:00
suggestShortcutName ( ) ;
}
2020-10-11 00:52:28 +00:00
else
2020-10-18 08:17:21 +00:00
_autoName = false ;
2020-10-11 00:52:28 +00:00
}
private string get_exe_file ( )
{
string textToReturn = "" ;
2020-05-31 10:09:43 +00:00
if ( dialog_open . ShowDialog ( this ) = = DialogResult . OK )
{
if ( File . Exists ( dialog_open . FileName ) & & Path . GetExtension ( dialog_open . FileName ) = = @".exe" )
{
2020-10-11 00:52:28 +00:00
textToReturn = dialog_open . FileName ;
2020-05-31 10:09:43 +00:00
dialog_open . FileName = string . Empty ;
}
else
{
MessageBox . Show (
Language . Selected_file_is_not_a_valid_executable_file ,
Language . Executable ,
MessageBoxButtons . OK ,
MessageBoxIcon . Exclamation ) ;
}
}
2020-10-11 00:52:28 +00:00
return textToReturn ;
2020-05-31 10:09:43 +00:00
}
2020-10-11 04:04:36 +00:00
private void btn_start_program1_Click ( object sender , EventArgs e )
{
txt_start_program1 . Text = get_exe_file ( ) ;
}
2020-05-31 10:09:43 +00:00
2020-10-11 00:52:28 +00:00
private void btn_start_program2_Click ( object sender , EventArgs e )
2020-05-31 10:09:43 +00:00
{
2020-10-11 04:04:36 +00:00
txt_start_program2 . Text = get_exe_file ( ) ;
2020-05-31 10:09:43 +00:00
}
2020-10-11 00:52:28 +00:00
private void btn_start_program3_Click ( object sender , EventArgs e )
2020-05-31 10:09:43 +00:00
{
2020-10-11 04:04:36 +00:00
txt_start_program3 . Text = get_exe_file ( ) ;
2020-05-31 10:09:43 +00:00
}
2020-10-10 05:09:19 +00:00
2020-10-11 00:52:28 +00:00
private void btn_start_program4_Click ( object sender , EventArgs e )
{
2020-10-11 04:04:36 +00:00
txt_start_program4 . Text = get_exe_file ( ) ;
2020-10-11 00:52:28 +00:00
}
2020-10-11 04:38:46 +00:00
private void cb_start_program1_CheckedChanged ( object sender , EventArgs e )
{
if ( _loadedShortcut )
_isUnsaved = true ;
// Disable the start program 1 fields
if ( cb_start_program1 . Checked )
{
// Enable the Executable Arguments Text field
txt_start_program1 . Visible = true ;
btn_start_program1 . Visible = true ;
cb_start_program_pass_args1 . Visible = true ;
cb_start_program_close1 . Visible = true ;
}
else
{
// Disable the Executable Arguments Text field
txt_start_program1 . Visible = false ;
btn_start_program1 . Visible = false ;
cb_start_program_pass_args1 . Visible = false ;
cb_start_program_close1 . Visible = false ;
}
}
private void cb_start_program2_CheckedChanged ( object sender , EventArgs e )
{
if ( _loadedShortcut )
_isUnsaved = true ;
2020-10-11 05:11:08 +00:00
// Disable the start program 2 fields
2020-10-11 04:38:46 +00:00
if ( cb_start_program2 . Checked )
{
// Enable the Executable Arguments Text field
txt_start_program2 . Visible = true ;
btn_start_program2 . Visible = true ;
cb_start_program_pass_args2 . Visible = true ;
cb_start_program_close2 . Visible = true ;
}
else
{
// Disable the Executable Arguments Text field
txt_start_program2 . Visible = false ;
btn_start_program2 . Visible = false ;
cb_start_program_pass_args2 . Visible = false ;
cb_start_program_close2 . Visible = false ;
}
}
private void cb_start_program3_CheckedChanged ( object sender , EventArgs e )
{
if ( _loadedShortcut )
_isUnsaved = true ;
2020-10-11 05:11:08 +00:00
// Disable the start program 3 fields
2020-10-11 04:38:46 +00:00
if ( cb_start_program3 . Checked )
{
// Enable the Executable Arguments Text field
txt_start_program3 . Visible = true ;
btn_start_program3 . Visible = true ;
cb_start_program_pass_args3 . Visible = true ;
cb_start_program_close3 . Visible = true ;
}
else
{
// Disable the Executable Arguments Text field
txt_start_program3 . Visible = false ;
btn_start_program3 . Visible = false ;
cb_start_program_pass_args3 . Visible = false ;
cb_start_program_close3 . Visible = false ;
}
}
private void cb_start_program4_CheckedChanged ( object sender , EventArgs e )
{
if ( _loadedShortcut )
_isUnsaved = true ;
2020-10-11 05:11:08 +00:00
// Disable the start program 4 fields
2020-10-11 04:38:46 +00:00
if ( cb_start_program4 . Checked )
{
// Enable the Executable Arguments Text field
txt_start_program4 . Visible = true ;
btn_start_program4 . Visible = true ;
cb_start_program_pass_args4 . Visible = true ;
cb_start_program_close4 . Visible = true ;
}
else
{
// Disable the Executable Arguments Text field
txt_start_program4 . Visible = false ;
btn_start_program4 . Visible = false ;
cb_start_program_pass_args4 . Visible = false ;
cb_start_program_close4 . Visible = false ;
}
}
2020-10-11 05:11:08 +00:00
private void cb_start_program_pass_args1_CheckedChanged ( object sender , EventArgs e )
{
if ( _loadedShortcut )
_isUnsaved = true ;
// Disable the start program 1 fields
if ( cb_start_program_pass_args1 . Checked )
{
// Enable the Executable Arguments Text field
txt_start_program_args1 . Visible = true ;
}
else
{
// Disable the Executable Arguments Text field
txt_start_program_args1 . Visible = false ;
}
}
private void cb_start_program_pass_args2_CheckedChanged ( object sender , EventArgs e )
{
if ( _loadedShortcut )
_isUnsaved = true ;
// Disable the start program 2 fields
if ( cb_start_program_pass_args2 . Checked )
{
// Enable the Executable Arguments Text field
txt_start_program_args2 . Visible = true ;
}
else
{
// Disable the Executable Arguments Text field
txt_start_program_args2 . Visible = false ;
}
}
private void cb_start_program_pass_args3_CheckedChanged ( object sender , EventArgs e )
{
if ( _loadedShortcut )
_isUnsaved = true ;
// Disable the start program 3 fields
if ( cb_start_program_pass_args3 . Checked )
{
// Enable the Executable Arguments Text field
txt_start_program_args3 . Visible = true ;
}
else
{
// Disable the Executable Arguments Text field
txt_start_program_args3 . Visible = false ;
}
}
private void cb_start_program_pass_args4_CheckedChanged ( object sender , EventArgs e )
{
if ( _loadedShortcut )
_isUnsaved = true ;
// Disable the start program 4 fields
if ( cb_start_program_pass_args4 . Checked )
{
// Enable the Executable Arguments Text field
txt_start_program_args4 . Visible = true ;
}
else
{
// Disable the Executable Arguments Text field
txt_start_program_args4 . Visible = false ;
}
}
2020-10-26 04:08:55 +00:00
2017-02-26 19:23:31 +00:00
}
}