Skip to content

Commit

Permalink
Replace Vogen with TransparentValueObjects
Browse files Browse the repository at this point in the history
  • Loading branch information
erri120 committed Jan 8, 2024
1 parent 9d002be commit 7a5f3c6
Show file tree
Hide file tree
Showing 28 changed files with 91 additions and 73 deletions.
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<PackageVersion Include="SHA3.Net" Version="2.0.0" />
<PackageVersion Include="System.Management" Version="8.0.0" />
<PackageVersion Include="ValveKeyValue" Version="0.9.0.267" />
<PackageVersion Include="Vogen" Version="3.0.23" />
<PackageVersion Include="TransparentValueObjects" Version="1.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down
1 change: 0 additions & 1 deletion src/GameFinder.Common/GameFinder.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@
<PackageReference Include="NexusMods.Paths" />
<PackageReference Include="FluentResults" />
<PackageReference Include="OneOf" />
<PackageReference Include="Vogen" />
</ItemGroup>
</Project>
8 changes: 6 additions & 2 deletions src/GameFinder.StoreHandlers.EADesktop/EADesktopGameId.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
using System;
using System.Collections.Generic;
using JetBrains.Annotations;
using Vogen;
using TransparentValueObjects;

namespace GameFinder.StoreHandlers.EADesktop;

/// <summary>
/// Represents an id for games installed with EA Desktop.
/// </summary>
[ValueObject<string>]
public readonly partial struct EADesktopGameId { }
public readonly partial struct EADesktopGameId : IAugmentWith<DefaultEqualityComparerAugment>
{
/// <inheritdoc/>
public static IEqualityComparer<string> InnerValueDefaultEqualityComparer { get; } = StringComparer.OrdinalIgnoreCase;
}

/// <inheritdoc/>
[PublicAPI]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<ItemGroup>
<PackageReference Include="SHA3.Net" />
<PackageReference Include="System.Management" />
<PackageReference Include="TransparentValueObjects" PrivateAssets="all" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
</ItemGroup>

<ItemGroup>
Expand Down
8 changes: 6 additions & 2 deletions src/GameFinder.StoreHandlers.EGS/EGSGameId.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
using System;
using System.Collections.Generic;
using JetBrains.Annotations;
using Vogen;
using TransparentValueObjects;

namespace GameFinder.StoreHandlers.EGS;

/// <summary>
/// Represents an id for games installed with the Epic Games Store.
/// </summary>
[ValueObject<string>]
public readonly partial struct EGSGameId { }
public readonly partial struct EGSGameId : IAugmentWith<DefaultEqualityComparerAugment>
{
/// <inheritdoc/>
public static IEqualityComparer<string> InnerValueDefaultEqualityComparer { get; } = StringComparer.OrdinalIgnoreCase;
}

/// <inheritdoc/>
[PublicAPI]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
<ProjectReference Include="..\GameFinder.RegistryUtils\GameFinder.RegistryUtils.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="TransparentValueObjects" PrivateAssets="all" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
</ItemGroup>

<ItemGroup>
<InternalsVisibleTo Include="GameFinder.StoreHandlers.EGS.Tests" />
</ItemGroup>
Expand Down
3 changes: 1 addition & 2 deletions src/GameFinder.StoreHandlers.GOG/GOGGameId.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Vogen;
using TransparentValueObjects;

namespace GameFinder.StoreHandlers.GOG;

Expand All @@ -7,4 +7,3 @@ namespace GameFinder.StoreHandlers.GOG;
/// </summary>
[ValueObject<long>]
public readonly partial struct GOGGameId { }

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
<ProjectReference Include="..\GameFinder.RegistryUtils\GameFinder.RegistryUtils.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="TransparentValueObjects" PrivateAssets="all" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
</ItemGroup>

<ItemGroup>
<InternalsVisibleTo Include="GameFinder.StoreHandlers.GOG.Tests" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
<ProjectReference Include="..\GameFinder.RegistryUtils\GameFinder.RegistryUtils.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="TransparentValueObjects" PrivateAssets="all" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
</ItemGroup>

