Skip to content

Commit

Permalink
Merge branch 'main' into compatibility-rework-2
Browse files Browse the repository at this point in the history
  • Loading branch information
rankynbass committed Sep 2, 2024
2 parents 5daf2e6 + 6cbc118 commit 679e1b8
Show file tree
Hide file tree
Showing 23 changed files with 65 additions and 104 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ XIVLauncher Core has community packages for various Linux distributions. Please
| ----------- | ----------- |
| [**Flathub (official)**](https://flathub.org/apps/details/dev.goats.xivlauncher) | ![Flathub](https://img.shields.io/flathub/v/dev.goats.xivlauncher) |
| [AUR](https://aur.archlinux.org/packages/xivlauncher) | ![AUR version](https://img.shields.io/aur/version/xivlauncher) |
| [AUR (bin)](https://aur.archlinux.org/packages/xivlauncher-bin) | ![AUR version](https://img.shields.io/aur/version/xivlauncher-bin) |
| [AUR (git)](https://aur.archlinux.org/packages/xivlauncher-git) | ![AUR version](https://img.shields.io/aur/version/xivlauncher-git) |
| [Copr (Fedora+openSuse+EL9)](https://copr.fedorainfracloud.org/coprs/rankyn/xivlauncher/) | ![COPR version](https://img.shields.io/endpoint?url=https%3A%2F%2Fraw.githubusercontent.com%2Frankynbass%2FXIVLauncher4rpm%2Fmain%2Fbadge.json)|
| [GURU (Gentoo)](https://gitweb.gentoo.org/repo/proj/guru.git/tree/games-util/xivlauncher) | ![GURU version](https://repology.org/badge/version-for-repo/gentoo_ovl_guru/xivlauncher.core.svg?header=guru) |
| [MPR (Debian+Ubuntu)](https://mpr.makedeb.org/packages/xivlauncher) | ![MPR package](https://repology.org/badge/version-for-repo/mpr/xivlauncher.core.svg?header=MPR) |
| [MPR (git) (Debian+Ubuntu)](https://mpr.makedeb.org/packages/xivlauncher-git) | ![MPR package](https://repology.org/badge/version-for-repo/mpr/xivlauncher.core.svg?header=MPR) |
| [nixpkgs stable](https://search.nixos.org/packages?channel=23.11&from=0&size=50&sort=relevance&type=packages&query=xivlauncher) | ![nixpkgs stable version](https://repology.org/badge/version-for-repo/nix_stable_23_11/xivlauncher.core.svg?header=nixpkgs%2023.11) |
| [nixpkgs stable](https://search.nixos.org/packages?channel=24.05&from=0&size=50&sort=relevance&type=packages&query=xivlauncher) | ![nixpkgs stable version](https://repology.org/badge/version-for-repo/nix_stable_24_05/xivlauncher.core.svg?header=nixpkgs%2024.05) |
| [nixpkgs unstable](https://search.nixos.org/packages?channel=unstable&from=0&size=50&sort=relevance&type=packages&query=xivlauncher) | ![nixpkgs unstable version](https://repology.org/badge/version-for-repo/nix_unstable/xivlauncher.core.svg?header=nixpkgs%20unstable) |
| [PPA (Ubuntu)](https://launchpad.net/~linneris/+archive/ubuntu/xivlauncher-core-stable) | ![PPA version](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Flaunchpad.net%2Fapi%2F1.0%2F~linneris%2F%2Barchive%2Fxivlauncher-core-stable%3Fws.op%3DgetPublishedBinaries%26status%3DPublished%26distro_arch_series%3Dhttps%3A%2F%2Flaunchpad.net%2Fapi%2F1.0%2Fubuntu%2Fjammy%2Famd64&query=%24.entries%5B0%5D.binary_package_version&logo=ubuntu&label=PPA&color=green) |
| [AppImage](https://github.com/rankynbass/XIVLauncher-AppImage/releases/latest) | ![v1.1.0-1](https://img.shields.io/endpoint?url=https%3A%2F%2Fraw.githubusercontent.com%2Frankynbass%2FXIVLauncher-AppImage%2Fmaster%2Fbadge.json) |
6 changes: 1 addition & 5 deletions src/XIVLauncher.Core/Accounts/AccountSwitcherEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@ public void UpdateProfileImage(DirectoryInfo storage)
}
else
{
using (var client = new HttpClient())
{
imageBytes = client.GetByteArrayAsync(uri).Result;
}

imageBytes = Program.HttpClient.GetByteArrayAsync(uri).Result;
File.WriteAllBytes(cacheFile, imageBytes);
}

Expand Down
9 changes: 3 additions & 6 deletions src/XIVLauncher.Core/Accounts/XivAccount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,8 @@ public static async Task<JObject> GetCharacterSearch(string name, string world)

public static async Task<dynamic> Get(string endpoint)
{
using (var client = new HttpClient())
{
var result = await client.GetStringAsync(URL + endpoint).ConfigureAwait(false);
var parsedObject = JObject.Parse(result);
return parsedObject;
}
var result = await Program.HttpClient.GetStringAsync(URL + endpoint).ConfigureAwait(false);
var parsedObject = JObject.Parse(result);
return parsedObject;
}
}
7 changes: 7 additions & 0 deletions src/XIVLauncher.Core/AppUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ public static string GetAssemblyVersion()
return fvi.FileVersion.ToString();
}

/// <summary>
/// Open a URL in the system's default browser.
/// </summary>
/// <remarks>
/// On Steam Deck this method will open the in-game overlay instead of a browser instance.
/// </remarks>
/// <param name="url">The URL to open.</param>
public static void OpenBrowser(string url)
{
if (Program.IsSteamDeckHardware && Program.Steam != null && Program.Steam.IsValid)
Expand Down
24 changes: 0 additions & 24 deletions src/XIVLauncher.Core/Components/Background.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,7 @@ public Background()
public override void Draw()
{
ImGui.SetCursorPos(new Vector2(0, ImGuiHelpers.ViewportSize.Y - bgTexture.Height));

ImGui.Image(bgTexture.ImGuiHandle, new Vector2(bgTexture.Width, bgTexture.Height));

/*
ImGui.SetCursorPos(new Vector2());
var vpSize = ImGuiHelpers.ViewportSize;
var width = vpSize.X;
var height = this.bgTexture.Height / (float)this.bgTexture.Width * width;
if (height < vpSize.Y)
{
height = vpSize.Y;
width = this.bgTexture.Width / (float)this.bgTexture.Height * height;
ImGui.SetCursorPosX((vpSize.X - width) / 2);
}
else
{
ImGui.SetCursorPosY((vpSize.Y - height) / 2);
}
ImGui.Image(this.bgTexture.ImGuiHandle, new Vector2(width, height));
*/

base.Draw();
}
}
14 changes: 0 additions & 14 deletions src/XIVLauncher.Core/Components/MainPage/ActionButtons.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ namespace XIVLauncher.Core.Components.MainPage;

public class ActionButtons : Component
{
public event Action? OnQueueButtonClicked;
public event Action? OnStatusButtonClicked;
public event Action? OnSettingsButtonClicked;

Expand All @@ -15,19 +14,6 @@ public override void Draw()
var btnSize = new Vector2(80) * ImGuiHelpers.GlobalScale;

ImGui.PushFont(FontManager.IconFont);

ImGui.BeginDisabled(this.OnQueueButtonClicked == null);
if (ImGui.Button(FontAwesomeIcon.Clock.ToIconString(), btnSize))
{
this.OnQueueButtonClicked?.Invoke();
}
ImGui.PushFont(FontManager.TextFont);
ImGuiHelpers.AddTooltip("Queue");
ImGui.PopFont();
ImGui.EndDisabled();

ImGui.SameLine();

ImGui.BeginDisabled(this.OnStatusButtonClicked == null);
if (ImGui.Button(FontAwesomeIcon.Globe.ToIconString(), btnSize))
{
Expand Down
12 changes: 8 additions & 4 deletions src/XIVLauncher.Core/Components/MainPage/MainPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,14 +246,18 @@ public async Task<bool> Login(string username, string password, bool isOtp, bool

private async Task<bool> TryProcessLoginResult(Launcher.LoginResult loginResult, bool isSteam, LoginAction action)
{
// Format error message in the way OauthLoginException expects.
var preErrorMsg = "window.external.user(\"login=auth,ng,err,";
var postErrorMsg = "\");";

if (loginResult.State == Launcher.LoginState.NoService)
{
throw new OauthLoginException("No service account or subscription");
throw new OauthLoginException(preErrorMsg + "No service account or subscription" + postErrorMsg);
}

if (loginResult.State == Launcher.LoginState.NoTerms)
{
throw new OauthLoginException("Need to accept terms of use");
throw new OauthLoginException(preErrorMsg + "Need to accept terms of use" + postErrorMsg);
}

/*
Expand All @@ -277,7 +281,7 @@ private async Task<bool> TryProcessLoginResult(Launcher.LoginResult loginResult,
"Error", MessageBoxButton.OK, MessageBoxImage.Error, parentWindow: _window);
*/

throw new OauthLoginException("Boot conflict, need reinstall");
throw new OauthLoginException(preErrorMsg + "Boot conflict, need reinstall" + postErrorMsg);
}

if (action == LoginAction.Repair)
Expand All @@ -299,7 +303,7 @@ private async Task<bool> TryProcessLoginResult(Launcher.LoginResult loginResult,
"The server sent an incorrect response - the repair cannot proceed."),
"Error", MessageBoxButton.OK, MessageBoxImage.Error, parentWindow: _window);
*/
throw new OauthLoginException("Repair login state not NeedsPatchGame");
throw new OauthLoginException(preErrorMsg + "Repair login state not NeedsPatchGame" + postErrorMsg);
}
}
catch (Exception)
Expand Down
3 changes: 1 addition & 2 deletions src/XIVLauncher.Core/Components/MainPage/NewsFrame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,10 @@ public void ReloadNews()
this.banners = new TextureWrap[bannerList.Count];
var client = new HttpClient();
for (var i = 0; i < bannerList.Count; i++)
{
var textureBytes = await client.GetByteArrayAsync(this.bannerList[i].LsbBanner).ConfigureAwait(false);
var textureBytes = await Program.HttpClient.GetByteArrayAsync(this.bannerList[i].LsbBanner).ConfigureAwait(false);
this.banners[i] = TextureWrap.Load(textureBytes);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public class SettingsPage : Page
new SettingsTabWine(),
new SettingsTabDxvk(),
new SettingsTabDalamud(),
new SettingsTabAutoStart(),
new SettingsTabAbout(),
new SettingsTabDebug(),
new SettingsTabTroubleshooting(),
Expand Down

This file was deleted.

9 changes: 9 additions & 0 deletions src/XIVLauncher.Core/CoreEnvironmentSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public static class CoreEnvironmentSettings
public static bool ClearAll => CheckEnvBool("XL_CLEAR_ALL");
public static bool? UseSteam => CheckEnvBoolOrNull("XL_USE_STEAM"); // Fix for Steam Deck users who lock themselves out
public static bool IsSteamCompatTool => CheckEnvBool("XL_SCT");
public static uint AltAppID => GetAltAppId(System.Environment.GetEnvironmentVariable("XL_APPID"));

private static bool CheckEnvBool(string key)
{
Expand All @@ -42,6 +43,14 @@ public static string GetCleanEnvironmentVariable(string envvar, string badstring
return string.Join(separator, Array.FindAll<string>(dirty.Split(separator, StringSplitOptions.RemoveEmptyEntries), s => !s.Contains(badstring)));
}

public static uint GetAltAppId(string? appid)
{
uint.TryParse(appid, out var result);

// Will return 0 if appid is invalid (or zero).
return result;
}

public static string GetCType()
{
if (System.OperatingSystem.IsWindows())
Expand Down
7 changes: 4 additions & 3 deletions src/XIVLauncher.Core/FontManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ namespace XIVLauncher.Core;
public class FontManager
{
private const float FONT_GAMMA = 1.4f;
private const string TEXT_FONT_NAME = "NotoSansCJKjp-Regular.otf";
private const string ICON_FONT_NAME = "FontAwesome5FreeSolid.otf";

public static ImFontPtr TextFont { get; private set; }

public static ImFontPtr IconFont { get; private set; }

public unsafe void SetupFonts(float pxSize)
Expand All @@ -21,8 +22,8 @@ public unsafe void SetupFonts(float pxSize)
ImFontConfigPtr fontConfig = ImGuiNative.ImFontConfig_ImFontConfig();
fontConfig.PixelSnapH = true;

var fontDataText = AppUtil.GetEmbeddedResourceBytes("NotoSansCJKjp-Regular.otf");
var fontDataIcons = AppUtil.GetEmbeddedResourceBytes("FontAwesome5FreeSolid.otf");
var fontDataText = AppUtil.GetEmbeddedResourceBytes(TEXT_FONT_NAME);
var fontDataIcons = AppUtil.GetEmbeddedResourceBytes(ICON_FONT_NAME);

var fontDataTextPtr = Marshal.AllocHGlobal(fontDataText.Length);
Marshal.Copy(fontDataText, 0, fontDataTextPtr, fontDataText.Length);
Expand Down
1 change: 0 additions & 1 deletion src/XIVLauncher.Core/ImGuiBindings.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.Diagnostics.CodeAnalysis;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
Expand Down
1 change: 0 additions & 1 deletion src/XIVLauncher.Core/ImGuiHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ namespace XIVLauncher.Core;
public static class ImGuiHelpers
{
public static Vector2 ViewportSize => ImGui.GetIO().DisplaySize;

public static float GlobalScale => ImGui.GetIO().FontGlobalScale;

public static void TextWrapped(string text)
Expand Down
8 changes: 3 additions & 5 deletions src/XIVLauncher.Core/LauncherApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class LauncherApp : Component
private string modalText = string.Empty;
private string modalTitle = string.Empty;
private string modalButtonText = string.Empty;
private Action modalButtonPressAction;
private Action modalButtonPressAction = null!;
private readonly ManualResetEvent modalWaitHandle = new(false);

#endregion
Expand All @@ -53,11 +53,9 @@ public LauncherState State
set
{
// If we are coming from the settings, we should reload the news, as the client language might have changed
switch (this.state)
if (this.state == LauncherState.Settings)
{
case LauncherState.Settings:
this.mainPage.ReloadNews();
break;
this.mainPage.ReloadNews();
}

this.state = value;
Expand Down
8 changes: 2 additions & 6 deletions src/XIVLauncher.Core/LauncherClientConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,11 @@ public readonly struct LauncherClientConfig
public string? cutOffBootver { get; init; }
public uint flags { get; init; }

public static async Task<LauncherClientConfig> Fetch()
public static async Task<LauncherClientConfig> GetAsync()
{
try
{
using var client = new HttpClient()
{
Timeout = TimeSpan.FromSeconds(5),
};
return await client.GetFromJsonAsync<LauncherClientConfig>(LAUNCHER_CONFIG_URL).ConfigureAwait(false);
return await Program.HttpClient.GetFromJsonAsync<LauncherClientConfig>(LAUNCHER_CONFIG_URL).ConfigureAwait(false);
}
catch (Exception ex)
{
Expand Down
19 changes: 16 additions & 3 deletions src/XIVLauncher.Core/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

namespace XIVLauncher.Core;

class Program
sealed class Program
{
private static Sdl2Window window = null!;
private static CommandList cl = null!;
Expand All @@ -47,6 +47,10 @@ class Program
public static DalamudOverlayInfoProxy DalamudLoadInfo { get; private set; } = null!;
public static CompatibilityTools CompatibilityTools { get; private set; } = null!;
public static ISecretProvider Secrets { get; private set; } = null!;
public static HttpClient HttpClient { get; private set; } = new()
{
Timeout = TimeSpan.FromSeconds(5)
};

private static readonly Vector3 ClearColor = new(0.1f, 0.1f, 0.1f);

Expand Down Expand Up @@ -210,7 +214,15 @@ private static void Main(string[] args)

uint appId, altId;
string appName, altName;
if (Config.IsFt == true)
// AppId of 0 is invalid (though still a valid uint)
if (CoreEnvironmentSettings.AltAppID > 0)
{
appId = CoreEnvironmentSettings.AltAppID;
altId = STEAM_APP_ID_FT;
appName = $"Override AppId={appId.ToString()}";
altName = "FFXIV Free Trial";
}
else if (Config.IsFt == true)
{
appId = STEAM_APP_ID_FT;
altId = STEAM_APP_ID;
Expand Down Expand Up @@ -306,7 +318,7 @@ private static void Main(string[] args)

needUpdate = CoreEnvironmentSettings.IsUpgrade ? true : needUpdate;

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

Invalidate(20);
Expand Down Expand Up @@ -357,6 +369,7 @@ private static void Main(string[] args)
gd.SwapBuffers(gd.MainSwapchain);
}

HttpClient.Dispose();
// Clean up Veldrid resources
gd.WaitForIdle();
bindings.Dispose();
Expand Down
Binary file removed src/XIVLauncher.Core/Resources/bg1.jpg
Binary file not shown.
10 changes: 5 additions & 5 deletions src/XIVLauncher.Core/Support/PackGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ public static string SavePack(Storage storage)
troubleEntry.Close();

var xlLogFile = new FileInfo(Path.Combine(storage.GetFolder("logs").FullName, "launcher.log"));
var patcherLogFile = new FileInfo(Path.Combine(storage.Root.FullName, "patcher.log"));
var dalamudLogFile = new FileInfo(Path.Combine(storage.Root.FullName, "dalamud.log"));
var dalamudInjectorLogFile = new FileInfo(Path.Combine(storage.Root.FullName, "dalamud.injector.log"));
var dalamudBootLogFile = new FileInfo(Path.Combine(storage.Root.FullName, "dalamud.boot.log"));
var ariaLogFile = new FileInfo(Path.Combine(storage.Root.FullName, "aria.log"));
var patcherLogFile = new FileInfo(Path.Combine(storage.GetFolder("logs").FullName, "patcher.log"));
var dalamudLogFile = new FileInfo(Path.Combine(storage.GetFolder("logs").FullName, "dalamud.log"));
var dalamudInjectorLogFile = new FileInfo(Path.Combine(storage.GetFolder("logs").FullName, "dalamud.injector.log"));
var dalamudBootLogFile = new FileInfo(Path.Combine(storage.GetFolder("logs").FullName, "dalamud.boot.log"));
var ariaLogFile = new FileInfo(Path.Combine(storage.GetFolder("logs").FullName, "aria.log"));
var wineLogFile = new FileInfo(Path.Combine(storage.GetFolder("logs").FullName, "wine.log"));

AddIfExist(xlLogFile, archive);
Expand Down
5 changes: 1 addition & 4 deletions src/XIVLauncher.Core/UpdateCheck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ public static async Task<VersionCheckResult> CheckForUpdate()
{
try
{
using var client = new HttpClient();
client.Timeout = TimeSpan.FromSeconds(5);

var response = await client.GetStringAsync(UPDATE_URL).ConfigureAwait(false);
var response = await Program.HttpClient.GetStringAsync(UPDATE_URL).ConfigureAwait(false);
var remoteVersion = Version.Parse(response);

var localVersion = Version.Parse(AppUtil.GetAssemblyVersion());
Expand Down
5 changes: 2 additions & 3 deletions src/XIVLauncher.Core/XIVLauncher.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,13 @@
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="Resources/FontAwesome5FreeSolid.otf"
<EmbeddedResource Include="Resources/fonts/FontAwesome5FreeSolid.otf"
LogicalName="FontAwesome5FreeSolid.otf" />
<EmbeddedResource Include="Resources/NotoSansCJKjp-Regular.otf"
<EmbeddedResource Include="Resources/fonts/NotoSansCJKjp-Regular.otf"
LogicalName="NotoSansCJKjp-Regular.otf" />

<EmbeddedResource Include="Resources/logo.png" LogicalName="logo.png" />

<EmbeddedResource Include="Resources/bg1.jpg" LogicalName="bg1.jpg" />
<EmbeddedResource Include="Resources/bg_logo.png" LogicalName="bg_logo.png" />

<EmbeddedResource Include="Resources/steamdeck_fts.png" LogicalName="steamdeck_fts.png" />
Expand Down

0 comments on commit 679e1b8

Please sign in to comment.