Make all versioning functions internal, move to separate class

This commit is contained in:
goaaats 2025-12-15 21:31:25 +01:00
parent a1409096fd
commit 20af5b40c7
20 changed files with 142 additions and 130 deletions

View file

@ -192,8 +192,8 @@ public sealed class EntryPoint
var dalamud = new Dalamud(info, fs, configuration, mainThreadContinueEvent);
Log.Information("This is Dalamud - Core: {GitHash}, CS: {CsGitHash} [{CsVersion}]",
Util.GetScmVersion(),
Util.GetGitHashClientStructs(),
Versioning.GetScmVersion(),
Versioning.GetGitHashClientStructs(),
FFXIVClientStructs.ThisAssembly.Git.Commits);
dalamud.WaitForUnload();

View file

@ -104,7 +104,7 @@ internal partial class ChatHandlers : IServiceType
if (this.configuration.PrintDalamudWelcomeMsg)
{
chatGui.Print(string.Format(Loc.Localize("DalamudWelcome", "Dalamud {0} loaded."), Util.GetScmVersion())
chatGui.Print(string.Format(Loc.Localize("DalamudWelcome", "Dalamud {0} loaded."), Versioning.GetScmVersion())
+ string.Format(Loc.Localize("PluginsWelcome", " {0} plugin(s) loaded."), pluginManager.InstalledPlugins.Count(x => x.IsLoaded)));
}
@ -116,7 +116,7 @@ internal partial class ChatHandlers : IServiceType
}
}
if (string.IsNullOrEmpty(this.configuration.LastVersion) || !Util.AssemblyVersion.StartsWith(this.configuration.LastVersion))
if (string.IsNullOrEmpty(this.configuration.LastVersion) || !Versioning.GetAssemblyVersion().StartsWith(this.configuration.LastVersion))
{
var linkPayload = chatGui.AddChatLinkHandler(
(_, _) => dalamudInterface.OpenPluginInstallerTo(PluginInstallerOpenKind.Changelogs));
@ -137,7 +137,7 @@ internal partial class ChatHandlers : IServiceType
Type = XivChatType.Notice,
});
this.configuration.LastVersion = Util.AssemblyVersion;
this.configuration.LastVersion = Versioning.GetAssemblyVersion();
this.configuration.QueueSave();
}

View file

@ -305,12 +305,12 @@ internal class DalamudCommands : IServiceType
chatGui.Print(new SeStringBuilder()
.AddItalics("Dalamud:")
.AddText($" {Util.GetScmVersion()}")
.AddText($" {Versioning.GetScmVersion()}")
.Build());
chatGui.Print(new SeStringBuilder()
.AddItalics("FFXIVCS:")
.AddText($" {Util.GetGitHashClientStructs()}")
.AddText($" {Versioning.GetGitHashClientStructs()}")
.Build());
}

View file