<ItemGroup>
<InternalsVisibleTo Include="GameFinder.StoreHandlers.Origin.Tests" />
</ItemGroup>
Expand Down
8 changes: 6 additions & 2 deletions src/GameFinder.StoreHandlers.Origin/OriginGameId.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
using System;
using System.Collections.Generic;
using JetBrains.Annotations;
using Vogen;
using TransparentValueObjects;

namespace GameFinder.StoreHandlers.Origin;

/// <summary>
/// Represents an id for games installed with Origin.
/// </summary>
[ValueObject<string>]
public readonly partial struct OriginGameId { }
public readonly partial struct OriginGameId : IAugmentWith<DefaultEqualityComparerAugment>
{
/// <inheritdoc/>
public static IEqualityComparer<string> InnerValueDefaultEqualityComparer { get; } = StringComparer.OrdinalIgnoreCase;
}

/// <inheritdoc/>
[PublicAPI]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

<ItemGroup>
<PackageReference Include="ValveKeyValue" />
<PackageReference Include="TransparentValueObjects" PrivateAssets="all" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
</ItemGroup>

<ItemGroup>
Expand Down
10 changes: 5 additions & 5 deletions src/GameFinder.StoreHandlers.Steam/Models/AppManifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public sealed record AppManifest
/// </remarks>
/// <seealso cref="GetCurrentUpdateNotesUrl"/>
/// <seealso cref="TargetBuildId"/>
public BuildId BuildId { get; init; } = BuildId.Empty;
public BuildId BuildId { get; init; } = BuildId.DefaultValue;

/// <summary>
/// Gets the last owner of this app.
Expand Down Expand Up @@ -160,7 +160,7 @@ public sealed record AppManifest
/// </remarks>
/// <seealso cref="GetNextUpdateNotesUrl"/>
/// <seealso cref="BuildId"/>
public BuildId TargetBuildId { get; init; } = BuildId.Empty;
public BuildId TargetBuildId { get; init; } = BuildId.DefaultValue;

/// <summary>
/// Gets the automatic update behavior for this app.
Expand Down Expand Up @@ -266,7 +266,7 @@ public AbsolutePath GetWorkshopManifestFilePath() => ManifestPath.Parent
/// Gets all locally installed DLCs.
/// </summary>
public IReadOnlyDictionary<AppId, InstalledDepot> GetInstalledDLCs() => InstalledDepots
.Where(kv => kv.Value.DLCAppId != AppId.Empty)
.Where(kv => kv.Value.DLCAppId != AppId.DefaultValue)
.ToDictionary(kv => kv.Value.DLCAppId, kv => kv.Value);

/// <summary>
Expand All @@ -278,9 +278,9 @@ public IReadOnlyDictionary<AppId, InstalledDepot> GetInstalledDLCs() => Installe
/// Gets the URL to the Update Notes for the next update using <see cref="TargetBuildId"/> on SteamDB.
/// </summary>
/// <remarks>
/// This value will be <c>null</c>, if <see cref="TargetBuildId"/> is <see cref="ValueTypes.BuildId.Empty"/>.
/// This value will be <c>null</c>, if <see cref="TargetBuildId"/> is <see cref="ValueTypes.BuildId.DefaultValue"/>.
/// </remarks>
public string? GetNextUpdateNotesUrl() => TargetBuildId == BuildId.Empty ? null : TargetBuildId.GetSteamDbUpdateNotesUrl();
public string? GetNextUpdateNotesUrl() => TargetBuildId == BuildId.DefaultValue ? null : TargetBuildId.GetSteamDbUpdateNotesUrl();

/// <summary>
/// Gets the user-data path for the current app using <see cref="LastOwner"/> and
Expand Down
4 changes: 2 additions & 2 deletions src/GameFinder.StoreHandlers.Steam/Models/InstalledDepot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ public record InstalledDepot
/// Gets the optionally unique identifier of the DLC that is associated with this depot.
/// </summary>
/// <remarks>
/// This value can be <see cref="AppId.Empty"/> if the depot is not associated with a DLC.
/// This value can be <see cref="AppId.DefaultValue"/> if the depot is not associated with a DLC.
/// </remarks>
public AppId DLCAppId { get; init; } = AppId.Empty;
public AppId DLCAppId { get; init; } = AppId.DefaultValue;

