Merged develop branch to simplify development

This commit is contained in:
Terry MacDonald 2021-08-30 12:35:52 +12:00
commit b374850bfe
31 changed files with 1439 additions and 7972 deletions

View File

@ -142,6 +142,12 @@
<DependentUpon>HotkeyForm.cs</DependentUpon>
</Compile>
<Compile Include="UIForms\ImageListViewRenderers.cs" />
<Compile Include="UIForms\ProfileSettingsForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="UIForms\ProfileSettingsForm.Designer.cs">
<DependentUpon>ProfileSettingsForm.cs</DependentUpon>
</Compile>
<Compile Include="UIForms\SettingsForm.cs">
<SubType>Form</SubType>
</Compile>
@ -206,6 +212,9 @@
<DependentUpon>MainForm.cs</DependentUpon>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="UIForms\ProfileSettingsForm.resx">
<DependentUpon>ProfileSettingsForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="UIForms\SettingsForm.resx">
<DependentUpon>SettingsForm.cs</DependentUpon>
</EmbeddedResource>

View File

@ -16,6 +16,7 @@ namespace DisplayMagician.GameLibraries
private string _epicGameDir;
private string _epicGameExe;
private string _epicGameProcessName;
private List<Process> _epicGameProcesses = new List<Process>();
private string _epicGameIconPath;
//private string _epicURI;
private static readonly EpicLibrary _epicGameLibrary = EpicLibrary.GetLibrary();
@ -90,13 +91,19 @@ namespace DisplayMagician.GameLibraries
set => _epicGameProcessName = value;
}
public override List<Process> Processes
{
get => _epicGameProcesses;
set => _epicGameProcesses = value;
}
public override bool IsRunning
{
get
{
int numGameProcesses = 0;
List<Process> gameProcesses = Process.GetProcessesByName(_epicGameProcessName).ToList();
foreach (Process gameProcess in gameProcesses)
_epicGameProcesses = Process.GetProcessesByName(_epicGameProcessName).ToList();
foreach (Process gameProcess in _epicGameProcesses)
{
try
{

View File

@ -556,7 +556,7 @@ namespace DisplayMagician.GameLibraries
return true;
}
public override Process StartGame(Game game, string gameArguments = "")
public override Process StartGame(Game game, string gameArguments = "", ProcessPriorityClass processPriority = ProcessPriorityClass.Normal)
{
string address = $@"com.epicgames.launcher://apps/{game.Id}?action=launch&silent=true";
if (String.IsNullOrWhiteSpace(gameArguments))
@ -564,6 +564,7 @@ namespace DisplayMagician.GameLibraries
address += "/" + gameArguments;
}
Process gameProcess = Process.Start(address);
gameProcess.PriorityClass = processPriority;
return gameProcess;
}

View File

@ -16,6 +16,7 @@ namespace DisplayMagician.GameLibraries
private string _gogGameDir;
private string _gogGameExe;
private string _gogGameProcessName;
private List<Process> _gogGameProcesses = new List<Process>();
private string _gogGameIconPath;
//private string _gogURI;
private static readonly GogLibrary _gogGameLibrary = GogLibrary.GetLibrary();
@ -90,13 +91,19 @@ namespace DisplayMagician.GameLibraries
set => _gogGameProcessName = value;
}
public override List<Process> Processes
{
get => _gogGameProcesses;
set => _gogGameProcesses = value;
}
public override bool IsRunning
{
get
{
int numGameProcesses = 0;
List<Process> gameProcesses = Process.GetProcessesByName(_gogGameProcessName).ToList();
foreach (Process gameProcess in gameProcesses)
_gogGameProcesses = Process.GetProcessesByName(_gogGameProcessName).ToList();
foreach (Process gameProcess in _gogGameProcesses)
{
try
{

View File

@ -551,15 +551,20 @@ namespace DisplayMagician.GameLibraries
return true;
}
public override Process StartGame(Game game, string gameArguments = "")
{
public override Process StartGame(Game game, string gameArguments = "", ProcessPriorityClass processPriority = ProcessPriorityClass.Normal)
{
string args = $@"/command=runGame /gameId={game.Id} /path=""{game.Directory}""";
if (String.IsNullOrWhiteSpace(gameArguments))
{
args += gameArguments;
}
Process gameProcess = Process.Start(_gogExe,args);
Process gameProcess = null;
uint processID = 0;
if (ProcessUtils.LaunchProcessWithPriority(_gogExe, args, processPriority, out processID))
{
gameProcess = Process.GetProcessById((int)processID);
}
return gameProcess;
}
#endregion

View File

@ -1,4 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
namespace DisplayMagician.GameLibraries
@ -29,6 +31,8 @@ namespace DisplayMagician.GameLibraries
public virtual string ProcessName { get; set; }
public virtual List<Process> Processes { get; set; }
public Bitmap GameBitmap { get; set; }
#endregion

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using DisplayMagician;
namespace DisplayMagician.GameLibraries
{
@ -102,7 +103,7 @@ namespace DisplayMagician.GameLibraries
return false;
}
public virtual Process StartGame(Game game, string gameArguments = "")
public virtual Process StartGame(Game game, string gameArguments = "", ProcessPriorityClass processPriority = ProcessPriorityClass.Normal)
{
return null;
}

View File

@ -16,6 +16,7 @@ namespace DisplayMagician.GameLibraries
private string _originGameDir;
private string _originGameExe;
private string _originGameProcessName;
private List<Process> _originGameProcesses = new List<Process>();
private string _originGameIconPath;
//private string _originURI;
private static readonly OriginLibrary _originGameLibrary = OriginLibrary.GetLibrary();
@ -89,13 +90,19 @@ namespace DisplayMagician.GameLibraries
set => _originGameProcessName = value;
}
public override List<Process> Processes
{
get => _originGameProcesses;
set => _originGameProcesses = value;
}
public override bool IsRunning
{
get
{
int numGameProcesses = 0;
List<Process> gameProcesses = Process.GetProcessesByName(_originGameProcessName).ToList();
foreach (Process gameProcess in gameProcesses)
_originGameProcesses = Process.GetProcessesByName(_originGameProcessName).ToList();
foreach (Process gameProcess in _originGameProcesses)
{
try
{

View File

@ -738,7 +738,7 @@ namespace DisplayMagician.GameLibraries
return true;
}
public override Process StartGame(Game game, string gameArguments = "")
public override Process StartGame(Game game, string gameArguments = "", ProcessPriorityClass processPriority = ProcessPriorityClass.Normal)
{
string address = $"origin2://game/launch?offerIds={game.Id}";
if (String.IsNullOrWhiteSpace(gameArguments))
@ -746,8 +746,10 @@ namespace DisplayMagician.GameLibraries
address += "/" + gameArguments;
}
Process gameProcess = Process.Start(address);
gameProcess.PriorityClass = processPriority;
return gameProcess;
}
#endregion
}

View File

@ -19,6 +19,7 @@ namespace DisplayMagician.GameLibraries
private string _steamGameDir;
private string _steamGameExe;
private string _steamGameProcessName;
private List<Process> _steamGameProcesses = new List<Process>();
private string _steamGameIconPath;
private static readonly SteamLibrary _steamGameLibrary = SteamLibrary.GetLibrary();
private static readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
@ -88,13 +89,19 @@ namespace DisplayMagician.GameLibraries
set => _steamGameProcessName = value;
}
public override List<Process> Processes
{
get => _steamGameProcesses;
set => _steamGameProcesses = value;
}
public override bool IsRunning
{
get
{
int numGameProcesses = 0;
List<Process> gameProcesses = Process.GetProcessesByName(_steamGameProcessName).ToList();
foreach (Process gameProcess in gameProcesses)
_steamGameProcesses = Process.GetProcessesByName(_steamGameProcessName).ToList();
foreach (Process gameProcess in _steamGameProcesses)
{
try
{

View File

@ -755,14 +755,15 @@ namespace DisplayMagician.GameLibraries
}
public override Process StartGame(Game game, string gameArguments = "")
public override Process StartGame(Game game, string gameArguments = "", ProcessPriorityClass processPriority = ProcessPriorityClass.Normal)
{
string address = $"steam://rungameid/{game.Id}";
string address = $@"steam://rungameid/{game.Id}";
if (!String.IsNullOrWhiteSpace(gameArguments))
{
address += "/" + gameArguments;
address += @"//" + gameArguments;
}
Process gameProcess = Process.Start(address);
gameProcess.PriorityClass = processPriority;
return gameProcess;
}
#endregion

View File

@ -17,6 +17,7 @@ namespace DisplayMagician.GameLibraries
private string _uplayGameDir;
private string _uplayGameExe;
private string _uplayGameProcessName;
private List<Process> _uplayGameProcesses = new List<Process>();
private string _uplayGameIconPath;
private static readonly UplayLibrary _uplayGameLibrary = UplayLibrary.GetLibrary();
private static readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
@ -88,13 +89,19 @@ namespace DisplayMagician.GameLibraries
set => _uplayGameProcessName = value;
}
public override List<Process> Processes
{
get => _uplayGameProcesses;
set => _uplayGameProcesses = value;
}
public override bool IsRunning
{
get
{
int numGameProcesses = 0;
List<Process> gameProcesses = Process.GetProcessesByName(_uplayGameProcessName).ToList();
foreach (Process gameProcess in gameProcesses)
_uplayGameProcesses = Process.GetProcessesByName(_uplayGameProcessName).ToList();
foreach (Process gameProcess in _uplayGameProcesses)
{
try
{

View File

@ -717,18 +717,19 @@ namespace DisplayMagician.GameLibraries
return true;
}
public override Process StartGame(Game game, string gameArguments = "")
public override Process StartGame(Game game, string gameArguments = "", ProcessPriorityClass processPriority = ProcessPriorityClass.Normal)
{
string address = $"uplay://launch/{game.Id}";
string address = $@"uplay://launch/{game.Id}";
if (String.IsNullOrWhiteSpace(gameArguments))
{
address += "/" + gameArguments;
address += @"/" + gameArguments;
}
else
{
address += "/0";
}
Process gameProcess = Process.Start(address);
gameProcess.PriorityClass = processPriority;
return gameProcess;
}

View File

@ -4,12 +4,87 @@ using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Management;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace DisplayMagician
{
[Flags]
public enum ProcessCreationFlags : uint
{
ZERO_FLAG = 0x00000000,
CREATE_BREAKAWAY_FROM_JOB = 0x01000000,
CREATE_DEFAULT_ERROR_MODE = 0x04000000,
CREATE_NEW_CONSOLE = 0x00000010,
CREATE_NEW_PROCESS_GROUP = 0x00000200,
CREATE_NO_WINDOW = 0x08000000,
CREATE_PROTECTED_PROCESS = 0x00040000,
CREATE_PRESERVE_CODE_AUTHZ_LEVEL = 0x02000000,
CREATE_SEPARATE_WOW_VDM = 0x00001000,
CREATE_SHARED_WOW_VDM = 0x00001000,
CREATE_SUSPENDED = 0x00000004,
CREATE_UNICODE_ENVIRONMENT = 0x00000400,
DEBUG_ONLY_THIS_PROCESS = 0x00000002,
DEBUG_PROCESS = 0x00000001,
DETACHED_PROCESS = 0x00000008,
EXTENDED_STARTUPINFO_PRESENT = 0x00080000,
INHERIT_PARENT_AFFINITY = 0x00010000,
// Process creations flags
ABOVE_NORMAL_PRIORITY_CLASS = 0x00008000,
BELOW_NORMAL_PRIORITY_CLASS = 0x00004000,
HIGH_PRIORITY_CLASS = 0x00000080,
IDLE_PRIORITY_CLASS = 0x00000040,
NORMAL_PRIORITY_CLASS = 0x00000020,
REALTIME_PRIORITY_CLASS = 0x00000100,
}
public struct PROCESS_INFORMATION
{
public IntPtr hProcess;
public IntPtr hThread;
public uint dwProcessId;
public uint dwThreadId;
}
public struct STARTUPINFO
{
public uint cb;
public string lpReserved;
public string lpDesktop;
public string lpTitle;
public uint dwX;
public uint dwY;
public uint dwXSize;
public uint dwYSize;
public uint dwXCountChars;
public uint dwYCountChars;
public uint dwFillAttribute;
public uint dwFlags;
public short wShowWindow;
public short cbReserved2;
public IntPtr lpReserved2;
public IntPtr hStdInput;
public IntPtr hStdOutput;
public IntPtr hStdError;
}
public static class NativeMethods
{
[DllImport("kernel32.dll")]
public static extern bool CreateProcess(string lpApplicationName, string lpCommandLine, IntPtr lpProcessAttributes, IntPtr lpThreadAttributes,
bool bInheritHandles, ProcessCreationFlags dwCreationFlags, IntPtr lpEnvironment,
string lpCurrentDirectory, ref STARTUPINFO lpStartupInfo, out PROCESS_INFORMATION lpProcessInformation);
[DllImport("kernel32.dll")]
public static extern uint ResumeThread(IntPtr hThread);
[DllImport("kernel32.dll")]
public static extern uint SuspendThread(IntPtr hThread);
}
class ProcessInfo : IComparable<ProcessInfo>
{
public Process TheProcess;
@ -38,6 +113,7 @@ namespace DisplayMagician
{
private static Dictionary<int, ProcessInfo> allProcessInfosDict;
private static readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
private static IntPtr ThreadHandle = IntPtr.Zero;
public static void Initialise()
{
@ -170,5 +246,77 @@ namespace DisplayMagician
}
return false;
}
public static ProcessPriorityClass TranslatePriorityToClass(ProcessPriority processPriorityClass)
{
ProcessPriorityClass wantedPriorityClass = ProcessPriorityClass.Normal;
switch (processPriorityClass)
{
case ProcessPriority.High:
wantedPriorityClass = ProcessPriorityClass.High;
break;
case ProcessPriority.AboveNormal:
wantedPriorityClass = ProcessPriorityClass.AboveNormal;
break;
case ProcessPriority.Normal:
wantedPriorityClass = ProcessPriorityClass.Normal;
break;
case ProcessPriority.BelowNormal:
wantedPriorityClass = ProcessPriorityClass.BelowNormal;
break;
case ProcessPriority.Idle:
wantedPriorityClass = ProcessPriorityClass.Idle;
break;
default:
wantedPriorityClass = ProcessPriorityClass.Normal;
break;
}
return wantedPriorityClass;
}
public static ProcessCreationFlags TranslatePriorityClassToFlags(ProcessPriorityClass processPriorityClass)
{
ProcessCreationFlags wantedPriorityClass = ProcessCreationFlags.NORMAL_PRIORITY_CLASS;
switch (processPriorityClass)
{
case ProcessPriorityClass.High:
wantedPriorityClass = ProcessCreationFlags.HIGH_PRIORITY_CLASS;
break;
case ProcessPriorityClass.AboveNormal:
wantedPriorityClass = ProcessCreationFlags.ABOVE_NORMAL_PRIORITY_CLASS;
break;
case ProcessPriorityClass.Normal:
wantedPriorityClass = ProcessCreationFlags.NORMAL_PRIORITY_CLASS;
break;
case ProcessPriorityClass.BelowNormal:
wantedPriorityClass = ProcessCreationFlags.BELOW_NORMAL_PRIORITY_CLASS;
break;
case ProcessPriorityClass.Idle:
wantedPriorityClass = ProcessCreationFlags.IDLE_PRIORITY_CLASS;
break;
default:
wantedPriorityClass = ProcessCreationFlags.NORMAL_PRIORITY_CLASS;
break;
}
return wantedPriorityClass;
}
public static bool LaunchProcessWithPriority(string exeName, string cmdLine, ProcessPriorityClass priorityClass, out uint PID)
{
ProcessCreationFlags processFlags = TranslatePriorityClassToFlags(priorityClass);
STARTUPINFO si = new STARTUPINFO();
PROCESS_INFORMATION pi = new PROCESS_INFORMATION();
bool success = NativeMethods.CreateProcess(exeName, cmdLine, IntPtr.Zero, IntPtr.Zero, false, processFlags, IntPtr.Zero, null, ref si, out pi);
ThreadHandle = pi.hThread;
PID = pi.dwProcessId;
return success;
}
public static void ResumeProcess()
{
NativeMethods.ResumeThread(ThreadHandle);
}
}
}

View File

@ -31,6 +31,7 @@ namespace DisplayMagician {
public static string AppIconPath = Path.Combine(Program.AppDataPath, $"Icons");
public static string AppProfilePath = Path.Combine(Program.AppDataPath, $"Profiles");
public static string AppShortcutPath = Path.Combine(Program.AppDataPath, $"Shortcuts");
public static string AppWallpaperPath = Path.Combine(Program.AppDataPath, $"Wallpaper");
public static string AppLogPath = Path.Combine(Program.AppDataPath, $"Logs");
public static string AppDisplayMagicianIconFilename = Path.Combine(AppIconPath, @"DisplayMagician.ico");
public static string AppOriginIconFilename = Path.Combine(AppIconPath, @"Origin.ico");
@ -184,6 +185,17 @@ namespace DisplayMagician {
logger.Error(ex, $"Program/StartUpNormally exception: Cannot create the Application Shortcut Folder {AppShortcutPath}");
}
}
if (!Directory.Exists(AppWallpaperPath))
{
try
{
Directory.CreateDirectory(AppWallpaperPath);
}
catch (Exception ex)
{
logger.Error(ex, $"Program/StartUpNormally exception: Cannot create the Application Wallpaper Folder {AppWallpaperPath}");
}
}
// Write the Application Name
Console.WriteLine($"{Application.ProductName} v{Application.ProductVersion}");

View File

@ -19,32 +19,41 @@ using TsudaKageyu;
namespace DisplayMagician
{
public enum ShortcutPermanence
public enum ShortcutPermanence : int
{
Permanent,
Temporary,
Permanent = 0,
Temporary = 1,
}
public enum ShortcutCategory
public enum ShortcutCategory : int
{
Application,
Game,
NoGame,
Application = 0,
Game = 1,
NoGame = 2,
}
public enum ShortcutValidity
public enum ShortcutValidity : int
{
Valid,
Warning,
Error,
Valid = 0,
Warning = 1,
Error = 2,
}
public enum ProcessPriority : int
{
High = 2,
AboveNormal = 1,
Normal = 0,
BelowNormal =-1,
Idle = -24,
}
public struct StartProgram
{
public int Priority;
public bool Disabled;
public ProcessPriority ProcessPriority;
public string Executable;
public string Arguments;
public bool ExecutableArgumentsRequired;
@ -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
@ -732,13 +757,8 @@ namespace DisplayMagician
// Now we need to find and populate the profileUuid
_profileUuid = profile.UUID;
_originalBitmap = profile.ProfileBitmap;
// We create the ShortcutBitmap from the OriginalBitmap
// (We only do it if there is a valid profile)
//if (_profileToUse is ProfileItem)
// _shortcutBitmap = ToBitmapOverlay(_originalBitmap, _profileToUse.ProfileTightestBitmap, 256, 256);
_shortcutBitmap = profile.ProfileBitmap;
ReplaceShortcutIconInCache();
RefreshValidity();
@ -782,6 +802,7 @@ namespace DisplayMagician
_gameArgumentsRequired = game.GameArgumentsRequired;
_differentGameExeToMonitor = game.DifferentGameExeToMonitor;
_monitorDifferentGameExe = game.MonitorDifferentGameExe;
_processPriority = game.ProcessPriority;
_changeAudioDevice = changeAudioDevice;
_audioDevice = audioDevice;
_setAudioVolume = setAudioVolume;
@ -855,6 +876,7 @@ namespace DisplayMagician
_executableArguments = executable.ExecutableArguments;
_executableArgumentsRequired = executable.ExecutableArgumentsRequired;
_processNameToMonitorUsesExecutable = executable.ProcessNameToMonitorUsesExecutable;
_processPriority = executable.ProcessPriority;
_changeAudioDevice = changeAudioDevice;
_audioDevice = audioDevice;
_setAudioVolume = setAudioVolume;
@ -910,6 +932,7 @@ namespace DisplayMagician
shortcut.ExecutableArguments = ExecutableArguments;
shortcut.ExecutableArgumentsRequired = ExecutableArgumentsRequired;
shortcut.ProcessNameToMonitorUsesExecutable = ProcessNameToMonitorUsesExecutable;
shortcut.ProcessPriority = ProcessPriority;
shortcut.GameAppId = GameAppId;
shortcut.GameName = GameName;
shortcut.GameLibrary = GameLibrary;
@ -1504,14 +1527,7 @@ namespace DisplayMagician
{
if (AutoName && _profileToUse is ProfileItem)
{
if (Category.Equals(ShortcutCategory.NoGame))
{
if (DisplayPermanence.Equals(ShortcutPermanence.Permanent))
_name = $"{_profileToUse.Name}";
else if (DisplayPermanence.Equals(ShortcutPermanence.Temporary))
_name = $"{_profileToUse.Name} (Temporary)";
}
else if (Category.Equals(ShortcutCategory.Game) && GameName.Length > 0)
if (Category.Equals(ShortcutCategory.Game) && GameName.Length > 0)
{
_name = $"{GameName} ({_profileToUse.Name})";
}
@ -1520,6 +1536,13 @@ namespace DisplayMagician
string baseName = Path.GetFileNameWithoutExtension(ExecutableNameAndPath);
_name = $"{baseName} ({_profileToUse.Name})";
}
else
{
if (DisplayPermanence.Equals(ShortcutPermanence.Permanent))
_name = $"{_profileToUse.Name}";
else if (DisplayPermanence.Equals(ShortcutPermanence.Temporary))
_name = $"{_profileToUse.Name} (Temporary)";
}
}
}

View File

@ -377,7 +377,15 @@ namespace DisplayMagician
// Replace any "Enabled": true with "Disabled": false
json = Regex.Replace(json, @" ""Enabled"": true,", @" ""Disabled"": false,");
// Replace any "Enabled": false with "Disabled": true
json = Regex.Replace(json, @" ""Enabled"": false,", @" ""Disabled"": true,");
json = Regex.Replace(json, @" ""Enabled"": false,", @" ""Disabled"": true,");
// If the shortcuts file doesn't have "ProcessPriority" in it, then we need to add it
if (!Regex.Match(json, @"""ProcessPriority""").Success)
{
// Add the ProcessPriority line as null so its in there at least and won't stop the json load
json = Regex.Replace(json, " \"DifferentExecutableToMonitor\"", " \"ProcessPriority\": null,\n \"DifferentExecutableToMonitor\"");
}
}
catch(Exception ex)
{
@ -400,7 +408,8 @@ namespace DisplayMagician
}
catch (Exception ex)
{
logger.Error(ex, $"ShortcutRepository/LoadShortcuts: Tried to parse the JSON in the {_shortcutStorageJsonFileName} but the JsonConvert threw an exception.");
logger.Error(ex, $"ShortcutRepository/LoadShortcuts: Tried to parse the JSON in the {_shortcutStorageJsonFileName} but the JsonConvert threw an exception. There is an error in the SHortcut JSON file!");
throw new Exception("ShortcutRepository/LoadShortcuts: Tried to parse the JSON in the {_shortcutStorageJsonFileName} but the JsonConvert threw an exception. There is an error in the SHortcut JSON file!");
}
// Lookup all the Profile Names in the Saved Profiles
@ -524,6 +533,34 @@ namespace DisplayMagician
}
}
private static ProcessPriorityClass TranslatePriorityClassToClass(ProcessPriority processPriority)
{
ProcessPriorityClass wantedPriorityClass = ProcessPriorityClass.Normal;
switch (processPriority.ToString("G"))
{
case "High":
wantedPriorityClass = ProcessPriorityClass.High;
break;
case "AboveNormal":
wantedPriorityClass = ProcessPriorityClass.AboveNormal;
break;
case "Normal":
wantedPriorityClass = ProcessPriorityClass.Normal;
break;
case "BelowNormal":
wantedPriorityClass = ProcessPriorityClass.BelowNormal;
break;
case "Idle":
wantedPriorityClass = ProcessPriorityClass.Idle;
break;
default:
wantedPriorityClass = ProcessPriorityClass.Normal;
break;
}
return wantedPriorityClass;
}
// ReSharper disable once CyclomaticComplexity
public static void RunShortcut(ShortcutItem shortcutToUse, NotifyIcon notifyIcon = null)
@ -766,6 +803,20 @@ namespace DisplayMagician
if (alreadyRunningProcesses.Length > 0)
{
logger.Info($"ShortcutRepository/RunShortcut: Process {processToStart.Executable} is already running, so we won't start a new one, and we won't stop it later");
try
{
foreach (Process runningProcess in alreadyRunningProcesses)
{
logger.Trace($"ShortcutRepository/RunShortcut: Setting priority of already running process {processToStart.Executable} to {processToStart.ProcessPriority.ToString("G")}");
runningProcess.PriorityClass = TranslatePriorityClassToClass(processToStart.ProcessPriority);
}
}
catch (Exception ex)
{
logger.Warn(ex, $"ShortcutRepository/RunShortcut: Exception setting priority of already running process {processToStart.Executable} to {processToStart.ProcessPriority.ToString("G")}");
}
continue;
}
@ -776,11 +827,35 @@ namespace DisplayMagician
Process process = null;
try
{
if (processToStart.ExecutableArgumentsRequired)
uint processID = 0;
if (ProcessUtils.LaunchProcessWithPriority(processToStart.Executable, processToStart.Arguments, ProcessUtils.TranslatePriorityToClass(processToStart.ProcessPriority), out processID))
{
process = Process.GetProcessById((int)processID);
}
/*if (processToStart.ExecutableArgumentsRequired)
{
process = System.Diagnostics.Process.Start(processToStart.Executable, processToStart.Arguments);
}
else
{
process = System.Diagnostics.Process.Start(processToStart.Executable);
// Record t
}*/
/*try
{
// Attempt to set the process priority to whatever the user wanted
logger.Trace($"ShortcutRepository/RunShortcut: Setting the start program process priority of start program we started to {shortcutToUse.ProcessPriority.ToString("G")}");
process.PriorityClass = TranslatePriorityClass(processToStart.ProcessPriority);
}
catch (Exception ex)
{
logger.Warn(ex, $"ShortcutRepository/RunShortcut: Exception setting the start program process priority of start program we started to {shortcutToUse.ProcessPriority.ToString("G")}");
}*/
// Record the program we started so we can close it later
if (processToStart.CloseOnFinish)
{
logger.Debug($"ShortcutRepository/RunShortcut: We need to stop {processToStart.Executable} after the main game or executable is closed.");
@ -883,10 +958,20 @@ namespace DisplayMagician
try
{
Process process = null;
if (shortcutToUse.ExecutableArgumentsRequired)
/*if (shortcutToUse.ExecutableArgumentsRequired)
{
process = System.Diagnostics.Process.Start(shortcutToUse.ExecutableNameAndPath, shortcutToUse.ExecutableArguments);
}
else
{
process = System.Diagnostics.Process.Start(shortcutToUse.ExecutableNameAndPath);
}*/
uint processID = 0;
if (ProcessUtils.LaunchProcessWithPriority(shortcutToUse.ExecutableNameAndPath, shortcutToUse.ExecutableArguments, ProcessUtils.TranslatePriorityToClass(shortcutToUse.ProcessPriority), out processID))
{
process = Process.GetProcessById((int)processID);
}
}
catch (Win32Exception ex)
{
@ -932,6 +1017,20 @@ namespace DisplayMagician
if (processesToMonitor.Count > 0)
{
logger.Debug($"ShortcutRepository/RunShortcut: Found {processesToMonitor.Count} '{processNameToLookFor}' processes to monitor");
try
{
foreach (Process monitoredProcess in processesToMonitor)
{
logger.Trace($"ShortcutRepository/RunShortcut: Setting priority of monitored executable process {processNameToLookFor} to {shortcutToUse.ProcessPriority.ToString("G")}");
monitoredProcess.PriorityClass = TranslatePriorityClassToClass(shortcutToUse.ProcessPriority);
}
}
catch(Exception ex)
{
logger.Warn(ex, $"ShortcutRepository/RunShortcut: Exception Setting priority of monitored executable process {processNameToLookFor} to {shortcutToUse.ProcessPriority.ToString("G")}");
}
break;
}
@ -1029,6 +1128,8 @@ namespace DisplayMagician
}
else if (shortcutToUse.Category.Equals(ShortcutCategory.Game))
{
logger.Info($"ShortcutRepository/RunShortcut: Starting the game that we wanted to run, and that we're going to monitor and watch");
Game gameToRun = null;
GameLibrary gameLibraryToUse = null;
@ -1089,7 +1190,7 @@ namespace DisplayMagician
Process gameProcess;
//string gameRunCmd = gameLibraryToUse.GetRunCmd(gameToRun, shortcutToUse.GameArguments);
//gameProcess = Process.Start(gameRunCmd);
gameProcess = gameLibraryToUse.StartGame(gameToRun, shortcutToUse.GameArguments);
gameProcess = gameLibraryToUse.StartGame(gameToRun, shortcutToUse.GameArguments, ProcessUtils.TranslatePriorityToClass(shortcutToUse.ProcessPriority));
// Delay 500ms
Thread.Sleep(500);
@ -1231,6 +1332,20 @@ namespace DisplayMagician
if (processesToMonitor.Count > 0)
{
logger.Debug($"ShortcutRepository/RunShortcut: Found {processesToMonitor.Count} '{altGameProcessToMonitor}' processes to monitor");
try
{
foreach (Process monitoredProcess in processesToMonitor)
{
logger.Trace($"ShortcutRepository/RunShortcut: Setting priority of alternative game monitored process {altGameProcessToMonitor} to {shortcutToUse.ProcessPriority.ToString("G")}");
monitoredProcess.PriorityClass = TranslatePriorityClassToClass(shortcutToUse.ProcessPriority);
}
}
catch (Exception ex)
{
logger.Warn(ex, $"ShortcutRepository/RunShortcut: Setting priority of alternative game monitored process {altGameProcessToMonitor} to {shortcutToUse.ProcessPriority.ToString("G")}");
}
break;
}
@ -1238,7 +1353,7 @@ namespace DisplayMagician
// any processes yet
Thread.Sleep(500);
}
// make sure we have an alternative game executable to monitor
// if none of the different game exe files are running, then we need a fallback
if (processesToMonitor.Count == 0)
{
// if we didn't find an alternative game exectuable to monitor, then we need to go for the game executable itself as a fall back
@ -1253,6 +1368,20 @@ namespace DisplayMagician
{
// The game is running! So now we continue processing
logger.Debug($"ShortcutRepository/RunShortcut: Found the '{gameToRun.Name}' process has started");
try
{
foreach (Process monitoredProcess in gameToRun.Processes)
{
logger.Trace($"ShortcutRepository/RunShortcut: Setting priority of fallback game monitored process {gameToRun.ProcessName} to {shortcutToUse.ProcessPriority.ToString("G")}");
monitoredProcess.PriorityClass = TranslatePriorityClassToClass(shortcutToUse.ProcessPriority);
}
}
catch (Exception ex)
{
logger.Warn(ex, $"ShortcutRepository/RunShortcut: Exception setting priority of fallback game monitored process {gameToRun.ProcessName} to {shortcutToUse.ProcessPriority.ToString("G")}");
}
break;
}
@ -1288,7 +1417,7 @@ namespace DisplayMagician
else
{
// The game has started correctly so we continue to monitor it!
// Tell the user
// Now we want to tell the user we're running a game!
// Construct the Windows toast content
@ -1348,7 +1477,7 @@ namespace DisplayMagician
}
else
{
// we found alternative game executable processes, so we'll just monitor them
// Otherwise we did find the alternative game executables supplied by the user, so we should monitor them
logger.Debug($"ShortcutRepository/RunShortcut: Waiting for alternative game proocess {altGameProcessToMonitor} to exit.");
logger.Debug($"ShortcutRepository/RunShortcut: {processesToMonitor.Count} Alternative Game Executable '{altGameProcessToMonitor}' processes are still running");
@ -1410,7 +1539,7 @@ namespace DisplayMagician
else
{
// we are monitoring the game thats actually running (the most common scenario)
// Add a status notification icon in the status area
if (gameToRun.Name.Length <= 41)
notifyIcon.Text = $"DisplayMagician: Running {gameToRun.Name}...";
@ -1447,6 +1576,20 @@ namespace DisplayMagician
{
// The game is running! So now we continue processing
logger.Debug($"ShortcutRepository/RunShortcut: Found the '{gameToRun.Name}' process has started");
try
{
foreach (Process monitoredProcess in gameToRun.Processes)
{
logger.Trace($"ShortcutRepository/RunShortcut: Setting priority of fallback game monitored process {gameToRun.ProcessName} to {shortcutToUse.ProcessPriority.ToString("G")}");
monitoredProcess.PriorityClass = TranslatePriorityClassToClass(shortcutToUse.ProcessPriority);
}
}
catch(Exception ex)
{
logger.Warn(ex, $"ShortcutRepository/RunShortcut: Exception setting priority of fallback game monitored process {gameToRun.ProcessName} to {shortcutToUse.ProcessPriority.ToString("G")}");
}
break;
}

View File

@ -392,6 +392,7 @@ namespace DisplayMagician.UIForms
this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
this.CancelButton = this.btn_back;
this.ClientSize = new System.Drawing.Size(976, 829);
this.Controls.Add(this.btn_profile_settings);
this.Controls.Add(this.lbl_hotkey_assigned);
this.Controls.Add(this.btn_hotkey);
this.Controls.Add(this.btn_save);

View File

@ -558,5 +558,17 @@ namespace DisplayMagician.UIForms
}
private void btn_profile_settings_Click(object sender, EventArgs e)
{
ProfileSettingsForm profileSettingsForm = new ProfileSettingsForm();
profileSettingsForm.Profile = _selectedProfile;
profileSettingsForm.ShowDialog(this);
// If the profile was previously saved and is now changed then save all the profiles
// otherwise we'll save it only when the user wants to save this profile.
if (_saveOrRenameMode == "rename" && profileSettingsForm.ProfileSettingChanged)
{
ProfileRepository.SaveProfiles();
}
}
}
}

View File

@ -0,0 +1,221 @@

namespace DisplayMagician.UIForms
{
partial class ProfileSettingsForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.btn_back = new System.Windows.Forms.Button();
this.gb_general = new System.Windows.Forms.GroupBox();
this.btn_current = new System.Windows.Forms.Button();
this.btn_clear = new System.Windows.Forms.Button();
this.pb_wallpaper = new System.Windows.Forms.PictureBox();
this.btn_select = new System.Windows.Forms.Button();
this.cb_set_wallpaper = new System.Windows.Forms.CheckBox();
this.lbl_style = new System.Windows.Forms.Label();
this.cmb_wallpaper_display_mode = new System.Windows.Forms.ComboBox();
this.gb_general.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pb_wallpaper)).BeginInit();
this.SuspendLayout();
//
// btn_back
//
this.btn_back.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.btn_back.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btn_back.FlatAppearance.MouseDownBackColor = System.Drawing.Color.IndianRed;
this.btn_back.FlatAppearance.MouseOverBackColor = System.Drawing.Color.Brown;
this.btn_back.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btn_back.ForeColor = System.Drawing.Color.White;
this.btn_back.Location = new System.Drawing.Point(476, 380);
this.btn_back.Name = "btn_back";
this.btn_back.Size = new System.Drawing.Size(75, 23);
this.btn_back.TabIndex = 9;
this.btn_back.Text = "&Back";
this.btn_back.UseVisualStyleBackColor = true;
this.btn_back.Click += new System.EventHandler(this.btn_back_Click);
//
// gb_general
//
this.gb_general.Controls.Add(this.btn_current);
this.gb_general.Controls.Add(this.btn_clear);
this.gb_general.Controls.Add(this.pb_wallpaper);
this.gb_general.Controls.Add(this.btn_select);
this.gb_general.Controls.Add(this.cb_set_wallpaper);
this.gb_general.Controls.Add(this.lbl_style);
this.gb_general.Controls.Add(this.cmb_wallpaper_display_mode);
this.gb_general.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.gb_general.ForeColor = System.Drawing.Color.White;
this.gb_general.Location = new System.Drawing.Point(27, 21);
this.gb_general.Name = "gb_general";
this.gb_general.Size = new System.Drawing.Size(525, 337);
this.gb_general.TabIndex = 11;
this.gb_general.TabStop = false;
this.gb_general.Text = "Wallpaper Settings";
//
// btn_current
//
this.btn_current.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btn_current.Enabled = false;
this.btn_current.FlatAppearance.MouseDownBackColor = System.Drawing.Color.IndianRed;
this.btn_current.FlatAppearance.MouseOverBackColor = System.Drawing.Color.Brown;
this.btn_current.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btn_current.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.btn_current.ForeColor = System.Drawing.Color.White;
this.btn_current.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.btn_current.Location = new System.Drawing.Point(417, 158);
this.btn_current.Name = "btn_current";
this.btn_current.Size = new System.Drawing.Size(75, 23);
this.btn_current.TabIndex = 19;
this.btn_current.Text = "&Use Current";
this.btn_current.UseVisualStyleBackColor = true;
this.btn_current.Click += new System.EventHandler(this.btn_current_Click);
//
// btn_clear
//
this.btn_clear.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btn_clear.Enabled = false;
this.btn_clear.FlatAppearance.MouseDownBackColor = System.Drawing.Color.IndianRed;
this.btn_clear.FlatAppearance.MouseOverBackColor = System.Drawing.Color.Brown;
this.btn_clear.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btn_clear.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.btn_clear.ForeColor = System.Drawing.Color.White;
this.btn_clear.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.btn_clear.Location = new System.Drawing.Point(417, 187);
this.btn_clear.Name = "btn_clear";
this.btn_clear.Size = new System.Drawing.Size(75, 23);
this.btn_clear.TabIndex = 18;
this.btn_clear.Text = "&Clear";
this.btn_clear.UseVisualStyleBackColor = true;
this.btn_clear.Click += new System.EventHandler(this.btn_clear_Click);
//
// pb_wallpaper
//
this.pb_wallpaper.BackColor = System.Drawing.Color.White;
this.pb_wallpaper.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
this.pb_wallpaper.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.pb_wallpaper.Enabled = false;
this.pb_wallpaper.Location = new System.Drawing.Point(28, 68);
this.pb_wallpaper.Name = "pb_wallpaper";
this.pb_wallpaper.Size = new System.Drawing.Size(381, 212);
this.pb_wallpaper.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.pb_wallpaper.TabIndex = 17;
this.pb_wallpaper.TabStop = false;
//
// btn_select
//
this.btn_select.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btn_select.Enabled = false;
this.btn_select.FlatAppearance.MouseDownBackColor = System.Drawing.Color.IndianRed;
this.btn_select.FlatAppearance.MouseOverBackColor = System.Drawing.Color.Brown;
this.btn_select.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btn_select.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.btn_select.ForeColor = System.Drawing.Color.White;
this.btn_select.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.btn_select.Location = new System.Drawing.Point(417, 129);
this.btn_select.Name = "btn_select";
this.btn_select.Size = new System.Drawing.Size(75, 23);
this.btn_select.TabIndex = 16;
this.btn_select.Text = "&Select";
this.btn_select.UseVisualStyleBackColor = true;
this.btn_select.Click += new System.EventHandler(this.btn_select_wallpaper_Click);
//
// cb_set_wallpaper
//
this.cb_set_wallpaper.Anchor = System.Windows.Forms.AnchorStyles.Top;
this.cb_set_wallpaper.AutoSize = true;
this.cb_set_wallpaper.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F);
this.cb_set_wallpaper.ForeColor = System.Drawing.Color.White;
this.cb_set_wallpaper.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.cb_set_wallpaper.Location = new System.Drawing.Point(28, 36);
this.cb_set_wallpaper.Name = "cb_set_wallpaper";
this.cb_set_wallpaper.Size = new System.Drawing.Size(333, 20);
this.cb_set_wallpaper.TabIndex = 14;
this.cb_set_wallpaper.Text = "Apply this Wallpaper when using this Display Profile";
this.cb_set_wallpaper.UseVisualStyleBackColor = true;
this.cb_set_wallpaper.CheckedChanged += new System.EventHandler(this.cb_set_wallpaper_CheckedChanged);
//
// lbl_style
//
this.lbl_style.AutoSize = true;
this.lbl_style.Enabled = false;
this.lbl_style.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lbl_style.ForeColor = System.Drawing.Color.Transparent;
this.lbl_style.Location = new System.Drawing.Point(176, 291);
this.lbl_style.Name = "lbl_style";
this.lbl_style.Size = new System.Drawing.Size(44, 16);
this.lbl_style.TabIndex = 13;
this.lbl_style.Text = "Style: ";
//
// cmb_wallpaper_display_mode
//
this.cmb_wallpaper_display_mode.Enabled = false;
this.cmb_wallpaper_display_mode.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.cmb_wallpaper_display_mode.FormattingEnabled = true;
this.cmb_wallpaper_display_mode.Location = new System.Drawing.Point(226, 286);
this.cmb_wallpaper_display_mode.Name = "cmb_wallpaper_display_mode";
this.cmb_wallpaper_display_mode.Size = new System.Drawing.Size(183, 24);
this.cmb_wallpaper_display_mode.TabIndex = 12;
this.cmb_wallpaper_display_mode.SelectedIndexChanged += new System.EventHandler(this.cmb_wallpaper_display_mode_SelectedIndexChanged);
//
// ProfileSettingsForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.Black;
this.ClientSize = new System.Drawing.Size(580, 427);
this.Controls.Add(this.gb_general);
this.Controls.Add(this.btn_back);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "ProfileSettingsForm";
this.ShowIcon = false;
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Profile Settings";
this.TopMost = true;
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.ProfileSettingsForm_FormClosing);
this.Load += new System.EventHandler(this.ProfileSettingsForm_Load);
this.gb_general.ResumeLayout(false);
this.gb_general.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pb_wallpaper)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Button btn_back;
private System.Windows.Forms.GroupBox gb_general;
private System.Windows.Forms.CheckBox cb_set_wallpaper;
private System.Windows.Forms.Label lbl_style;
private System.Windows.Forms.ComboBox cmb_wallpaper_display_mode;
private System.Windows.Forms.Button btn_select;
private System.Windows.Forms.Button btn_clear;
private System.Windows.Forms.PictureBox pb_wallpaper;
private System.Windows.Forms.Button btn_current;
}
}

View File

@ -0,0 +1,278 @@
using DisplayMagicianShared;
//using Microsoft.Win32;
using NHotkey;
using NHotkey.WindowsForms;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Windows.Forms;
namespace DisplayMagician.UIForms
{
public partial class ProfileSettingsForm : Form
{
private static readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
private Dictionary<Wallpaper.Style, string> wallpaperStyleText = new Dictionary<Wallpaper.Style, string>();
Bitmap wallpaperImage = null;
private bool _profileSettingChanged = false;
public ProfileSettingsForm()
{
logger.Info($"ProfileSettingsForm/ProfileSettingsForm: Creating a ProfileSettingsForm UI Form");
InitializeComponent();
// Populate the Style dictionary
wallpaperStyleText.Add(Wallpaper.Style.Center, "Center the Wallpaper");
wallpaperStyleText.Add(Wallpaper.Style.Fill, "Fill the Wallpaper");
wallpaperStyleText.Add(Wallpaper.Style.Fit, "Fit the Wallpaper");
wallpaperStyleText.Add(Wallpaper.Style.Stretch, "Stretch the Wallpaper");
wallpaperStyleText.Add(Wallpaper.Style.Span, "Span the Wallpaper");
wallpaperStyleText.Add(Wallpaper.Style.Tile, "Tile the Wallpaper");
cmb_wallpaper_display_mode.DisplayMember = "Value";
cmb_wallpaper_display_mode.ValueMember = "Text";
cmb_wallpaper_display_mode.DataSource = new BindingSource(wallpaperStyleText, null);
}
public ProfileItem Profile
{
get;
set;
}
public bool ProfileSettingChanged
{
get
{
return _profileSettingChanged;
}
set
{
_profileSettingChanged = value;
}
}
private void ProfileSettingsForm_Load(object sender, EventArgs e)
{
if (Profile.SetWallpaper)
{
logger.Info($"ProfileSettingsForm/ProfileSettingsForm_Load: Profile {Profile.Name} has loaded with Set Wallpaper enabled and Wallpaper Style {Profile.WallpaperStyle.ToString("G")} and Wallpaper Filename of {Profile.WallpaperBitmapFilename}.");
cb_set_wallpaper.Checked = true;
cmb_wallpaper_display_mode.SelectedIndex = cmb_wallpaper_display_mode.FindStringExact(wallpaperStyleText[Profile.WallpaperStyle]);
if (Profile.WallpaperBitmapFilename != "" && File.Exists(Profile.WallpaperBitmapFilename))
{
// Load the existing Wallpaper into the PictureBox
//Read the contents of the file into a stream
FileStream fileStream = new FileStream(Profile.WallpaperBitmapFilename,FileMode.Open);
wallpaperImage = new Bitmap(fileStream);
fileStream.Close();
pb_wallpaper.Image = wallpaperImage;
}
}
else
{
cb_set_wallpaper.Checked = false;
}
}
private void ProfileSettingsForm_FormClosing(object sender, FormClosingEventArgs e)
{
Profile.SetWallpaper = cb_set_wallpaper.Checked;
Profile.WallpaperStyle = ((KeyValuePair<Wallpaper.Style, string>)cmb_wallpaper_display_mode.SelectedItem).Key;
}
private void btn_back_Click(object sender, EventArgs e)
{
// Check that if there isn't an image, and yet apply this profile checkbox is selected, then we need to unselect it to stop an error state
if (cb_set_wallpaper.Checked == true && (Profile.WallpaperBitmapFilename == "" || Profile.WallpaperBitmapFilename == null))
{
// We need to force turn off the application of the desktop wallpaper as it won't work
Profile.SetWallpaper = false;
Profile.WallpaperBitmapFilename = "";
cb_set_wallpaper.Checked = false;
}
this.Close();
}
private void cb_set_wallpaper_CheckedChanged(object sender, EventArgs e)
{
_profileSettingChanged = true;
if (cb_set_wallpaper.Checked)
{
// Enable all the things
pb_wallpaper.Enabled = true;
btn_select.Enabled = true;
btn_current.Enabled = true;
btn_clear.Enabled = true;
lbl_style.Enabled = true;
cmb_wallpaper_display_mode.Enabled = true;
}
else
{
// Disable all the things
pb_wallpaper.Enabled = false;
btn_select.Enabled = false;
btn_current.Enabled = false;
btn_clear.Enabled = false;
lbl_style.Enabled = false;
cmb_wallpaper_display_mode.Enabled = false;
}
}
private void cmb_wallpaper_display_mode_SelectedIndexChanged(object sender, EventArgs e)
{
_profileSettingChanged = true;
}
private void btn_select_wallpaper_Click(object sender, EventArgs e)
{
_profileSettingChanged = true;
string filePath = string.Empty;
string wallpaperPath = string.Empty;
try
{
using (OpenFileDialog openFileDialog = new OpenFileDialog())
{
openFileDialog.InitialDirectory = Environment.SpecialFolder.MyPictures.ToString();
openFileDialog.Filter = "Image Files(*.bmp; *.jpg; *.gif; *.png; *.tiff)| *.bmp; *.jpg; *.gif; *.png; *.tiff | All files(*.*) | *.*";
openFileDialog.FilterIndex = 2;
openFileDialog.RestoreDirectory = true;
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
//Get the path of specified file
filePath = openFileDialog.FileName;
wallpaperPath = Path.Combine(Program.AppWallpaperPath, $"wallpaper-{Profile.UUID}.jpg");
SharedLogger.logger.Trace($"ProfileSettingsForm/btn_select_wallpaper_Click: Storing desktop wallpaper {filePath} as {wallpaperPath} for use in profile {Profile.Name}");
//Read the contents of the file into a stream
Stream fileStream = openFileDialog.OpenFile();
// Create a bitmap
wallpaperImage = new Bitmap(fileStream);
// Save a copy of the bitmap as PNG
wallpaperImage.Save(wallpaperPath, ImageFormat.Png);
// Close the original file to free it up
fileStream.Close();
// Save the path of the saved wallpaper
Profile.WallpaperBitmapFilename = wallpaperPath;
// Show the wallpaper image so that the user can decide to use it
pb_wallpaper.Image = wallpaperImage;
}
}
}
catch (ArgumentNullException ex)
{
SharedLogger.logger.Warn(ex, $"ProfileSettingsForm/btn_select_wallpaper_Click: Argument Null Exception while while storing desktop wallpaper in {wallpaperPath}");
}
catch (System.Runtime.InteropServices.ExternalException ex)
{
SharedLogger.logger.Warn(ex, $"ProfileSettingsForm/btn_select_wallpaper_Click: External InteropServices Exception while while storing desktop wallpaper in {wallpaperPath}");
}
catch (Exception ex)
{
SharedLogger.logger.Warn(ex, $"ProfileSettingsForm/btn_select_wallpaper_Click: Exception while while storing desktop wallpaper in {wallpaperPath}");
}
}
private void btn_clear_Click(object sender, EventArgs e)
{
// clear the wallpaper sample picturebox
pb_wallpaper.Image = null;
// delete the saved wallpaper item
try
{
if (File.Exists(Profile.WallpaperBitmapFilename))
{
File.Delete(Profile.WallpaperBitmapFilename);
}
}
catch (Exception ex)
{
}
// Empty the file name in the Profile
Profile.WallpaperBitmapFilename = "";
}
private void btn_current_Click(object sender, EventArgs e)
{
SharedLogger.logger.Trace($"ProfileSettingsForm/btn_current_Click: User requested we get the current windows desktop wallpaper and add them to this display profile");
// Check if there is a current desktop wallpaper
Microsoft.Win32.RegistryKey wallpaperKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop", true);
string wallpaperLocation = (string)wallpaperKey.GetValue("WallPaper");
if (wallpaperLocation == null || wallpaperLocation == String.Empty)
{
// There is no current desktop wallpaper to use
SharedLogger.logger.Trace($"ProfileSettingsForm/btn_current_Click: There is no existing desktop wallpaper for us to use!");
MessageBox.Show("There isn't a desktop wallpaper currently being used in Windows, so we have nothing to use!","Cannot find Wallpaper",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
}
else
{
// Grab the current desktop wallpaper and save that with this profile
SharedLogger.logger.Trace($"ProfileSettingsForm/btn_current_Click: There IS an existing desktop wallpaper for us to use!");
// Figure out the stored filename we want
string savedWallpaperPath = Path.Combine(Program.AppWallpaperPath, $"wallpaper-{Profile.UUID}.jpg");
// Try and grab the file from the location listed in the wallpaper key
if (File.Exists(wallpaperLocation))
{
// If the file is there then great!, we can grab it and save a copy of it
SharedLogger.logger.Trace($"ProfileSettingsForm/btn_current_Click: The existing desktop wallpaper file {wallpaperLocation} exists");
File.Copy(wallpaperLocation, savedWallpaperPath);
}
else
{
// If the file doesn't exist, then we need to try another way to get it.
// We try the themes folder first
//% appdata %\Microsoft\Windows\Themes and look for TrancodedWallpaper, and just shove a .jpg on it
wallpaperLocation = Path.Combine(Environment.SpecialFolder.ApplicationData.ToString(), @"Microsoft\Windows\Themes\TranscodedWallpaper");
SharedLogger.logger.Trace($"ProfileSettingsForm/btn_current_Click: Now looking for the TranscodedWallpaper file in {wallpaperLocation}");
if (!File.Exists(wallpaperLocation))
{
SharedLogger.logger.Trace($"ProfileSettingsForm/btn_current_Click: The TranscodedWallpaper file does NOT exist in {wallpaperLocation}");
wallpaperLocation = Path.Combine(Environment.SpecialFolder.ApplicationData.ToString(), @"Microsoft\Windows\Themes\CachedFiles\TranscodedWallpaper");
if (!File.Exists(wallpaperLocation))
{
SharedLogger.logger.Trace($"ProfileSettingsForm/btn_current_Click: The TranscodedWallpaper file does NOT exist in {wallpaperLocation} either!");
return;
}
SharedLogger.logger.Trace($"ProfileSettingsForm/btn_current_Click: The TranscodedWallpaper file exists in {wallpaperLocation} (2nd try)");
}
else
{
SharedLogger.logger.Trace($"ProfileSettingsForm/btn_current_Click: The TranscodedWallpaper file exists in {wallpaperLocation}");
}
}
// Create an image from the wallpaper
wallpaperImage = new Bitmap(wallpaperLocation);
// Save a copy of the bitmap as PNG
wallpaperImage.Save(savedWallpaperPath, ImageFormat.Png);
// Save the path of the saved wallpaper
Profile.WallpaperBitmapFilename = savedWallpaperPath;
// Show the wallpaper image so that the user can decide to use it
pb_wallpaper.Image = wallpaperImage;
}
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

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);
@ -42,7 +41,6 @@ namespace DisplayMagician.UIForms
this.lbl_profile_shown_subtitle = new System.Windows.Forms.Label();
this.lbl_profile_shown = new System.Windows.Forms.Label();
this.ilv_saved_profiles = new Manina.Windows.Forms.ImageListView();
this.dv_profile = new DisplayMagicianShared.UserControls.DisplayView();
this.tabp_audio = new System.Windows.Forms.TabPage();
this.lbl_no_active_capture_devices = new System.Windows.Forms.Label();
this.lbl_no_active_audio_devices = new System.Windows.Forms.Label();
@ -68,12 +66,15 @@ 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_startprograms = 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();
this.tabp_game = new System.Windows.Forms.TabPage();
this.lbl_no_game_libraries = new System.Windows.Forms.Label();
this.p_standalone = new System.Windows.Forms.Panel();
this.cbx_exe_priority = new System.Windows.Forms.ComboBox();
this.lbl_exe_priority = new System.Windows.Forms.Label();
this.btn_exe_to_start = new System.Windows.Forms.Button();
this.txt_args_executable = new System.Windows.Forms.TextBox();
this.cb_args_executable = new System.Windows.Forms.CheckBox();
@ -88,13 +89,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 +118,8 @@ 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.dv_profile = new DisplayMagicianShared.UserControls.DisplayView();
this.btn_find_examples_game = new System.Windows.Forms.Button();
this.tabc_shortcut.SuspendLayout();
this.tabp_display.SuspendLayout();
this.tabp_audio.SuspendLayout();
@ -269,23 +271,6 @@ namespace DisplayMagician.UIForms
this.ilv_saved_profiles.View = Manina.Windows.Forms.View.HorizontalStrip;
this.ilv_saved_profiles.ItemClick += new Manina.Windows.Forms.ItemClickEventHandler(this.ilv_saved_profiles_ItemClick);
//
// dv_profile
//
this.dv_profile.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.dv_profile.BackColor = System.Drawing.Color.DimGray;
this.dv_profile.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.dv_profile.Font = new System.Drawing.Font("Consolas", 50F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.dv_profile.ForeColor = System.Drawing.Color.MidnightBlue;
this.dv_profile.Location = new System.Drawing.Point(0, 0);
this.dv_profile.Margin = new System.Windows.Forms.Padding(18);
this.dv_profile.Name = "dv_profile";
this.dv_profile.PaddingX = 100;
this.dv_profile.PaddingY = 100;
this.dv_profile.Profile = null;
this.dv_profile.Size = new System.Drawing.Size(1082, 467);
this.dv_profile.TabIndex = 23;
//
// tabp_audio
//
this.tabp_audio.BackColor = System.Drawing.Color.Black;
@ -616,7 +601,7 @@ namespace DisplayMagician.UIForms
// tabp_before
//
this.tabp_before.BackColor = System.Drawing.Color.Black;
this.tabp_before.Controls.Add(this.btn_find_examples);
this.tabp_before.Controls.Add(this.btn_find_examples_startprograms);
this.tabp_before.Controls.Add(this.label3);
this.tabp_before.Controls.Add(this.btn_add_new_start_program);
this.tabp_before.Controls.Add(this.flp_start_programs);
@ -629,6 +614,22 @@ namespace DisplayMagician.UIForms
this.tabp_before.TabIndex = 1;
this.tabp_before.Text = "3. Choose what happens before";
//
// btn_find_examples_startprograms
//
this.btn_find_examples_startprograms.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btn_find_examples_startprograms.FlatAppearance.MouseDownBackColor = System.Drawing.Color.IndianRed;
this.btn_find_examples_startprograms.FlatAppearance.MouseOverBackColor = System.Drawing.Color.Brown;
this.btn_find_examples_startprograms.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btn_find_examples_startprograms.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.btn_find_examples_startprograms.ForeColor = System.Drawing.Color.White;
this.btn_find_examples_startprograms.Location = new System.Drawing.Point(953, 72);
this.btn_find_examples_startprograms.Name = "btn_find_examples_startprograms";
this.btn_find_examples_startprograms.Size = new System.Drawing.Size(117, 25);
this.btn_find_examples_startprograms.TabIndex = 40;
this.btn_find_examples_startprograms.Text = "Show me &Examples";
this.btn_find_examples_startprograms.UseVisualStyleBackColor = true;
this.btn_find_examples_startprograms.Click += new System.EventHandler(this.btn_find_examples_startprograms_Click);
//
// label3
//
this.label3.AutoSize = true;
@ -672,6 +673,7 @@ namespace DisplayMagician.UIForms
// tabp_game
//
this.tabp_game.BackColor = System.Drawing.Color.Black;
this.tabp_game.Controls.Add(this.btn_find_examples_game);
this.tabp_game.Controls.Add(this.lbl_no_game_libraries);
this.tabp_game.Controls.Add(this.p_standalone);
this.tabp_game.Controls.Add(this.rb_standalone);
@ -705,6 +707,8 @@ namespace DisplayMagician.UIForms
//
// p_standalone
//
this.p_standalone.Controls.Add(this.cbx_exe_priority);
this.p_standalone.Controls.Add(this.lbl_exe_priority);
this.p_standalone.Controls.Add(this.btn_exe_to_start);
this.p_standalone.Controls.Add(this.txt_args_executable);
this.p_standalone.Controls.Add(this.cb_args_executable);
@ -722,6 +726,26 @@ namespace DisplayMagician.UIForms
this.p_standalone.Size = new System.Drawing.Size(1006, 160);
this.p_standalone.TabIndex = 10;
//
// cbx_exe_priority
//
this.cbx_exe_priority.AllowDrop = true;
this.cbx_exe_priority.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cbx_exe_priority.FormattingEnabled = true;
this.cbx_exe_priority.Location = new System.Drawing.Point(786, 83);
this.cbx_exe_priority.Name = "cbx_exe_priority";
this.cbx_exe_priority.Size = new System.Drawing.Size(179, 28);
this.cbx_exe_priority.TabIndex = 31;
//
// lbl_exe_priority
//
this.lbl_exe_priority.AutoSize = true;
this.lbl_exe_priority.ForeColor = System.Drawing.Color.White;
this.lbl_exe_priority.Location = new System.Drawing.Point(642, 86);
this.lbl_exe_priority.Name = "lbl_exe_priority";
this.lbl_exe_priority.Size = new System.Drawing.Size(143, 20);
this.lbl_exe_priority.TabIndex = 30;
this.lbl_exe_priority.Text = "Executable Priority:";
//
// btn_exe_to_start
//
this.btn_exe_to_start.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
@ -760,7 +784,7 @@ namespace DisplayMagician.UIForms
//
this.btn_choose_alternative_executable.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btn_choose_alternative_executable.ForeColor = System.Drawing.Color.White;
this.btn_choose_alternative_executable.Location = new System.Drawing.Point(877, 115);
this.btn_choose_alternative_executable.Location = new System.Drawing.Point(880, 121);
this.btn_choose_alternative_executable.Name = "btn_choose_alternative_executable";
this.btn_choose_alternative_executable.Size = new System.Drawing.Size(85, 27);
this.btn_choose_alternative_executable.TabIndex = 9;
@ -771,7 +795,7 @@ namespace DisplayMagician.UIForms
// txt_alternative_executable
//
this.txt_alternative_executable.Enabled = false;
this.txt_alternative_executable.Location = new System.Drawing.Point(493, 116);
this.txt_alternative_executable.Location = new System.Drawing.Point(496, 122);
this.txt_alternative_executable.Name = "txt_alternative_executable";
this.txt_alternative_executable.Size = new System.Drawing.Size(378, 26);
this.txt_alternative_executable.TabIndex = 4;
@ -781,7 +805,7 @@ namespace DisplayMagician.UIForms
//
this.rb_wait_alternative_executable.AutoSize = true;
this.rb_wait_alternative_executable.ForeColor = System.Drawing.Color.White;
this.rb_wait_alternative_executable.Location = new System.Drawing.Point(23, 118);
this.rb_wait_alternative_executable.Location = new System.Drawing.Point(23, 122);
this.rb_wait_alternative_executable.Name = "rb_wait_alternative_executable";
this.rb_wait_alternative_executable.Size = new System.Drawing.Size(468, 24);
this.rb_wait_alternative_executable.TabIndex = 8;
@ -795,7 +819,7 @@ namespace DisplayMagician.UIForms
this.rb_wait_executable.AutoSize = true;
this.rb_wait_executable.Checked = true;
this.rb_wait_executable.ForeColor = System.Drawing.Color.White;
this.rb_wait_executable.Location = new System.Drawing.Point(23, 87);
this.rb_wait_executable.Location = new System.Drawing.Point(23, 83);
this.rb_wait_executable.Name = "rb_wait_executable";
this.rb_wait_executable.Size = new System.Drawing.Size(439, 24);
this.rb_wait_executable.TabIndex = 7;
@ -879,13 +903,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 +921,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 +979,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 +987,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
//
@ -1041,10 +1067,10 @@ namespace DisplayMagician.UIForms
this.rb_launcher.ForeColor = System.Drawing.Color.White;
this.rb_launcher.Location = new System.Drawing.Point(15, 262);
this.rb_launcher.Name = "rb_launcher";
this.rb_launcher.Size = new System.Drawing.Size(332, 24);
this.rb_launcher.Size = new System.Drawing.Size(466, 24);
this.rb_launcher.TabIndex = 6;
this.rb_launcher.TabStop = true;
this.rb_launcher.Text = "Launch a Game installed in Steam or Uplay";
this.rb_launcher.Text = "Launch a Game installed in Steam, Origin, Uplay, Epic or GOG";
this.rb_launcher.UseVisualStyleBackColor = true;
this.rb_launcher.CheckedChanged += new System.EventHandler(this.rb_launcher_CheckedChanged);
//
@ -1263,21 +1289,38 @@ 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
// dv_profile
//
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);
this.dv_profile.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.dv_profile.BackColor = System.Drawing.Color.DimGray;
this.dv_profile.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.dv_profile.Font = new System.Drawing.Font("Consolas", 50F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.dv_profile.ForeColor = System.Drawing.Color.MidnightBlue;
this.dv_profile.Location = new System.Drawing.Point(0, 0);
this.dv_profile.Margin = new System.Windows.Forms.Padding(18);
this.dv_profile.Name = "dv_profile";
this.dv_profile.PaddingX = 100;
this.dv_profile.PaddingY = 100;
this.dv_profile.Profile = null;
this.dv_profile.Size = new System.Drawing.Size(1082, 467);
this.dv_profile.TabIndex = 23;
//
// btn_find_examples_game
//
this.btn_find_examples_game.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btn_find_examples_game.FlatAppearance.MouseDownBackColor = System.Drawing.Color.IndianRed;
this.btn_find_examples_game.FlatAppearance.MouseOverBackColor = System.Drawing.Color.Brown;
this.btn_find_examples_game.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btn_find_examples_game.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.btn_find_examples_game.ForeColor = System.Drawing.Color.White;
this.btn_find_examples_game.Location = new System.Drawing.Point(953, 17);
this.btn_find_examples_game.Name = "btn_find_examples_game";
this.btn_find_examples_game.Size = new System.Drawing.Size(117, 25);
this.btn_find_examples_game.TabIndex = 41;
this.btn_find_examples_game.Text = "Show me &Examples";
this.btn_find_examples_game.UseVisualStyleBackColor = true;
this.btn_find_examples_game.Click += new System.EventHandler(this.btn_find_examples_game_Click);
//
// ShortcutForm
//
@ -1297,7 +1340,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 +1401,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;
@ -1428,6 +1469,10 @@ namespace DisplayMagician.UIForms
private System.Windows.Forms.Button btn_add_new_start_program;
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.Button btn_find_examples_startprograms;
private System.Windows.Forms.ComboBox cbx_game_priority;
private System.Windows.Forms.ComboBox cbx_exe_priority;
private System.Windows.Forms.Label lbl_exe_priority;
private System.Windows.Forms.Button btn_find_examples_game;
}
}

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;
@ -82,7 +84,7 @@ namespace DisplayMagician.UIForms
ilv_games.ThumbnailSize = new Size(100, 100);
ilv_games.AllowDrag = false;
ilv_games.AllowDrop = false;
ilv_games.SetRenderer(new GameILVRenderer());
ilv_games.SetRenderer(new GameILVRenderer());
}
catch (Exception ex)
@ -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);
@ -494,18 +495,19 @@ namespace DisplayMagician.UIForms
if (rb_launcher.Checked)
{
logger.Trace($"ShortcutForm/btn_save_Click: We're saving a game!");
_gameToUse = new GameStruct
{
{
StartTimeout = Convert.ToInt32(nud_timeout_game.Value),
GameArguments = txt_args_game.Text,
GameArgumentsRequired = cb_args_game.Checked,
DifferentGameExeToMonitor = txt_alternative_game.Text,
MonitorDifferentGameExe = cb_wait_alternative_game.Checked
MonitorDifferentGameExe = cb_wait_alternative_game.Checked,
ProcessPriority = (ProcessPriority)cbx_game_priority.SelectedValue,
};
// 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 +515,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();
@ -596,7 +598,8 @@ namespace DisplayMagician.UIForms
ExecutableArguments = txt_args_executable.Text,
ExecutableArgumentsRequired = cb_args_executable.Checked,
ExecutableNameAndPath = txt_executable.Text,
ExecutableTimeout = Convert.ToInt32(nud_timeout_executable.Value)
ExecutableTimeout = Convert.ToInt32(nud_timeout_executable.Value),
ProcessPriority = (ProcessPriority)cbx_exe_priority.SelectedValue,
};
if (rb_wait_alternative_executable.Checked && !String.IsNullOrWhiteSpace(txt_alternative_executable.Text))
@ -821,6 +824,32 @@ namespace DisplayMagician.UIForms
bool foundChosenProfileInLoadedProfiles = false;
ProfileItem chosenProfile = null;
// Prepare the Game process priority combo box
cbx_game_priority.DataSource = new ComboItem[] {
new ComboItem{ Value = ProcessPriority.High, Text = "High" },
new ComboItem{ Value = ProcessPriority.AboveNormal, Text = "Above Normal" },
new ComboItem{ Value = ProcessPriority.Normal, Text = "Normal" },
new ComboItem{ Value = ProcessPriority.BelowNormal, Text = "Below Normal" },
new ComboItem{ Value = ProcessPriority.Idle, Text = "Idle" },
};
cbx_game_priority.ValueMember = "Value";
cbx_game_priority.DisplayMember = "Text";
cbx_game_priority.SelectedIndex = 2; //Normal
cbx_game_priority.Enabled = true;
// Prepare the exe process priority combo box
cbx_exe_priority.DataSource = new ComboItem[] {
new ComboItem{ Value = ProcessPriority.High, Text = "High" },
new ComboItem{ Value = ProcessPriority.AboveNormal, Text = "Above Normal" },
new ComboItem{ Value = ProcessPriority.Normal, Text = "Normal" },
new ComboItem{ Value = ProcessPriority.BelowNormal, Text = "Below Normal" },
new ComboItem{ Value = ProcessPriority.Idle, Text = "Idle" },
};
cbx_exe_priority.ValueMember = "Value";
cbx_exe_priority.DisplayMember = "Text";
cbx_exe_priority.SelectedIndex = 2; //Normal
cbx_exe_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 +1180,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,11 +1196,12 @@ 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;
txt_args_game.Text = _shortcutToEdit.GameArguments;
cbx_game_priority.SelectedValue = _shortcutToEdit.ProcessPriority;
if (_shortcutToEdit.GameArgumentsRequired)
{
cb_args_game.Checked = true;
@ -1184,6 +1214,7 @@ namespace DisplayMagician.UIForms
txt_executable.Text = _shortcutToEdit.ExecutableNameAndPath;
nud_timeout_executable.Value = _shortcutToEdit.StartTimeout;
txt_args_executable.Text = _shortcutToEdit.ExecutableArguments;
cbx_exe_priority.SelectedValue = _shortcutToEdit.ProcessPriority;
if (_shortcutToEdit.ExecutableArgumentsRequired)
{
cb_args_executable.Checked = true;
@ -1208,7 +1239,6 @@ namespace DisplayMagician.UIForms
txt_shortcut_save_name.Text = _shortcutToEdit.Name;
// Set up the start programs
if (_shortcutToEdit.StartPrograms is List<StartProgram> && _shortcutToEdit.StartPrograms.Count > 0)
{
flp_start_programs.Controls.Clear();
@ -2257,7 +2287,7 @@ namespace DisplayMagician.UIForms
{
if (_loadedShortcut)
_isUnsaved = true;
txt_game_launcher.Text = game.GameLibrary.ToString();
_gameLauncher = game.GameLibrary.ToString();
_gameId = game.Id;
}
}
@ -2273,10 +2303,23 @@ namespace DisplayMagician.UIForms
SelectGameInImageListView();
}
private void btn_find_examples_Click(object sender, EventArgs e)
private void btn_find_examples_startprograms_Click(object sender, EventArgs e)
{
string targetURL = @"https://github.com/terrymacdonald/DisplayMagician/wiki/Start-Program-Examples";
System.Diagnostics.Process.Start(targetURL);
}
private void btn_find_examples_game_Click(object sender, EventArgs e)
{
string targetURL = @"https://github.com/terrymacdonald/DisplayMagician/wiki/Main-Game-and-Application-Examples";
System.Diagnostics.Process.Start(targetURL);
}
}
// Class used to populate combo boxes
class ComboItem
{
public ProcessPriority Value { get; set; }
public string Text { get; set; }
}
}

File diff suppressed because it is too large Load Diff

View File

@ -41,6 +41,8 @@ namespace DisplayMagician.UIForms
this.lbl_priority = new System.Windows.Forms.Label();
this.pb_up_arrow = new System.Windows.Forms.PictureBox();
this.pb_down_arrow = new System.Windows.Forms.PictureBox();
this.cbx_start_program_priority = new System.Windows.Forms.ComboBox();
this.lbl_start_program_priority = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.pb_up_arrow)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pb_down_arrow)).BeginInit();
this.SuspendLayout();
@ -50,7 +52,7 @@ namespace DisplayMagician.UIForms
this.cb_dont_start_if_running.AutoSize = true;
this.cb_dont_start_if_running.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.cb_dont_start_if_running.ForeColor = System.Drawing.Color.White;
this.cb_dont_start_if_running.Location = new System.Drawing.Point(160, 86);
this.cb_dont_start_if_running.Location = new System.Drawing.Point(160, 83);
this.cb_dont_start_if_running.Name = "cb_dont_start_if_running";
this.cb_dont_start_if_running.Size = new System.Drawing.Size(289, 24);
this.cb_dont_start_if_running.TabIndex = 26;
@ -77,7 +79,7 @@ namespace DisplayMagician.UIForms
this.cb_start_program_close.CheckState = System.Windows.Forms.CheckState.Checked;
this.cb_start_program_close.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.cb_start_program_close.ForeColor = System.Drawing.Color.White;
this.cb_start_program_close.Location = new System.Drawing.Point(506, 86);
this.cb_start_program_close.Location = new System.Drawing.Point(506, 115);
this.cb_start_program_close.Name = "cb_start_program_close";
this.cb_start_program_close.Size = new System.Drawing.Size(458, 24);
this.cb_start_program_close.TabIndex = 24;
@ -104,7 +106,7 @@ namespace DisplayMagician.UIForms
this.txt_start_program_args.BackColor = System.Drawing.Color.White;
this.txt_start_program_args.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.txt_start_program_args.ForeColor = System.Drawing.Color.Black;
this.txt_start_program_args.Location = new System.Drawing.Point(398, 56);
this.txt_start_program_args.Location = new System.Drawing.Point(398, 50);
this.txt_start_program_args.Name = "txt_start_program_args";
this.txt_start_program_args.Size = new System.Drawing.Size(506, 26);
this.txt_start_program_args.TabIndex = 22;
@ -115,7 +117,7 @@ namespace DisplayMagician.UIForms
this.cb_start_program_pass_args.AutoSize = true;
this.cb_start_program_pass_args.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.cb_start_program_pass_args.ForeColor = System.Drawing.Color.White;
this.cb_start_program_pass_args.Location = new System.Drawing.Point(160, 56);
this.cb_start_program_pass_args.Location = new System.Drawing.Point(160, 50);
this.cb_start_program_pass_args.Name = "cb_start_program_pass_args";
this.cb_start_program_pass_args.Size = new System.Drawing.Size(228, 24);
this.cb_start_program_pass_args.TabIndex = 21;
@ -143,7 +145,7 @@ namespace DisplayMagician.UIForms
this.cb_disable_start_program.AutoSize = true;
this.cb_disable_start_program.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.cb_disable_start_program.ForeColor = System.Drawing.Color.White;
this.cb_disable_start_program.Location = new System.Drawing.Point(160, 114);
this.cb_disable_start_program.Location = new System.Drawing.Point(159, 115);
this.cb_disable_start_program.Name = "cb_disable_start_program";
this.cb_disable_start_program.Size = new System.Drawing.Size(312, 24);
this.cb_disable_start_program.TabIndex = 28;
@ -198,12 +200,37 @@ namespace DisplayMagician.UIForms
this.pb_down_arrow.MouseEnter += new System.EventHandler(this.pb_down_arrow_MouseEnter);
this.pb_down_arrow.MouseLeave += new System.EventHandler(this.pb_down_arrow_MouseLeave);
//
// cbx_start_program_priority
//
this.cbx_start_program_priority.AllowDrop = true;
this.cbx_start_program_priority.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cbx_start_program_priority.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.cbx_start_program_priority.FormattingEnabled = true;
this.cbx_start_program_priority.Location = new System.Drawing.Point(725, 84);
this.cbx_start_program_priority.Name = "cbx_start_program_priority";
this.cbx_start_program_priority.Size = new System.Drawing.Size(179, 28);
this.cbx_start_program_priority.TabIndex = 34;
this.cbx_start_program_priority.SelectedIndexChanged += new System.EventHandler(this.cbx_start_program_priority_SelectedIndexChanged);
//
// lbl_start_program_priority
//
this.lbl_start_program_priority.AutoSize = true;
this.lbl_start_program_priority.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lbl_start_program_priority.ForeColor = System.Drawing.Color.White;
this.lbl_start_program_priority.Location = new System.Drawing.Point(563, 87);
this.lbl_start_program_priority.Name = "lbl_start_program_priority";
this.lbl_start_program_priority.Size = new System.Drawing.Size(163, 20);
this.lbl_start_program_priority.TabIndex = 33;
this.lbl_start_program_priority.Text = "Start Program Priority:";
//
// StartProgramControl
//
this.AllowDrop = true;
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
this.AutoSize = true;
this.BackColor = System.Drawing.Color.Black;
this.Controls.Add(this.cbx_start_program_priority);
this.Controls.Add(this.lbl_start_program_priority);
this.Controls.Add(this.pb_up_arrow);
this.Controls.Add(this.pb_down_arrow);
this.Controls.Add(this.lbl_priority);
@ -241,5 +268,7 @@ namespace DisplayMagician.UIForms
private System.Windows.Forms.Label lbl_priority;
private System.Windows.Forms.PictureBox pb_down_arrow;
private System.Windows.Forms.PictureBox pb_up_arrow;
private System.Windows.Forms.ComboBox cbx_start_program_priority;
private System.Windows.Forms.Label lbl_start_program_priority;
}
}