@ -182,7 +182,7 @@ internal class DalamudInterface : IInternalDisposableService
() => Service<DalamudInterface>.GetNullable()?.ToggleDevMenu(),
VirtualKey.SHIFT);
if (Util.GetActiveTrack() != "release")
if (Versioning.GetActiveTrack() != "release")
{
titleScreenMenu.AddEntryCore(
Loc.Localize("TSMDalamudDevMenu", "Developer Menu"),
@ -865,7 +865,7 @@ internal class DalamudInterface : IInternalDisposableService
}
ImGui.MenuItem(this.dalamud.StartInfo.GameVersion?.ToString() ?? "Unknown version", false, false);
ImGui.MenuItem($"D: {Util.GetScmVersion()} CS: {Util.GetGitHashClientStructs()}[{FFXIVClientStructs.ThisAssembly.Git.Commits}]", false, false);
ImGui.MenuItem($"D: {Versioning.GetScmVersion()} CS: {Versioning.GetGitHashClientStructs()}[{FFXIVClientStructs.ThisAssembly.Git.Commits}]", false, false);
ImGui.MenuItem($"CLR: {Environment.Version}", false, false);
ImGui.EndMenu();
@ -1076,8 +1076,8 @@ internal class DalamudInterface : IInternalDisposableService
{
ImGui.PushFont(InterfaceManager.MonoFont);
ImGui.BeginMenu($"{Util.GetActiveTrack() ?? "???"} on {Util.GetGitBranch() ?? "???"}", false);
ImGui.BeginMenu($"{Util.GetScmVersion()}", false);
ImGui.BeginMenu($"{Versioning.GetActiveTrack() ?? "???"} on {Versioning.GetGitBranch() ?? "???"}", false);
ImGui.BeginMenu($"{Versioning.GetScmVersion()}", false);
ImGui.BeginMenu(this.FrameCount.ToString("000000"), false);
ImGui.BeginMenu(ImGui.GetIO().Framerate.ToString("000"), false);
ImGui.BeginMenu($"W:{Util.FormatBytes(GC.GetTotalMemory(false))}", false);

View file

@ -47,7 +47,7 @@ public class BranchSwitcherWindow : Window
this.branches = await client.GetFromJsonAsync<Dictionary<string, VersionEntry>>(BranchInfoUrl);
Debug.Assert(this.branches != null, "this.branches != null");
var trackName = Util.GetActiveTrack();
var trackName = Versioning.GetActiveTrack();
this.selectedBranchIndex = this.branches.IndexOf(x => x.Value.Track == trackName);
if (this.selectedBranchIndex == -1)
{

View file

@ -147,7 +147,7 @@ internal sealed class ChangelogWindow : Window, IDisposable
var pmWantsChangelog = pm?.InstalledPlugins.Any() ?? true;
return (string.IsNullOrEmpty(configuration.LastChangelogMajorMinor) ||
(!WarrantsChangelogForMajorMinor.StartsWith(configuration.LastChangelogMajorMinor) &&
Util.AssemblyVersion.StartsWith(WarrantsChangelogForMajorMinor))) && pmWantsChangelog;
Versioning.GetAssemblyVersion().StartsWith(WarrantsChangelogForMajorMinor))) && pmWantsChangelog;
}
/// <inheritdoc/>
@ -357,7 +357,7 @@ internal sealed class ChangelogWindow : Window, IDisposable
{
case State.WindowFadeIn:
case State.ExplainerIntro:
ImGui.TextWrapped($"Welcome to Dalamud v{Util.GetScmVersion()}!");
ImGui.TextWrapped($"Welcome to Dalamud v{Versioning.GetScmVersion()}!");
ImGuiHelpers.ScaledDummy(5);
ImGui.TextWrapped(ChangeLog);
ImGuiHelpers.ScaledDummy(5);

View file

@ -144,7 +144,7 @@ internal class SeStringCreatorWidget : IDataWindowWidget
new TextEntry(TextEntryType.Macro, " <string(lstr1)>"),
];
private SeStringParameter[]? localParameters = [Util.GetScmVersion()];
private SeStringParameter[]? localParameters = [Versioning.GetScmVersion()];
private ReadOnlySeString input;
private ClientLanguage? language;
private Task? validImportSheetNamesTask;

View file

