Skip to content

Commit

Permalink
Merge pull request #233 from Founntain/logging
Browse files Browse the repository at this point in the history
Implementation of console logging & Project Restructure
  • Loading branch information
Founntain authored Oct 24, 2023
2 parents 839579f + 362de5b commit ed389b2
Show file tree
Hide file tree
Showing 169 changed files with 1,614 additions and 1,071 deletions.
5 changes: 1 addition & 4 deletions OsuPlayer.CrashHandler/OsuPlayer.CrashHandler.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,4 @@
<DependentUpon>CrashHandlerMainWindow.axaml</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OsuPlayer.Extensions\OsuPlayer.Extensions.csproj" />
</ItemGroup>
</Project>
</Project>
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
using System.Diagnostics;
using OsuPlayer.IO.DbReader.Interfaces;
using OsuPlayer.Data.DataModels.Interfaces;

namespace OsuPlayer.IO.DbReader.DataModels;
namespace OsuPlayer.Data.DataModels;

/// <summary>
/// a full beatmap entry with optionally used data
/// <remarks>only created on a <see cref="IMapEntryBase.ReadFullEntry" /> call</remarks>
/// </summary>
internal class DbMapEntry : DbMapEntryBase, IMapEntry
public class DbMapEntry : DbMapEntryBase, IMapEntry
{
public string ArtistUnicode { get; init; } = string.Empty;
public string TitleUnicode { get; init; } = string.Empty;
Expand Down
112 changes: 112 additions & 0 deletions OsuPlayer.Data/DataModels/DbMapEntryBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
using System.Text;
using Nein.Extensions;
using OsuPlayer.Data.DataModels.Interfaces;

namespace OsuPlayer.Data.DataModels;

/// <summary>
/// a minimal beatmap entry with only frequently used data
/// </summary>
public class DbMapEntryBase : IMapEntryBase
{
public required IDbReaderFactory DbReaderFactory { get; init; }

public long DbOffset { get; init; }
public string? OsuPath { get; init; }
public string Artist { get; init; } = string.Empty;
public string Title { get; init; } = string.Empty;
public string Hash { get; init; } = string.Empty;
public int BeatmapSetId { get; init; }
public int TotalTime { get; init; }
public string TotalTimeString => TimeSpan.FromMilliseconds(TotalTime).FormatTime();
public string SongName => GetSongName();
public string ArtistString => GetArtist();
public string TitleString => GetTitle();

/// <summary>
/// Gets the artist
/// <remarks>may be overridden for usage with <see cref="DbMapEntry.UseUnicode" /></remarks>
/// </summary>
/// <returns>the artist</returns>
public virtual string GetArtist()
{
return Artist;
}

/// <summary>
/// Gets the title
/// <remarks>may be overridden for usage with <see cref="DbMapEntry.UseUnicode" /></remarks>
/// </summary>
/// <returns>the title</returns>
public virtual string GetTitle()
{
return Title;
}

public string GetSongName()
{
return $"{GetArtist()} - {GetTitle()}";
}

/// <summary>
/// Reads a osu!.db map entry and fills a full <see cref="DbMapEntry" /> with data
/// </summary>
/// <returns>a new <see cref="DbMapEntry" /> generated from osu!.db data</returns>
public IMapEntry? ReadFullEntry()
{
if (OsuPath == null) return null;

var reader = GetReader();

if (reader == default)
return null;

return reader.ReadFullEntry(OsuPath, this, dbOffset: DbOffset);
}

public IDatabaseReader? GetReader()
{
if (OsuPath == null)
return null;

return DbReaderFactory.CreateDatabaseReader(OsuPath);
}

public bool Equals(IMapEntryBase? other)
{
return Hash == other?.Hash;
}

public int CompareTo(IMapEntryBase? other)
{
return string.Compare(Hash, other?.Hash, StringComparison.OrdinalIgnoreCase);
}

public override string ToString()
{
return GetSongName();
}

public static bool operator ==(DbMapEntryBase? left, IMapEntryBase? right)
{
return left?.Hash == right?.Hash;
}

public static bool operator !=(DbMapEntryBase? left, IMapEntryBase? right)
{
return left?.Hash != right?.Hash;
}

public override bool Equals(object? other)
{
if (other is IMapEntryBase map)
return Hash == map.Hash;

return false;
}

public override int GetHashCode()
{
return BitConverter.ToInt32(Encoding.UTF8.GetBytes(Hash));
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using OsuPlayer.IO.DbReader.Interfaces;
using OsuPlayer.Data.DataModels.Interfaces;

namespace OsuPlayer.IO.DbReader.DataModels.Extensions;
namespace OsuPlayer.Data.DataModels.Extensions;

public class HistoricalMapEntry : IComparable<HistoricalMapEntry>
{
Expand All @@ -9,7 +9,7 @@ public class HistoricalMapEntry : IComparable<HistoricalMapEntry>

public string TimePlayedString => $"Last Played: {TimePlayed:G}";

public HistoricalMapEntry(IMapEntryBase mapEntry) :this(mapEntry, DateTimeOffset.Now)
public HistoricalMapEntry(IMapEntryBase mapEntry) : this(mapEntry, DateTimeOffset.Now)
{
}

Expand All @@ -26,7 +26,7 @@ public int CompareTo(HistoricalMapEntry other)

public override bool Equals(object? obj)
{
if(obj is HistoricalMapEntry other)
if (obj is HistoricalMapEntry other)
{
return MapEntry.Hash == other.MapEntry.Hash;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
namespace OsuPlayer.IO.DbReader.DataModels.Extensions;
namespace OsuPlayer.Data.DataModels.Extensions;

public class HistoricalMapEntryComparer : IEqualityComparer<HistoricalMapEntry>
{
public bool Equals(HistoricalMapEntry? x, HistoricalMapEntry? y)
{
if(x == null && y == null) return true;
if(x == null || y == null) return false;
if (x == null && y == null) return true;
if (x == null || y == null) return false;

return x.MapEntry.Hash == y.MapEntry.Hash;
}

Expand Down
11 changes: 11 additions & 0 deletions OsuPlayer.Data/DataModels/IDbReaderFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using OsuPlayer.Data.DataModels.Interfaces;
using OsuPlayer.Data.Enums;

namespace OsuPlayer.Data.DataModels;

public interface IDbReaderFactory
{
public DbCreationType Type { get; set; }

public IDatabaseReader CreateDatabaseReader(string path);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace OsuPlayer.IO.DbReader.Interfaces;
namespace OsuPlayer.Data.DataModels.Interfaces;

/// <summary>
/// Interface used by the database readers used to read the osu databases.
Expand All @@ -22,6 +22,16 @@ public interface IDatabaseReader : IDisposable
/// Reads the osu! collections from the database.
/// </summary>
/// <param name="path">the osu! path</param>
/// <returns>a list of <see cref="Collection" />s</returns>
public Task<List<Collection>?> GetCollections(string path);
/// <returns>a list of <see cref="OsuCollection" />s</returns>
public Task<List<OsuCollection>?> GetCollections(string path);

/// <summary>
/// Reads the full map entry from the existing <see cref="IMapEntryBase"/>
/// </summary>
/// <param name="path">the osu! path</param>
/// <param name="mapEntryBase">the corresponding <see cref="IMapEntryBase"/></param>
/// <param name="dbOffset">the db offset (if applicable)</param>
/// <param name="id">the database id (if applicable)</param>
/// <returns></returns>
public IMapEntry? ReadFullEntry(string path, IMapEntryBase mapEntryBase, long? dbOffset = null, Guid? id = null);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace OsuPlayer.IO.DbReader.Interfaces;
namespace OsuPlayer.Data.DataModels.Interfaces;

public interface IMapEntry : IMapEntryBase
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using Nein.Extensions;

namespace OsuPlayer.IO.DbReader.Interfaces;
namespace OsuPlayer.Data.DataModels.Interfaces;

public interface IMapEntryBase : IEquatable<IMapEntryBase>, IComparable<IMapEntryBase>
{
public IDbReaderFactory DbReaderFactory { get; init; }

public string Artist { get; }
public string Title { get; }
public string Hash { get; }
Expand Down Expand Up @@ -34,7 +36,7 @@ public string GetSongName()
/// a full <see cref="IMapEntry" /> for extended usage. Returns null if the path doesn't exist or the map was not
/// found.
/// </returns>
public Task<IMapEntry?> ReadFullEntry();
public IMapEntry? ReadFullEntry();

/// <summary>
/// Gets the corresponding <see cref="IDatabaseReader" /> of the beatmap
Expand Down
23 changes: 23 additions & 0 deletions OsuPlayer.Data/DataModels/Interfaces/IUser.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Avalonia.Media;

namespace OsuPlayer.Data.DataModels.Interfaces;

public interface IUser
{
public Guid UniqueId { get; }

public string SongsPlayedString { get; }
public string LevelAndTotalXpString { get; }
public string LevelProgressString { get; }
public Brush RoleColor { get; }
public string RoleString { get; }
public string DescriptionTitleString { get; }
public string LevelString { get; }
public string JoinDateString { get; }
public string TotalXpString { get; }

public int GetXpNeededForNextLevel();
public static abstract int GetXpNeededForNextLevel(int level);
public Brush GetRoleColorBrush();
public string GetRoleString();
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
using OsuPlayer.IO.DbReader.Interfaces;
using OsuPlayer.Data.DataModels.Interfaces;

namespace OsuPlayer.Modules.Services;
namespace OsuPlayer.Data.DataModels;

public class ObservableSorter : IObservable<IComparer<IMapEntryBase>>
{
private readonly List<IObserver<IComparer<IMapEntryBase>>> _observers;
private readonly List<IObserver<IComparer<IMapEntryBase>>> _observers = new();
private IComparer<IMapEntryBase>? _lastComparer;

public ObservableSorter()
{
_observers = new List<IObserver<IComparer<IMapEntryBase>>>();
}

public IDisposable Subscribe(IObserver<IComparer<IMapEntryBase>> observer)
{
if (!_observers.Contains(observer))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Globalization;

namespace OsuPlayer.Network.Online;
namespace OsuPlayer.Data.DataModels.Online;

public sealed class Article
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Globalization;

namespace OsuPlayer.Network.Online;
namespace OsuPlayer.Data.DataModels.Online;

public sealed class News
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using OsuPlayer.Api.Data.API.EntityModels;
using OsuPlayer.Api.Data.API.Enums;

namespace OsuPlayer.Network.Online;
namespace OsuPlayer.Data.DataModels.Online;

public sealed class OnlineUserStatusModelExtended : UserOnlineStatusModel
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Avalonia.Media;

namespace OsuPlayer.Network.Online;
namespace OsuPlayer.Data.DataModels.Online;

/// <summary>
/// A list of all available role colors
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
namespace OsuPlayer.IO.DbReader;
namespace OsuPlayer.Data.DataModels;

/// <summary>
/// Represents a collection from osu!
/// </summary>
public class Collection
public class OsuCollection
{
public string Name { get; set; } = string.Empty;
public List<string> BeatmapHashes { get; private set; } = new();

public Collection()
public OsuCollection()
{
}

public Collection(string name, List<string> beatmapHashes)
public OsuCollection(string name, List<string> beatmapHashes)
{
Name = name;
BeatmapHashes = beatmapHashes;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using OsuPlayer.IO.DbReader.Interfaces;
using OsuPlayer.Data.DataModels.Interfaces;

namespace OsuPlayer.IO.DbReader.DataModels;
namespace OsuPlayer.Data.DataModels;

/// <summary>
/// a full beatmap entry with optionally used data
/// <remarks>only created on a <see cref="IMapEntryBase.ReadFullEntry" /> call</remarks>
/// </summary>
internal class RealmMapEntry : RealmMapEntryBase, IMapEntry
public class RealmMapEntry : RealmMapEntryBase, IMapEntry
{
public string BackgroundFileLocation { get; init; } = string.Empty;
public string ArtistUnicode { get; init; } = string.Empty;
Expand Down
Loading

0 comments on commit ed389b2

Please sign in to comment.