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

Fix warnings #126

Merged
merged 3 commits into from
Mar 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
12 changes: 5 additions & 7 deletions src/XIVLauncher.Core/Accounts/AccountManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace XIVLauncher.Core.Accounts;

public class AccountManager
{
public ObservableCollection<XivAccount> Accounts;
public ObservableCollection<XivAccount> Accounts = new();

public XivAccount? CurrentAccount
{
Expand All @@ -22,7 +22,7 @@ public AccountManager(FileInfo configFile)
Accounts.CollectionChanged += Accounts_CollectionChanged;
}

private void Accounts_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
private void Accounts_CollectionChanged(object? sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
Save();
}
Expand All @@ -31,13 +31,13 @@ public void UpdatePassword(XivAccount account, string password)
{
Log.Information("UpdatePassword() called");
var existingAccount = Accounts.FirstOrDefault(a => a.Id == account.Id);
existingAccount.Password = password;
if (existingAccount is not null) existingAccount.Password = password;
}

public void UpdateLastSuccessfulOtp(XivAccount account, string lastOtp)
{
var existingAccount = Accounts.FirstOrDefault(a => a.Id == account.Id);
existingAccount.LastSuccessfulOtp = lastOtp;
if (existingAccount is not null) existingAccount.LastSuccessfulOtp = lastOtp;
Save();
}

Expand Down Expand Up @@ -78,8 +78,6 @@ public void Load()
{
if (!this.configFile.Exists)
{
Accounts = new ObservableCollection<XivAccount>();

Save();
return;
}
Expand All @@ -91,4 +89,4 @@ public void Load()
}

#endregion
}
}
6 changes: 3 additions & 3 deletions src/XIVLauncher.Core/Accounts/AccountSwitcherEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ public void UpdateProfileImage(DirectoryInfo storage)
}
else
{
using (var client = new WebClient())
using (var client = new HttpClient())
{
imageBytes = client.DownloadData(uri);
imageBytes = client.GetByteArrayAsync(uri).Result;
}

File.WriteAllBytes(cacheFile, imageBytes);
Expand All @@ -54,4 +54,4 @@ public void UpdateProfileImage(DirectoryInfo storage)
ProfileImage = bitmapImage;
*/
}
}
}
19 changes: 8 additions & 11 deletions src/XIVLauncher.Core/Accounts/XivAccount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Serilog;
using System.Net;
using Newtonsoft.Json.Linq;
using SharpGen.Runtime;

namespace XIVLauncher.Core.Accounts;

Expand Down Expand Up @@ -38,12 +39,11 @@ public string Password
public bool UseSteamServiceAccount { get; set; }
public bool UseOtp { get; set; }

public string ChosenCharacterName;
public string ChosenCharacterWorld;
public string ChosenCharacterName = string.Empty;
public string ChosenCharacterWorld = string.Empty;
public string ThumbnailUrl = string.Empty;

public string ThumbnailUrl;

public string LastSuccessfulOtp;
public string LastSuccessfulOtp = string.Empty;

