Skip to content

Commit

Permalink
2.2.0 - Update GameFinder, remove dependabot
Browse files Browse the repository at this point in the history
  • Loading branch information
diogotr7 committed Oct 10, 2023
1 parent a1d6812 commit 009dae7
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 80 deletions.
13 changes: 0 additions & 13 deletions .github/dependabot.yml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Artemis.GameFinder\Artemis.GameFinder.csproj" />
<PackageReference Include="ArtemisRGB.Core" Version="1.2023.1009.1"/>
<ProjectReference Include="..\Artemis.GameFinder\Artemis.GameFinder.csproj" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion src/Artemis.GameFinder.Example/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public static class Program
{
public static void Main(string[] args)
{
var steamInstalled = new IsSteamInstalledPrerequisite(null);
var steamInstalled = new IsSteamInstalledPrerequisite(null!);
Console.WriteLine($"Steam installed: {steamInstalled.IsMet()}");

var gameInstalled = new IsSteamGameInstalledPrerequisite(548430);
Expand Down
8 changes: 4 additions & 4 deletions src/Artemis.GameFinder/Artemis.GameFinder.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<PropertyGroup>
<PackageVersion>2.1.0</PackageVersion>
<PackageVersion>2.2.0</PackageVersion>
<PackageId>ArtemisRGB.GameFinder</PackageId>
<Title>Artemis GameFinder</Title>
<Authors>diogotr7</Authors>
Expand All @@ -16,8 +16,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="ArtemisRGB.Core" Version="1.2023.917.4" IncludeAssets="compile;build;buildTransitive" />
<PackageReference Include="GameFinder.StoreHandlers.Steam" Version="3.1.0" />
<PackageReference Include="ArtemisRGB.Core" Version="1.*"/>
<PackageReference Include="GameFinder.StoreHandlers.Steam" Version="4.0.0"/>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System.Runtime.InteropServices;
using Artemis.Core;
using Artemis.GameFinder.Utils;
using GameFinder.RegistryUtils;
using GameFinder.StoreHandlers.Steam;
using GameFinder.StoreHandlers.Steam.Models.ValueTypes;

namespace Artemis.GameFinder.PrerequisiteActions;

Expand All @@ -15,32 +13,32 @@ public class CopyFileToSteamGameFolderAction : PluginPrerequisiteAction
/// <param name="steamId">The steam game id</param>
/// <param name="source">The absolute path to the file to copy</param>
/// <param name="destination">The destination path of the file, relative to the game root.</param>
public CopyFileToSteamGameFolderAction(string name, int steamId, string source, string destination)
public CopyFileToSteamGameFolderAction(string name, uint steamId, string source, string destination)
: base(name)
{
SteamId = steamId;
Source = source;
Destination = destination;
ProgressIndeterminate = true;
}
public int SteamId { get; }

public uint SteamId { get; }
public string Source { get; }
public string Destination { get; }

public override async Task Execute(CancellationToken cancellationToken)
{
var steamHandler = SteamHandlerFactory.Create();
var game = steamHandler.FindOneGameById(SteamGameId.From(SteamId), out var errors);

var game = steamHandler.FindOneGameById(AppId.From(SteamId), out var errors);
if (game == null)
throw new ArtemisPluginException("Could not find game with id " + SteamId);

var destinationPath = Path.Combine(game.Path.GetFullPath(), Destination);

await using var source = File.Open(Source, FileMode.Open);
await using var destination = File.Create(destinationPath);

await source.CopyToAsync(destination, cancellationToken);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System.Runtime.InteropServices;
using Artemis.Core;
using Artemis.Core;
using Artemis.GameFinder.Utils;
using GameFinder.RegistryUtils;
using GameFinder.StoreHandlers.Steam;
using GameFinder.StoreHandlers.Steam.Models.ValueTypes;

namespace Artemis.GameFinder.PrerequisiteActions;

Expand All @@ -14,22 +12,22 @@ public class DeleteFileFromSteamGameFolder : PluginPrerequisiteAction
/// <param name="name">The name of the action</param>
/// <param name="steamId">The id of the steam game</param>
/// <param name="filePath">The path to the file to delete, relative to the game root.</param>
public DeleteFileFromSteamGameFolder(string name, int steamId, string filePath)
public DeleteFileFromSteamGameFolder(string name, uint steamId, string filePath)
: base(name)
{
SteamId = steamId;
FilePath = filePath;
ProgressIndeterminate = true;
}
public int SteamId { get; }

public uint SteamId { get; }
public string FilePath { get; }

public override Task Execute(CancellationToken cancellationToken)
{
var steamHandler = SteamHandlerFactory.Create();

var game = steamHandler.FindOneGameById(SteamGameId.From(SteamId), out var errors);
var game = steamHandler.FindOneGameById(AppId.From(SteamId), out var errors);
if (game == null)
throw new ArtemisPluginException("Could not find game with id " + SteamId);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
using Artemis.Core;
using Artemis.GameFinder.PrerequisiteActions;
using Artemis.GameFinder.Utils;
using DryIoc.ImTools;
using GameFinder.RegistryUtils;
using GameFinder.StoreHandlers.Steam;
using GameFinder.StoreHandlers.Steam.Models.ValueTypes;

namespace Artemis.GameFinder.Prerequisites;

Expand All @@ -14,9 +12,9 @@ public class IsFilePresentInSteamGameFolderPrerequisite : PluginPrerequisite
private readonly SteamHandler _steamHandler;
private readonly string _destinationPathRelative;
private readonly string _sourcePath;
private readonly int _gameId;
private readonly uint _gameId;

public IsFilePresentInSteamGameFolderPrerequisite(int gameId, string sourcePath, string destinationPathRelative)
public IsFilePresentInSteamGameFolderPrerequisite(uint gameId, string sourcePath, string destinationPathRelative)
{
_gameId = gameId;
_destinationPathRelative = destinationPathRelative;
Expand All @@ -25,44 +23,44 @@ public IsFilePresentInSteamGameFolderPrerequisite(int gameId, string sourcePath,

Name = $"File present in game folder";
Description = $"File \"{destinationPathRelative}\" must be present in Steam game folder to use this plugin";
InstallActions = new()
InstallActions = new List<PluginPrerequisiteAction>
{
new CopyFileToSteamGameFolderAction(
"Copy CS:GO GSI Config",
_gameId,
_gameId,
_sourcePath,
_destinationPathRelative)
};

UninstallActions = new()
UninstallActions = new List<PluginPrerequisiteAction>
{
new DeleteFileFromSteamGameFolder(
"Delete CS:GO GSI Config",
_gameId,
_destinationPathRelative)
};
}

public override string Name { get; }
public override string Description { get; }
public override List<PluginPrerequisiteAction> InstallActions { get; }
public override List<PluginPrerequisiteAction> UninstallActions { get; }

public override bool IsMet()
{
if (!TryGetGamePath(_gameId, out var path))
return false;

return File.Exists(Path.Combine(path, _destinationPathRelative));
}
private bool TryGetGamePath(int id, [NotNullWhen(true)] out string? path)

private bool TryGetGamePath(uint id, [NotNullWhen(true)] out string? path)
{
var games = _steamHandler.FindAllGames();
var game = games.Where(x => x.IsT0)
.Select(r => r.AsT0)
.FirstOrDefault(g => g?.AppId == SteamGameId.From(id));
.Select(r => r.AsT0)
.FirstOrDefault(g => g?.AppId == AppId.From(id));

if (game is null)
{
path = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using System.Runtime.InteropServices;
using Artemis.Core;
using Artemis.Core;
using Artemis.GameFinder.Utils;
using GameFinder.Common;
using GameFinder.RegistryUtils;
using GameFinder.StoreHandlers.Steam;
using GameFinder.StoreHandlers.Steam.Models.ValueTypes;

namespace Artemis.GameFinder.Prerequisites;

Expand All @@ -13,35 +11,36 @@ namespace Artemis.GameFinder.Prerequisites;
public class IsSteamGameInstalledPrerequisite : PluginPrerequisite
{
private readonly SteamHandler _steamHandler;
public IsSteamGameInstalledPrerequisite(int gameId, string? gameName = null)

public IsSteamGameInstalledPrerequisite(uint gameId, string? gameName = null)
{
var gameNameOrId = gameName ?? gameId.ToString();
InstallActions = new()
InstallActions = new List<PluginPrerequisiteAction>
{
new RunInlinePowerShellAction($"Install game {gameNameOrId}", $"start \"steam://run/{gameId}\"")
};
UninstallActions = new();
UninstallActions = new List<PluginPrerequisiteAction>();
GameId = gameId;
Name = $"Steam game \"{gameNameOrId}\" installed";
Description = $"Steam game {gameNameOrId} must be installed to use this plugin";

_steamHandler = SteamHandlerFactory.Create();
}

public override bool IsMet()
{
try
{
var maybeGames = _steamHandler.FindAllGames();
return maybeGames.Any(option => option.TryPickT0(out var game, out var _) && game.AppId == GameId);
return maybeGames.Any(option => option.TryPickT0(out var game, out var _) && game.AppId == AppId.From(GameId));
}
catch
{
return false;
}
}

public int GameId { get; }
public uint GameId { get; }
public override string Name { get; }
public override string Description { get; }
public override List<PluginPrerequisiteAction> InstallActions { get; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,28 @@
using System.Runtime.InteropServices;
using Artemis.Core;
using Artemis.Core;
using Artemis.GameFinder.Utils;
using GameFinder.RegistryUtils;
using GameFinder.StoreHandlers.Steam;

namespace Artemis.GameFinder.Prerequisites;

/// <summary>
/// Checks if Steam is installed
/// </summary>
public class IsSteamInstalledPrerequisite : PluginPrerequisite
public class IsSteamInstalledPrerequisite : PluginPrerequisite
{
public IsSteamInstalledPrerequisite(Plugin plugin)
{
Name = "Steam installed";
Description = "Steam must be installed to use this plugin";
var installPath = plugin.ResolveRelativePath("SteamSetup.exe");
InstallActions = new()

var installPath = plugin?.ResolveRelativePath("SteamSetup.exe") ?? "SteamSetup.exe";
InstallActions = new List<PluginPrerequisiteAction>
{
new DownloadFileAction("Download Steam", "https://cdn.akamai.steamstatic.com/client/installer/SteamSetup.exe", installPath),
new ExecuteFileAction("Install Steam", installPath, "/S"),
new DeleteFileAction("Delete Steam installer", installPath)
new DownloadFileAction("Download Steam", "https://cdn.akamai.steamstatic.com/client/installer/SteamSetup.exe", installPath),
new ExecuteFileAction("Install Steam", installPath, "/S"),
new DeleteFileAction("Delete Steam installer", installPath)
};
UninstallActions = new();
UninstallActions = new List<PluginPrerequisiteAction>();
}

public override bool IsMet()
{
var handler = SteamHandlerFactory.Create();
Expand Down
2 changes: 1 addition & 1 deletion src/Artemis.GameFinder/Utils/SteamHandlerFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ public static SteamHandler Create()
{
return RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
? new SteamHandler(FileSystem.Shared, WindowsRegistry.Shared)
: new SteamHandler(FileSystem.Shared, registry: null);
: new SteamHandler(FileSystem.Shared, null);
}
}

0 comments on commit 009dae7

Please sign in to comment.