mirror of
https://github.com/terrymacdonald/DisplayMagician.git
synced 2024-08-30 18:32:20 +00:00
a9bb295d1f
Renamed app to HeliosPlus namespace so that the updated changes don't interfere with HeliosDisplayManagement if that is also installed. The fact that I've changed so much of the app means that my changes would be unlikely to be accepted by Soroush, so I'm best to release this work in a similar way to other projects like Notepad++, by keeping the same root name, and adding a plus. I've also changed the Shortcut form to put all the games in a single list to reduce the number of clicks a user has to do in order for them to create a shortcut. I have begun to prepare the form so that it will support multiple game libraries, but now I am at a point that I need to fix the Steam and Uplay game detection mechanisms so that they report the correct information for the lv_games list view.
137 lines
3.6 KiB
C#
137 lines
3.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
using Microsoft.Win32;
|
|
|
|
namespace HeliosPlus.Shared
|
|
{
|
|
public class Helios
|
|
{
|
|
public static string Address
|
|
{
|
|
get
|
|
{
|
|
try
|
|
{
|
|
using (
|
|
var key =
|
|
Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Helios Display Management", false))
|
|
{
|
|
var executableAddress = key?.GetValue(@"ExecutableAddress", null) as string;
|
|
|
|
if (!string.IsNullOrWhiteSpace(executableAddress) && File.Exists(executableAddress))
|
|
{
|
|
return executableAddress;
|
|
}
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
// ignored
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public static bool IsInstalled
|
|
{
|
|
get => !string.IsNullOrWhiteSpace(Address);
|
|
}
|
|
|
|
// ReSharper disable once MethodTooLong
|
|
// ReSharper disable once TooManyArguments
|
|
public static void Open(
|
|
HeliosStartupAction action = HeliosStartupAction.None,
|
|
Profile profile = null,
|
|
string programAddress = null,
|
|
bool asAdmin = false)
|
|
{
|
|
try
|
|
{
|
|
if (!IsInstalled)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var args = new List<string> {$"-a {action}"};
|
|
|
|
if (profile != null)
|
|
{
|
|
args.Add($"-p \"{profile.Id}\"");
|
|
}
|
|
|
|
if (!string.IsNullOrWhiteSpace(programAddress))
|
|
{
|
|
args.Add($"-e \"{programAddress}\"");
|
|
}
|
|
|
|
var processInfo = new ProcessStartInfo(Address, string.Join(" ", args))
|
|
{
|
|
UseShellExecute = true
|
|
};
|
|
|
|
if (asAdmin)
|
|
{
|
|
processInfo.Verb = @"runas";
|
|
}
|
|
|
|
Process.Start(processInfo);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
// Check if operation canceled by user
|
|
if ((e as Win32Exception)?.NativeErrorCode == 1223)
|
|
{
|
|
return;
|
|
}
|
|
|
|
throw;
|
|
}
|
|
}
|
|
|
|
public static void OpenSteamGame(
|
|
HeliosStartupAction action = HeliosStartupAction.None,
|
|
Profile profile = null,
|
|
uint steamAppId = 0)
|
|
{
|
|
try
|
|
{
|
|
if (!IsInstalled)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var args = new List<string> {$@"-a {action}"};
|
|
|
|
if (profile != null)
|
|
{
|
|
args.Add($"-p \"{profile.Id}\"");
|
|
}
|
|
|
|
if (steamAppId > 0)
|
|
{
|
|
args.Add($"-s \"{steamAppId}\"");
|
|
}
|
|
|
|
var processInfo = new ProcessStartInfo(Address, string.Join(" ", args))
|
|
{
|
|
UseShellExecute = true
|
|
};
|
|
Process.Start(processInfo);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
// Check if operation canceled by user
|
|
if ((e as Win32Exception)?.NativeErrorCode == 1223)
|
|
{
|
|
return;
|
|
}
|
|
|
|
throw;
|
|
}
|
|
}
|
|
}
|
|
} |