Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix EA Desktop implementation #67

Merged
merged 2 commits into from
Feb 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 19 additions & 17 deletions GameLauncher_Console/GameLauncher_Console/Dock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class CDock
public const char SEPARATOR_SYMBOL = '│';
public const char RATING_SYMBOL = '*';

public static readonly string FILENAME = Path.GetFileNameWithoutExtension(Environment.GetCommandLineArgs()[0]);
public static readonly string filename = Path.GetFileNameWithoutExtension(Environment.GetCommandLineArgs()[0]);

CConsoleHelper m_dockConsole;
private int nColumnCount = 2;
Expand All @@ -57,8 +57,12 @@ public class CDock
public static int m_nCurrentSelection = 0;

public static readonly string currentPath = Path.GetDirectoryName(AppContext.BaseDirectory);
public static readonly string version = Assembly.GetEntryAssembly().GetName().Version.ToString();
public static readonly List<string> supportedImages = new() { "ICO", "PNG", "JPG", "JPE", "JPEG", "GIF", "BMP", "TIF", "TIFF", "EPR", "EPRT", "EXI", "EXIF" };
public static readonly string title = Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyTitleAttribute>().Title;
//public static readonly string product = Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyProductAttribute>().Product;
public static readonly string version = Assembly.GetEntryAssembly().GetName().Version.ToString();
public static readonly string description = Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyDescriptionAttribute>().Description;

