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

style: apply consistent formatting #199

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
30 changes: 15 additions & 15 deletions src/XIVLauncher.Core/Accounts/AccountManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,44 @@ namespace XIVLauncher.Core.Accounts;

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

public XivAccount? CurrentAccount
{
get { return Accounts.Count > 1 ? Accounts.FirstOrDefault(a => a.Id == Program.Config.CurrentAccountId) : Accounts.FirstOrDefault(); }
get { return this.Accounts.Count > 1 ? this.Accounts.FirstOrDefault(a => a.Id == Program.Config.CurrentAccountId) : this.Accounts.FirstOrDefault(); }
set => Program.Config.CurrentAccountId = value?.Id;
}

public AccountManager(FileInfo configFile)
{
this.configFile = configFile;
Load();
this.Load();

Accounts.CollectionChanged += Accounts_CollectionChanged;
this.Accounts.CollectionChanged += this.Accounts_CollectionChanged;
}

private void Accounts_CollectionChanged(object? sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
Save();
this.Save();
}

public void UpdatePassword(XivAccount account, string password)
{
Log.Information("UpdatePassword() called");
var existingAccount = Accounts.FirstOrDefault(a => a.Id == account.Id);
var existingAccount = this.Accounts.FirstOrDefault(a => a.Id == account.Id);
if (existingAccount is not null) existingAccount.Password = password;
}

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

public void AddAccount(XivAccount account)
{
var existingAccount = Accounts.FirstOrDefault(a => a.Id == account.Id);
var existingAccount = this.Accounts.FirstOrDefault(a => a.Id == account.Id);

Log.Verbose($"existingAccount: {existingAccount?.Id}");

Expand All @@ -59,12 +59,12 @@ public void AddAccount(XivAccount account)
if (existingAccount != null)
return;

Accounts.Add(account);
this.Accounts.Add(account);
}

public void RemoveAccount(XivAccount account)
{
Accounts.Remove(account);
this.Accounts.Remove(account);
}

#region SaveLoad
Expand All @@ -73,21 +73,21 @@ public void RemoveAccount(XivAccount account)

public void Save()
{
File.WriteAllText(this.configFile.FullName, JsonConvert.SerializeObject(Accounts, Formatting.Indented));
File.WriteAllText(this.configFile.FullName, JsonConvert.SerializeObject(this.Accounts, Formatting.Indented));
}

public void Load()
{
if (!this.configFile.Exists)
{
Save();
this.Save();
return;
}

Accounts = JsonConvert.DeserializeObject<ObservableCollection<XivAccount>>(File.ReadAllText(this.configFile.FullName));
this.Accounts = JsonConvert.DeserializeObject<ObservableCollection<XivAccount>>(File.ReadAllText(this.configFile.FullName));

// If the file is corrupted, this will be null anyway
Accounts ??= new ObservableCollection<XivAccount>();
this.Accounts ??= [];
}

#endregion
Expand Down
4 changes: 2 additions & 2 deletions src/XIVLauncher.Core/Accounts/AccountSwitcherEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ public AccountSwitcherEntry(XivAccount account)

public void UpdateProfileImage(DirectoryInfo storage)
{
if (string.IsNullOrEmpty(Account.ThumbnailUrl))
if (string.IsNullOrEmpty(this.Account.ThumbnailUrl))
return;

var cacheFolder = Path.Combine(storage.FullName, "profilePictures");
Directory.CreateDirectory(cacheFolder);

var uri = new Uri(Account.ThumbnailUrl);
var uri = new Uri(this.Account.ThumbnailUrl);
var cacheFile = Path.Combine(cacheFolder, uri.Segments.Last());

byte[] imageBytes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public FileSecretProvider(FileInfo configFile)
if (configFile.Exists)
this.savedPasswords = JsonSerializer.Deserialize<Dictionary<string, string>>(configFile.OpenText().ReadToEnd())!;

this.savedPasswords ??= new Dictionary<string, string>();
this.savedPasswords ??= [];
}

public string? GetPassword(string accountName)
Expand All @@ -36,14 +36,14 @@ public void SavePassword(string accountName, string password)
this.savedPasswords.Add(accountName, password);
}

Save();
this.Save();
}

public void DeletePassword(string accountName)
{
this.savedPasswords.Remove(accountName);

Save();
this.Save();
}

private void Save()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class KeychainSecretProvider : ISecretProvider

public KeychainSecretProvider()
{
this.IsAvailable = SetDummyAndCheck();
this.IsAvailable = this.SetDummyAndCheck();
}