@ -302,7 +302,7 @@ internal class PluginInstallerWindow : Window, IDisposable
this.profileManagerWidget.Reset();
if (this.staleDalamudNewVersion == null && !Util.GetActiveTrack().IsNullOrEmpty())
if (this.staleDalamudNewVersion == null && !Versioning.GetActiveTrack().IsNullOrEmpty())
{
Service<DalamudReleases>.Get().GetVersionForCurrentTrack().ContinueWith(t =>
{
@ -310,7 +310,7 @@ internal class PluginInstallerWindow : Window, IDisposable
return;
var versionInfo = t.Result;
if (versionInfo.AssemblyVersion != Util.GetScmVersion())
if (versionInfo.AssemblyVersion != Versioning.GetScmVersion())
{
this.staleDalamudNewVersion = versionInfo.AssemblyVersion;
}
@ -1670,7 +1670,7 @@ internal class PluginInstallerWindow : Window, IDisposable
DrawWarningIcon();
DrawLinesCentered("A new version of Dalamud is available.\n" +
"Please restart the game to ensure compatibility with updated plugins.\n" +
$"old: {Util.GetScmVersion()} new: {this.staleDalamudNewVersion}");
$"old: {Versioning.GetScmVersion()} new: {this.staleDalamudNewVersion}");
ImGuiHelpers.ScaledDummy(10);
}
@ -2461,7 +2461,7 @@ internal class PluginInstallerWindow : Window, IDisposable
var isOutdated = effectiveApiLevel < PluginManager.DalamudApiLevel;
var isIncompatible = manifest.MinimumDalamudVersion != null &&
manifest.MinimumDalamudVersion > Util.AssemblyVersionParsed;
manifest.MinimumDalamudVersion > Versioning.GetAssemblyVersionParsed();
var enableInstallButton = this.updateStatus != OperationStatus.InProgress &&
this.installStatus != OperationStatus.InProgress &&

View file

@ -223,7 +223,7 @@ Contribute at: https://github.com/goatcorp/Dalamud
.Select(plugin => $"{plugin.Manifest.Name} by {plugin.Manifest.Author}\n")
.Aggregate(string.Empty, (current, next) => $"{current}{next}");
this.creditsText = string.Format(CreditsTextTempl, typeof(Dalamud).Assembly.GetName().Version, pluginCredits, Util.GetGitHashClientStructs());
this.creditsText = string.Format(CreditsTextTempl, typeof(Dalamud).Assembly.GetName().Version, pluginCredits, Versioning.GetGitHashClientStructs());
var gameGui = Service<GameGui>.Get();
var playerState = PlayerState.Instance();

View file

@ -503,7 +503,7 @@ internal class TitleScreenMenuWindow : Window, IDisposable
lssb.PushEdgeColorType(701).PushColorType(539)
.Append(SeIconChar.BoxedLetterD.ToIconChar())
.PopColorType().PopEdgeColorType();
lssb.Append($" Dalamud: {Util.GetScmVersion()}");
lssb.Append($" Dalamud: {Versioning.GetScmVersion()}");
lssb.Append($" - {count} {(count != 1 ? "plugins" : "plugin")} loaded");

View file

@ -36,7 +36,7 @@ internal class HappyHttpClient : IInternalDisposableService
{
UserAgent =
{
new ProductInfoHeaderValue("Dalamud", Util.AssemblyVersion),
new ProductInfoHeaderValue("Dalamud", Versioning.GetAssemblyVersion()),
},
},
};

View file

