diff --git a/ProjectLighthouse.Servers.Website/Pages/Layouts/BaseLayout.cshtml b/ProjectLighthouse.Servers.Website/Pages/Layouts/BaseLayout.cshtml index 7225271b..78d36de4 100644 --- a/ProjectLighthouse.Servers.Website/Pages/Layouts/BaseLayout.cshtml +++ b/ProjectLighthouse.Servers.Website/Pages/Layouts/BaseLayout.cshtml @@ -192,25 +192,7 @@
@{ - string? firstRemoteUnparsedUrl = null; - string? firstRemoteParsedUrl = null; - - if (VersionHelper.Remotes != null) - { - firstRemoteUnparsedUrl = VersionHelper.Remotes.FirstOrDefault(); - } - - if (firstRemoteUnparsedUrl != null) - { - if (firstRemoteUnparsedUrl.Contains("git@")) - { - firstRemoteParsedUrl = firstRemoteUnparsedUrl.Replace("git@", "").Replace(":", "/").Split(".git").FirstOrDefault(); - } - else if (firstRemoteUnparsedUrl.Contains("https://")) - { - firstRemoteParsedUrl = firstRemoteUnparsedUrl.Replace("https://", "").Split(".git").FirstOrDefault(); - } - } + string? remoteUrl = VersionHelper.DetermineRemoteUrl(); } @Model.Translate(BaseLayoutStrings.GeneratedBy, VersionHelper.FullVersion) @@ -224,11 +206,11 @@ AGPL-3.0 License · - @if (!string.IsNullOrWhiteSpace(firstRemoteParsedUrl)) + @if (!string.IsNullOrWhiteSpace(remoteUrl)) { - + Source Code - + } else { diff --git a/ProjectLighthouse/Helpers/VersionHelper.cs b/ProjectLighthouse/Helpers/VersionHelper.cs index b571ef2c..3262437d 100644 --- a/ProjectLighthouse/Helpers/VersionHelper.cs +++ b/ProjectLighthouse/Helpers/VersionHelper.cs @@ -32,11 +32,8 @@ public static class VersionHelper } catch { - Logger.Error - ( - "Project Lighthouse was built incorrectly. Please make sure git is available when building.", - LogArea.Startup - ); + Logger.Error("Project Lighthouse was built incorrectly. Please make sure git is available when building.", + LogArea.Startup); CommitHash = "invalid"; Branch = "invalid"; CanCheckForUpdates = false; @@ -44,37 +41,65 @@ public static class VersionHelper if (!IsDirty) return; - Logger.Warn - ( - "This is a modified version of Project Lighthouse. " + - "Please make sure you are properly disclosing the source code to any users who may be using this instance.", - LogArea.Startup - ); + Logger.Warn("This is a modified version of Project Lighthouse. " + + "Please make sure you are properly disclosing the source code to any users who may be using this instance.", + LogArea.Startup); CanCheckForUpdates = false; } + #nullable enable + /// + /// Determines the URL of the git remote. This doesn't return a complete URL and it's only really used for the + /// "Source Code" hyperlink in the BaseLayout. Use this with caution. + /// + public static string? DetermineRemoteUrl() + { + string? remoteUnparsedUrl = null; + string? remoteParsedUrl = null; + + if (Remotes != null) remoteUnparsedUrl = Remotes.FirstOrDefault(); + if (remoteUnparsedUrl == null) return null; + + if (remoteUnparsedUrl.Contains("git@")) + { + remoteParsedUrl = remoteUnparsedUrl.Replace("git@", "").Replace(":", "/").Split(".git").FirstOrDefault(); + } + else if (remoteUnparsedUrl.Contains("https://")) + { + remoteParsedUrl = remoteUnparsedUrl.Replace("https://", "").Split(".git").FirstOrDefault(); + } + + return remoteParsedUrl; + } + #nullable disable + public static string CommitHash { get; set; } public static string Branch { get; set; } /// - /// The full revision string. States current revision hash and, if not main, the branch. + /// The full revision string. States current revision hash and, if not main, the branch. /// - public static string FullRevision { get; set; } + private static string FullRevision { get; set; } /// - /// The server's branding (environment version) to show to LBP clients. Shows the environment name next to the revision. + /// The server's branding (environment version) to show to LBP clients. Shows the environment name next to the + /// revision. /// public static string EnvVer => $"{ServerConfiguration.Instance.Customization.EnvironmentName} {FullRevision}"; - public static string FullVersion => $"Project Lighthouse {ServerConfiguration.Instance.Customization.EnvironmentName} {Branch}@{CommitHash} {Build}"; - public static bool IsDirty => CommitHash.EndsWith("-dirty") || CommitsOutOfDate != 1 || CommitHash == "invalid" || Branch == "invalid"; + public static string FullVersion => + $"Project Lighthouse {ServerConfiguration.Instance.Customization.EnvironmentName} {Branch}@{CommitHash} {Build}"; + public static bool IsDirty => CommitHash.EndsWith("-dirty") || + CommitsOutOfDate != 1 || + CommitHash == "invalid" || + Branch == "invalid"; public static int CommitsOutOfDate { get; set; } public static bool CanCheckForUpdates { get; set; } public static string[] Remotes { get; set; } public const string Build = - #if DEBUG + #if DEBUG "Debug"; - #elif RELEASE + #elif RELEASE "Release"; - #else - "Unknown"; - #endif + #else + "Unknown"; + #endif } \ No newline at end of file