public bool SetDummyAndCheck()
Expand Down
18 changes: 9 additions & 9 deletions src/XIVLauncher.Core/Accounts/XivAccount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ namespace XIVLauncher.Core.Accounts;
public class XivAccount
{
[JsonIgnore]
public string Id => $"{UserName}-{UseOtp}-{UseSteamServiceAccount}";
public string Id => $"{this.UserName}-{this.UseOtp}-{this.UseSteamServiceAccount}";

public override string ToString() => Id;
public override string ToString() => this.Id;

public string UserName { get; private set; }

Expand All @@ -19,17 +19,17 @@ public string Password
{
get
{
if (string.IsNullOrEmpty(UserName))
if (string.IsNullOrEmpty(this.UserName))
return string.Empty;

var credentials = Program.Secrets.GetPassword(UserName);
var credentials = Program.Secrets.GetPassword(this.UserName);
return credentials ?? string.Empty;
}
set
{
if (!string.IsNullOrEmpty(value))
{
Program.Secrets.SavePassword(UserName, value);
Program.Secrets.SavePassword(this.UserName, value);
}
}
}
Expand All @@ -46,25 +46,25 @@ public string Password

public XivAccount(string userName)
{
UserName = userName.ToLower();
this.UserName = userName.ToLower();
}

public string? FindCharacterThumb()
{
if (string.IsNullOrEmpty(ChosenCharacterName) || string.IsNullOrEmpty(ChosenCharacterWorld))
if (string.IsNullOrEmpty(this.ChosenCharacterName) || string.IsNullOrEmpty(this.ChosenCharacterWorld))
return null;

try
{
dynamic searchResponse = GetCharacterSearch(ChosenCharacterName, ChosenCharacterWorld)
dynamic searchResponse = GetCharacterSearch(this.ChosenCharacterName, this.ChosenCharacterWorld)
.GetAwaiter().GetResult();

if (searchResponse.Results.Count > 1) //If we get more than one match from XIVAPI
{
foreach (var accountInfo in searchResponse.Results)
{
//We have to check with it all lower in case they type their character name LiKe ThIsLoL. The server XIVAPI returns also contains the DC name, so let's just do a contains on the server to make it easy.
if (accountInfo.Name.Value.ToLower() == ChosenCharacterName.ToLower() && accountInfo.Server.Value.ToLower().Contains(ChosenCharacterWorld.ToLower()))
if (accountInfo.Name.Value.ToLower() == this.ChosenCharacterName.ToLower() && accountInfo.Server.Value.ToLower().Contains(this.ChosenCharacterWorld.ToLower()))
{
return accountInfo.Avatar.Value;
}
Expand Down
4 changes: 2 additions & 2 deletions src/XIVLauncher.Core/Components/Background.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ 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(0, ImGuiHelpers.ViewportSize.Y - this.bgTexture.Height));
ImGui.Image(this.bgTexture.ImGuiHandle, new Vector2(this.bgTexture.Width, this.bgTexture.Height));
base.Draw();
}
}
18 changes: 9 additions & 9 deletions src/XIVLauncher.Core/Components/Common/Button.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,22 @@ public class Button : Component

public Button(string label, bool isEnabled = true, Vector4? color = null, Vector4? hoverColor = null, Vector4? textColor = null)
{
Label = label;
IsEnabled = isEnabled;
Color = color ?? ImGuiColors.Blue;
HoverColor = hoverColor ?? ImGuiColors.BlueShade3;
TextColor = textColor ?? ImGuiColors.DalamudWhite;
this.Label = label;
this.IsEnabled = isEnabled;
this.Color = color ?? ImGuiColors.Blue;
this.HoverColor = hoverColor ?? ImGuiColors.BlueShade3;
this.TextColor = textColor ?? ImGuiColors.DalamudWhite;
}

public override void Draw()
{
ImGui.PushStyleVar(ImGuiStyleVar.FramePadding, new Vector2(16f, 16f));
ImGui.PushStyleVar(ImGuiStyleVar.FrameRounding, 0);
ImGui.PushStyleColor(ImGuiCol.Button, Color);
ImGui.PushStyleColor(ImGuiCol.ButtonHovered, HoverColor);
ImGui.PushStyleColor(ImGuiCol.Text, TextColor);
ImGui.PushStyleColor(ImGuiCol.Button, this.Color);
ImGui.PushStyleColor(ImGuiCol.ButtonHovered, this.HoverColor);
ImGui.PushStyleColor(ImGuiCol.Text, this.TextColor);

if (ImGui.Button(Label, new Vector2(Width ?? -1, 0)) || (ImGui.IsItemFocused() && ImGui.IsKeyPressed(ImGuiKey.Enter)))
if (ImGui.Button(this.Label, new Vector2(this.Width ?? -1, 0)) || (ImGui.IsItemFocused() && ImGui.IsKeyPressed(ImGuiKey.Enter)))
{
this.Click?.Invoke();
}
Expand Down
14 changes: 7 additions & 7 deletions src/XIVLauncher.Core/Components/Common/Checkbox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ public class Checkbox : Component

public bool Value
{
get => inputBacking;
set => inputBacking = value;
get => this.inputBacking;
set => this.inputBacking = value;
}

public event Action<bool>? OnChange;

public Checkbox(string label, bool value = false, bool isEnabled = true)
{
Label = label;
Value = value;
IsEnabled = isEnabled;
this.Label = label;
this.Value = value;
this.IsEnabled = isEnabled;
}

public override void Draw()
Expand All @@ -40,7 +40,7 @@ public override void Draw()
if (!this.IsEnabled)
ImGui.BeginDisabled();

if (ImGui.Checkbox($"###{Id}", ref inputBacking))
if (ImGui.Checkbox($"###{this.Id}", ref this.inputBacking))
{
this.OnChange?.Invoke(this.inputBacking);
}
Expand All @@ -50,7 +50,7 @@ public override void Draw()

ImGui.SameLine();

ImGui.Text(Label);
ImGui.Text(this.Label);

if (ImGui.IsItemClicked(ImGuiMouseButton.Left))
{
Expand Down
32 changes: 16 additions & 16 deletions src/XIVLauncher.Core/Components/Common/Input.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public class Input : Component

public string Value
{
get => inputBacking;
set => inputBacking = value;
get => this.inputBacking;
set => this.inputBacking = value;
}

public Input(
Expand All @@ -46,19 +46,19 @@ public Input(
bool isEnabled = true,
ImGuiInputTextFlags flags = ImGuiInputTextFlags.None)
{
Label = label;
Hint = hint;
MaxLength = maxLength;
Flags = flags;
IsEnabled = isEnabled;
Spacing = spacing ?? Vector2.Zero;
this.Label = label;
this.Hint = hint;
this.MaxLength = maxLength;
this.Flags = flags;
this.IsEnabled = isEnabled;
this.Spacing = spacing ?? Vector2.Zero;

SteamDeckPrompt = hint;
this.SteamDeckPrompt = hint;

if (Program.Steam != null)
{
Program.Steam.OnGamepadTextInputDismissed += this.SteamOnOnGamepadTextInputDismissed;
HasSteamDeckInput = Program.IsSteamDeckHardware;
this.HasSteamDeckInput = Program.IsSteamDeckHardware;
}
}

Expand All @@ -80,10 +80,10 @@ public override void Draw()
ImGui.PushStyleColor(ImGuiCol.TextDisabled, ImGuiColors.TextDisabled);
ImGui.PushStyleColor(ImGuiCol.Text, ImGuiColors.Text);

if (TakeKeyboardFocus && ImGui.IsWindowAppearing())
if (this.TakeKeyboardFocus && ImGui.IsWindowAppearing())
ImGui.SetKeyboardFocusHere();

ImGui.Text(Label);
ImGui.Text(this.Label);

if (!this.IsEnabled || this.isSteamDeckInputActive)
ImGui.BeginDisabled();
Expand All @@ -93,20 +93,20 @@ public override void Draw()

ImGui.PopStyleColor();

ImGui.InputTextWithHint($"###{Id}", Hint, ref inputBacking, MaxLength, Flags);
ImGui.InputTextWithHint($"###{this.Id}", this.Hint, ref this.inputBacking, this.MaxLength, this.Flags);

if (ImGui.IsItemFocused() && ImGui.IsKeyPressed(ImGuiKey.Enter))
{
Enter?.Invoke();
}

if (ImGui.IsItemActivated() && HasSteamDeckInput && Program.Steam != null && Program.Steam.IsValid)
if (ImGui.IsItemActivated() && this.HasSteamDeckInput && Program.Steam != null && Program.Steam.IsValid)
{
this.isSteamDeckInputActive = Program.Steam?.ShowGamepadTextInput(Flags.HasFlag(ImGuiInputTextFlags.Password), false, SteamDeckPrompt, (int)MaxLength, this.inputBacking) ?? false;
this.isSteamDeckInputActive = Program.Steam?.ShowGamepadTextInput(this.Flags.HasFlag(ImGuiInputTextFlags.Password), false, this.SteamDeckPrompt, (int)this.MaxLength, this.inputBacking) ?? false;
Log.Information("SteamDeck Input Active({Name}): {IsActive}", this.Label, this.isSteamDeckInputActive);
}

ImGui.Dummy(Spacing);
ImGui.Dummy(this.Spacing);

if (!this.IsEnabled || this.isSteamDeckInputActive)
ImGui.EndDisabled();
Expand Down
4 changes: 2 additions & 2 deletions src/XIVLauncher.Core/Components/Component.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ public abstract class Component

public Margins Margins { get; set; } = new();

public BlockingCollection<Component> Children { get; } = new();
public BlockingCollection<Component> Children { get; } = [];

protected Guid Id { get; } = Guid.NewGuid();

public virtual void Draw()
{
foreach (var child in Children)
foreach (var child in this.Children)
{
if (child.Enabled)
child.Draw();
Expand Down
Loading
Loading