[WIP} Partial process priority implementation

This commit is contained in:
Terry MacDonald 2021-07-24 22:11:49 +12:00
parent 764d759e10
commit f740055cd3
4 changed files with 121 additions and 7887 deletions

View File

@ -19,26 +19,34 @@ using TsudaKageyu;
namespace DisplayMagician
{
public enum ShortcutPermanence
public enum ShortcutPermanence : int
{
Permanent,
Temporary,
Permanent = 1,
Temporary = 2,
}
public enum ShortcutCategory
public enum ShortcutCategory : int
{
Application,
Game,
NoGame,
Application = 1,
Game = 2,
NoGame = 3,
}
public enum ShortcutValidity
public enum ShortcutValidity : int
{
Valid,
Warning,
Error,
Valid = 1,
Warning = 2,
Error =3,
}
public enum ProcessPriority : int
{
High = 1,
AboveNormal = 2,
Normal = 3,
BelowNormal = 4,
Idle = 5,
}
public struct StartProgram
@ -50,6 +58,7 @@ namespace DisplayMagician
public bool ExecutableArgumentsRequired;
public bool CloseOnFinish;
public bool DontStartIfAlreadyRunning;
public ProcessPriority ProcessPriority;
}
public struct Executable
@ -60,6 +69,7 @@ namespace DisplayMagician
public string ExecutableArguments;
public bool ExecutableArgumentsRequired;
public bool ProcessNameToMonitorUsesExecutable;
public ProcessPriority ProcessPriority;
}
public struct GameStruct
@ -70,6 +80,7 @@ namespace DisplayMagician
public bool GameArgumentsRequired;
public string DifferentGameExeToMonitor;
public bool MonitorDifferentGameExe;
public ProcessPriority ProcessPriority;
}
public struct ShortcutError
@ -92,6 +103,7 @@ namespace DisplayMagician
private string _executableArguments;
private bool _executableArgumentsRequired = false;
private bool _processNameToMonitorUsesExecutable = true;
private ProcessPriority _processPriority = ProcessPriority.Normal;
private string _gameAppId;
private string _gameName;
private SupportedGameLibraryType _gameLibrary = SupportedGameLibraryType.Unknown;
@ -292,6 +304,19 @@ namespace DisplayMagician
}
}
public ProcessPriority ProcessPriority
{
get
{
return _processPriority;
}
set
{
_processPriority = value;
}
}
public string DifferentExecutableToMonitor
{
get

View File

@ -32,7 +32,6 @@ namespace DisplayMagician.UIForms
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ShortcutForm));
this.btn_save = new System.Windows.Forms.Button();
this.btn_cancel = new System.Windows.Forms.Button();
this.il_games = new System.Windows.Forms.ImageList(this.components);
@ -68,6 +67,7 @@ namespace DisplayMagician.UIForms
this.rb_change_audio = new System.Windows.Forms.RadioButton();
this.rb_no_change_audio = new System.Windows.Forms.RadioButton();
this.tabp_before = new System.Windows.Forms.TabPage();
this.btn_find_examples = new System.Windows.Forms.Button();
this.label3 = new System.Windows.Forms.Label();
this.btn_add_new_start_program = new System.Windows.Forms.Button();
this.flp_start_programs = new System.Windows.Forms.FlowLayoutPanel();
@ -88,13 +88,13 @@ namespace DisplayMagician.UIForms
this.rb_standalone = new System.Windows.Forms.RadioButton();
this.rb_no_game = new System.Windows.Forms.RadioButton();
this.p_game = new System.Windows.Forms.Panel();
this.cbx_game_priority = new System.Windows.Forms.ComboBox();
this.ilv_games = new Manina.Windows.Forms.ImageListView();
this.cb_wait_alternative_game = new System.Windows.Forms.CheckBox();
this.btn_choose_alternative_game = new System.Windows.Forms.Button();
this.txt_alternative_game = new System.Windows.Forms.TextBox();
this.txt_game_launcher = new System.Windows.Forms.TextBox();
this.txt_game_name = new System.Windows.Forms.TextBox();
this.lbl_game_library = new System.Windows.Forms.Label();
this.lbl_game_priority = new System.Windows.Forms.Label();
this.lbl_game_name = new System.Windows.Forms.Label();
this.txt_args_game = new System.Windows.Forms.TextBox();
this.cb_args_game = new System.Windows.Forms.CheckBox();
@ -117,7 +117,6 @@ namespace DisplayMagician.UIForms
this.cb_autosuggest = new System.Windows.Forms.CheckBox();
this.btn_hotkey = new System.Windows.Forms.Button();
this.lbl_hotkey_assigned = new System.Windows.Forms.Label();
this.btn_find_examples = new System.Windows.Forms.Button();
this.tabc_shortcut.SuspendLayout();
this.tabp_display.SuspendLayout();
this.tabp_audio.SuspendLayout();
@ -629,6 +628,22 @@ namespace DisplayMagician.UIForms
this.tabp_before.TabIndex = 1;
this.tabp_before.Text = "3. Choose what happens before";
//
// btn_find_examples
//
this.btn_find_examples.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btn_find_examples.FlatAppearance.MouseDownBackColor = System.Drawing.Color.IndianRed;
this.btn_find_examples.FlatAppearance.MouseOverBackColor = System.Drawing.Color.Brown;
this.btn_find_examples.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btn_find_examples.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.btn_find_examples.ForeColor = System.Drawing.Color.White;
this.btn_find_examples.Location = new System.Drawing.Point(976, 72);
this.btn_find_examples.Name = "btn_find_examples";
this.btn_find_examples.Size = new System.Drawing.Size(94, 25);
this.btn_find_examples.TabIndex = 40;
this.btn_find_examples.Text = "Find &Examples";
this.btn_find_examples.UseVisualStyleBackColor = true;
this.btn_find_examples.Click += new System.EventHandler(this.btn_find_examples_Click);
//
// label3
//
this.label3.AutoSize = true;
@ -879,13 +894,13 @@ namespace DisplayMagician.UIForms
//
// p_game
//
this.p_game.Controls.Add(this.cbx_game_priority);
this.p_game.Controls.Add(this.ilv_games);
this.p_game.Controls.Add(this.cb_wait_alternative_game);
this.p_game.Controls.Add(this.btn_choose_alternative_game);
this.p_game.Controls.Add(this.txt_alternative_game);
this.p_game.Controls.Add(this.txt_game_launcher);
this.p_game.Controls.Add(this.txt_game_name);
this.p_game.Controls.Add(this.lbl_game_library);
this.p_game.Controls.Add(this.lbl_game_priority);
this.p_game.Controls.Add(this.lbl_game_name);
this.p_game.Controls.Add(this.txt_args_game);
this.p_game.Controls.Add(this.cb_args_game);
@ -897,6 +912,16 @@ namespace DisplayMagician.UIForms
this.p_game.Size = new System.Drawing.Size(1076, 323);
this.p_game.TabIndex = 7;
//
// cbx_game_priority
//
this.cbx_game_priority.AllowDrop = true;
this.cbx_game_priority.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cbx_game_priority.FormattingEnabled = true;
this.cbx_game_priority.Location = new System.Drawing.Point(150, 43);
this.cbx_game_priority.Name = "cbx_game_priority";
this.cbx_game_priority.Size = new System.Drawing.Size(179, 28);
this.cbx_game_priority.TabIndex = 29;
//
// ilv_games
//
this.ilv_games.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
@ -945,14 +970,6 @@ namespace DisplayMagician.UIForms
this.txt_alternative_game.Size = new System.Drawing.Size(193, 26);
this.txt_alternative_game.TabIndex = 24;
//
// txt_game_launcher
//
this.txt_game_launcher.Location = new System.Drawing.Point(150, 43);
this.txt_game_launcher.Name = "txt_game_launcher";
this.txt_game_launcher.ReadOnly = true;
this.txt_game_launcher.Size = new System.Drawing.Size(149, 26);
this.txt_game_launcher.TabIndex = 23;
//
// txt_game_name
//
this.txt_game_name.Location = new System.Drawing.Point(150, 11);
@ -961,16 +978,16 @@ namespace DisplayMagician.UIForms
this.txt_game_name.Size = new System.Drawing.Size(385, 26);
this.txt_game_name.TabIndex = 21;
//
// lbl_game_library
// lbl_game_priority
//
this.lbl_game_library.AutoSize = true;
this.lbl_game_library.ForeColor = System.Drawing.Color.White;
this.lbl_game_library.Location = new System.Drawing.Point(36, 46);
this.lbl_game_library.Name = "lbl_game_library";
this.lbl_game_library.Size = new System.Drawing.Size(108, 20);
this.lbl_game_library.TabIndex = 18;
this.lbl_game_library.Text = "Game Library:";
this.lbl_game_library.Paint += new System.Windows.Forms.PaintEventHandler(this.label_Paint);
this.lbl_game_priority.AutoSize = true;
this.lbl_game_priority.ForeColor = System.Drawing.Color.White;
this.lbl_game_priority.Location = new System.Drawing.Point(36, 46);
this.lbl_game_priority.Name = "lbl_game_priority";
this.lbl_game_priority.Size = new System.Drawing.Size(108, 20);
this.lbl_game_priority.TabIndex = 18;
this.lbl_game_priority.Text = "Game Priority:";
this.lbl_game_priority.Paint += new System.Windows.Forms.PaintEventHandler(this.label_Paint);
//
// lbl_game_name
//
@ -1263,22 +1280,6 @@ namespace DisplayMagician.UIForms
this.lbl_hotkey_assigned.Visible = false;
this.lbl_hotkey_assigned.Click += new System.EventHandler(this.lbl_hotkey_assigned_Click);
//
// btn_find_examples
//
this.btn_find_examples.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btn_find_examples.FlatAppearance.MouseDownBackColor = System.Drawing.Color.IndianRed;
this.btn_find_examples.FlatAppearance.MouseOverBackColor = System.Drawing.Color.Brown;
this.btn_find_examples.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btn_find_examples.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.btn_find_examples.ForeColor = System.Drawing.Color.White;
this.btn_find_examples.Location = new System.Drawing.Point(976, 72);
this.btn_find_examples.Name = "btn_find_examples";
this.btn_find_examples.Size = new System.Drawing.Size(94, 25);
this.btn_find_examples.TabIndex = 40;
this.btn_find_examples.Text = "Find &Examples";
this.btn_find_examples.UseVisualStyleBackColor = true;
this.btn_find_examples.Click += new System.EventHandler(this.btn_find_examples_Click);
//
// ShortcutForm
//
this.AcceptButton = this.btn_save;
@ -1297,7 +1298,6 @@ namespace DisplayMagician.UIForms
this.Controls.Add(this.btn_cancel);
this.Controls.Add(this.btn_save);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "ShortcutForm";
@ -1359,9 +1359,8 @@ namespace DisplayMagician.UIForms
private System.Windows.Forms.TabPage tabp_after;
private System.Windows.Forms.TextBox txt_shortcut_save_name;
private System.Windows.Forms.Panel p_game;
private System.Windows.Forms.TextBox txt_game_launcher;
private System.Windows.Forms.TextBox txt_game_name;
private System.Windows.Forms.Label lbl_game_library;
private System.Windows.Forms.Label lbl_game_priority;
private System.Windows.Forms.Label lbl_game_name;
private System.Windows.Forms.TextBox txt_args_game;
private System.Windows.Forms.CheckBox cb_args_game;
@ -1429,5 +1428,6 @@ namespace DisplayMagician.UIForms
private System.Windows.Forms.Label label3;
internal Manina.Windows.Forms.ImageListView ilv_games;
private System.Windows.Forms.Button btn_find_examples;
private System.Windows.Forms.ComboBox cbx_game_priority;
}
}

