Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let dev builds use future spec versions #4266

Merged
merged 1 commit into from
Nov 26, 2024
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
2 changes: 1 addition & 1 deletion ConsoleUI/AuthTokenListScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public AuthTokenScreen(ConsoleTheme theme) : base(theme)
/// Put CKAN 1.25.5 in top left corner
/// </summary>
protected override string LeftHeader()
=> $"{Meta.GetProductName()} {Meta.GetVersion()}";
=> $"{Meta.ProductName} {Meta.GetVersion()}";

/// <summary>
/// Put description in top center
Expand Down
2 changes: 1 addition & 1 deletion ConsoleUI/DeleteDirectoriesScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ directories.Selection is null
/// <summary>
/// Put CKAN 1.25.5 in top left corner
/// </summary>
protected override string LeftHeader() => $"{Meta.GetProductName()} {Meta.GetVersion()}";
protected override string LeftHeader() => $"{Meta.ProductName} {Meta.GetVersion()}";

/// <summary>
/// Show the Delete Directories header
Expand Down
2 changes: 1 addition & 1 deletion ConsoleUI/DependencyScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public DependencyScreen(ConsoleTheme theme,
/// <summary>
/// Put CKAN 1.25.5 in top left corner
/// </summary>
protected override string LeftHeader() => $"{Meta.GetProductName()} {Meta.GetVersion()}";
protected override string LeftHeader() => $"{Meta.ProductName} {Meta.GetVersion()}";

/// <summary>
/// Put description in top center
Expand Down
4 changes: 2 additions & 2 deletions ConsoleUI/ExitScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ private void Draw(ConsoleTheme theme)
Console.Clear();

// Specially formatted snippets
var ckanPiece = new FancyLinePiece(Meta.GetProductName(), theme.ExitInnerBg, theme.ExitHighlightFg);
var ckanVersionPiece = new FancyLinePiece($"{Meta.GetProductName()} {Meta.GetVersion()}", theme.ExitInnerBg, theme.ExitHighlightFg);
var ckanPiece = new FancyLinePiece(Meta.ProductName, theme.ExitInnerBg, theme.ExitHighlightFg);
var ckanVersionPiece = new FancyLinePiece($"{Meta.ProductName} {Meta.GetVersion()}", theme.ExitInnerBg, theme.ExitHighlightFg);
var releaseLinkPiece = new FancyLinePiece("https://github.com/KSP-CKAN/CKAN/releases/latest", theme.ExitInnerBg, theme.ExitLinkFg);
var issuesLinkPiece = new FancyLinePiece("https://github.com/KSP-CKAN/CKAN/issues", theme.ExitInnerBg, theme.ExitLinkFg);
var authorsLinkPiece = new FancyLinePiece("https://github.com/KSP-CKAN/CKAN/graphs/contributors", theme.ExitInnerBg, theme.ExitLinkFg);
Expand Down
2 changes: 1 addition & 1 deletion ConsoleUI/GameInstanceListScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public GameInstanceListScreen(ConsoleTheme theme,
/// Put CKAN 1.25.5 in top left corner
/// </summary>
protected override string LeftHeader()
=> $"{Meta.GetProductName()} {Meta.GetVersion()}";
=> $"{Meta.ProductName} {Meta.GetVersion()}";

/// <summary>
/// Put description in top center
Expand Down
2 changes: 1 addition & 1 deletion ConsoleUI/GameInstanceScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ protected GameInstanceScreen(ConsoleTheme theme, GameInstanceManager mgr, string
/// Put CKAN 1.25.5 in top left corner
/// </summary>
protected override string LeftHeader()
=> $"{Meta.GetProductName()} {Meta.GetVersion()}";
=> $"{Meta.ProductName} {Meta.GetVersion()}";

/// <summary>
/// Return whether the fields currently are valid.
Expand Down
2 changes: 1 addition & 1 deletion ConsoleUI/InstallFiltersScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public InstallFiltersScreen(ConsoleTheme theme, IConfiguration globalConfig, Gam
/// Put CKAN 1.25.5 in top left corner
/// </summary>
protected override string LeftHeader()
=> $"{Meta.GetProductName()} {Meta.GetVersion()}";
=> $"{Meta.ProductName} {Meta.GetVersion()}";

/// <summary>
/// Put description in top center
Expand Down
2 changes: 1 addition & 1 deletion ConsoleUI/ModInfoScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public ModInfoScreen(ConsoleTheme theme,
/// Put CKAN 1.25.5 in top left corner
/// </summary>
protected override string LeftHeader()
=> $"{Meta.GetProductName()} {Meta.GetVersion()}";
=> $"{Meta.ProductName} {Meta.GetVersion()}";

/// <summary>
/// Put description in top center
Expand Down
2 changes: 1 addition & 1 deletion ConsoleUI/ModListScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ is int i and > 0
/// Put CKAN 1.25.5 in top left corner
/// </summary>
protected override string LeftHeader()
=> $"{Meta.GetProductName()} {Meta.GetVersion()}";
=> $"{Meta.ProductName} {Meta.GetVersion()}";

/// <summary>
/// Put description in top center
Expand Down
2 changes: 1 addition & 1 deletion ConsoleUI/ProgressScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public ProgressScreen(ConsoleTheme theme, string descrip, string initMsg = "")
/// Put CKAN 1.25.5 in upper left corner
/// </summary>
protected override string LeftHeader()
=> $"{Meta.GetProductName()} {Meta.GetVersion()}";
=> $"{Meta.ProductName} {Meta.GetVersion()}";

/// <summary>
/// Put description of what we're doing in top center
Expand Down
2 changes: 1 addition & 1 deletion ConsoleUI/RepoScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ protected RepoScreen(ConsoleTheme theme,
/// Put CKAN 1.25.5 in top left corner
/// </summary>
protected override string LeftHeader()
=> $"{Meta.GetProductName()} {Meta.GetVersion()}";
=> $"{Meta.ProductName} {Meta.GetVersion()}";

/// <summary>
/// Put description in top center
Expand Down
2 changes: 1 addition & 1 deletion Core/CKANPathUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static class CKANPathUtils
/// </summary>
public static readonly string AppDataPath = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
Meta.GetProductName());
Meta.ProductName);

private static readonly ILog log = LogManager.GetLogger(typeof(CKANPathUtils));

Expand Down
56 changes: 30 additions & 26 deletions Core/Meta.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using System;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;

using CKAN.Extensions;
using CKAN.Versioning;

namespace CKAN
Expand All @@ -13,37 +14,40 @@ public static class Meta
/// so we don't have to embed that string in many places
/// </summary>
/// <returns>"CKAN"</returns>
public static string GetProductName()
=> Assembly.GetExecutingAssembly()
.GetAssemblyAttribute<AssemblyProductAttribute>()
.Product;
public static readonly string ProductName =
Assembly.GetExecutingAssembly()
.GetAssemblyAttribute<AssemblyProductAttribute>()
.Product;

public static readonly ModuleVersion ReleaseVersion = new ModuleVersion(GetVersion());

public static bool IsNetKAN
=> Assembly.GetExecutingAssembly()
.GetAssemblyAttribute<AssemblyTitleAttribute>()
.Title.Contains("NetKAN");
public static readonly ModuleVersion SpecVersion =
// A dev build always has an odd patch version, and
// an odd number always ends with an odd digit in base 10
new Regex(@"^(?<prefix>v\d+\.)(?<minor>\d+)\.\d*[13579]\.")
.TryMatch(ReleaseVersion.ToString(), out Match? m)
&& int.TryParse(m.Groups["minor"].Value, out int minor)
? new ModuleVersion($"{m.Groups["prefix"]}{minor + 1}.999")
: ReleaseVersion;

public static string GetVersion(VersionFormat format = VersionFormat.Normal)
{
var version = Assembly
.GetExecutingAssembly()
.GetAssemblyAttribute<AssemblyInformationalVersionAttribute>()
.InformationalVersion;
public static readonly bool IsNetKAN =
Assembly.GetExecutingAssembly()
.GetAssemblyAttribute<AssemblyTitleAttribute>()
.Title.Contains("NetKAN");

switch (format)
public static string GetVersion(VersionFormat format = VersionFormat.Normal)
=> "v" + (format switch
{
case VersionFormat.Normal:
return "v" + Assembly.GetExecutingAssembly()
.GetAssemblyAttribute<AssemblyFileVersionAttribute>()
.Version;
case VersionFormat.Full:
return $"v{version}";
default:
throw new ArgumentOutOfRangeException(nameof(format), format, null);
}
}
VersionFormat.Full =>
Assembly.GetExecutingAssembly()
.GetAssemblyAttribute<AssemblyInformationalVersionAttribute>()
.InformationalVersion,

VersionFormat.Normal or _ =>
Assembly.GetExecutingAssembly()
.GetAssemblyAttribute<AssemblyFileVersionAttribute>()
.Version,
});

private static T GetAssemblyAttribute<T>(this Assembly assembly)
=> (T)assembly.GetCustomAttributes(typeof(T), false)
Expand Down
2 changes: 1 addition & 1 deletion Core/Types/CkanModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ bool IEquatable<CkanModule>.Equals(CkanModule? other)
/// Returns true if we support at least spec_version of the CKAN spec.
/// </summary>
internal static bool IsSpecSupported(ModuleVersion spec_version)
=> Meta.IsNetKAN || Meta.ReleaseVersion.IsGreaterThan(spec_version);
=> Meta.IsNetKAN || Meta.SpecVersion.IsGreaterThan(spec_version);

/// <summary>
/// Returns true if we support the CKAN spec used by this module.
Expand Down
8 changes: 4 additions & 4 deletions GUI/Main/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ public Main(string[] cmdlineArgs,
// Set the window name and class for X11
if (Platform.IsX11)
{
HandleCreated += (sender, e) => X11.SetWMClass(Meta.GetProductName(),
Meta.GetProductName(), Handle);
HandleCreated += (sender, e) => X11.SetWMClass(Meta.ProductName,
Meta.ProductName, Handle);
}

currentUser = new GUIUser(this, Wait, StatusLabel, StatusProgress);
Expand Down Expand Up @@ -427,8 +427,8 @@ private void CurrentInstanceUpdated()

Util.Invoke(this, () =>
{
Text = $"{Meta.GetProductName()} {Meta.GetVersion()} - {CurrentInstance.game.ShortName} {CurrentInstance.Version()} -- {Platform.FormatPath(CurrentInstance.GameDir())}";
minimizeNotifyIcon.Text = $"{Meta.GetProductName()} - {CurrentInstance.Name}";
Text = $"{Meta.ProductName} {Meta.GetVersion()} - {CurrentInstance.game.ShortName} {CurrentInstance.Version()} -- {Platform.FormatPath(CurrentInstance.GameDir())}";
minimizeNotifyIcon.Text = $"{Meta.ProductName} - {CurrentInstance.Name}";
UpdateStatusBar();
});

Expand Down