@ -38,7 +38,7 @@ internal sealed class ClientHelloService : IInternalDisposableService
return new ClientHelloResponse
{
ApiVersion = "1.0",
DalamudVersion = Util.GetScmVersion(),
DalamudVersion = Versioning.GetScmVersion(),
GameVersion = dalamud.StartInfo.GameVersion?.ToString() ?? "Unknown",
ProcessId = Environment.ProcessId,
ProcessStartTime = new DateTimeOffset(Process.GetCurrentProcess().StartTime).ToUnixTimeSeconds(),

View file

@ -1790,7 +1790,7 @@ internal class PluginManager : IInternalDisposableService
var updates = this.AvailablePlugins
.Where(remoteManifest => plugin.Manifest.InternalName == remoteManifest.InternalName)
.Where(remoteManifest => plugin.Manifest.InstalledFromUrl == remoteManifest.SourceRepo.PluginMasterUrl || !remoteManifest.SourceRepo.IsThirdParty)
.Where(remoteManifest => remoteManifest.MinimumDalamudVersion == null || Util.AssemblyVersionParsed >= remoteManifest.MinimumDalamudVersion)
.Where(remoteManifest => remoteManifest.MinimumDalamudVersion == null || Versioning.GetAssemblyVersionParsed() >= remoteManifest.MinimumDalamudVersion)
.Where(remoteManifest =>
{
var useTesting = this.UseTesting(remoteManifest);

View file

@ -315,7 +315,7 @@ internal class LocalPlugin : IAsyncDisposable
if (!this.CheckPolicy())
throw new PluginPreconditionFailedException($"Unable to load {this.Name} as a load policy forbids it");
if (this.Manifest.MinimumDalamudVersion != null && this.Manifest.MinimumDalamudVersion > Util.AssemblyVersionParsed)
if (this.Manifest.MinimumDalamudVersion != null && this.Manifest.MinimumDalamudVersion > Versioning.GetAssemblyVersionParsed())
throw new PluginPreconditionFailedException($"Unable to load {this.Name}, Dalamud version is lower than minimum required version {this.Manifest.MinimumDalamudVersion}");
this.State = PluginState.Loading;

View file

@ -59,7 +59,7 @@ internal class PluginRepository
},
UserAgent =
{
new ProductInfoHeaderValue("Dalamud", Util.AssemblyVersion),
new ProductInfoHeaderValue("Dalamud", Versioning.GetAssemblyVersion()),
},
},
};
@ -164,7 +164,7 @@ internal class PluginRepository
}
this.PluginMaster = pluginMaster.Where(this.IsValidManifest).ToList().AsReadOnly();
// API9 HACK: Force IsHide to false, we should remove that
if (!this.IsThirdParty)
{
@ -197,7 +197,7 @@ internal class PluginRepository
Log.Error("Plugin {PluginName} in {RepoLink} has an invalid Name.", manifest.InternalName, this.PluginMasterUrl);
return false;
}
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
if (manifest.AssemblyVersion == null)
{
@ -224,7 +224,7 @@ internal class PluginRepository
request.Headers.CacheControl = new CacheControlHeaderValue { NoCache = true };
using var requestCts = new CancellationTokenSource(TimeSpan.FromSeconds(timeout));
return await httpClient.SendAsync(request, requestCts.Token);
}
}

View file

@ -37,7 +37,7 @@ internal static class BugBait
Name = plugin.InternalName,
Version = isTesting ? plugin.TestingAssemblyVersion?.ToString() : plugin.AssemblyVersion.ToString(),
Platform = Util.GetHostPlatform().ToString(),
DalamudHash = Util.GetScmVersion(),
DalamudHash = Versioning.GetScmVersion(),
};
if (includeException)

View file