View File

@ -50,6 +50,20 @@ namespace DisplayMagician.UIForms
// Update the text with the start program info
myStartProgram = startProgram;
myStartProgram.Priority = startProgramOrder;
// Prepare the start program process priority combo box
cbx_start_program_priority.DataSource = new ComboItem[] {
new ComboItem{ Value = ProcessPriority.High, Text = "High" },
new ComboItem{ Value = ProcessPriority.AboveNormal, Text = "Above Normal" },
new ComboItem{ Value = ProcessPriority.Normal, Text = "Normal" },
new ComboItem{ Value = ProcessPriority.BelowNormal, Text = "Below Normal" },
new ComboItem{ Value = ProcessPriority.Idle, Text = "Idle" },
};
cbx_start_program_priority.ValueMember = "Value";
cbx_start_program_priority.DisplayMember = "Text";
cbx_start_program_priority.SelectedItem = "Normal";
cbx_start_program_priority.Enabled = true;
UpdateUI();
}
@ -63,6 +77,7 @@ namespace DisplayMagician.UIForms
txt_start_program_args.Text = myStartProgram.Arguments;
cb_start_program_close.Checked = myStartProgram.CloseOnFinish;
cb_dont_start_if_running.Checked = myStartProgram.DontStartIfAlreadyRunning;
cbx_start_program_priority.SelectedValue = myStartProgram.ProcessPriority;
}
@ -92,6 +107,7 @@ namespace DisplayMagician.UIForms
cb_start_program_pass_args.Enabled = false;
cb_start_program_close.Enabled = false;
cb_dont_start_if_running.Enabled = false;
cbx_start_program_priority.Enabled = false;
}
else
{
@ -103,6 +119,7 @@ namespace DisplayMagician.UIForms
cb_start_program_pass_args.Enabled = true;
cb_start_program_close.Enabled = true;
cb_dont_start_if_running.Enabled = true;
cbx_start_program_priority.Enabled = true;
}
}
@ -215,5 +232,10 @@ namespace DisplayMagician.UIForms
{
myStartProgram.Arguments = txt_start_program_args.Text;
}
private void cbx_start_program_priority_SelectedIndexChanged(object sender, EventArgs e)
{
myStartProgram.ProcessPriority = (ProcessPriority)cbx_start_program_priority.SelectedValue;
}
}
}

