2020-04-27 10:55:44 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Net;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.Security;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using HeliosPlus.Resources;
|
|
|
|
|
using HeliosPlus.Shared;
|
|
|
|
|
using HtmlAgilityPack;
|
|
|
|
|
using Microsoft.Win32;
|
|
|
|
|
using Newtonsoft.Json;
|
2020-05-01 10:30:27 +00:00
|
|
|
|
//using VdfParser;
|
|
|
|
|
//using Gameloop.Vdf;
|
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
|
using ValveKeyValue;
|
|
|
|
|
using System.Security.Cryptography;
|
|
|
|
|
using System.ServiceModel.Configuration;
|
2020-11-10 09:26:02 +00:00
|
|
|
|
//using HeliosPlus.GameLibraries.UplayAppInfoParser;
|
2020-05-01 10:30:27 +00:00
|
|
|
|
using TsudaKageyu;
|
|
|
|
|
using System.Drawing.IconLib;
|
|
|
|
|
using System.Drawing.IconLib.Exceptions;
|
2020-11-10 09:26:02 +00:00
|
|
|
|
using System.Diagnostics;
|
2020-04-27 10:55:44 +00:00
|
|
|
|
|
|
|
|
|
namespace HeliosPlus.GameLibraries
|
|
|
|
|
{
|
2020-11-10 09:26:02 +00:00
|
|
|
|
public class UplayGame : Game
|
2020-04-27 10:55:44 +00:00
|
|
|
|
{
|
2020-11-10 09:26:02 +00:00
|
|
|
|
/*private static string UplayLibrary.UplayExe;
|
|
|
|
|
private static string UplayLibrary.UplayPath;
|
2020-04-27 10:55:44 +00:00
|
|
|
|
private static string _uplayConfigVdfFile;
|
|
|
|
|
private static string _registryUplayKey = @"SOFTWARE\\Valve\\Uplay";
|
2020-11-10 09:26:02 +00:00
|
|
|
|
private static string _registryAppsKey = $@"{_registryUplayKey}\\Apps";*/
|
2020-04-27 10:55:44 +00:00
|
|
|
|
private string _gameRegistryKey;
|
|
|
|
|
private uint _uplayGameId;
|
|
|
|
|
private string _uplayGameName;
|
2020-11-10 09:26:02 +00:00
|
|
|
|
private string _uplayGameExePath;
|
|
|
|
|
private string _uplayGameDir;
|
2020-04-27 10:55:44 +00:00
|
|
|
|
private string _uplayGameExe;
|
2020-11-10 09:26:02 +00:00
|
|
|
|
private string _uplayGameProcessName;
|
2020-05-01 10:30:27 +00:00
|
|
|
|
private string _uplayGameIconPath;
|
2020-11-10 09:26:02 +00:00
|
|
|
|
private static List<UplayGame> _allInstalledUplayGames = null;
|
2020-04-27 10:55:44 +00:00
|
|
|
|
|
2020-11-10 09:26:02 +00:00
|
|
|
|
/*private struct UplayAppInfo
|
2020-05-01 10:30:27 +00:00
|
|
|
|
{
|
2020-11-10 09:26:02 +00:00
|
|
|
|
public uint GameID;
|
2020-05-01 10:30:27 +00:00
|
|
|
|
public string GameName;
|
|
|
|
|
public List<string> GameExes;
|
|
|
|
|
public string GameInstallDir;
|
|
|
|
|
public string GameUplayIconPath;
|
2020-11-10 09:26:02 +00:00
|
|
|
|
}*/
|
2020-04-27 10:55:44 +00:00
|
|
|
|
|
|
|
|
|
static UplayGame()
|
|
|
|
|
{
|
|
|
|
|
ServicePointManager.ServerCertificateValidationCallback +=
|
|
|
|
|
(send, certificate, chain, sslPolicyErrors) => true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2020-11-10 09:26:02 +00:00
|
|
|
|
public UplayGame(uint uplayGameId, string uplayGameName, string uplayGameExePath, string uplayGameIconPath)
|
2020-04-27 10:55:44 +00:00
|
|
|
|
{
|
|
|
|
|
|
2020-11-10 09:26:02 +00:00
|
|
|
|
_gameRegistryKey = $@"{UplayLibrary.registryUplayInstallsKey}\\{uplayGameId}";
|
2020-04-27 10:55:44 +00:00
|
|
|
|
_uplayGameId = uplayGameId;
|
|
|
|
|
_uplayGameName = uplayGameName;
|
2020-11-10 09:26:02 +00:00
|
|
|
|
_uplayGameExePath = uplayGameExePath;
|
|
|
|
|
_uplayGameDir = Path.GetDirectoryName(uplayGameExePath);
|
|
|
|
|
_uplayGameExe = Path.GetFileName(_uplayGameExePath);
|
|
|
|
|
_uplayGameProcessName = Path.GetFileNameWithoutExtension(_uplayGameExePath);
|
2020-05-01 10:30:27 +00:00
|
|
|
|
_uplayGameIconPath = uplayGameIconPath;
|
|
|
|
|
|
2020-11-10 09:26:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override uint Id
|
|
|
|
|
{
|
|
|
|
|
get => _uplayGameId;
|
|
|
|
|
set => _uplayGameId = value;
|
|
|
|
|
}
|
2020-04-27 10:55:44 +00:00
|
|
|
|
|
2020-11-10 09:26:02 +00:00
|
|
|
|
public override string Name
|
|
|
|
|
{
|
|
|
|
|
get => _uplayGameName;
|
|
|
|
|
set => _uplayGameName = value;
|
2020-04-27 10:55:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-11-10 09:26:02 +00:00
|
|
|
|
public override SupportedGameLibrary GameLibrary
|
|
|
|
|
{
|
|
|
|
|
get => SupportedGameLibrary.Uplay;
|
|
|
|
|
}
|
2020-04-27 10:55:44 +00:00
|
|
|
|
|
2020-11-10 09:26:02 +00:00
|
|
|
|
public override string IconPath
|
|
|
|
|
{
|
|
|
|
|
get => _uplayGameIconPath;
|
|
|
|
|
set => _uplayGameIconPath = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string ExePath
|
|
|
|
|
{
|
|
|
|
|
get => _uplayGameExePath;
|
|
|
|
|
set => _uplayGameExePath = value;
|
|
|
|
|
}
|
2020-04-27 10:55:44 +00:00
|
|
|
|
|
2020-11-10 09:26:02 +00:00
|
|
|
|
public override string Directory
|
|
|
|
|
{
|
|
|
|
|
get => _uplayGameExePath;
|
|
|
|
|
set => _uplayGameExePath = value;
|
|
|
|
|
}
|
2020-04-27 10:55:44 +00:00
|
|
|
|
|
2020-11-10 09:26:02 +00:00
|
|
|
|
public override bool IsRunning
|
2020-04-27 10:55:44 +00:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2020-11-10 09:26:02 +00:00
|
|
|
|
/*try
|
2020-04-27 10:55:44 +00:00
|
|
|
|
{
|
|
|
|
|
using (
|
|
|
|
|
var key = Registry.CurrentUser.OpenSubKey(_gameRegistryKey, RegistryKeyPermissionCheck.ReadSubTree))
|
|
|
|
|
{
|
|
|
|
|
if ((int)key?.GetValue(@"Running", 0) == 1)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-07-15 08:11:38 +00:00
|
|
|
|
catch (SecurityException ex)
|
2020-04-27 10:55:44 +00:00
|
|
|
|
{
|
2020-11-10 09:26:02 +00:00
|
|
|
|
Console.WriteLine($"UplayGame/IsRunning securityexception: {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
|
2020-07-15 08:11:38 +00:00
|
|
|
|
if (ex.Source != null)
|
|
|
|
|
Console.WriteLine("SecurityException source: {0} - Message: {1}", ex.Source, ex.Message);
|
2020-04-27 10:55:44 +00:00
|
|
|
|
throw;
|
|
|
|
|
}
|
2020-07-15 08:11:38 +00:00
|
|
|
|
catch (IOException ex)
|
2020-04-27 10:55:44 +00:00
|
|
|
|
{
|
|
|
|
|
// Extract some information from this exception, and then
|
|
|
|
|
// throw it to the parent method.
|
2020-11-10 09:26:02 +00:00
|
|
|
|
Console.WriteLine($"UplayGame/IsRunning ioexception: {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
|
2020-07-15 08:11:38 +00:00
|
|
|
|
if (ex.Source != null)
|
|
|
|
|
Console.WriteLine("IOException source: {0} - Message: {1}", ex.Source, ex.Message);
|
2020-04-27 10:55:44 +00:00
|
|
|
|
throw;
|
2020-11-10 09:26:02 +00:00
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
bool isRunning = Process.GetProcessesByName(_uplayGameProcessName)
|
|
|
|
|
.FirstOrDefault(p => p.MainModule.FileName
|
|
|
|
|
.StartsWith(ExePath, StringComparison.OrdinalIgnoreCase)) != default(Process);
|
|
|
|
|
return isRunning;
|
2020-04-27 10:55:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-10 09:26:02 +00:00
|
|
|
|
public override bool IsUpdating
|
2020-04-27 10:55:44 +00:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
using (
|
|
|
|
|
var key = Registry.CurrentUser.OpenSubKey(_gameRegistryKey, RegistryKeyPermissionCheck.ReadSubTree))
|
|
|
|
|
{
|
|
|
|
|
if ((int)key?.GetValue(@"Updating", 0) == 1)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-07-15 08:11:38 +00:00
|
|
|
|
catch (SecurityException ex)
|
2020-04-27 10:55:44 +00:00
|
|
|
|
{
|
2020-11-10 09:26:02 +00:00
|
|
|
|
Console.WriteLine($"UplayGame/IsUpdating securityexception: {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
|
2020-07-15 08:11:38 +00:00
|
|
|
|
if (ex.Source != null)
|
|
|
|
|
Console.WriteLine("SecurityException source: {0} - Message: {1}", ex.Source, ex.Message);
|
2020-04-27 10:55:44 +00:00
|
|
|
|
throw;
|
|
|
|
|
}
|
2020-07-15 08:11:38 +00:00
|
|
|
|
catch (IOException ex)
|
2020-04-27 10:55:44 +00:00
|
|
|
|
{
|
|
|
|
|
// Extract some information from this exception, and then
|
|
|
|
|
// throw it to the parent method.
|
2020-11-10 09:26:02 +00:00
|
|
|
|
Console.WriteLine($"UplayGame/IsUpdating ioexception: {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
|
2020-07-15 08:11:38 +00:00
|
|
|
|
if (ex.Source != null)
|
|
|
|
|
Console.WriteLine("IOException source: {0} - Message: {1}", ex.Source, ex.Message);
|
2020-04-27 10:55:44 +00:00
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-10 09:26:02 +00:00
|
|
|
|
public bool CopyTo(UplayGame uplayGame)
|
2020-04-27 10:55:44 +00:00
|
|
|
|
{
|
2020-11-10 09:26:02 +00:00
|
|
|
|
if (!(uplayGame is UplayGame))
|
2020-04-27 10:55:44 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
2020-11-10 09:26:02 +00:00
|
|
|
|
// Copy all the game data over to the other game
|
|
|
|
|
uplayGame.IconPath = IconPath;
|
|
|
|
|
uplayGame.Id = Id;
|
|
|
|
|
uplayGame.Name = Name;
|
|
|
|
|
uplayGame.ExePath = ExePath;
|
|
|
|
|
return true;
|
2020-04-27 10:55:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
|
|
|
|
var name = _uplayGameName;
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(name))
|
|
|
|
|
{
|
|
|
|
|
name = Language.Unknown;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (IsRunning)
|
|
|
|
|
{
|
|
|
|
|
return name + " " + Language.Running;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (IsUpdating)
|
|
|
|
|
{
|
|
|
|
|
return name + " " + Language.Updating;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-10 09:26:02 +00:00
|
|
|
|
return name;
|
2020-04-27 10:55:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|