@ -38,7 +38,7 @@ internal class DalamudReleases : IServiceType
/// <returns>The version info for the current track.</returns>
public async Task<DalamudVersionInfo?> GetVersionForCurrentTrack()
{
var currentTrack = Util.GetActiveTrack();
var currentTrack = Versioning.GetActiveTrack();
if (currentTrack.IsNullOrEmpty())
return null;

View file

@ -69,11 +69,11 @@ public static class Troubleshooting
LoadedPlugins = pluginManager?.InstalledPlugins?.Select(x => x.Manifest as LocalPluginManifest)?.OrderByDescending(x => x.InternalName).ToArray(),
PluginStates = pluginManager?.InstalledPlugins?.Where(x => !x.IsDev).ToDictionary(x => x.Manifest.InternalName, x => x.IsBanned ? "Banned" : x.State.ToString()),
EverStartedLoadingPlugins = pluginManager?.InstalledPlugins.Where(x => x.HasEverStartedLoad).Select(x => x.InternalName).ToList(),
DalamudVersion = Util.GetScmVersion(),
DalamudGitHash = Util.GetGitHash() ?? "Unknown",
DalamudVersion = Versioning.GetScmVersion(),
DalamudGitHash = Versioning.GetGitHash() ?? "Unknown",
GameVersion = startInfo.GameVersion?.ToString() ?? "Unknown",
Language = startInfo.Language.ToString(),
BetaKey = Util.GetActiveTrack(),
BetaKey = Versioning.GetActiveTrack(),
DoPluginTest = configuration.DoPluginTest,
LoadAllApiLevels = pluginManager?.LoadAllApiLevels == true,
InterfaceLoaded = interfaceManager?.IsReady ?? false,

View file

@ -68,96 +68,10 @@ public static partial class Util
];
private static readonly Type GenericSpanType = typeof(Span<>);
private static string? scmVersionInternal;
private static string? gitHashInternal;
private static string? gitHashClientStructsInternal;
private static string? branchInternal;
private static ulong moduleStartAddr;
private static ulong moduleEndAddr;
/// <summary>
/// Gets the Dalamud version.
/// </summary>
[Api13ToDo("Remove. Make both versions here internal. Add an API somewhere.")]
public static string AssemblyVersion { get; } =
Assembly.GetAssembly(typeof(ChatHandlers))!.GetName().Version!.ToString();
/// <summary>
/// Gets the Dalamud version.
/// </summary>
internal static Version AssemblyVersionParsed { get; } =
Assembly.GetAssembly(typeof(ChatHandlers))!.GetName().Version!;
/// <summary>
/// Gets the SCM Version from the assembly, or null if it cannot be found. This method will generally return
/// the <c>git describe</c> output for this build, which will be a raw version if this is a stable build or an
/// appropriately-annotated version if this is *not* stable. Local builds will return a `Local Build` text string.
/// </summary>
/// <returns>The SCM version of the assembly.</returns>
public static string GetScmVersion()
{
if (scmVersionInternal != null) return scmVersionInternal;
var asm = typeof(Util).Assembly;
var attrs = asm.GetCustomAttributes<AssemblyMetadataAttribute>();
return scmVersionInternal = attrs.First(a => a.Key == "SCMVersion").Value
?? asm.GetName().Version!.ToString();
}
/// <summary>
/// Gets the git commit hash value from the assembly or null if it cannot be found. Will be null for Debug builds,
/// and will be suffixed with `-dirty` if in release with pending changes.
/// </summary>
/// <returns>The git hash of the assembly.</returns>
public static string? GetGitHash()
{
if (gitHashInternal != null)
return gitHashInternal;
var asm = typeof(Util).Assembly;
var attrs = asm.GetCustomAttributes<AssemblyMetadataAttribute>();
return gitHashInternal = attrs.FirstOrDefault(a => a.Key == "GitHash")?.Value ?? "N/A";
}
/// <summary>
/// Gets the git hash value from the assembly or null if it cannot be found.
/// </summary>
/// <returns>The git hash of the assembly.</returns>
public static string? GetGitHashClientStructs()
{
if (gitHashClientStructsInternal != null)
return gitHashClientStructsInternal;
var asm = typeof(Util).Assembly;
var attrs = asm.GetCustomAttributes<AssemblyMetadataAttribute>();
gitHashClientStructsInternal = attrs.First(a => a.Key == "GitHashClientStructs").Value;
return gitHashClientStructsInternal;
}
/// <summary>
/// Gets the Git branch name this version of Dalamud was built from, or null, if this is a Debug build.
/// </summary>
/// <returns>The branch name.</returns>
public static string? GetGitBranch()
{
if (branchInternal != null)
return branchInternal;
var asm = typeof(Util).Assembly;
var attrs = asm.GetCustomAttributes<AssemblyMetadataAttribute>();
var gitBranch = attrs.FirstOrDefault(a => a.Key == "GitBranch")?.Value;
if (gitBranch == null)
return null;
return branchInternal = gitBranch;
}
/// <inheritdoc cref="DescribeAddress(nint)"/>
public static unsafe string DescribeAddress(void* p) => DescribeAddress((nint)p);
@ -693,16 +607,6 @@ public static partial class Util
}
}
/// <summary>
/// Gets the active Dalamud track, if this instance was launched through XIVLauncher and used a version
/// downloaded from webservices.
/// </summary>
/// <returns>The name of the track, or null.</returns>
internal static string? GetActiveTrack()
{
return Environment.GetEnvironmentVariable("DALAMUD_BRANCH");
}
/// <summary>
/// Gets a random, inoffensive, human-friendly string.
/// </summary>

