Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
fix: add rotations version warning.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Jun 5, 2024
1 parent d70dced commit 3cd8a87
Show file tree
Hide file tree
Showing 5 changed files with 467 additions and 433 deletions.
2 changes: 1 addition & 1 deletion RotationSolver.Basic
29 changes: 26 additions & 3 deletions RotationSolver/Helpers/RotationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,22 @@ namespace RotationSolver.Helpers;
internal static class RotationHelper
{
private static readonly Dictionary<Assembly, AssemblyInfo> _assemblyInfos = [];
private static readonly Dictionary<Assembly, UiString> _assemblyVersionWarnings = [];

public static List<LoadedAssembly> LoadedCustomRotations { get; } = [];

private static readonly Version? RsVersion = GetRSBasicVersion(typeof(RotationHelper).Assembly);

public static Version? GetRSBasicVersion(Assembly assembly)
public static UiString GetWarning(this Assembly assembly)
{
if (_assemblyVersionWarnings.TryGetValue(assembly, out var info))
{
return info;
}
return UiString.None;
}

private static Version? GetRSBasicVersion(Assembly assembly)
{
return assembly.GetReferencedAssemblies().Where(n => n.Name == "RotationSolver.Basic").FirstOrDefault()?.Version;
}
Expand Down Expand Up @@ -72,16 +82,29 @@ public static Assembly LoadCustomRotationAssembly(string filePath)
var version = GetRSBasicVersion(assembly);
if (version is not null && RsVersion is not null)
{
if(version.Major < RsVersion.Major
UiString warning;
if (version.Major == RsVersion.Major
|| version.Minor == RsVersion.Minor
|| version.Build == RsVersion.Build)
{
warning = UiString.None;
}
else if (version.Major < RsVersion.Major
|| version.Minor < RsVersion.Minor
|| version.Build < RsVersion.Build)
{
Svc.Log.Error($"The assembly from \"{filePath}\" may be too old, please update it.");
warning = UiString.AssemblyLowVersion;
if (existingAssembly != null)
{
return existingAssembly;
}
}
else
{
warning = UiString.AssemblyHighVersion;
}

_assemblyVersionWarnings[assembly] = warning;
}

var assemblyName = assembly.GetName().Name;
Expand Down
4 changes: 3 additions & 1 deletion RotationSolver/Localization/Localization.json
Original file line number Diff line number Diff line change
Expand Up @@ -792,5 +792,7 @@
"RotationSolver.Basic.Data.UiString.ConfigWindow_About_UserCount": "There are {0} RS users among the world!",
"RotationSolver.Basic.Data.UiString.ThanksForSupporting": "Thank you for supporting!",
"RotationSolver.Basic.Data.UiString.AutoHealOnTimeline": "Auto heal on timeline",
"RotationSolver.Basic.Data.UiString.AutoDefenseOnTimeline": "Auto defense on timeline"
"RotationSolver.Basic.Data.UiString.AutoDefenseOnTimeline": "Auto defense on timeline",
"RotationSolver.Basic.Data.UiString.AssemblyLowVersion": "This rotation's dependency is too LOW, which may cause some errors. Please update this rotations!",
"RotationSolver.Basic.Data.UiString.AssemblyHighVersion": "This rotation's dependency is too HIGH, which may cause some errors. Please update the Rotation Solver!"
}
Loading

0 comments on commit 3cd8a87

Please sign in to comment.