Skip to content

Commit

Permalink
[WIP] Use IGameVersion as source for install dir
Browse files Browse the repository at this point in the history
  • Loading branch information
affederaffe committed Dec 3, 2023
1 parent d0bff50 commit e3624bc
Show file tree
Hide file tree
Showing 20 changed files with 217 additions and 100 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System.Text.Json.Serialization;

using BeatSaberModManager.Models.Implementations.LegacyVersions;
using BeatSaberModManager.Models.Implementations.Versions;


namespace BeatSaberModManager.Models.Implementations.Json
{
[JsonSerializable(typeof(SteamLegacyGameVersion[]))]
[JsonSerializable(typeof(SteamGameVersion[]))]
internal sealed partial class LegacyGameVersionJsonSerializerContext : JsonSerializerContext;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
using System;

using BeatSaberModManager.Models.Interfaces;


namespace BeatSaberModManager.Models.Implementations.Versions
{
/// <summary>
///
/// </summary>
public class OculusGameVersion : IGameVersion
{
/// <inheritdoc />
public required string GameVersion { get; init; }

/// <inheritdoc />
public DateTime ReleaseDate { get; init; }

/// <inheritdoc />
public Uri? ReleaseUrl { get; init; }

/// <inheritdoc />
public Uri? ReleaseImage { get; init; }

/// <summary>
///
/// </summary>
public string? InstallDir { get; set; }

/// <inheritdoc />
public int CompareTo(IGameVersion? other) => throw new NotImplementedException();

public override bool Equals(object obj)

Check failure on line 33 in BeatSaberModManager/Models/Implementations/Versions/OculusGameVersion.cs

View workflow job for this annotation

GitHub Actions / Build Windows

Nullability of type of parameter 'obj' doesn't match overridden member (possibly because of nullability attributes).

Check failure on line 33 in BeatSaberModManager/Models/Implementations/Versions/OculusGameVersion.cs

View workflow job for this annotation

GitHub Actions / Build Linux

Nullability of type of parameter 'obj' doesn't match overridden member (possibly because of nullability attributes).
{
if (ReferenceEquals(this, obj))
{
return true;
}

if (ReferenceEquals(obj, null))
{
return false;
}

throw new NotImplementedException();

Check failure on line 45 in BeatSaberModManager/Models/Implementations/Versions/OculusGameVersion.cs

View workflow job for this annotation

GitHub Actions / Build Windows

Equals creates an exception of type NotImplementedException. Exceptions should not be raised in this type of method. If this exception instance might be raised, change this method's logic so it no longer raises an exception. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1065)

Check failure on line 45 in BeatSaberModManager/Models/Implementations/Versions/OculusGameVersion.cs

View workflow job for this annotation

GitHub Actions / Build Linux

Equals creates an exception of type NotImplementedException. Exceptions should not be raised in this type of method. If this exception instance might be raised, change this method's logic so it no longer raises an exception. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1065)
}

public override int GetHashCode()
{
throw new NotImplementedException();

Check failure on line 50 in BeatSaberModManager/Models/Implementations/Versions/OculusGameVersion.cs

View workflow job for this annotation

GitHub Actions / Build Windows

GetHashCode creates an exception of type NotImplementedException. Exceptions should not be raised in this type of method. If this exception instance might be raised, change this method's logic so it no longer raises an exception. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1065)

Check failure on line 50 in BeatSaberModManager/Models/Implementations/Versions/OculusGameVersion.cs

View workflow job for this annotation

GitHub Actions / Build Linux

GetHashCode creates an exception of type NotImplementedException. Exceptions should not be raised in this type of method. If this exception instance might be raised, change this method's logic so it no longer raises an exception. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1065)
}

public static bool operator ==(OculusGameVersion left, OculusGameVersion right)
{
if (ReferenceEquals(left, null))
{
return ReferenceEquals(right, null);
}

return left.Equals(right);
}

public static bool operator !=(OculusGameVersion left, OculusGameVersion right)
{
return !(left == right);
}

public static bool operator <(OculusGameVersion left, OculusGameVersion right)
{
return ReferenceEquals(left, null) ? !ReferenceEquals(right, null) : left.CompareTo(right) < 0;
}

public static bool operator <=(OculusGameVersion left, OculusGameVersion right)
{
return ReferenceEquals(left, null) || left.CompareTo(right) <= 0;
}

/// <summary>
///
/// </summary>
/// <param name="left"></param>
/// <param name="right"></param>
/// <returns></returns>
public static bool operator >(OculusGameVersion left, OculusGameVersion right)
{
return !ReferenceEquals(left, null) && left.CompareTo(right) > 0;
}

/// <summary>
///
/// </summary>
/// <param name="left"></param>
/// <param name="right"></param>
/// <returns></returns>
public static bool operator >=(OculusGameVersion left, OculusGameVersion right)
{
return ReferenceEquals(left, null) ? ReferenceEquals(right, null) : left.CompareTo(right) >= 0;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
using BeatSaberModManager.Models.Interfaces;


namespace BeatSaberModManager.Models.Implementations.LegacyVersions
namespace BeatSaberModManager.Models.Implementations.Versions
{
/// <summary>
/// TODO
/// </summary>
public class SteamLegacyGameVersion : ILegacyGameVersion
public class SteamGameVersion : IGameVersion
{
/// <inheritdoc />
public override int GetHashCode() => ManifestId.GetHashCode();
Expand All @@ -22,7 +22,7 @@ public class SteamLegacyGameVersion : ILegacyGameVersion
/// <inheritdoc />
[JsonPropertyName("ReleaseDate")]
[JsonConverter(typeof(UnixDateTimeConverter))]
public required DateTime ReleaseDate { get; init; }
public DateTime ReleaseDate { get; init; }

/// <inheritdoc />
[JsonPropertyName("ReleaseURL")]
Expand All @@ -37,7 +37,13 @@ public class SteamLegacyGameVersion : ILegacyGameVersion
/// </summary>
[JsonPropertyName("BSManifest")]
[JsonNumberHandling(JsonNumberHandling.AllowReadingFromString)]
public required ulong ManifestId { get; init; }
public ulong ManifestId { get; init; }

/// <summary>
///
/// </summary>
[JsonIgnore]
public string? InstallDir { get; set; }

[JsonIgnore]
private Version Version
Expand All @@ -60,11 +66,11 @@ private Version Version
private Version? _version;

/// <inheritdoc />
public int CompareTo(ILegacyGameVersion? other)
public int CompareTo(IGameVersion? other)
{
if (ReferenceEquals(this, other))
return 0;
if (other is not SteamLegacyGameVersion steamLegacyGameVersion)
if (other is not SteamGameVersion steamLegacyGameVersion)
return 1;
return Version.CompareTo(steamLegacyGameVersion.Version);
}
Expand All @@ -74,7 +80,7 @@ public override bool Equals(object? obj)
{
if (ReferenceEquals(this, obj))
return true;
if (obj is not SteamLegacyGameVersion steamLegacyGameVersion)
if (obj is not SteamGameVersion steamLegacyGameVersion)
return false;
return ManifestId == steamLegacyGameVersion.ManifestId;
}
Expand All @@ -85,7 +91,7 @@ public override bool Equals(object? obj)
/// <param name="left"></param>
/// <param name="right"></param>
/// <returns></returns>
public static bool operator ==(SteamLegacyGameVersion? left, SteamLegacyGameVersion? right)
public static bool operator ==(SteamGameVersion? left, SteamGameVersion? right)
{
if (left is null)
return right is null;
Expand All @@ -98,15 +104,15 @@ public override bool Equals(object? obj)
/// <param name="left"></param>
/// <param name="right"></param>
/// <returns></returns>
public static bool operator !=(SteamLegacyGameVersion left, SteamLegacyGameVersion right) => !(left == right);
public static bool operator !=(SteamGameVersion left, SteamGameVersion right) => !(left == right);

/// <summary>
///
/// </summary>
/// <param name="left"></param>
/// <param name="right"></param>
/// <returns></returns>
public static bool operator <(SteamLegacyGameVersion? left, SteamLegacyGameVersion? right)
public static bool operator <(SteamGameVersion? left, SteamGameVersion? right)
{
if (left is null)
return right is not null;
Expand All @@ -119,22 +125,22 @@ public override bool Equals(object? obj)
/// <param name="left"></param>
/// <param name="right"></param>
/// <returns></returns>
public static bool operator <=(SteamLegacyGameVersion? left, SteamLegacyGameVersion? right) => left is null || left.CompareTo(right) <= 0;
public static bool operator <=(SteamGameVersion? left, SteamGameVersion? right) => left is null || left.CompareTo(right) <= 0;

/// <summary>
///
/// </summary>
/// <param name="left"></param>
/// <param name="right"></param>
/// <returns></returns>
public static bool operator >(SteamLegacyGameVersion? left, SteamLegacyGameVersion? right) => left is not null && left.CompareTo(right) > 0;
public static bool operator >(SteamGameVersion? left, SteamGameVersion? right) => left is not null && left.CompareTo(right) > 0;

/// <summary>
///
/// </summary>
/// <param name="left"></param>
/// <param name="right"></param>
/// <returns></returns>
public static bool operator >=(SteamLegacyGameVersion? left, SteamLegacyGameVersion? right) => left is null ? right is null : left.CompareTo(right) >= 0;
public static bool operator >=(SteamGameVersion? left, SteamGameVersion? right) => left is null ? right is null : left.CompareTo(right) >= 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace BeatSaberModManager.Models.Interfaces
/// <summary>
///
/// </summary>
public interface ILegacyGameVersion : IComparable<ILegacyGameVersion>
public interface IGameVersion : IComparable<IGameVersion>
{
/// <summary>
///
Expand Down
2 changes: 1 addition & 1 deletion BeatSaberModManager/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
using BeatSaberModManager.Services.Implementations.BeatSaber.Playlists;
using BeatSaberModManager.Services.Implementations.DependencyManagement;
using BeatSaberModManager.Services.Implementations.Http;
using BeatSaberModManager.Services.Implementations.LegacyVersions.Steam;
using BeatSaberModManager.Services.Implementations.Progress;
using BeatSaberModManager.Services.Implementations.ProtocolHandlerRegistrars;
using BeatSaberModManager.Services.Implementations.Settings;
using BeatSaberModManager.Services.Implementations.Updater;
using BeatSaberModManager.Services.Implementations.Versions.Steam;
using BeatSaberModManager.Services.Interfaces;
using BeatSaberModManager.ViewModels;
using BeatSaberModManager.Views;
Expand Down
3 changes: 2 additions & 1 deletion BeatSaberModManager/Resources/Styles/AsyncImage.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
<Image Name="PART_Image"
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
VerticalAlignment="{TemplateBinding VerticalAlignment}"
Stretch="{TemplateBinding Stretch}">
Stretch="{TemplateBinding Stretch}"
>
</Image>
</Grid>
</Border>
Expand Down
4 changes: 2 additions & 2 deletions BeatSaberModManager/Resources/Styles/CardControl.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
xmlns:c="using:BeatSaberModManager.Views.Controls">

<ControlTheme x:Key="{x:Type c:CardControl}" TargetType="c:CardControl">
<Setter Property="Padding" Value="10" />
<Setter Property="Padding" Value="0" />
<Setter Property="Width" Value="200"/>
<Setter Property="Height" Value="260"/>
<Setter Property="BoxShadow" Value="0 0 7 0 #000000" />
<Setter Property="InternalBoxShadow" Value="0 0 5 0 #000000" />
<Setter Property="InternalCornerRadius" Value="7" />
<Setter Property="CornerRadius" Value="7" />
<Setter Property="InternalPadding" Value="20" />
<Setter Property="InternalPadding" Value="0" />
<Setter Property="ScaleOnPointerOver" Value="True"/>
<Setter Property="Background" Value="{DynamicResource ThemeControlHighBrush}" />
<Setter Property="SecondaryBackground" Value="{DynamicResource ThemeControlMidBrush}" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
using System;
using System.Diagnostics;
using System.IO;

using BeatSaberModManager.Models.Implementations;
using BeatSaberModManager.Models.Implementations.Versions;
using BeatSaberModManager.Models.Interfaces;
using BeatSaberModManager.Services.Interfaces;
using BeatSaberModManager.Utils;


namespace BeatSaberModManager.Services.Implementations.BeatSaber
{
/// <inheritdoc />
public class BeatSaberGameLauncher(IInstallDirLocator installDirLocator) : IGameLauncher
public class BeatSaberGameLauncher : IGameLauncher
{
/// <inheritdoc />
public void LaunchGame(string installDir)
public void LaunchGame(IGameVersion gameVersion)
{
switch (installDirLocator.DetectPlatform(installDir))
switch (gameVersion)
{
case PlatformType.Steam when new DirectoryInfo(installDir).Parent?.Parent?.Name == "steamapps":
case SteamGameVersion steamGameVersion:
PlatformUtils.TryOpenUri(new Uri("steam://rungameid/620980"));
break;
case PlatformType.Oculus:
PlatformUtils.TryStartProcess(new ProcessStartInfo("Beat Saber.exe") { WorkingDirectory = installDir }, out _);
case OculusGameVersion oculusGameVersion:
PlatformUtils.TryStartProcess(new ProcessStartInfo("Beat Saber.exe") { WorkingDirectory = oculusGameVersion.InstallDir }, out _);
break;
default:
throw new InvalidOperationException("Could not detect platform.");
Expand Down
Loading

0 comments on commit e3624bc

Please sign in to comment.