From c5ce1815e03485bc94b53cf3a2dfb22d6a7e97bd Mon Sep 17 00:00:00 2001
From: goat <16760685+goaaats@users.noreply.github.com>
Date: Sun, 10 Jul 2022 17:26:41 +0200
Subject: [PATCH 1/2] ci: save git hash separately on version meta
---
.github/workflows/main.yml | 1 +
1 file changed, 1 insertion(+)
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 1d270429e..0edf6b413 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -82,6 +82,7 @@ jobs:
} else {
Move-Item -Force ".\canary.zip" ".\${branchName}\latest.zip"
$versionData.AssemblyVersion = $newVersion
+ $versionData.GitSha = $newVersion
$versionData | ConvertTo-Json -Compress | Out-File ".\${branchName}\version"
}
From 190ef494c5383e2c9cf65ad4f510c9128ba5d448 Mon Sep 17 00:00:00 2001
From: goat <16760685+goaaats@users.noreply.github.com>
Date: Sun, 10 Jul 2022 17:31:52 +0200
Subject: [PATCH 2/2] feat: add visual branch switcher
---
.../Internal/DalamudConfiguration.cs | 11 --
.../Interface/Internal/DalamudInterface.cs | 18 ++-
.../Internal/Windows/BranchSwitcherWindow.cs | 144 ++++++++++++++++++
3 files changed, 156 insertions(+), 17 deletions(-)
create mode 100644 Dalamud/Interface/Internal/Windows/BranchSwitcherWindow.cs
diff --git a/Dalamud/Configuration/Internal/DalamudConfiguration.cs b/Dalamud/Configuration/Internal/DalamudConfiguration.cs
index ccbfc17dc..c201f96e0 100644
--- a/Dalamud/Configuration/Internal/DalamudConfiguration.cs
+++ b/Dalamud/Configuration/Internal/DalamudConfiguration.cs
@@ -18,11 +18,6 @@ namespace Dalamud.Configuration.Internal
[Serializable]
internal sealed class DalamudConfiguration : IServiceType
{
- ///
- /// Currently used beta key for Dalamud staging builds.
- ///
- public const string DalamudCurrentBetaKey = "proof of context";
-
private static readonly JsonSerializerSettings SerializerSettings = new()
{
TypeNameHandling = TypeNameHandling.All,
@@ -44,12 +39,6 @@ namespace Dalamud.Configuration.Internal
///
public event DalamudConfigurationSavedDelegate DalamudConfigurationSaved;
- ///
- /// Gets a value indicating whether or not Dalamud staging is enabled.
- ///
- [JsonIgnore]
- public bool IsConventionalStaging => this.DalamudBetaKey == DalamudCurrentBetaKey;
-
///
/// Gets or sets a list of muted works.
///
diff --git a/Dalamud/Interface/Internal/DalamudInterface.cs b/Dalamud/Interface/Internal/DalamudInterface.cs
index 5a6bae722..66579e0ae 100644
--- a/Dalamud/Interface/Internal/DalamudInterface.cs
+++ b/Dalamud/Interface/Internal/DalamudInterface.cs
@@ -56,6 +56,7 @@ namespace Dalamud.Interface.Internal
private readonly TitleScreenMenuWindow titleScreenMenuWindow;
private readonly FallbackFontNoticeWindow fallbackFontNoticeWindow;
private readonly ProfilerWindow profilerWindow;
+ private readonly BranchSwitcherWindow branchSwitcherWindow;
private readonly TextureWrap logoTexture;
private readonly TextureWrap tsmLogoTexture;
@@ -100,6 +101,7 @@ namespace Dalamud.Interface.Internal
this.titleScreenMenuWindow = new TitleScreenMenuWindow() { IsOpen = false };
this.fallbackFontNoticeWindow = new FallbackFontNoticeWindow() { IsOpen = interfaceManager.IsFallbackFontMode && !configuration.DisableFontFallbackNotice };
this.profilerWindow = new ProfilerWindow() { IsOpen = false };
+ this.branchSwitcherWindow = new BranchSwitcherWindow() { IsOpen = false };
this.WindowSystem.AddWindow(this.changelogWindow);
this.WindowSystem.AddWindow(this.colorDemoWindow);
@@ -117,6 +119,7 @@ namespace Dalamud.Interface.Internal
this.WindowSystem.AddWindow(this.titleScreenMenuWindow);
this.WindowSystem.AddWindow(this.fallbackFontNoticeWindow);
this.WindowSystem.AddWindow(this.profilerWindow);
+ this.WindowSystem.AddWindow(this.branchSwitcherWindow);
ImGuiManagedAsserts.AssertsEnabled = configuration.AssertsEnabledAtStartup;
this.isImGuiDrawDevMenu = this.isImGuiDrawDevMenu || configuration.DevBarOpenAtStartup;
@@ -140,7 +143,7 @@ namespace Dalamud.Interface.Internal
tsm.AddEntryCore(Loc.Localize("TSMDalamudPlugins", "Plugin Installer"), this.tsmLogoTexture, () => this.pluginWindow.IsOpen = true);
tsm.AddEntryCore(Loc.Localize("TSMDalamudSettings", "Dalamud Settings"), this.tsmLogoTexture, () => this.settingsWindow.IsOpen = true);
- if (configuration.IsConventionalStaging)
+ if (!configuration.DalamudBetaKind.IsNullOrEmpty())
{
tsm.AddEntryCore(Loc.Localize("TSMDalamudDevMenu", "Developer Menu"), this.tsmLogoTexture, () => this.isImGuiDrawDevMenu = true);
}
@@ -272,6 +275,11 @@ namespace Dalamud.Interface.Internal
///
public void OpenProfiler() => this.profilerWindow.IsOpen = true;
+ ///
+ /// Opens the
+ ///
+ public void OpenBranchSwitcher() => this.branchSwitcherWindow.IsOpen = true;
+
#endregion
#region Close
@@ -621,17 +629,15 @@ namespace Dalamud.Interface.Internal
ImGui.Separator();
- var isBeta = configuration.DalamudBetaKey == DalamudConfiguration.DalamudCurrentBetaKey;
- if (ImGui.MenuItem("Enable Dalamud testing", string.Empty, isBeta))
+ if (ImGui.MenuItem("Open Dalamud branch switcher"))
{
- configuration.DalamudBetaKey = isBeta ? null : DalamudConfiguration.DalamudCurrentBetaKey;
- configuration.Save();
+ this.OpenBranchSwitcher();
}
var startInfo = Service.Get();
ImGui.MenuItem(Util.AssemblyVersion, false);
ImGui.MenuItem(startInfo.GameVersion.ToString(), false);
- ImGui.MenuItem($"CS: {Util.GetGitHashClientStructs()}", false);
+ ImGui.MenuItem($"D: {Util.GetGitHash()} CS: {Util.GetGitHashClientStructs()}", false);
ImGui.EndMenu();
}
diff --git a/Dalamud/Interface/Internal/Windows/BranchSwitcherWindow.cs b/Dalamud/Interface/Internal/Windows/BranchSwitcherWindow.cs
new file mode 100644
index 000000000..bdff07e3e
--- /dev/null
+++ b/Dalamud/Interface/Internal/Windows/BranchSwitcherWindow.cs
@@ -0,0 +1,144 @@
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.IO;
+using System.Linq;
+using System.Net.Http;
+using System.Net.Http.Json;
+using System.Threading.Tasks;
+
+using Dalamud.Configuration.Internal;
+using Dalamud.Interface.Colors;
+using Dalamud.Interface.Windowing;
+using ImGuiNET;
+using Newtonsoft.Json;
+
+namespace Dalamud.Interface.Internal.Windows;
+
+///
+/// Window responsible for switching Dalamud beta branches.
+///
+public class BranchSwitcherWindow : Window
+{
+ private const string BranchInfoUrl = "https://kamori.goats.dev/Dalamud/Release/Meta";
+
+ private Dictionary? branches;
+ private int selectedBranchIndex;
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public BranchSwitcherWindow()
+ : base("Branch Switcher", ImGuiWindowFlags.AlwaysAutoResize)
+ {
+ this.ShowCloseButton = false;
+ this.RespectCloseHotkey = false;
+ }
+
+ ///
+ public override void OnOpen()
+ {
+ Task.Run(async () =>
+ {
+ using var client = new HttpClient();
+ this.branches = await client.GetFromJsonAsync>(BranchInfoUrl);
+ Debug.Assert(this.branches != null, "this.branches != null");
+
+ var config = Service.Get();
+ this.selectedBranchIndex = this.branches!.Any(x => x.Key == config.DalamudBetaKind) ?
+ this.branches.TakeWhile(x => x.Key != config.DalamudBetaKind).Count()
+ : 0;
+
+ if (this.branches.ElementAt(this.selectedBranchIndex).Value.Key != config.DalamudBetaKey)
+ this.selectedBranchIndex = 0;
+ });
+
+ base.OnOpen();
+ }
+
+ ///
+ public override void Draw()
+ {
+ if (this.branches == null)
+ {
+ ImGui.TextColored(ImGuiColors.DalamudGrey, "Loading branches...");
+ return;
+ }
+
+ var si = Service.Get();
+
+ var itemsArray = this.branches.Select(x => x.Key).ToArray();
+ ImGui.ListBox("Branch", ref this.selectedBranchIndex, itemsArray, itemsArray.Length);
+
+ var pickedBranch = this.branches.ElementAt(this.selectedBranchIndex);
+
+ if (pickedBranch.Value.SupportedGameVer != si.GameVersion)
+ {
+ ImGui.PushStyleColor(ImGuiCol.Text, ImGuiColors.DalamudRed);
+ ImGui.TextWrapped("Can't pick this branch. GameVer != SupportedGameVer.");
+ }
+ else
+ {
+ ImGui.Text($"Version: {pickedBranch.Value.AssemblyVersion} ({pickedBranch.Value.GitSha ?? "unk"})");
+ ImGui.Text($"Runtime: {pickedBranch.Value.RuntimeVersion}");
+
+ ImGuiHelpers.ScaledDummy(5);
+
+ void Pick()
+ {
+ var config = Service.Get();
+ config.DalamudBetaKind = pickedBranch.Key;
+ config.DalamudBetaKey = pickedBranch.Value.Key;
+ config.Save();
+ }
+
+ if (ImGui.Button("Pick"))
+ {
+ Pick();
+ }
+
+ ImGui.SameLine();
+
+ if (ImGui.Button("Pick & Restart"))
+ {
+ Pick();
+
+ var appData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
+ var xlPath = Path.Combine(appData, "XIVLauncher", "XIVLauncher.exe");
+
+ if (File.Exists(xlPath))
+ {
+ Process.Start(xlPath);
+ Environment.Exit(0);
+ }
+ }
+ }
+ }
+
+ private class VersionEntry
+ {
+ [JsonProperty("key")]
+ public string? Key { get; set; }
+
+ [JsonProperty("track")]
+ public string? Track { get; set; }
+
+ [JsonProperty("assemblyVersion")]
+ public string? AssemblyVersion { get; set; }
+
+ [JsonProperty("runtimeVersion")]
+ public string? RuntimeVersion { get; set; }
+
+ [JsonProperty("runtimeRequired")]
+ public bool RuntimeRequired { get; set; }
+
+ [JsonProperty("supportedGameVer")]
+ public string? SupportedGameVer { get; set; }
+
+ [JsonProperty("downloadUrl")]
+ public string? DownloadUrl { get; set; }
+
+ [JsonProperty("gitSha")]
+ public string? GitSha { get; set; }
+ }
+}