[WIP] Correction of game search

This commit is contained in:
Terry MacDonald 2021-04-02 22:25:38 +13:00
parent 87fcc3e8d0
commit ac48efe19d
6 changed files with 198 additions and 209 deletions

View File

@ -32,7 +32,7 @@ namespace DisplayMagician.GameLibraries
public OriginGame(string originGameId, string originGameName, string originGameExePath, string originGameIconPath)
{
_gameRegistryKey = $@"{OriginLibrary.SteamAppsRegistryKey}\\{originGameId}";
_gameRegistryKey = $@"{OriginLibrary.OriginAppsRegistryKey}\\{originGameId}";
_originGameId = originGameId;
_originGameName = originGameName;
_originGameExePath = originGameExePath;

View File

@ -18,7 +18,7 @@ namespace DisplayMagician.GameLibraries
#region Class Variables
// Common items to the class
private static List<Game> _allOriginGames = new List<Game>();
//private static string steamAppIdRegex = @"/^[0-9A-F]{1,10}$";
private static string originAppIdRegex = @"/^[0-9A-F]{1,10}$";
private static string _originExe;
private static string _originPath;
private static string _originLocalContent = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData),"Origin");
@ -92,7 +92,7 @@ namespace DisplayMagician.GameLibraries
}
}
public static string OriginRegistryKey
/* public static string OriginRegistryKey
{
get
{
@ -107,7 +107,7 @@ namespace DisplayMagician.GameLibraries
return _registryAppsKey;
}
}
*/
public static string OriginExe
{
get
@ -137,27 +137,27 @@ namespace DisplayMagician.GameLibraries
#endregion
#region Class Methods
public static bool AddOriginGame(OriginGame steamGame)
public static bool AddOriginGame(OriginGame originGame)
{
if (!(steamGame is OriginGame))
if (!(originGame is OriginGame))
return false;
// Doublecheck if it already exists
// Because then we just update the one that already exists
if (ContainsOriginGame(steamGame))
if (ContainsOriginGame(originGame))
{
// We update the existing Shortcut with the data over
OriginGame steamGameToUpdate = GetOriginGame(steamGame.Id.ToString());
steamGame.CopyInto(steamGameToUpdate);
OriginGame originGameToUpdate = GetOriginGame(originGame.Id.ToString());
originGame.CopyInto(originGameToUpdate);
}
else
{
// Add the steamGame to the list of steamGames
_allOriginGames.Add(steamGame);
// Add the originGame to the list of originGames
_allOriginGames.Add(originGame);
}
//Doublecheck it's been added
if (ContainsOriginGame(steamGame))
if (ContainsOriginGame(originGame))
{
return true;
}
@ -166,13 +166,13 @@ namespace DisplayMagician.GameLibraries
}
public static bool RemoveOriginGame(OriginGame steamGame)
public static bool RemoveOriginGame(OriginGame originGame)
{
if (!(steamGame is OriginGame))
if (!(originGame is OriginGame))
return false;
// Remove the steamGame from the list.
int numRemoved = _allOriginGames.RemoveAll(item => item.Id.Equals(steamGame.Id));
// Remove the originGame from the list.
int numRemoved = _allOriginGames.RemoveAll(item => item.Id.Equals(originGame.Id));
if (numRemoved == 1)
{
@ -184,13 +184,13 @@ namespace DisplayMagician.GameLibraries
throw new OriginLibraryException();
}
public static bool RemoveOriginGameId(string steamGameId)
public static bool RemoveOriginGameById(string originGameId)
{
if (steamGameId<=0)
if (originGameId.Equals("0"))
return false;
// Remove the steamGame from the list.
int numRemoved = _allOriginGames.RemoveAll(item => item.Id.Equals(steamGameId));
// Remove the originGame from the list.
int numRemoved = _allOriginGames.RemoveAll(item => item.Id.Equals(originGameId));
if (numRemoved == 1)
{
@ -203,17 +203,17 @@ namespace DisplayMagician.GameLibraries
}
public static bool RemoveOriginGame(string steamGameNameOrUuid)
public static bool RemoveOriginGame(string originGameNameOrId)
{
if (String.IsNullOrWhiteSpace(steamGameNameOrUuid))
if (String.IsNullOrWhiteSpace(originGameNameOrId))
return false;
int numRemoved;
Match match = Regex.Match(steamGameNameOrUuid, steamAppIdRegex, RegexOptions.IgnoreCase);
Match match = Regex.Match(originGameNameOrId, originAppIdRegex, RegexOptions.IgnoreCase);
if (match.Success)
numRemoved = _allOriginGames.RemoveAll(item => steamGameNameOrUuid.Equals(Convert.ToUInt32(item.Id)));
numRemoved = _allOriginGames.RemoveAll(item => originGameNameOrId.Equals(item.Id));
else
numRemoved = _allOriginGames.RemoveAll(item => steamGameNameOrUuid.Equals(item.Name));
numRemoved = _allOriginGames.RemoveAll(item => originGameNameOrId.Equals(item.Name));
if (numRemoved == 1)
return true;
@ -224,32 +224,32 @@ namespace DisplayMagician.GameLibraries
}
public static bool ContainsOriginGame(OriginGame steamGame)
public static bool ContainsOriginGame(OriginGame originGame)
{
if (!(steamGame is OriginGame))
if (!(originGame is OriginGame))
return false;
foreach (OriginGame testOriginGame in _allOriginGames)
{
if (testOriginGame.Id.Equals(steamGame.Id))
if (testOriginGame.Id.Equals(originGame.Id))
return true;
}
return false;
}
public static bool ContainsOriginGame(string steamGameNameOrUuid)
public static bool ContainsOriginGame(string originGameNameOrUuid)
{
if (String.IsNullOrWhiteSpace(steamGameNameOrUuid))
if (String.IsNullOrWhiteSpace(originGameNameOrUuid))
return false;
Match match = Regex.Match(steamGameNameOrUuid, steamAppIdRegex, RegexOptions.IgnoreCase);
Match match = Regex.Match(originGameNameOrUuid, originAppIdRegex, RegexOptions.IgnoreCase);
if (match.Success)
{
foreach (OriginGame testOriginGame in _allOriginGames)
{
if (steamGameNameOrUuid.Equals(Convert.ToInt32(testOriginGame.Id)))
if (originGameNameOrUuid.Equals(Convert.ToInt32(testOriginGame.Id)))
return true;
}
@ -258,7 +258,7 @@ namespace DisplayMagician.GameLibraries
{
foreach (OriginGame testOriginGame in _allOriginGames)
{
if (steamGameNameOrUuid.Equals(testOriginGame.Name))
if (originGameNameOrUuid.Equals(testOriginGame.Name))
return true;
}
@ -268,11 +268,11 @@ namespace DisplayMagician.GameLibraries
}
public static bool ContainsOriginGameId(string steamGameId)
public static bool ContainsOriginGameById(string originGameId)
{
foreach (OriginGame testOriginGame in _allOriginGames)
{
if (steamGameId == testOriginGame.Id)
if (originGameId == testOriginGame.Id)
return true;
}
@ -282,17 +282,17 @@ namespace DisplayMagician.GameLibraries
}
public static OriginGame GetOriginGame(string steamGameNameOrUuid)
public static OriginGame GetOriginGame(string originGameNameOrId)
{
if (String.IsNullOrWhiteSpace(steamGameNameOrUuid))
if (String.IsNullOrWhiteSpace(originGameNameOrId))
return null;
Match match = Regex.Match(steamGameNameOrUuid, steamAppIdRegex, RegexOptions.IgnoreCase);
Match match = Regex.Match(originGameNameOrId, originAppIdRegex, RegexOptions.IgnoreCase);
if (match.Success)
{
foreach (OriginGame testOriginGame in _allOriginGames)
{
if (steamGameNameOrUuid.Equals(Convert.ToInt32(testOriginGame.Id)))
if (originGameNameOrId.Equals(Convert.ToInt32(testOriginGame.Id)))
return testOriginGame;
}
@ -301,7 +301,7 @@ namespace DisplayMagician.GameLibraries
{
foreach (OriginGame testOriginGame in _allOriginGames)
{
if (steamGameNameOrUuid.Equals(testOriginGame.Name))
if (originGameNameOrId.Equals(testOriginGame.Name))
return testOriginGame;
}
@ -311,11 +311,11 @@ namespace DisplayMagician.GameLibraries
}
public static OriginGame GetOriginGame(int steamGameId)
public static OriginGame GetOriginGameById(string originGameId)
{
foreach (OriginGame testOriginGame in _allOriginGames)
{
if (steamGameId == testOriginGame.Id)
if (originGameId == testOriginGame.Id)
return testOriginGame;
}
@ -351,8 +351,8 @@ namespace DisplayMagician.GameLibraries
}
//Icon _originIcon = Icon.ExtractAssociatedIcon(_originExe);
//IconExtractor steamIconExtractor = new IconExtractor(_originExe);
//Icon _originIcon = steamIconExtractor.GetIcon(0);
//IconExtractor originIconExtractor = new IconExtractor(_originExe);
//Icon _originIcon = originIconExtractor.GetIcon(0);
//MultiIcon _originIcon = new MultiIcon();
//_originIcon.Load(_originExe);
@ -475,26 +475,26 @@ namespace DisplayMagician.GameLibraries
List<int> steamAppIdsInstalled = new List<int>();
List<int> originAppIdsInstalled = new List<int>();
// Now look for what games app id's are actually installed on this computer
using (RegistryKey steamAppsKey = Registry.CurrentUser.OpenSubKey(_registryAppsKey, RegistryKeyPermissionCheck.ReadSubTree))
using (RegistryKey originAppsKey = Registry.CurrentUser.OpenSubKey(_registryAppsKey, RegistryKeyPermissionCheck.ReadSubTree))
{
if (steamAppsKey != null)
if (originAppsKey != null)
{
// Loop through the subKeys as they are the Origin Game IDs
foreach (string steamGameKeyName in steamAppsKey.GetSubKeyNames())
foreach (string originGameKeyName in originAppsKey.GetSubKeyNames())
{
if (int.TryParse(steamGameKeyName, out int steamAppId))
if (int.TryParse(originGameKeyName, out int originAppId))
{
string steamGameKeyFullName = $"{_registryAppsKey}\\{steamGameKeyName}";
using (RegistryKey steamGameKey = Registry.CurrentUser.OpenSubKey(steamGameKeyFullName, RegistryKeyPermissionCheck.ReadSubTree))
string originGameKeyFullName = $"{_registryAppsKey}\\{originGameKeyName}";
using (RegistryKey originGameKey = Registry.CurrentUser.OpenSubKey(originGameKeyFullName, RegistryKeyPermissionCheck.ReadSubTree))
{
// If the Installed Value is set to 1, then the game is installed
// We want to keep track of that for later
if ((int)steamGameKey.GetValue(@"Installed", 0) == 1)
if ((int)originGameKey.GetValue(@"Installed", 0) == 1)
{
// Add this Origin App ID to the list we're keeping for later
steamAppIdsInstalled.Add(steamAppId);
originAppIdsInstalled.Add(originAppId);
}
}
@ -504,12 +504,12 @@ namespace DisplayMagician.GameLibraries
}
}
// Now we parse the steam appinfo.vdf to get access to things like:
// Now we parse the origin appinfo.vdf to get access to things like:
// - The game name
// - THe game installation dir
// - Sometimes the game icon
// - Sometimes the game executable name (from which we can get the icon)
Dictionary<int, OriginAppInfo> steamAppInfo = new Dictionary<int, OriginAppInfo>();
Dictionary<int, OriginAppInfo> originAppInfo = new Dictionary<int, OriginAppInfo>();
string appInfoVdfFile = Path.Combine(_originPath, "appcache", "appinfo.vdf");
var newAppInfo = new AppInfo();
@ -523,13 +523,13 @@ namespace DisplayMagician.GameLibraries
// We only care about the appIDs we have listed as actual games
// (The AppIds include all other DLC and Origin specific stuff too)
int detectedAppID = Convert.ToInt32(app.AppID);
if (steamAppIdsInstalled.Contains(detectedAppID))
if (originAppIdsInstalled.Contains(detectedAppID))
{
try
{
OriginAppInfo steamGameAppInfo = new OriginAppInfo
OriginAppInfo originGameAppInfo = new OriginAppInfo
{
GameID = detectedAppID,
GameExes = new List<string>()
@ -549,12 +549,12 @@ namespace DisplayMagician.GameLibraries
if (common.Name == "name")
{
Debug.WriteLine($"App: {app.AppID} - Common {common.Name}: {common.Value}");
steamGameAppInfo.GameName = common.Value.ToString();
originGameAppInfo.GameName = common.Value.ToString();
}
else if (common.Name == "clienticon")
{
Debug.WriteLine($"App: {app.AppID} - Common {common.Name}: {common.Value}");
steamGameAppInfo.GameOriginIconPath = Path.Combine(_originPath, @"steam", @"games", String.Concat(common.Value, @".ico"));
originGameAppInfo.GameOriginIconPath = Path.Combine(_originPath, @"origin", @"games", String.Concat(common.Value, @".ico"));
}
else if (common.Name == "type")
{
@ -571,7 +571,7 @@ namespace DisplayMagician.GameLibraries
if (config.Name == "installdir")
{
Debug.WriteLine($"App: {detectedAppID} - Config {config.Name}: {config.Value}");
steamGameAppInfo.GameInstallDir = config.Value.ToString();
originGameAppInfo.GameInstallDir = config.Value.ToString();
}
else if (config.Name == "launch")
{
@ -582,7 +582,7 @@ namespace DisplayMagician.GameLibraries
if (launch_num.Name == "executable")
{
Debug.WriteLine($"App: {detectedAppID} - Config - Launch {launch.Name} - {launch_num.Name}: {launch_num.Value}");
steamGameAppInfo.GameExes.Add(launch_num.Value.ToString());
originGameAppInfo.GameExes.Add(launch_num.Value.ToString());
}
}
@ -592,7 +592,7 @@ namespace DisplayMagician.GameLibraries
}
}
steamAppInfo.Add(detectedAppID, steamGameAppInfo);
originAppInfo.Add(detectedAppID, originGameAppInfo);
}
catch (ArgumentException ex)
{
@ -609,65 +609,65 @@ namespace DisplayMagician.GameLibraries
// Now we access the config.vdf that lives in the Origin Config file, as that lists all
// the OriginLibraries. We need to find out where they areso we can interrogate them
_originConfigVdfFile = Path.Combine(_originPath, "config", "config.vdf");
string steamConfigVdfText = File.ReadAllText(_originConfigVdfFile, Encoding.UTF8);
string originConfigVdfText = File.ReadAllText(_originConfigVdfFile, Encoding.UTF8);
List<string> steamLibrariesPaths = new List<string>();
List<string> originLibrariesPaths = new List<string>();
// Now we have to parse the config.vdf looking for the location of the OriginLibraries
// We look for lines similar to this: "BaseInstallFolder_1" "E:\\OriginLibrary"
// There may be multiple so we need to check the whole file
Regex steamLibrariesRegex = new Regex(@"""BaseInstallFolder_\d+""\s+""(.*)""", RegexOptions.IgnoreCase);
Regex originLibrariesRegex = new Regex(@"""BaseInstallFolder_\d+""\s+""(.*)""", RegexOptions.IgnoreCase);
// Try to match all lines against the Regex.
MatchCollection steamLibrariesMatches = steamLibrariesRegex.Matches(steamConfigVdfText);
MatchCollection originLibrariesMatches = originLibrariesRegex.Matches(originConfigVdfText);
// If at least one of them matched!
foreach (Match steamLibraryMatch in steamLibrariesMatches)
foreach (Match originLibraryMatch in originLibrariesMatches)
{
if (steamLibraryMatch.Success)
if (originLibraryMatch.Success)
{
string steamLibraryPath = Regex.Unescape(steamLibraryMatch.Groups[1].Value);
Debug.WriteLine($"Found steam library: {steamLibraryPath}");
steamLibrariesPaths.Add(steamLibraryPath);
string originLibraryPath = Regex.Unescape(originLibraryMatch.Groups[1].Value);
Debug.WriteLine($"Found origin library: {originLibraryPath}");
originLibrariesPaths.Add(originLibraryPath);
}
}
// Now we go off and find the details for the games in each Origin Library
foreach (string steamLibraryPath in steamLibrariesPaths)
foreach (string originLibraryPath in originLibrariesPaths)
{
// Work out the path to the appmanifests for this steamLibrary
string steamLibraryAppManifestPath = Path.Combine(steamLibraryPath, @"steamapps");
// Work out the path to the appmanifests for this originLibrary
string originLibraryAppManifestPath = Path.Combine(originLibraryPath, @"originapps");
// Get the names of the App Manifests for the games installed in this OriginLibrary
string[] steamLibraryAppManifestFilenames = Directory.GetFiles(steamLibraryAppManifestPath, "appmanifest_*.acf");
string[] originLibraryAppManifestFilenames = Directory.GetFiles(originLibraryAppManifestPath, "appmanifest_*.acf");
// Go through each app and extract it's details
foreach (string steamLibraryAppManifestFilename in steamLibraryAppManifestFilenames)
foreach (string originLibraryAppManifestFilename in originLibraryAppManifestFilenames)
{
// Read in the contents of the file
string steamLibraryAppManifestText = File.ReadAllText(steamLibraryAppManifestFilename);
string originLibraryAppManifestText = File.ReadAllText(originLibraryAppManifestFilename);
// Grab the appid from the file
Regex appidRegex = new Regex(@"""appid""\s+""(\d+)""", RegexOptions.IgnoreCase);
Match appidMatches = appidRegex.Match(steamLibraryAppManifestText);
Match appidMatches = appidRegex.Match(originLibraryAppManifestText);
if (appidMatches.Success)
{
if (int.TryParse(appidMatches.Groups[1].Value, out int steamGameId))
if (int.TryParse(appidMatches.Groups[1].Value, out int originGameId))
{
// Check if this game is one that was installed
if (steamAppInfo.ContainsKey(steamGameId))
if (originAppInfo.ContainsKey(originGameId))
{
// This game is an installed game! so we start to populate it with data!
string steamGameExe = "";
string originGameExe = "";
string steamGameName = steamAppInfo[steamGameId].GameName;
string originGameName = originAppInfo[originGameId].GameName;
// Construct the full path to the game dir from the appInfo and libraryAppManifest data
string steamGameInstallDir = Path.Combine(steamLibraryPath, @"steamapps", @"common", steamAppInfo[steamGameId].GameInstallDir);
string originGameInstallDir = Path.Combine(originLibraryPath, @"originapps", @"common", originAppInfo[originGameId].GameInstallDir);
// And finally we try to populate the 'where', to see what gets run
// And so we can extract the process name
if (steamAppInfo[steamGameId].GameExes.Count > 0)
if (originAppInfo[originGameId].GameExes.Count > 0)
{
foreach (string gameExe in steamAppInfo[steamGameId].GameExes)
foreach (string gameExe in originAppInfo[originGameId].GameExes)
{
steamGameExe = Path.Combine(steamGameInstallDir, gameExe);
originGameExe = Path.Combine(originGameInstallDir, gameExe);
// If the game executable exists, then we can proceed
if (File.Exists(steamGameExe))
if (File.Exists(originGameExe))
{
break;
}
@ -676,26 +676,26 @@ namespace DisplayMagician.GameLibraries
}
// Next, we need to get the Icons we want to use, and make sure it's the latest one.
string steamGameIconPath = "";
string originGameIconPath = "";
// First of all, we attempt to use the Icon that Origin has cached, if it's available, as that will be updated to the latest
if (File.Exists(steamAppInfo[steamGameId].GameOriginIconPath) && steamAppInfo[steamGameId].GameOriginIconPath.EndsWith(".ico"))
if (File.Exists(originAppInfo[originGameId].GameOriginIconPath) && originAppInfo[originGameId].GameOriginIconPath.EndsWith(".ico"))
{
steamGameIconPath = steamAppInfo[steamGameId].GameOriginIconPath;
originGameIconPath = originAppInfo[originGameId].GameOriginIconPath;
}
// If there isn't an icon for us to use, then we need to extract one from the Game Executables
else if (!String.IsNullOrEmpty(steamGameExe))
else if (!String.IsNullOrEmpty(originGameExe))
{
steamGameIconPath = steamGameExe;
originGameIconPath = originGameExe;
}
// The absolute worst case means we don't have an icon to use. SO we use the Origin one.
else
{
// And we have to make do with a Origin Icon
steamGameIconPath = _originPath;
originGameIconPath = _originPath;
}
// And we add the Game to the list of games we have!
_allOriginGames.Add(new OriginGame(steamGameId, steamGameName, steamGameExe, steamGameIconPath));
_allOriginGames.Add(new OriginGame(originGameId, originGameName, originGameExe, originGameIconPath));
}
}

View File

@ -184,9 +184,9 @@ namespace DisplayMagician.GameLibraries
throw new SteamLibraryException();
}
public static bool RemoveSteamGame(int steamGameId)
public static bool RemoveSteamGameById(string steamGameId)
{
if (steamGameId<=0)
if (steamGameId.Equals("0"))
return false;
// Remove the steamGame from the list.
@ -203,17 +203,17 @@ namespace DisplayMagician.GameLibraries
}
public static bool RemoveSteamGame(string steamGameNameOrUuid)
public static bool RemoveSteamGame(string steamGameNameOrId)
{
if (String.IsNullOrWhiteSpace(steamGameNameOrUuid))
if (String.IsNullOrWhiteSpace(steamGameNameOrId))
return false;
int numRemoved;
Match match = Regex.Match(steamGameNameOrUuid, steamAppIdRegex, RegexOptions.IgnoreCase);
Match match = Regex.Match(steamGameNameOrId, steamAppIdRegex, RegexOptions.IgnoreCase);
if (match.Success)
numRemoved = _allSteamGames.RemoveAll(item => steamGameNameOrUuid.Equals(Convert.ToUInt32(item.Id)));
numRemoved = _allSteamGames.RemoveAll(item => steamGameNameOrId.Equals(item.Id));
else
numRemoved = _allSteamGames.RemoveAll(item => steamGameNameOrUuid.Equals(item.Name));
numRemoved = _allSteamGames.RemoveAll(item => steamGameNameOrId.Equals(item.Name));
if (numRemoved == 1)
return true;
@ -268,7 +268,7 @@ namespace DisplayMagician.GameLibraries
}
public static bool ContainsSteamGameId(string steamGameId)
public static bool ContainsSteamGameById(string steamGameId)
{
foreach (SteamGame testSteamGame in _allSteamGames)
{
@ -311,7 +311,7 @@ namespace DisplayMagician.GameLibraries
}
public static SteamGame GetSteamGameId(string steamGameId)
public static SteamGame GetSteamGameById(string steamGameId)
{
foreach (SteamGame testSteamGame in _allSteamGames)
{

View File

@ -175,9 +175,9 @@ namespace DisplayMagician.GameLibraries
throw new UplayLibraryException();
}
public static bool RemoveUplayGame(int uplayGameId)
public static bool RemoveUplayGameById(string uplayGameId)
{
if (uplayGameId<=0)
if (uplayGameId.Equals(0))
return false;
logger.Debug($"UplayLibrary/RemoveUplayGame2: Removing Uplay game with ID {uplayGameId} from the Uplay library");
@ -199,28 +199,28 @@ namespace DisplayMagician.GameLibraries
throw new UplayLibraryException();
}
public static bool RemoveUplayGame(string uplayGameNameOrUuid)
public static bool RemoveUplayGame(string uplayGameNameOrId)
{
if (String.IsNullOrWhiteSpace(uplayGameNameOrUuid))
if (String.IsNullOrWhiteSpace(uplayGameNameOrId))
return false;
logger.Debug($"UplayLibrary/RemoveUplayGame3: Removing Uplay game with Name or UUID {uplayGameNameOrUuid} from the Uplay library");
logger.Debug($"UplayLibrary/RemoveUplayGame3: Removing Uplay game with Name or ID {uplayGameNameOrId} from the Uplay library");
int numRemoved;
Match match = Regex.Match(uplayGameNameOrUuid, uplayAppIdRegex, RegexOptions.IgnoreCase);
Match match = Regex.Match(uplayGameNameOrId, uplayAppIdRegex, RegexOptions.IgnoreCase);
if (match.Success)
numRemoved = _allUplayGames.RemoveAll(item => uplayGameNameOrUuid.Equals(Convert.ToUInt32(item.Id)));
numRemoved = _allUplayGames.RemoveAll(item => uplayGameNameOrId.Equals(item.Id));
else
numRemoved = _allUplayGames.RemoveAll(item => uplayGameNameOrUuid.Equals(item.Name));
numRemoved = _allUplayGames.RemoveAll(item => uplayGameNameOrId.Equals(item.Name));
if (numRemoved == 1)
{
logger.Debug($"UplayLibrary/RemoveUplayGame3: Removed Uplay game with Name or UUID {uplayGameNameOrUuid} ");
logger.Debug($"UplayLibrary/RemoveUplayGame3: Removed Uplay game with Name or UUID {uplayGameNameOrId} ");
return true;
}
else if (numRemoved == 0)
{
logger.Debug($"UplayLibrary/RemoveUplayGame3: Didn't remove Uplay game with Name or UUID {uplayGameNameOrUuid} from the Uplay Library");
logger.Debug($"UplayLibrary/RemoveUplayGame3: Didn't remove Uplay game with Name or UUID {uplayGameNameOrId} from the Uplay Library");
return false;
}
else
@ -242,7 +242,7 @@ namespace DisplayMagician.GameLibraries
return false;
}
public static bool ContainsUplayGameId(string uplayGameId)
public static bool ContainsUplayGameById(string uplayGameId)
{
foreach (UplayGame testUplayGame in _allUplayGames)
{
@ -255,18 +255,18 @@ namespace DisplayMagician.GameLibraries
}
public static bool ContainsUplayGame(string uplayGameNameOrUuid)
public static bool ContainsUplayGame(string uplayGameNameOrId)
{
if (String.IsNullOrWhiteSpace(uplayGameNameOrUuid))
if (String.IsNullOrWhiteSpace(uplayGameNameOrId))
return false;
Match match = Regex.Match(uplayGameNameOrUuid, uplayAppIdRegex, RegexOptions.IgnoreCase);
Match match = Regex.Match(uplayGameNameOrId, uplayAppIdRegex, RegexOptions.IgnoreCase);
if (match.Success)
{
foreach (UplayGame testUplayGame in _allUplayGames)
{
if (uplayGameNameOrUuid.Equals(Convert.ToInt32(testUplayGame.Id)))
if (uplayGameNameOrId.Equals(Convert.ToInt32(testUplayGame.Id)))
return true;
}
@ -275,7 +275,7 @@ namespace DisplayMagician.GameLibraries
{
foreach (UplayGame testUplayGame in _allUplayGames)
{
if (uplayGameNameOrUuid.Equals(testUplayGame.Name))
if (uplayGameNameOrId.Equals(testUplayGame.Name))
return true;
}
@ -286,17 +286,17 @@ namespace DisplayMagician.GameLibraries
}
public static UplayGame GetUplayGame(string uplayGameNameOrUuid)
public static UplayGame GetUplayGame(string uplayGameNameOrId)
{
if (String.IsNullOrWhiteSpace(uplayGameNameOrUuid))
if (String.IsNullOrWhiteSpace(uplayGameNameOrId))
return null;
Match match = Regex.Match(uplayGameNameOrUuid, uplayAppIdRegex, RegexOptions.IgnoreCase);
Match match = Regex.Match(uplayGameNameOrId, uplayAppIdRegex, RegexOptions.IgnoreCase);
if (match.Success)
{
foreach (UplayGame testUplayGame in _allUplayGames)
{
if (uplayGameNameOrUuid.Equals(Convert.ToInt32(testUplayGame.Id)))
if (uplayGameNameOrId.Equals(Convert.ToInt32(testUplayGame.Id)))
return testUplayGame;
}
@ -305,7 +305,7 @@ namespace DisplayMagician.GameLibraries
{
foreach (UplayGame testUplayGame in _allUplayGames)
{
if (uplayGameNameOrUuid.Equals(testUplayGame.Name))
if (uplayGameNameOrId.Equals(testUplayGame.Name))
return testUplayGame;
}
@ -315,7 +315,7 @@ namespace DisplayMagician.GameLibraries
}
public static UplayGame GetUplayGameId(string uplayGameId)
public static UplayGame GetUplayGameById(string uplayGameId)
{
foreach (UplayGame testUplayGame in _allUplayGames)
{
@ -401,46 +401,6 @@ namespace DisplayMagician.GameLibraries
// for each game record grab:
UplayAppInfo uplayGameAppInfo = new UplayAppInfo();
/* // name: (lookup the id in lookup table to find the name if needed)
if (uplayEntryLines.Exists(a => a.StartsWith(" name:", StringComparison.InvariantCultureIgnoreCase)))
{
mc = Regex.Matches(uplayEntry, @" name\: (.*)");
uplayGameAppInfo.GameName = mc[0].Groups[1].ToString();
// if the name contains a localization reference, then dereference it
if (localizations.ContainsKey(uplayGameAppInfo.GameName))
{
uplayGameAppInfo.GameName = localizations[uplayGameAppInfo.GameName];
}
}
else
continue;
*/
// icon_image: (lookup the id in lookup table to find the ICON)
/*if (uplayEntryLines.Exists(a => a.StartsWith(" icon_image:", StringComparison.InvariantCultureIgnoreCase)))
{
mc = Regex.Matches(uplayEntry, @"icon_image: (.*)");
string iconImageFileName = mc[0].Groups[1].ToString();
// if the icon_image contains a localization reference, then dereference it
if (localizations.ContainsKey(iconImageFileName))
{
iconImageFileName = localizations[iconImageFileName];
}
//61fdd16f06ae08158d0a6d476f1c6bd5.ico
string uplayGameIconPath = _uplayPath + @"data\games\" + iconImageFileName;
if (File.Exists(uplayGameIconPath) && uplayGameIconPath.EndsWith(".ico"))
{
uplayGameAppInfo.GameUplayIconPath = uplayGameIconPath;
}
}*/
// find the exe name looking at root: -> start_game: -> online: -> executables: -> path: -> relative: (get ACU.exe)
// Lookup the Game registry key from looking at root: -> start_game: -> online: -> executables: -> working_directory: -> register: (get HKEY_LOCAL_MACHINE\SOFTWARE\Ubisoft\Launcher\Installs\720\InstallDir)
// Extract the GameAppID from the number in the working directory (e.g. 720)
// Lookup the Game install path by reading the game registry key: D:/Ubisoft Game Launcher/Assassin's Creed Unity/
// join the Game install path and the exe name to get the full game exe path: D:/Ubisoft Game Launcher/Assassin's Creed Unity/ACU.exe
//if (uplayEntryLines.Find (a => a.StartsWith(" icon_image:", StringComparison.InvariantCultureIgnoreCase)))
bool gotGameIconPath = false;
bool gotGameName = false;
string gameFileName = "";

View File

@ -998,7 +998,7 @@ namespace DisplayMagician
if (shortcutToUse.GameLibrary.Equals(SupportedGameLibrary.Steam))
{
// We now need to get the SteamGame info
SteamGame steamGameToRun = SteamLibrary.GetSteamGame(shortcutToUse.GameAppId);
SteamGame steamGameToRun = SteamLibrary.GetSteamGameById(shortcutToUse.GameAppId);
logger.Info($"ShortcutRepository/RunShortcut: Starting the {steamGameToRun.Name} Steam Game, and then we're going to monitor it to wait for it to close.");
@ -1116,7 +1116,7 @@ namespace DisplayMagician
else if (shortcutToUse.GameLibrary.Equals(SupportedGameLibrary.Uplay))
{
// We now need to get the Uplay Game info
UplayGame uplayGameToRun = UplayLibrary.GetUplayGame(shortcutToUse.GameAppId);
UplayGame uplayGameToRun = UplayLibrary.GetUplayGameById(shortcutToUse.GameAppId);
logger.Info($"ShortcutRepository/RunShortcut: Starting the {uplayGameToRun.Name} Uplay Game, and then we're going to monitor it to wait for it to close.");
@ -1275,17 +1275,17 @@ namespace DisplayMagician
else if (shortcutToUse.GameLibrary.Equals(SupportedGameLibrary.Origin))
{
// We now need to get the Origin Game info
OriginGame originGameToRun = UplayLibrary.GetOriginGame(shortcutToUse.GameAppId);
OriginGame originGameToRun = OriginLibrary.GetOriginGameById(shortcutToUse.GameAppId);
logger.Info($"ShortcutRepository/RunShortcut: Starting the {originGameToRun.Name} Uplay Game, and then we're going to monitor it to wait for it to close.");
logger.Info($"ShortcutRepository/RunShortcut: Starting the {originGameToRun.Name} Origin Game, and then we're going to monitor it to wait for it to close.");
// If the GameAppID matches a Uplay game, then lets run it
// If the GameAppID matches a Origin game, then lets run it
if (originGameToRun is OriginGame)
{
// Prepare to start the Uplay game using the URI interface
// Prepare to start the Origin game using the URI interface
// as used by Uplay for it's own desktop shortcuts.
var address = $"origin2://game/launch?offerIds={originGameToRun.Id}";
logger.Debug($"ShortcutRepository/RunShortcut: Uplay launch address is {address}");
logger.Debug($"ShortcutRepository/RunShortcut: Origin launch address is {address}");
if (shortcutToUse.GameArgumentsRequired)
{
address += "/" + shortcutToUse.GameArguments;
@ -1295,12 +1295,12 @@ namespace DisplayMagician
address += "/0";
}
// Now we want to tell the user we're starting upc.exe
// Now we want to tell the user we're starting Origin
// Construct the Windows toast content
ToastContentBuilder tcBuilder = new ToastContentBuilder()
.AddToastActivationInfo("notify=startingUplay", ToastActivationType.Foreground)
.AddText($"Starting Uplay", hintMaxLines: 1)
.AddText($"Waiting for Uplay to start (and update if needed)...");
.AddToastActivationInfo("notify=startingOrigin", ToastActivationType.Foreground)
.AddText($"Starting Origin", hintMaxLines: 1)
.AddText($"Waiting for Origin to start (and update if needed)...");
//.AddButton("Stop", ToastActivationType.Background, "notify=runningGame&action=stop");
ToastContent toastContent = tcBuilder.Content;
// Make sure to use Windows.Data.Xml.Dom
@ -1314,24 +1314,24 @@ namespace DisplayMagician
DesktopNotifications.DesktopNotificationManagerCompat.CreateToastNotifier().Show(toast);
// Start the URI Handler to run Uplay
Console.WriteLine($"Starting Uplay Game: {uplayGameToRun.Name}");
logger.Info($"ShortcutRepository/RunShortcut: Starting Uplay Game: {uplayGameToRun.Name}");
Process uplayStartProcess = Process.Start(address);
// Start the URI Handler to run Origin
Console.WriteLine($"Starting Origin Game: {originGameToRun.Name}");
logger.Info($"ShortcutRepository/RunShortcut: Starting Origin Game: {originGameToRun.Name}");
Process originStartProcess = Process.Start(address);
// Wait for Uplay to start
List<Process> uplayProcesses = null;
// Wait for Origin to start
List<Process> originProcesses = null;
for (int secs = 0; secs >= (shortcutToUse.StartTimeout * 1000); secs += 500)
{
// Look for the processes with the ProcessName we sorted out earlier
uplayProcesses = Process.GetProcessesByName("upc").ToList();
originProcesses = Process.GetProcessesByName("origin").ToList();
// If we have found one or more processes then we should be good to go
// so let's break
if (uplayProcesses.Count > 0)
if (originProcesses.Count > 0)
{
logger.Debug($"ShortcutRepository/RunShortcut: Found {uplayProcesses.Count} 'upc' processes have started");
logger.Debug($"ShortcutRepository/RunShortcut: Found {originProcesses.Count} 'origin' processes have started");
break;
}
@ -1343,16 +1343,16 @@ namespace DisplayMagician
// Delay 5secs
Thread.Sleep(5000);
logger.Debug($"ShortcutRepository/RunShortcut: Pausing for 5 seconds to let the Uplay process start the game.");
logger.Debug($"ShortcutRepository/RunShortcut: Pausing for 5 seconds to let the Origin process start the game.");
// Now we know the Uplay app is running then
// we wait until the Uplay game is running (*allows for uplay update)
// Now we know the Origin app is running then
// we wait until the Origin game is running (*allows for origin update)
for (int secs = 0; secs >= (shortcutToUse.StartTimeout * 1000); secs += 500)
{
if (uplayGameToRun.IsRunning)
if (originGameToRun.IsRunning)
{
logger.Debug($"ShortcutRepository/RunShortcut: Found the '{uplayGameToRun.Name}' process has started");
logger.Debug($"ShortcutRepository/RunShortcut: Found the '{originGameToRun.Name}' process has started");
break;
}
@ -1361,23 +1361,23 @@ namespace DisplayMagician
}
// Store the Uplay Process ID for later
IPCService.GetInstance().HoldProcessId = uplayStartProcess?.Id ?? 0;
// Store the Origin Process ID for later
IPCService.GetInstance().HoldProcessId = originStartProcess?.Id ?? 0;
IPCService.GetInstance().Status = InstanceStatus.OnHold;
// Add a status notification icon in the status area
if (uplayGameToRun.Name.Length <= 41)
notifyIcon.Text = $"DisplayMagician: Running {uplayGameToRun.Name}...";
if (originGameToRun.Name.Length <= 41)
notifyIcon.Text = $"DisplayMagician: Running {originGameToRun.Name}...";
else
notifyIcon.Text = $"DisplayMagician: Running {uplayGameToRun.Name.Substring(0, 41)}...";
notifyIcon.Text = $"DisplayMagician: Running {originGameToRun.Name.Substring(0, 41)}...";
Application.DoEvents();
// Now we want to tell the user we're running a game!
// Construct the Windows toast content
tcBuilder = new ToastContentBuilder()
.AddToastActivationInfo("notify=runningUplayGame", ToastActivationType.Foreground)
.AddToastActivationInfo("notify=runningOriginGame", ToastActivationType.Foreground)
.AddText($"Running {shortcutToUse.GameName}", hintMaxLines: 1)
.AddText($"Waiting for the Uplay Game {shortcutToUse.GameName} to exit...");
.AddText($"Waiting for the Origin Game {shortcutToUse.GameName} to exit...");
//.AddButton("Stop", ToastActivationType.Background, "notify=runningGame&action=stop");
toastContent = tcBuilder.Content;
// Make sure to use Windows.Data.Xml.Dom
@ -1394,13 +1394,13 @@ namespace DisplayMagician
Thread.Sleep(5000);
// Wait for the game to exit
Console.WriteLine($"Waiting for {uplayGameToRun.Name} to exit.");
logger.Debug($"ShortcutRepository/RunShortcut: waiting for Uplay Game {uplayGameToRun.Name} to exit.");
Console.WriteLine($"Waiting for {originGameToRun.Name} to exit.");
logger.Debug($"ShortcutRepository/RunShortcut: waiting for Origin Game {originGameToRun.Name} to exit.");
while (true)
{
if (!uplayGameToRun.IsRunning)
if (!originGameToRun.IsRunning)
{
logger.Debug($"ShortcutRepository/RunShortcut: Uplay Game {uplayGameToRun.Name} is no longer running (IsRunning is false).");
logger.Debug($"ShortcutRepository/RunShortcut: Origin Game {originGameToRun.Name} is no longer running (IsRunning is false).");
break;
}
@ -1409,8 +1409,8 @@ namespace DisplayMagician
System.Threading.Thread.CurrentThread.Join(0);
Thread.Sleep(1000);
}
Console.WriteLine($"{uplayGameToRun.Name} has exited.");
logger.Debug($"ShortcutRepository/RunShortcut: Uplay Game {uplayGameToRun.Name} has exited.");
Console.WriteLine($"{originGameToRun.Name} has exited.");
logger.Debug($"ShortcutRepository/RunShortcut: Origin Game {originGameToRun.Name} has exited.");
// Tell the user that the Uplay Game has closed
// Construct the toast content

View File

@ -440,7 +440,7 @@ namespace DisplayMagician.UIForms
);
}
// If the game is a SteamGame
// If the game is a UplayGame
else if (txt_game_launcher.Text == SupportedGameLibrary.Uplay.ToString())
{
// Find the UplayGame
@ -474,6 +474,40 @@ namespace DisplayMagician.UIForms
);
}
// If the game is an Origin Game
else if (txt_game_launcher.Text == SupportedGameLibrary.Origin.ToString())
{
// Find the OriginGame
_gameToUse = new GameStruct
{
GameToPlay = (from originGame in OriginLibrary.AllInstalledGames where originGame.Id == _gameId select originGame).First(),
StartTimeout = Convert.ToInt32(nud_timeout_game.Value),
GameArguments = txt_args_game.Text,
GameArgumentsRequired = cb_args_game.Checked
};
_shortcutToEdit.UpdateGameShortcut(
txt_shortcut_save_name.Text,
_profileToUse,
_gameToUse,
_displayPermanence,
_audioPermanence,
_capturePermanence,
_gameToUse.GameToPlay.IconPath,
_changeAudioDevice,
_audioDevice,
_setAudioVolume,
_audioVolume,
_changeCaptureDevice,
_captureDevice,
_setCaptureVolume,
_captureVolume,
_startPrograms,
_autoName,
_uuid
);
}
}
else if (rb_standalone.Checked)
{
@ -817,11 +851,6 @@ namespace DisplayMagician.UIForms
// Add the images to the images array
il_games.Images.Add(bm);
/*if (!Visible)
{
//return;
}*/
// ADd the game to the game array
lv_games.Items.Add(new ListViewItem
{