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;
|
|
|
|
|
//using VdfParser;
|
2020-05-01 10:30:27 +00:00
|
|
|
|
//using Gameloop.Vdf;
|
2020-04-27 10:55:44 +00:00
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
|
using ValveKeyValue;
|
|
|
|
|
using System.Security.Cryptography;
|
|
|
|
|
using System.ServiceModel.Configuration;
|
|
|
|
|
using HeliosPlus.GameLibraries.SteamAppInfoParser;
|
2020-05-01 10:30:27 +00:00
|
|
|
|
using TsudaKageyu;
|
|
|
|
|
using System.Drawing.IconLib;
|
|
|
|
|
using System.Drawing.IconLib.Exceptions;
|
2020-10-13 08:25:10 +00:00
|
|
|
|
using System.Diagnostics;
|
2020-04-27 10:55:44 +00:00
|
|
|
|
|
|
|
|
|
namespace HeliosPlus.GameLibraries
|
|
|
|
|
{
|
2020-10-18 08:15:19 +00:00
|
|
|
|
public class SteamGame
|
2020-04-27 10:55:44 +00:00
|
|
|
|
{
|
2020-07-21 11:40:33 +00:00
|
|
|
|
/*private static string SteamLibrary.SteamExe;
|
|
|
|
|
private static string SteamLibrary.SteamPath;
|
2020-04-27 10:55:44 +00:00
|
|
|
|
private static string _steamConfigVdfFile;
|
|
|
|
|
private static string _registrySteamKey = @"SOFTWARE\\Valve\\Steam";
|
2020-07-21 11:40:33 +00:00
|
|
|
|
private static string _registryAppsKey = $@"{_registrySteamKey}\\Apps";*/
|
2020-04-27 10:55:44 +00:00
|
|
|
|
private string _gameRegistryKey;
|
|
|
|
|
private uint _steamGameId;
|
|
|
|
|
private string _steamGameName;
|
2020-10-18 08:15:19 +00:00
|
|
|
|
private string _steamGamePath;
|
2020-04-27 10:55:44 +00:00
|
|
|
|
private string _steamGameExe;
|
2020-10-13 08:25:10 +00:00
|
|
|
|
private string _steamGameProcessName;
|
2020-05-01 10:30:27 +00:00
|
|
|
|
private string _steamGameIconPath;
|
2020-07-21 11:40:33 +00:00
|
|
|
|
private static List<SteamGame> _allInstalledSteamGames = null;
|
2020-04-27 10:55:44 +00:00
|
|
|
|
|
2020-07-21 11:40:33 +00:00
|
|
|
|
/*private struct SteamAppInfo
|
2020-04-27 10:55:44 +00:00
|
|
|
|
{
|
|
|
|
|
public uint GameID;
|
|
|
|
|
public string GameName;
|
|
|
|
|
public List<string> GameExes;
|
|
|
|
|
public string GameInstallDir;
|
|
|
|
|
public string GameSteamIconPath;
|
2020-07-21 11:40:33 +00:00
|
|
|
|
}*/
|
2020-04-27 10:55:44 +00:00
|
|
|
|
|
|
|
|
|
static SteamGame()
|
|
|
|
|
{
|
|
|
|
|
ServicePointManager.ServerCertificateValidationCallback +=
|
|
|
|
|
(send, certificate, chain, sslPolicyErrors) => true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2020-10-18 08:15:19 +00:00
|
|
|
|
public SteamGame(uint steamGameId, string steamGameName, string steamGamePath, string steamGameExe, string steamGameIconPath)
|
2020-04-27 10:55:44 +00:00
|
|
|
|
{
|
|
|
|
|
|
2020-07-21 11:40:33 +00:00
|
|
|
|
_gameRegistryKey = $@"{SteamLibrary.SteamAppsRegistryKey}\\{steamGameId}";
|
2020-04-27 10:55:44 +00:00
|
|
|
|
_steamGameId = steamGameId;
|
|
|
|
|
_steamGameName = steamGameName;
|
2020-10-18 08:15:19 +00:00
|
|
|
|
_steamGamePath = steamGamePath;
|
|
|
|
|
_steamGameExe = steamGameExe;
|
|
|
|
|
_steamGameProcessName = Path.GetFileNameWithoutExtension(_steamGameExe);
|
2020-05-01 10:30:27 +00:00
|
|
|
|
_steamGameIconPath = steamGameIconPath;
|
2020-04-27 10:55:44 +00:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-18 08:15:19 +00:00
|
|
|
|
public uint GameId {
|
2020-07-22 09:52:36 +00:00
|
|
|
|
get => _steamGameId;
|
|
|
|
|
set => _steamGameId = value;
|
|
|
|
|
}
|
2020-04-27 10:55:44 +00:00
|
|
|
|
|
2020-10-18 08:15:19 +00:00
|
|
|
|
public SupportedGameLibrary GameLibrary {
|
2020-07-22 09:52:36 +00:00
|
|
|
|
get => SupportedGameLibrary.Steam;
|
|
|
|
|
}
|
2020-04-27 10:55:44 +00:00
|
|
|
|
|
2020-10-18 08:15:19 +00:00
|
|
|
|
public string GameIconPath {
|
2020-07-22 09:52:36 +00:00
|
|
|
|
get => _steamGameIconPath;
|
|
|
|
|
set => _steamGameIconPath = value;
|
|
|
|
|
}
|
2020-10-18 08:15:19 +00:00
|
|
|
|
|
|
|
|
|
public bool IsRunning
|
2020-04-27 10:55:44 +00:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2020-10-13 08:25:10 +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-07-24 04:51:48 +00:00
|
|
|
|
Console.WriteLine($"SteamGame/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-07-24 04:51:48 +00:00
|
|
|
|
Console.WriteLine($"SteamGame/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-10-13 08:25:10 +00:00
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
bool isRunning = Process.GetProcessesByName(_steamGameProcessName)
|
|
|
|
|
.FirstOrDefault(p => p.MainModule.FileName
|
2020-10-18 08:15:19 +00:00
|
|
|
|
.StartsWith(GamePath,StringComparison.OrdinalIgnoreCase)) != default(Process);
|
2020-10-13 08:25:10 +00:00
|
|
|
|
return isRunning;
|
2020-04-27 10:55:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-18 08:15:19 +00:00
|
|
|
|
public 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-07-24 04:51:48 +00:00
|
|
|
|
Console.WriteLine($"SteamGame/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-07-24 04:51:48 +00:00
|
|
|
|
Console.WriteLine($"SteamGame/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-10-18 08:15:19 +00:00
|
|
|
|
public string GameName {
|
|
|
|
|
get => _steamGameName;
|
|
|
|
|
set => _steamGameName = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string GamePath {
|
|
|
|
|
get => _steamGamePath;
|
|
|
|
|
set => _steamGamePath = value;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-21 11:40:33 +00:00
|
|
|
|
public bool CopyTo(SteamGame steamGame)
|
2020-04-27 10:55:44 +00:00
|
|
|
|
{
|
2020-07-21 11:40:33 +00:00
|
|
|
|
if (!(steamGame is SteamGame))
|
2020-04-27 10:55:44 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
2020-07-22 09:52:36 +00:00
|
|
|
|
// Copy all the game data over to the other game
|
2020-10-18 08:15:19 +00:00
|
|
|
|
steamGame.GameIconPath = GameIconPath;
|
|
|
|
|
steamGame.GameId = GameId;
|
|
|
|
|
steamGame.GameName = GameName;
|
|
|
|
|
steamGame.GamePath = GamePath;
|
2020-07-21 11:40:33 +00:00
|
|
|
|
return true;
|
2020-04-27 10:55:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
|
|
|
|
var name = _steamGameName;
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(name))
|
|
|
|
|
{
|
|
|
|
|
name = Language.Unknown;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (IsRunning)
|
|
|
|
|
{
|
|
|
|
|
return name + " " + Language.Running;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (IsUpdating)
|
|
|
|
|
{
|
|
|
|
|
return name + " " + Language.Updating;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-02 02:51:28 +00:00
|
|
|
|
return name;
|
2020-04-27 10:55:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|