View file

@ -0,0 +1,108 @@
using System.Linq;
using System.Reflection;
namespace Dalamud.Utility;
/// <summary>
/// Helpers to access Dalamud versioning information.
/// </summary>
internal static class Versioning
{
private static string? scmVersionInternal;
private static string? gitHashInternal;
private static string? gitHashClientStructsInternal;
private static string? branchInternal;
/// <summary>
/// Gets the Dalamud version.
/// </summary>
/// <returns>The raw Dalamud assembly version.</returns>
internal static string GetAssemblyVersion() =>
Assembly.GetAssembly(typeof(Versioning))!.GetName().Version!.ToString();
/// <summary>
/// Gets the Dalamud version.
/// </summary>
/// <returns>The parsed Dalamud assembly version.</returns>
internal static Version GetAssemblyVersionParsed() =>
Assembly.GetAssembly(typeof(Versioning))!.GetName().Version!;
/// <summary>
/// Gets the SCM Version from the assembly, or null if it cannot be found. This method will generally return
/// the <c>git describe</c> output for this build, which will be a raw version if this is a stable build or an
/// appropriately-annotated version if this is *not* stable. Local builds will return a `Local Build` text string.
/// </summary>
/// <returns>The SCM version of the assembly.</returns>
internal static string GetScmVersion()
{
if (scmVersionInternal != null) return scmVersionInternal;
var asm = typeof(Util).Assembly;
var attrs = asm.GetCustomAttributes<AssemblyMetadataAttribute>();
return scmVersionInternal = attrs.First(a => a.Key == "SCMVersion").Value
?? asm.GetName().Version!.ToString();
}
/// <summary>
/// Gets the git commit hash value from the assembly or null if it cannot be found. Will be null for Debug builds,
/// and will be suffixed with `-dirty` if in release with pending changes.
/// </summary>
/// <returns>The git hash of the assembly.</returns>
internal static string? GetGitHash()
{
if (gitHashInternal != null)
return gitHashInternal;
var asm = typeof(Util).Assembly;
var attrs = asm.GetCustomAttributes<AssemblyMetadataAttribute>();
return gitHashInternal = attrs.FirstOrDefault(a => a.Key == "GitHash")?.Value ?? "N/A";
}
/// <summary>
/// Gets the git hash value from the assembly or null if it cannot be found.
/// </summary>
/// <returns>The git hash of the assembly.</returns>
internal static string? GetGitHashClientStructs()
{
if (gitHashClientStructsInternal != null)
return gitHashClientStructsInternal;
var asm = typeof(Util).Assembly;
var attrs = asm.GetCustomAttributes<AssemblyMetadataAttribute>();
gitHashClientStructsInternal = attrs.First(a => a.Key == "GitHashClientStructs").Value;
return gitHashClientStructsInternal;
}
/// <summary>
/// Gets the Git branch name this version of Dalamud was built from, or null, if this is a Debug build.
/// </summary>
/// <returns>The branch name.</returns>
internal static string? GetGitBranch()
{
if (branchInternal != null)
return branchInternal;
var asm = typeof(Util).Assembly;
var attrs = asm.GetCustomAttributes<AssemblyMetadataAttribute>();
var gitBranch = attrs.FirstOrDefault(a => a.Key == "GitBranch")?.Value;
if (gitBranch == null)
return null;
return branchInternal = gitBranch;
}
/// <summary>
/// Gets the active Dalamud track, if this instance was launched through XIVLauncher and used a version
/// downloaded from webservices.
/// </summary>
/// <returns>The name of the track, or null.</returns>
internal static string? GetActiveTrack()
{
return Environment.GetEnvironmentVariable("DALAMUD_BRANCH");
}
}