public XivAccount(string userName)
{
Expand Down Expand Up @@ -86,17 +86,14 @@ public XivAccount(string userName)

public static async Task<JObject> GetCharacterSearch(string name, string world)
{
return await Get("character/search" + $"?name={name}&server={world}");
return await Get("character/search" + $"?name={name}&server={world}").ConfigureAwait(false);
}

public static async Task<dynamic> Get(string endpoint)
{
using (var client = new WebClient())
{
var result = client.DownloadString(URL + endpoint);

using (var client = new HttpClient()) {
var result = await client.GetStringAsync(URL + endpoint).ConfigureAwait(false);
var parsedObject = JObject.Parse(result);

return parsedObject;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/XIVLauncher.Core/Components/Common/Checkbox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public bool Value
set => inputBacking = value;
}

public event Action<bool> OnChange;
public event Action<bool>? OnChange;

public Checkbox(string label, bool value = false, bool isEnabled = true)
{
Expand Down Expand Up @@ -60,4 +60,4 @@ public override void Draw()
ImGui.PopStyleVar(2);
ImGui.PopStyleColor(5);
}
}
}
66 changes: 28 additions & 38 deletions src/XIVLauncher.Core/Components/MainPage/MainPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,14 +218,14 @@ public async Task<bool> Login(string username, string password, bool isOtp, bool
if (gateStatus == null)
{
App.ShowMessageBlocking("Login servers could not be reached or maintenance is in progress. This might be a problem with your connection.");
return null;
return null!;
}
#endif

try
{
var enableUidCache = App.Settings.IsUidCacheEnabled ?? false;
var gamePath = App.Settings.GamePath;
var gamePath = App.Settings.GamePath!;

if (action == LoginAction.Repair)
return await App.Launcher.Login(username, password, otp, isSteam, false, gamePath, true, App.Settings.IsFt.GetValueOrDefault(false)).ConfigureAwait(false);
Expand All @@ -243,16 +243,12 @@ private async Task<bool> TryProcessLoginResult(Launcher.LoginResult loginResult,
{
if (loginResult.State == Launcher.LoginState.NoService)
{
throw new Exception("No service account or subscription");

return false;
throw new OauthLoginException("No service account or subscription");
}

if (loginResult.State == Launcher.LoginState.NoTerms)
{
throw new Exception("Need to accept terms of use");

return false;
throw new OauthLoginException("Need to accept terms of use");
}

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

throw new Exception("Boot conflict, need reinstall");

return false;
throw new OauthLoginException("Boot conflict, need reinstall");
}

if (action == LoginAction.Repair)
Expand All @@ -300,12 +294,10 @@ 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 Exception("Repair login state not NeedsPatchGame");

return false;
throw new OauthLoginException("Repair login state not NeedsPatchGame");
}
}
catch (Exception ex)
catch (Exception)
{
/*
* We should never reach here.
Expand All @@ -314,8 +306,6 @@ private async Task<bool> TryProcessLoginResult(Launcher.LoginResult loginResult,
*/
//CustomMessageBox.Builder.NewFrom(ex, "TryProcessLoginResult/Repair").WithParentWindow(_window).Show();
throw;

return false;
}
}

Expand Down Expand Up @@ -374,11 +364,11 @@ private async Task<bool> TryProcessLoginResult(Launcher.LoginResult loginResult,
using var process = await StartGameAndAddon(loginResult, isSteam, action == LoginAction.GameNoDalamud, action == LoginAction.GameNoThirdparty).ConfigureAwait(false);

if (process is null)
throw new Exception("Could not obtain Process Handle");
throw new InvalidOperationException("Could not obtain Process Handle");

if (process.ExitCode != 0 && (App.Settings.TreatNonZeroExitCodeAsFailure ?? false))
{
throw new Exception("Game exited with non-zero exit code");
throw new InvalidOperationException("Game exited with non-zero exit code");

/*
switch (new CustomMessageBox.Builder()
Expand Down Expand Up @@ -683,21 +673,21 @@ public async Task<Process> StartGameAndAddon(Launcher.LoginResult loginResult, b
IGameRunner runner;

// Hack: Force C.utf8 to fix incorrect unicode paths
if (App.Settings.FixLocale.Value && !string.IsNullOrEmpty(Program.CType))
if (App.Settings.FixLocale == true && !string.IsNullOrEmpty(Program.CType))
{
System.Environment.SetEnvironmentVariable("LC_ALL", Program.CType);
System.Environment.SetEnvironmentVariable("LC_CTYPE", Program.CType);
}

// Hack: Strip out gameoverlayrenderer.so entries from LD_PRELOAD
if (App.Settings.FixLDP.Value)
if (App.Settings.FixLDP == true)
{
var ldpreload = CoreEnvironmentSettings.GetCleanEnvironmentVariable("LD_PRELOAD", "gameoverlayrenderer.so");
System.Environment.SetEnvironmentVariable("LD_PRELOAD", ldpreload);
}

// Hack: XMODIFIERS=@im=null
if (App.Settings.FixIM.Value)
if (App.Settings.FixIM == true)
{
System.Environment.SetEnvironmentVariable("XMODIFIERS", "@im=null");
}
Expand Down Expand Up @@ -745,13 +735,13 @@ public async Task<Process> StartGameAndAddon(Launcher.LoginResult loginResult, b
if (App.Settings.WineStartupType == WineStartupType.Custom)
{
if (App.Settings.WineBinaryPath == null)
throw new Exception("Custom wine binary path wasn't set.");
throw new InvalidOperationException("Custom wine binary path wasn't set.");
else if (!Directory.Exists(App.Settings.WineBinaryPath))
throw new Exception("Custom wine binary path is invalid: no such directory.\n" +
"Check path carefully for typos: " + App.Settings.WineBinaryPath);
throw new InvalidOperationException("Custom wine binary path is invalid: no such directory.\n" +
"Check path carefully for typos: " + App.Settings.WineBinaryPath);
else if (!File.Exists(Path.Combine(App.Settings.WineBinaryPath, "wine64")))
throw new Exception("Custom wine binary path is invalid: no wine64 found at that location.\n" +
"Check path carefully for typos: " + App.Settings.WineBinaryPath);
throw new InvalidOperationException("Custom wine binary path is invalid: no wine64 found at that location.\n" +
"Check path carefully for typos: " + App.Settings.WineBinaryPath);
}

var signal = new ManualResetEvent(false);
Expand Down Expand Up @@ -789,17 +779,17 @@ public async Task<Process> StartGameAndAddon(Launcher.LoginResult loginResult, b
App.StartLoading("Ensuring compatibility tool...", "This may take a little while. Please hold!");
signal.WaitOne();
signal.Dispose();

if (isFailed)
return null;
return null!;

App.StartLoading("Starting game...", "Have fun!");

runner = new UnixGameRunner(Program.CompatibilityTools, dalamudLauncher, dalamudOk);

// SE has its own way of encoding spaces when encrypting arguments, which interferes
// with quoting, but they are necessary when passing paths unencrypted
var userPath = Program.CompatibilityTools.UnixToWinePath(App.Settings.GameConfigPath.FullName);
var userPath = Program.CompatibilityTools.UnixToWinePath(App.Settings.GameConfigPath!.FullName);
if (App.Settings.IsEncryptArgs.GetValueOrDefault(true))
gameArgs += $" UserPath={userPath}";
else
Expand Down Expand Up @@ -837,7 +827,7 @@ public async Task<Process> StartGameAndAddon(Launcher.LoginResult loginResult, b
{
Log.Information("GameProcess was null...");
IsLoggingIn = false;
return null;
return null!;
}

var addonMgr = new AddonManager();
Expand All @@ -850,7 +840,7 @@ public async Task<Process> StartGameAndAddon(Launcher.LoginResult loginResult, b

addonMgr.RunAddons(launchedProcess.Id, addons);
}
catch (Exception ex)
catch (Exception)
{
/*
CustomMessageBox.Builder
Expand Down Expand Up @@ -879,7 +869,7 @@ public async Task<Process> StartGameAndAddon(Launcher.LoginResult loginResult, b

try
{
if (App.Steam.IsValid)
if (App.Steam?.IsValid == true)
{
App.Steam.Shutdown();
}
Expand All @@ -894,7 +884,7 @@ public async Task<Process> StartGameAndAddon(Launcher.LoginResult loginResult, b

private void PersistAccount(string username, string password, bool isOtp, bool isSteam)
{
if (App.Accounts.CurrentAccount != null && App.Accounts.CurrentAccount.UserName.Equals(username) &&
if (App.Accounts.CurrentAccount != null && App.Accounts.CurrentAccount.UserName.Equals(username, StringComparison.Ordinal) &&
App.Accounts.CurrentAccount.Password != password &&
App.Accounts.CurrentAccount.SavePassword)
App.Accounts.UpdatePassword(App.Accounts.CurrentAccount, password);
Expand Down Expand Up @@ -927,11 +917,11 @@ private async Task<bool> HandleBootCheck()

App.Settings.PatchPath ??= new DirectoryInfo(Path.Combine(Paths.RoamingPath, "patches"));

PatchListEntry[] bootPatches = null;
PatchListEntry[] bootPatches;

try
{
bootPatches = await App.Launcher.CheckBootVersion(App.Settings.GamePath).ConfigureAwait(false);
bootPatches = await App.Launcher.CheckBootVersion(App.Settings.GamePath!).ConfigureAwait(false);
}
catch (Exception ex)
{
Expand All @@ -947,7 +937,7 @@ private async Task<bool> HandleBootCheck()
if (bootPatches == null)
return true;

return await TryHandlePatchAsync(Repository.Boot, bootPatches, null).ConfigureAwait(false);
return await TryHandlePatchAsync(Repository.Boot, bootPatches, "").ConfigureAwait(false);
}
catch (Exception ex)
{
Expand Down Expand Up @@ -1247,4 +1237,4 @@ private void Reactivate()

Program.ShowWindow();
}
}
}
Loading
Loading