View File

@ -21,6 +21,7 @@ using NHotkey;
namespace DisplayMagician.UIForms
{
public partial class ShortcutForm : Form
{
@ -28,6 +29,7 @@ namespace DisplayMagician.UIForms
private GameAdaptor _gameAdaptor;
//private List<ProfileItem> _loadedProfiles = new List<ProfileItem>();
private ProfileItem _profileToUse = null;
private string _gameLauncher = "";
private GameStruct _gameToUse;
private Executable _executableToUse;
private ShortcutPermanence _displayPermanence = ShortcutPermanence.Temporary;
@ -114,23 +116,23 @@ namespace DisplayMagician.UIForms
{
get
{
if (txt_game_launcher.Text.Contains("Steam"))
if (_gameLauncher.Contains("Steam"))
{
return SupportedGameLibraryType.Steam;
}
else if (txt_game_launcher.Text.Contains("Uplay"))
else if (_gameLauncher.Contains("Uplay"))
{
return SupportedGameLibraryType.Uplay;
}
else if (txt_game_launcher.Text.Contains("Origin"))
else if (_gameLauncher.Contains("Origin"))
{
return SupportedGameLibraryType.Origin;
}
else if (txt_game_launcher.Text.Contains("Epic"))
else if (_gameLauncher.Contains("Epic"))
{
return SupportedGameLibraryType.Epic;
}
else if (txt_game_launcher.Text.Contains("GOG"))
else if (_gameLauncher.Contains("GOG"))
{
return SupportedGameLibraryType.GOG;
}
@ -142,29 +144,28 @@ namespace DisplayMagician.UIForms
switch (value)
{
case SupportedGameLibraryType.Steam:
txt_game_launcher.Text = Enum.GetName(typeof(SupportedGameLibraryType), SupportedGameLibraryType.Steam);
_gameLauncher = Enum.GetName(typeof(SupportedGameLibraryType), SupportedGameLibraryType.Steam);
break;
case SupportedGameLibraryType.Uplay:
txt_game_launcher.Text = Enum.GetName(typeof(SupportedGameLibraryType), SupportedGameLibraryType.Uplay);
_gameLauncher = Enum.GetName(typeof(SupportedGameLibraryType), SupportedGameLibraryType.Uplay);
break;
case SupportedGameLibraryType.Origin:
txt_game_launcher.Text = Enum.GetName(typeof(SupportedGameLibraryType), SupportedGameLibraryType.Origin);
_gameLauncher = Enum.GetName(typeof(SupportedGameLibraryType), SupportedGameLibraryType.Origin);
break;
case SupportedGameLibraryType.Epic:
txt_game_launcher.Text = Enum.GetName(typeof(SupportedGameLibraryType), SupportedGameLibraryType.Epic);
_gameLauncher = Enum.GetName(typeof(SupportedGameLibraryType), SupportedGameLibraryType.Epic);
break;
case SupportedGameLibraryType.GOG:
txt_game_launcher.Text = Enum.GetName(typeof(SupportedGameLibraryType), SupportedGameLibraryType.GOG);
_gameLauncher = Enum.GetName(typeof(SupportedGameLibraryType), SupportedGameLibraryType.GOG);
break;
case SupportedGameLibraryType.Unknown:
txt_game_launcher.Text = "No supported Game Libraries found";
_gameLauncher = "No supported Game Libraries found";
break;
}
}
@ -330,7 +331,7 @@ namespace DisplayMagician.UIForms
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?",
$"This shortcut refers to the '{txt_game_name.Text}' game that was installed in your {_gameLauncher} 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);
@ -505,7 +506,7 @@ namespace DisplayMagician.UIForms
};
// If the game is a SteamGame
if (txt_game_launcher.Text == SupportedGameLibraryType.Steam.ToString())
if (_gameLauncher == SupportedGameLibraryType.Steam.ToString())
{
logger.Trace($"ShortcutForm/btn_save_Click: We're saving a Steam game!");
// Find the SteamGame
@ -513,26 +514,26 @@ namespace DisplayMagician.UIForms
_gameToUse.GameToPlay = (from steamGame in SteamLibrary.GetLibrary().AllInstalledGames where steamGame.Id == _gameId select steamGame).First();
}
// If the game is a UplayGame
else if (txt_game_launcher.Text == SupportedGameLibraryType.Uplay.ToString())
else if (_gameLauncher == SupportedGameLibraryType.Uplay.ToString())
{
logger.Trace($"ShortcutForm/btn_save_Click: We're saving a Uplay game!");
// Find the UplayGame
_gameToUse.GameToPlay = (from uplayGame in UplayLibrary.GetLibrary().AllInstalledGames where uplayGame.Id == _gameId select uplayGame).First();
}
// If the game is an Origin Game
else if (txt_game_launcher.Text == SupportedGameLibraryType.Origin.ToString())
else if (_gameLauncher == SupportedGameLibraryType.Origin.ToString())
{
logger.Trace($"ShortcutForm/btn_save_Click: We're saving an Origin game!");
_gameToUse.GameToPlay = (from originGame in OriginLibrary.GetLibrary().AllInstalledGames where originGame.Id == _gameId select originGame).First();
}
// If the game is an Epic Game
else if (txt_game_launcher.Text == SupportedGameLibraryType.Epic.ToString())
else if (_gameLauncher == SupportedGameLibraryType.Epic.ToString())
{
logger.Trace($"ShortcutForm/btn_save_Click: We're saving an Epic game!");
_gameToUse.GameToPlay = (from epicGame in EpicLibrary.GetLibrary().AllInstalledGames where epicGame.Id == _gameId select epicGame).First();
}
// If the game is an GOG Game
else if (txt_game_launcher.Text == SupportedGameLibraryType.GOG.ToString())
else if (_gameLauncher == SupportedGameLibraryType.GOG.ToString())
{
logger.Trace($"ShortcutForm/btn_save_Click: We're saving an GOG game!");
_gameToUse.GameToPlay = (from gogGame in GogLibrary.GetLibrary().AllInstalledGames where gogGame.Id == _gameId select gogGame).First();
@ -821,6 +822,19 @@ namespace DisplayMagician.UIForms
bool foundChosenProfileInLoadedProfiles = false;
ProfileItem chosenProfile = null;
// Prepare the process priority combo box
cbx_game_priority.DataSource = new ComboItem[] {
new ComboItem{ ID = 1, Text = "High" },
new ComboItem{ ID = 2, Text = "Above Normal" },
new ComboItem{ ID = 3, Text = "Normal" },
new ComboItem{ ID = 4, Text = "Below Normal" },
new ComboItem{ ID = 5, Text = "Idle" },
};
cbx_game_priority.ValueMember = "Text";
cbx_game_priority.DisplayMember = "Text";
cbx_game_priority.SelectedItem = "Normal";
cbx_game_priority.Enabled = true;
// Populate all the Audio devices in the audio devices list.
// Set the Audio device to the shortcut audio device only if
// the Change Audio radiobutton is set
@ -1151,7 +1165,7 @@ namespace DisplayMagician.UIForms
if (DisplayMagician.GameLibraries.GameLibrary.AllInstalledGamesInAllLibraries.Count <= 0)
{
// Fill in the game library information to highliught there isn't one detected.
txt_game_launcher.Text = "None detected";
_gameLauncher = "None detected";
txt_game_name.Text = "No supported game libraries detected";
txt_args_game.Text = "";
@ -1167,7 +1181,7 @@ namespace DisplayMagician.UIForms
}
else
{
txt_game_launcher.Text = _shortcutToEdit.GameLibrary.ToString();
_gameLauncher = _shortcutToEdit.GameLibrary.ToString();
txt_game_name.Text = _shortcutToEdit.GameName;
_gameId = _shortcutToEdit.GameAppId;
nud_timeout_game.Value = _shortcutToEdit.StartTimeout;
@ -2257,7 +2271,7 @@ namespace DisplayMagician.UIForms
{
if (_loadedShortcut)
_isUnsaved = true;
txt_game_launcher.Text = game.GameLibrary.ToString();
_gameLauncher = game.GameLibrary.ToString();
_gameId = game.Id;
}
}
@ -2279,4 +2293,11 @@ namespace DisplayMagician.UIForms
System.Diagnostics.Process.Start(targetURL);
}
}
// Class used to populate combo boxes
class ComboItem
{
public int ID { get; set; }
public string Text { get; set; }
}
}

File diff suppressed because it is too large Load Diff