Skip to content
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
19 changes: 19 additions & 0 deletions Quaver.API/Maps/Qua.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ namespace Quaver.API.Maps
[Serializable] // ReSharper disable CognitiveComplexity CompareOfFloatsByEqualityOperator
public class Qua
{
// 0 versioning added
public int QuaVersion { get; set; } = 0;

// Max supported version by this client
// This should be incremented whenever breaking changes are made to quas
// DetermineMinimumQuaVersion() should also be updated to allow older clients to load maps without new features
public const int CurrentQuaVersion = 0;

/// <summary>
/// The name of the audio file
/// </summary>
Expand Down Expand Up @@ -303,6 +311,12 @@ private bool CompareTimingGroups(Dictionary<string, TimingGroup> other)
.WithTagMapping("!ScrollGroup", typeof(ScrollGroup))
.Build();


public int DetermineMinimumQuaVersion()
{
return 0;
}

/// <summary>
/// Loads a .qua file from a stream
/// </summary>
Expand Down Expand Up @@ -375,6 +389,8 @@ x.Signature is TimeSignature.Quadruple
// Sort the object before saving.
Sort();

QuaVersion = DetermineMinimumQuaVersion();

// Set default values to zero so they don't waste space in the .qua file.
var originalTimingPoints = TimingPoints;
var originalHitObjects = HitObjects;
Expand Down Expand Up @@ -1165,6 +1181,9 @@ private static void AfterLoad(Qua qua, bool checkValidity)
if (checkValidity && qua.Validate() is var errors && errors.Count > 0)
throw new ArgumentException(string.Join("\n", errors));

if (qua.QuaVersion > Qua.CurrentQuaVersion)
throw new QuaVersionException($"Map \"{qua.Artist} - {qua.Title}\" cannot be loaded because it requires features from a newer client.");

// Try to sort the Qua before returning.
qua.Sort();
}
Expand Down
7 changes: 7 additions & 0 deletions Quaver.API/Maps/QuaVersionException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[System.Serializable]
public class QuaVersionException : System.Exception
{
public QuaVersionException() { }
public QuaVersionException(string message) : base(message) { }
public QuaVersionException(string message, System.Exception inner) : base(message, inner) { }
}
Loading