/// <summary>
/// Gets the URL to the SteamDB page for the depot.
Expand Down
12 changes: 4 additions & 8 deletions src/GameFinder.StoreHandlers.Steam/Models/ValueTypes/AppId.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using System.Globalization;
using System.Web;
using JetBrains.Annotations;
using Vogen;

[assembly: VogenDefaults(debuggerAttributes: DebuggerAttributeGeneration.Basic)]
using TransparentValueObjects;

namespace GameFinder.StoreHandlers.Steam.Models.ValueTypes;

Expand All @@ -13,12 +11,10 @@ namespace GameFinder.StoreHandlers.Steam.Models.ValueTypes;
/// <example><c>262060</c></example>
[PublicAPI]
[ValueObject<uint>]
public readonly partial struct AppId
public readonly partial struct AppId : IAugmentWith<DefaultValueAugment>
{
/// <summary>
/// Empty or default value of <c>0</c>.
/// </summary>
public static readonly AppId Empty = From(0);
/// <inheritdoc/>
public static AppId DefaultValue { get; } = From(0);

/// <summary>
/// Gets the URL to the SteamDB page of the app associated with this id.
Expand Down
10 changes: 4 additions & 6 deletions src/GameFinder.StoreHandlers.Steam/Models/ValueTypes/BuildId.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Globalization;
using JetBrains.Annotations;
using Vogen;
using TransparentValueObjects;

namespace GameFinder.StoreHandlers.Steam.Models.ValueTypes;

Expand All @@ -10,12 +10,10 @@ namespace GameFinder.StoreHandlers.Steam.Models.ValueTypes;
/// <example><c>9545898</c></example>
[PublicAPI]
[ValueObject<uint>]
public readonly partial struct BuildId
public readonly partial struct BuildId : IAugmentWith<DefaultValueAugment>
{
/// <summary>
/// Empty or default value of <c>0</c>.
/// </summary>
public static readonly BuildId Empty = From(0);
/// <inheritdoc/>
public static BuildId DefaultValue { get; } = From(0);

/// <summary>
/// Gets the URL to the SteamDB Update Notes for the build associated with this id.
Expand Down
10 changes: 4 additions & 6 deletions src/GameFinder.StoreHandlers.Steam/Models/ValueTypes/DepotId.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Globalization;
using JetBrains.Annotations;
using Vogen;
using TransparentValueObjects;

namespace GameFinder.StoreHandlers.Steam.Models.ValueTypes;

Expand All @@ -10,12 +10,10 @@ namespace GameFinder.StoreHandlers.Steam.Models.ValueTypes;
/// <example><c>262061</c></example>
[PublicAPI]
[ValueObject<uint>]
public readonly partial struct DepotId
public readonly partial struct DepotId : IAugmentWith<DefaultValueAugment>
{
/// <summary>
/// Empty or default value of <c>0</c>.
/// </summary>
public static readonly DepotId Empty = From(0);
/// <inheritdoc/>
public static DepotId DefaultValue { get; } = From(0);

/// <summary>
/// Gets the URL to the SteamDB page of this depot.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Diagnostics.CodeAnalysis;
using JetBrains.Annotations;
using Vogen;
using TransparentValueObjects;

namespace GameFinder.StoreHandlers.Steam.Models.ValueTypes;

Expand All @@ -17,12 +17,10 @@ namespace GameFinder.StoreHandlers.Steam.Models.ValueTypes;
/// <example><c>5542773349944116172</c></example>
[PublicAPI]
[ValueObject<ulong>]
public readonly partial struct ManifestId
public readonly partial struct ManifestId : IAugmentWith<DefaultValueAugment>
{
/// <summary>
/// Empty or default value of <c>0</c>.
/// </summary>
public static readonly ManifestId Empty = From(0);
/// <inheritdoc/>
public static ManifestId DefaultValue { get; } = From(0);

/// <summary>
/// Gets the URL to the SteamDB page for the Changeset of the manifest associated with this id.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using JetBrains.Annotations;
using Vogen;
using TransparentValueObjects;

namespace GameFinder.StoreHandlers.Steam.Models.ValueTypes;

Expand All @@ -16,12 +16,10 @@ namespace GameFinder.StoreHandlers.Steam.Models.ValueTypes;
/// <example><c>942405260</c></example>
[PublicAPI]
[ValueObject<ulong>]
public readonly partial struct WorkshopItemId
public readonly partial struct WorkshopItemId : IAugmentWith<DefaultValueAugment>
{
/// <summary>
/// Empty or default value of <c>0</c>.
/// </summary>
public static readonly WorkshopItemId Empty = From(0);
/// <inheritdoc/>
public static WorkshopItemId DefaultValue { get; } = From(0);

/// <summary>
/// Gets the URL to the Steam Workshop page of this item.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using JetBrains.Annotations;
using Vogen;
using TransparentValueObjects;

namespace GameFinder.StoreHandlers.Steam.Models.ValueTypes;

Expand All @@ -13,10 +13,8 @@ namespace GameFinder.StoreHandlers.Steam.Models.ValueTypes;
/// <seealso cref="ManifestId"/>
[PublicAPI]
[ValueObject<ulong>]
public readonly partial struct WorkshopManifestId
public readonly partial struct WorkshopManifestId : IAugmentWith<DefaultValueAugment>
{
/// <summary>
/// Empty or default value of <c>0</c>.
/// </summary>
public static readonly WorkshopManifestId Empty = From(0);
/// <inheritdoc/>
public static WorkshopManifestId DefaultValue { get; } = From(0);
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ public static Result<AppManifest> ParseManifestFile(AbsolutePath manifestPath)
var lastUpdatedResult = ParseOptionalChildObject(appState, "LastUpdated", ParseDateTimeOffset, DateTimeOffset.UnixEpoch);
var sizeOnDiskResult = ParseOptionalChildObject(appState, "SizeOnDisk", ParseSize, Size.Zero);
var stagingSizeResult = ParseOptionalChildObject(appState, "StagingSize", ParseSize, Size.Zero);
var buildIdResult = ParseOptionalChildObject(appState, "buildid", ParseBuildId, BuildId.Empty);
var buildIdResult = ParseOptionalChildObject(appState, "buildid", ParseBuildId, BuildId.DefaultValue);
var lastOwnerResult = ParseOptionalChildObject(appState, "LastOwner", ParseSteamId, SteamId.Empty);
var updateResult = ParseOptionalChildObject(appState, "UpdateResult", ParseUInt32, default);
var bytesToDownloadResult = ParseOptionalChildObject(appState, "BytesToDownload", ParseSize, Size.Zero);
var bytesDownloadedResult = ParseOptionalChildObject(appState, "BytesDownloaded", ParseSize, Size.Zero);
var bytesToStageResult = ParseOptionalChildObject(appState, "BytesToStage", ParseSize, Size.Zero);
var bytesStagedResult = ParseOptionalChildObject(appState, "BytesStaged", ParseSize, Size.Zero);
var targetBuildIdResult = ParseOptionalChildObject(appState, "TargetBuildID", ParseBuildId, BuildId.Empty);
var targetBuildIdResult = ParseOptionalChildObject(appState, "TargetBuildID", ParseBuildId, BuildId.DefaultValue);
var autoUpdateBehaviorResult = ParseOptionalChildObject(appState, "AutoUpdateBehavior", ParseByte, default).Map(x => (AutoUpdateBehavior)x);
var backgroundDownloadBehaviorResult = ParseOptionalChildObject(appState, "AllowOtherDownloadsWhileRunning", ParseByte, default).Map(x => (BackgroundDownloadBehavior)x);
var scheduledAutoUpdateResult = ParseOptionalChildObject(appState, "ScheduledAutoUpdate", ParseDateTimeOffset, DateTimeOffset.UnixEpoch);
Expand Down Expand Up @@ -225,7 +225,7 @@ private static Result<InstalledDepot> ParseInstalledDepot(KVObject depotObject)

var manifestIdResult = ParseRequiredChildObject(depotObject, "manifest", ParseManifestId);
var sizeOnDiskResult = ParseRequiredChildObject(depotObject, "size", ParseSize);
var dlcAppIdResult = ParseOptionalChildObject(depotObject, "dlcappid", ParseAppId, AppId.Empty);
var dlcAppIdResult = ParseOptionalChildObject(depotObject, "dlcappid", ParseAppId, AppId.DefaultValue);

var mergedResults = Result.Merge(
manifestIdResult,
Expand Down
Loading

0 comments on commit 7a5f3c6

Please sign in to comment.