533a7356fd
* Add new service to handle profile migrations * Handle various null checks * Remove unecessary assignments * Further works on this: - Loads profiles as JObject's initally, so migration can take place on profiles that don't have proper compatability - Adds prerequisite migrations, and sorts them after one another * Throw exception if profile can't be deserialized after migration * Cleanup & use profile version * Further migrations work, support 3.10 & 3.11 profiles upgrading to 4.0 * Update parameter name
83 lines
2.5 KiB
C#
83 lines
2.5 KiB
C#
using System.Text.Json.Nodes;
|
|
using SPTarkov.DI.Annotations;
|
|
using SPTarkov.Server.Core.Models.Eft.Profile;
|
|
using SPTarkov.Server.Core.Utils;
|
|
using Range = SemanticVersioning.Range;
|
|
|
|
namespace SPTarkov.Server.Core.Migration.Migrations
|
|
{
|
|
[Injectable]
|
|
public class ThreeElevenToFourZero(Watermark watermark) : AbstractProfileMigration
|
|
{
|
|
public override string FromVersion
|
|
{
|
|
get { return "~3.11"; }
|
|
}
|
|
|
|
public override string ToVersion
|
|
{
|
|
get { return "4.0"; }
|
|
}
|
|
|
|
public override string MigrationName
|
|
{
|
|
get { return "311x-SPTSharp"; }
|
|
}
|
|
|
|
public override IEnumerable<Type> PrerequisiteMigrations
|
|
{
|
|
get { return [typeof(ThreeTenToThreeEleven)]; }
|
|
}
|
|
|
|
public override bool CanMigrate(
|
|
JsonObject profile,
|
|
IEnumerable<IProfileMigration> previouslyRanMigrations
|
|
)
|
|
{
|
|
var profileVersion = GetProfileVersion(profile);
|
|
|
|
var fromRange = Range.Parse(FromVersion);
|
|
|
|
var versionMatches =
|
|
fromRange.IsSatisfied(profileVersion)
|
|
|| PrerequisiteMigrations.All(prereq =>
|
|
previouslyRanMigrations.Any(r => r.GetType() == prereq)
|
|
);
|
|
|
|
return versionMatches;
|
|
}
|
|
|
|
public override JsonObject? Migrate(JsonObject profile)
|
|
{
|
|
if (profile["characters"]!["pmc"]!["Hideout"]!["Production"] is JsonObject production)
|
|
{
|
|
foreach (var entry in production)
|
|
{
|
|
if (
|
|
entry.Value is JsonObject productionEntry
|
|
&& productionEntry["StartTimestamp"] is JsonValue startTimestampValue
|
|
&& startTimestampValue.TryGetValue<string>(out var startTimestampStr)
|
|
&& long.TryParse(startTimestampStr, out var startTimestampInt)
|
|
)
|
|
{
|
|
productionEntry["StartTimestamp"] = startTimestampInt;
|
|
}
|
|
}
|
|
}
|
|
|
|
//Todo: TaskConditionCounters CounterCrafting?
|
|
|
|
return profile;
|
|
}
|
|
|
|
public override bool PostMigrate(SptProfile profile)
|
|
{
|
|
profile.SptData.ExtraRepeatableQuests = [];
|
|
|
|
profile.SptData.Version = $"{watermark.GetVersionTag()} (Migrated from 3.11)";
|
|
|
|
return base.PostMigrate(profile);
|
|
}
|
|
}
|
|
}
|