public static readonly List<string> supportedImages = new() { "ICO", "PNG", "JPG", "JPE", "JPEG", "GIF", "BMP", "TIF", "TIFF", "EPR", "EPRT", "EXI", "EXIF" };
public static bool noInteractive = false;
public static Size sizeIcon;
public static Size sizeImage;
Expand All @@ -72,8 +76,8 @@ public class CDock
// 0|-------|---------|---------|---------|---------|---------|---------|---------|80
" This program will scan your system for installed video games and display",
" them as a list. The following platforms are supported:",
" * Amazon * Battle.net * Big Fish * EA * Epic * GOG * Indiegala * itch",
" * Legacy * Oculus * Paradox * Plarium * Riot * Steam * Ubisoft * Wargaming",
" *Amazon *Battle.net *Big Fish *EA *Epic *GOG *Indiegala *itch *Legacy",
" *Oculus *Paradox *Plarium *Riot *Rockstar *Steam *Ubisoft *Wargaming",
"",
" The games list and configuration are stored in .json files in the same folder",
" as this program. You can manually add games by placing a shortcut (.lnk) in",
Expand Down Expand Up @@ -180,10 +184,10 @@ public void MainLoop(string[] args)
{
if (OperatingSystem.IsWindows())
{
if (PathEnvironmentUpdate.Add(Path.GetDirectoryName(AppContext.BaseDirectory), false))
if (PathEnvironmentUpdate.Add(currentPath, false))
{
CLogger.LogInfo("Added program location to PATH.");
Console.WriteLine("Added {0}.exe location to your PATH environment variable.", FILENAME);
Console.WriteLine("Added {0}.exe location to your PATH environment variable.", filename);
}
else
{
Expand Down Expand Up @@ -1593,8 +1597,7 @@ private void DisplayHelp(int height, CConfig.Colours cols)

Console.Clear();
WriteWithBreak(ref line, height, cols.titleCC, cols.titleLtCC, cols.titleCC, cols.titleLtCC,
string.Format("{0} version {1}", Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyProductAttribute>().Product,
Assembly.GetEntryAssembly().GetName().Version.ToString()));
string.Format("{0} version {1}", title, version));
foreach (string str in m_helpLines)
{
WriteWithBreak(ref line, height, cols.entryCC, cols.entryLtCC, cols.titleCC, cols.titleLtCC, str);
Expand Down Expand Up @@ -1797,19 +1800,17 @@ public static void DisplayUsage(CConfig.Colours cols, string parent, List<CMatch
Console.WriteLine();
// 0|-------|---------|---------|---------|---------|---------|---------|---------|80
SetFgColour(cols.titleCC);
Console.WriteLine("{0} version {1}",
Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyProductAttribute>().Product,
Assembly.GetEntryAssembly().GetName().Version.ToString());
Console.WriteLine(Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyDescriptionAttribute>().Description);
Console.WriteLine("{0} version {1}", title, version);
Console.WriteLine(description);
Console.WriteLine();
Console.WriteLine("Usage:");
Console.ResetColor();
Console.WriteLine("Start in interactive mode by running with no parameters,");
Console.WriteLine("or launch a game by entering search on the command-line, e.g.:");
Console.WriteLine(" .\\{0} \"My Game\"", FILENAME);
Console.WriteLine(" .\\{0} \"My Game\"", filename);
Console.WriteLine("If there are multiple results in command-line mode, to select an item from a");
Console.WriteLine("prior search, enter e.g.:");
Console.WriteLine(" .\\{0} /2", FILENAME);
Console.WriteLine(" .\\{0} /2", filename);
Console.WriteLine();
SetFgColour(cols.titleCC);
Console.WriteLine("Other parameters:");
Expand All @@ -1825,7 +1826,7 @@ public static void DisplayUsage(CConfig.Colours cols, string parent, List<CMatch
//Console.WriteLine("/U \"My Game\": Uninstall game"); // TODO
//Console.WriteLine("/A myalias \"My Game Name\": Change game's alias"); // TODO
Console.WriteLine(" /C : Toggle command-line only mode");
Console.WriteLine(" /P : Add {0}.exe location to your path", FILENAME);
Console.WriteLine(" /P : Add {0}.exe location to your path", filename);
Console.WriteLine("/?|/H : Display this help");
if (parent.Equals("explorer"))
{
Expand Down Expand Up @@ -2256,7 +2257,8 @@ public static void BackupCustomImage(string title, bool restore = false)
[SupportedOSPlatform("windows")]
public static Guid GetGuid()
{
using RegistryKey key = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Cryptography", RegistryKeyPermissionCheck.ReadSubTree); // HKLM64
using RegistryKey key = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine,
RegistryView.Registry64).OpenSubKey("SOFTWARE\\Microsoft\\Cryptography", RegistryKeyPermissionCheck.ReadSubTree); // HKLM64
return Guid.Parse((string)key.GetValue("MachineGuid"));
}

Expand Down
9 changes: 4 additions & 5 deletions GameLauncher_Console/GameLauncher_Console/Game.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using GameLauncher_Console;
using SqlDB;
using SqlDB;
using System;
using System.Collections.Generic;
using System.ComponentModel;
Expand All @@ -16,14 +15,14 @@ namespace CGame_Test // TODO: GameLauncher_Console
public static class CGame
{
// AttributeName definitions
public static readonly string A_GAME_TAG = "TAG";
private static readonly string _a_game_tag = "TAG";

/// <summary>
/// Game title articles.
/// Removed from titles when creating default aliases
/// Ignored during title searches
/// </summary>
public static readonly string[] ARTICLES =
private static readonly string[] _articles =
{
"The ", // English definite
"A ", "An ", // English indefinite
Expand Down Expand Up @@ -292,7 +291,7 @@ public List<int> SortGames(SortFlag flag, bool ascending, bool noArticle)
{
if((flag & i) > 0)
{
orderByString += CExtensions.GetDescription(i);
orderByString += GameLauncher_Console.CExtensions.GetDescription(i);
if(!ascending)
{
orderByString += " DESC, ";
Expand Down
46 changes: 36 additions & 10 deletions GameLauncher_Console/GameLauncher_Console/GameData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Text;

namespace GameLauncher_Console
{
Expand Down Expand Up @@ -106,7 +107,7 @@ public struct Sorter
public bool isAscending;
}

public static List<string> articles = new()
public static readonly List<string> _articles = new()
{
"The ", // English definite
"A ", "An " // English indefinite
Expand Down Expand Up @@ -1195,6 +1196,7 @@ public static void SortGames(CConsoleHelper.SortMethod sortMethod, bool faveSort
/// <param name="gameSet">Set of games</param>
private static void SortGameSet(ref HashSet<CGame> gameSet, CConsoleHelper.SortMethod sortMethod, bool faveSort = true, bool instSort = true, bool ignoreArticle = false)
{
List<string> articles = _articles;
if (ignoreArticle)
articles = new List<string>() { };

Expand Down Expand Up @@ -1332,7 +1334,7 @@ public static string GetAlias(string title)
*/

// remove leading "the" or "a/an"
foreach (string art in articles)
foreach (string art in _articles)
{
if (alias.StartsWith(art + " "))
alias = alias[(art.Length + 1)..];
Expand All @@ -1346,12 +1348,36 @@ public static string GetAlias(string title)
return alias;
}

/// <summary>
/// Return set of games from a fuzzy match
/// </summary>
/// <returns>dictionary of titles with confidence levels</returns>
/// <param name="match">String to match</param>
public static Dictionary<string, int> FindMatchingTitles(string match)
/// <summary>
/// Remove Unicode characters from a string
/// </summary>
/// <param name="s">A string</param>
/// <returns>simplified string</returns>
public static string StripUnicode(string s)
{
StringBuilder sb = new(s.Length);
foreach (char c in s)
{
if (c >= 127)
continue;
if (c < 32)
continue;
if (c == '%')
continue;
if (c == '?')
continue;
sb.Append(c);
}

return sb.ToString();
}

/// <summary>
/// Return set of games from a fuzzy match
/// </summary>
/// <returns>dictionary of titles with confidence levels</returns>
/// <param name="match">String to match</param>
public static Dictionary<string, int> FindMatchingTitles(string match)
{
return FindMatchingTitles(match, 0);
}
Expand Down Expand Up @@ -1379,7 +1405,7 @@ public static Dictionary<string, int> FindMatchingTitles(string match, int max)
shortTitle = shortTitle.Substring(prep.Length + 1);
}
*/
foreach (string art in articles)
foreach (string art in _articles)
{
if (shortTitle.StartsWith(art + " "))
shortTitle = shortTitle[(art.Length + 1)..];
Expand Down Expand Up @@ -1466,7 +1492,7 @@ public static HashSet<CGame> MatchGame(string match)
shortTitle = shortTitle.Substring(prep.Length + 1);
}
*/
foreach (string art in articles)
foreach (string art in _articles)
{
if (shortTitle.StartsWith(art + " "))
shortTitle = shortTitle[(art.Length + 1)..];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,23 +129,25 @@
<WCFMetadata Include="Connected Services\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="protobuf-net" Version="3.1.25" />
<PackageReference Include="protobuf-net.Core" Version="3.1.25" />
<PackageReference Include="protobuf-net" Version="3.1.33" />
<PackageReference Include="protobuf-net.Core" Version="3.1.33" />
<PackageReference Include="PureOrigin.API" Version="1.0.3" />
<PackageReference Include="SHA3.Net" Version="2.0.0" />
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
<PackageReference Include="Microsoft.DotNet.UpgradeAssistant.Extensions.Default.Analyzers" Version="0.4.355802">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.Windows.Compatibility" Version="7.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="7.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="7.0.2" />
<PackageReference Include="HtmlAgilityPack" Version="1.11.46" />
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="7.0.0" />
<PackageReference Include="SQLite" Version="3.13.0" />
<PackageReference Include="System.Data.SqlClient" Version="4.8.5" />
<PackageReference Include="System.Data.SQLite" Version="1.0.117" />
<PackageReference Include="System.Management" Version="7.0.0" />
<PackageReference Include="System.Resources.Extensions" Version="7.0.0" />
<PackageReference Include="System.Text.Encodings.Web" Version="7.0.0" />
<PackageReference Include="System.Text.Json" Version="7.0.0" />
<PackageReference Include="System.Text.Json" Version="7.0.1" />
</ItemGroup>
<ItemGroup>
<Compile Remove="DockConsole.cs" />
Expand Down
Loading