Skip to content

Commit

Permalink
Merge pull request #127 from goatcorp/bootver-cutoff
Browse files Browse the repository at this point in the history
  • Loading branch information
Blooym authored Mar 19, 2024
2 parents 731b88d + 42b3d5b commit d0c6f3c
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 9 deletions.
43 changes: 36 additions & 7 deletions src/XIVLauncher.Core/LauncherApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public class LauncherApp : Component
private bool modalOnNextFrame = false;
private string modalText = string.Empty;
private string modalTitle = string.Empty;
private string modalButtonText = string.Empty;
private Action modalButtonPressAction;
private readonly ManualResetEvent modalWaitHandle = new(false);

#endregion
Expand Down Expand Up @@ -125,7 +127,7 @@ public LauncherState State

private readonly Background background = new();

public LauncherApp(Storage storage, bool needsUpdateWarning, string frontierUrl)
public LauncherApp(Storage storage, bool needsUpdateWarning, string frontierUrl, string? cutOffBootver)
{
this.Storage = storage;

Expand All @@ -141,6 +143,21 @@ public LauncherApp(Storage storage, bool needsUpdateWarning, string frontierUrl)
this.updateWarnPage = new UpdateWarnPage(this);
this.steamDeckPromptPage = new SteamDeckPromptPage(this);

if (!string.IsNullOrEmpty(cutOffBootver))
{
var bootver = SeVersion.Parse(Repository.Boot.GetVer(Program.Config.GamePath));
var cutoff = SeVersion.Parse(cutOffBootver);

if (bootver > cutoff)
{
this.ShowMessage("XIVLauncher is unavailable at this time as there were changes to the login process during a recent patch." +
"\n\nnWe need to adjust to these changes and verify that our adjustments are safe before we can re-enable the launcher." +
"\n\nYou can use the Official Launcher instead until XIVLauncher has been updated.",
"XIVLauncher", "Close Launcher", () => Environment.Exit(0));
return;
}
}

if (needsUpdateWarning)
{
this.State = LauncherState.UpdateWarn;
Expand All @@ -155,18 +172,32 @@ public LauncherApp(Storage storage, bool needsUpdateWarning, string frontierUrl)
#endif
}

public void ShowMessage(string text, string title)
public void ShowMessage(string text, string title = "XIVLauncher", string modalButtonText = "OK", Action? modalPressedAction = default)
{
if (this.isModalDrawing)
throw new InvalidOperationException("Cannot open modal while another modal is open");

this.modalText = text;
this.modalTitle = title;
this.modalButtonText = modalButtonText;
if (modalPressedAction is null)
{
this.modalButtonPressAction = () =>
{
ImGui.CloseCurrentPopup();
this.isModalDrawing = false;
this.modalWaitHandle.Set();
};
}
else
{
this.modalButtonPressAction = modalPressedAction;
}
this.isModalDrawing = true;
this.modalOnNextFrame = true;
}

public void ShowMessageBlocking(string text, string title = "XIVLauncher")
public void ShowMessageBlocking(string text, string title = "XIVLauncher", bool canContinue = true)
{
if (!this.modalWaitHandle.WaitOne(0) && this.isModalDrawing)
throw new InvalidOperationException("Cannot open modal while another modal is open");
Expand Down Expand Up @@ -307,11 +338,9 @@ private void DrawModal()
const float BUTTON_WIDTH = 120f;
ImGui.SetCursorPosX((ImGui.GetWindowWidth() - BUTTON_WIDTH) / 2);

if (ImGui.Button("OK", new Vector2(BUTTON_WIDTH, 40)))
if (ImGui.Button(modalButtonText, new Vector2(BUTTON_WIDTH, 40)))
{
ImGui.CloseCurrentPopup();
this.isModalDrawing = false;
this.modalWaitHandle.Set();
modalButtonPressAction();
}

ImGui.EndPopup();
Expand Down
40 changes: 40 additions & 0 deletions src/XIVLauncher.Core/LauncherClientConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

using System.Net.Http.Json;
using Serilog;

namespace XIVLauncher.Core;


/// <summary>
/// Represents a response from Kamori's GetLauncherClientConfig endpoint.
/// </summary>
public readonly struct LauncherClientConfig
{
private const string LAUNCHER_CONFIG_URL = "https://kamori.goats.dev/Launcher/GetLauncherClientConfig";
private const string FRONTIER_FALLBACK = "https://launcher.finalfantasyxiv.com/v650/index.html?rc_lang={0}&time={1}";

public required string frontierUrl { get; init; }
public string? cutOffBootver { get; init; }
public uint flags { get; init; }

public static async Task<LauncherClientConfig> Fetch()
{
try
{
using var client = new HttpClient()
{
Timeout = TimeSpan.FromSeconds(5),
};
return await client.GetFromJsonAsync<LauncherClientConfig>(LAUNCHER_CONFIG_URL).ConfigureAwait(false);
}
catch (Exception ex)
{
Log.Error(ex, "Could not obtain LauncherClientConfig");
return new LauncherClientConfig()
{
frontierUrl = FRONTIER_FALLBACK,
};
}
}
}

4 changes: 2 additions & 2 deletions src/XIVLauncher.Core/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ class Program
private static uint invalidationFrames = 0;
private static Vector2 lastMousePosition;

private const string FRONTIER_FALLBACK = "https://launcher.finalfantasyxiv.com/v650/index.html?rc_lang={0}&time={1}";

public static string CType = CoreEnvironmentSettings.GetCType();

Expand Down Expand Up @@ -292,7 +291,8 @@ private static void Main(string[] args)

needUpdate = CoreEnvironmentSettings.IsUpgrade ? true : needUpdate;

launcherApp = new LauncherApp(storage, needUpdate, FRONTIER_FALLBACK);
var launcherClientConfig = LauncherClientConfig.Fetch().GetAwaiter().GetResult();
launcherApp = new LauncherApp(storage, needUpdate, launcherClientConfig.frontierUrl, launcherClientConfig.cutOffBootver);

Invalidate(20);

Expand Down

0 comments on commit d0c6f3c

Please sign in to comment.