View File

@ -89,6 +89,7 @@
<Compile Include="Windows\WinProfileItem.cs" />
<Compile Include="Windows\CCD.cs" />
<Compile Include="Windows\WinLibrary.cs" />
<Compile Include="Wallpaper.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Properties\Resources.resx">
@ -105,6 +106,9 @@
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<PackageReference Include="AdvancedDLSupport">
<Version>3.2.0</Version>
</PackageReference>
<PackageReference Include="EDIDParser">
<Version>1.2.0.1</Version>
</PackageReference>

View File

@ -61,12 +61,14 @@ namespace DisplayMagicianShared
private List<ScreenPosition> _screens = new List<ScreenPosition>();
internal static string AppDataPath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "DisplayMagician");
private static string AppWallpaperPath = Path.Combine(AppDataPath, $"Wallpaper");
private static readonly string uuidV4Regex = @"(?im)^[{(]?[0-9A-F]{8}[-]?(?:[0-9A-F]{4}[-]?){3}[0-9A-F]{12}[)}]?$";
private string _uuid = "";
private bool _isPossible = false;
private Keys _hotkey = Keys.None;
private string _wallpaperBitmapFilename = "";
#region JsonConverterBitmap
internal class CustomBitmapConverter : JsonConverter
@ -236,6 +238,21 @@ namespace DisplayMagicianShared
public string SavedProfileIconCacheFilename { get; set; }
public bool SetWallpaper { get; set; }
public Wallpaper.Style WallpaperStyle { get; set; }
public string WallpaperBitmapFilename{
get
{
return _wallpaperBitmapFilename;
}
set
{
_wallpaperBitmapFilename = value;
}
}
public virtual List<string> ProfileDisplayIdentifiers
{
get
@ -341,6 +358,9 @@ namespace DisplayMagicianShared
profile.ProfileBitmap = ProfileBitmap;
profile.ProfileTightestBitmap = ProfileTightestBitmap;
profile.ProfileDisplayIdentifiers = ProfileDisplayIdentifiers;
profile.SetWallpaper = SetWallpaper;
profile.WallpaperBitmapFilename = WallpaperBitmapFilename;
profile.WallpaperStyle = WallpaperStyle;
return true;
}

View File

@ -284,6 +284,7 @@ namespace DisplayMagicianShared
try
{
File.Delete(ProfileToRemove.SavedProfileIconCacheFilename);
File.Delete(ProfileToRemove.WallpaperBitmapFilename);
}
catch (UnauthorizedAccessException ex)
{
@ -335,6 +336,7 @@ namespace DisplayMagicianShared
try
{
File.Delete(ProfileToRemove.SavedProfileIconCacheFilename);
File.Delete(ProfileToRemove.WallpaperBitmapFilename);
}
catch (UnauthorizedAccessException ex)
{
@ -384,6 +386,7 @@ namespace DisplayMagicianShared
try
{
File.Delete(ProfileToRemove.SavedProfileIconCacheFilename);
File.Delete(ProfileToRemove.WallpaperBitmapFilename);
}
catch (UnauthorizedAccessException ex)
{
@ -567,9 +570,6 @@ namespace DisplayMagicianShared
return false;
}
}
public static void UpdateActiveProfile()
{
@ -1049,6 +1049,18 @@ namespace DisplayMagicianShared
}
finally
{
// If the applying path info worked, then we attempt to set the desktop background
if (profile.SetWallpaper)
{
if (Wallpaper.Set(profile.SavedProfileIconCacheFilename, profile.WallpaperStyle))
{
logger.Trace($"Program/ApplyProfile: We attempted to set the desktop wallpaper to {profile.SavedProfileIconCacheFilename} using {profile.WallpaperStyle} style for profile {profile.Name}, and it worked!");
}
else
{
logger.Warn($"Program/ApplyProfile: We attempted to set the desktop wallpaper to {profile.SavedProfileIconCacheFilename} using {profile.WallpaperStyle} style for profile {profile.Name}, and it failed :(");
}
}
// We stop the stop watch
stopWatch.Stop();
// Get the elapsed time as a TimeSpan value.

View File

@ -0,0 +1,87 @@
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace DisplayMagicianShared
{
public sealed class Wallpaper
{
Wallpaper() { }
const int SPI_SETDESKWALLPAPER = 20;
const int SPIF_UPDATEINIFILE = 0x01;
const int SPIF_SENDWININICHANGE = 0x02;
[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern int SystemParametersInfo(int uAction, int uParam, string lpvParam, int fuWinIni);
public enum Style : int
{
Tile,
Center,
Stretch,
Fill,
Fit,
Span
}
public static bool Set(String filename, Style style)
{
//System.IO.Stream s = new System.Net.WebClient().OpenRead(uri.ToString());
Bitmap img = new Bitmap(filename);
RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop", true);
if (style == Style.Fill)
{
key.SetValue(@"WallpaperStyle", 10.ToString());
key.SetValue(@"TileWallpaper", 0.ToString());
}
if (style == Style.Fit)
{
key.SetValue(@"WallpaperStyle", 6.ToString());
key.SetValue(@"TileWallpaper", 0.ToString());
}
if (style == Style.Span) // Windows 8 or newer only!
{
key.SetValue(@"WallpaperStyle", 22.ToString());
key.SetValue(@"TileWallpaper", 0.ToString());
}
if (style == Style.Stretch)
{
key.SetValue(@"WallpaperStyle", 2.ToString());
key.SetValue(@"TileWallpaper", 0.ToString());
}
if (style == Style.Tile)
{
key.SetValue(@"WallpaperStyle", 0.ToString());
key.SetValue(@"TileWallpaper", 1.ToString());
}
if (style == Style.Center)
{
key.SetValue(@"WallpaperStyle", 0.ToString());
key.SetValue(@"TileWallpaper", 0.ToString());
}
if (SystemParametersInfo(SPI_SETDESKWALLPAPER,
0,
filename,
SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE) > 0)
{
// applying desktop wallpaper worked!
return true;
}
else
{
// applying desktop wallpaper failed!
return false;
}
}
}
}