0
0
mirror of https://github.com/sp-tarkov/launcher.git synced 2025-02-12 17:10:44 -05:00

Implement NotifyPropertyChangedBase, optimization (!66)

- NotifyPropertyChangedBase created and implemented in classes that inherit INotifyPropertyChangedBase
- Some optimization fixes in models (one of this - `Where(predicate).Count() == 0` to `All(invertedPredicate)`

Co-authored-by: Valery Varaksa <varaksav62@gmail.com>
Reviewed-on: SPT/Launcher#66
Co-authored-by: loyvsc <loyvsc@noreply.dev.sp-tarkov.com>
Co-committed-by: loyvsc <loyvsc@noreply.dev.sp-tarkov.com>
This commit is contained in:
loyvsc 2024-09-02 07:53:58 +00:00 committed by chomp
parent 5ae20122f7
commit 441fb128fe
16 changed files with 347 additions and 1426 deletions

View File

@ -13,6 +13,7 @@ using Newtonsoft.Json;
using System; using System;
using System.ComponentModel; using System.ComponentModel;
using System.IO; using System.IO;
using SPT.Launcher.Utilities;
using SPT.Launcher.Controllers; using SPT.Launcher.Controllers;
namespace SPT.Launcher.Helpers namespace SPT.Launcher.Helpers
@ -23,7 +24,7 @@ namespace SPT.Launcher.Helpers
public static Settings Instance { get; } = Json.Load<Settings>(DefaultSettingsFileLocation) ?? new Settings(); public static Settings Instance { get; } = Json.Load<Settings>(DefaultSettingsFileLocation) ?? new Settings();
} }
public class Settings : INotifyPropertyChanged public class Settings : NotifyPropertyChangedBase
{ {
public bool FirstRun { get; set; } = true; public bool FirstRun { get; set; } = true;
@ -72,121 +73,65 @@ namespace SPT.Launcher.Helpers
public string DefaultLocale { get; set; } = "English"; public string DefaultLocale { get; set; } = "English";
private bool _IsAddingServer; private bool _isAddingServer;
[JsonIgnore] [JsonIgnore]
public bool IsAddingServer public bool IsAddingServer
{ {
get => _IsAddingServer; get => _isAddingServer;
set set => SetProperty(ref _isAddingServer, value);
{
if (_IsAddingServer != value)
{
_IsAddingServer = value;
RaisePropertyChanged(nameof(IsAddingServer));
}
}
} }
private bool _AllowSettings; private bool _allowSettings;
[JsonIgnore] [JsonIgnore]
public bool AllowSettings public bool AllowSettings
{ {
get => _AllowSettings; get => _allowSettings;
set set => SetProperty(ref _allowSettings, value);
{
if (_AllowSettings != value)
{
_AllowSettings = value;
RaisePropertyChanged(nameof(AllowSettings));
}
}
} }
private bool _GameRunning; private bool _gameRunning;
[JsonIgnore] [JsonIgnore]
public bool GameRunning public bool GameRunning
{ {
get => _GameRunning; get => _gameRunning;
set set => SetProperty(ref _gameRunning, value);
{
if (_GameRunning != value)
{
_GameRunning = value;
RaisePropertyChanged(nameof(GameRunning));
}
}
} }
private LauncherAction _LauncherStartGameAction; private LauncherAction _launcherStartGameAction;
public LauncherAction LauncherStartGameAction public LauncherAction LauncherStartGameAction
{ {
get => _LauncherStartGameAction; get => _launcherStartGameAction;
set set => SetProperty(ref _launcherStartGameAction, value);
{
if (_LauncherStartGameAction != value)
{
_LauncherStartGameAction = value;
RaisePropertyChanged(nameof(LauncherStartGameAction));
}
}
} }
private bool _UseAutoLogin; private bool _useAutoLogin;
public bool UseAutoLogin public bool UseAutoLogin
{ {
get => _UseAutoLogin; get => _useAutoLogin;
set set => SetProperty(ref _useAutoLogin, value);
{
if (_UseAutoLogin != value)
{
_UseAutoLogin = value;
RaisePropertyChanged(nameof(UseAutoLogin));
}
}
} }
private bool _IsDevMode; private bool _isDevMode;
public bool IsDevMode public bool IsDevMode
{ {
get => _IsDevMode; get => _isDevMode;
set set => SetProperty(ref _isDevMode, value);
{
if (_IsDevMode != value)
{
_IsDevMode = value;
RaisePropertyChanged(nameof(IsDevMode));
}
}
} }
private string _GamePath; private string _gamePath;
public string GamePath public string GamePath
{ {
get => _GamePath; get => _gamePath;
set set => SetProperty(ref _gamePath, value);
{
if (_GamePath != value)
{
_GamePath = value;
RaisePropertyChanged(nameof(GamePath));
}
}
} }
private string[] _ExcludeFromCleanup; private string[] _excludeFromCleanup = [];
public string[] ExcludeFromCleanup public string[] ExcludeFromCleanup
{ {
get => _ExcludeFromCleanup ??= Array.Empty<string>(); get => _excludeFromCleanup;
set set => SetProperty(ref _excludeFromCleanup, value);
{
if (_ExcludeFromCleanup != value)
{
_ExcludeFromCleanup = value;
RaisePropertyChanged(nameof(ExcludeFromCleanup));
}
}
} }
public ServerSetting Server { get; set; } = new ServerSetting(); public ServerSetting Server { get; set; } = new ServerSetting();
@ -202,18 +147,15 @@ namespace SPT.Launcher.Helpers
GamePath = Environment.CurrentDirectory; GamePath = Environment.CurrentDirectory;
IsDevMode = false; IsDevMode = false;
Server = new ServerSetting { Name = "SPT", Url = "http://127.0.0.1:6969" }; Server = new ServerSetting
{
Name = "SPT",
Url = "http://127.0.0.1:6969"
};
SaveSettings(); SaveSettings();
} }
LogManager.Instance.Info($"Using launcher config at: {LauncherSettingsProvider.DefaultSettingsFileLocation}"); LogManager.Instance.Info($"Using launcher config at: {LauncherSettingsProvider.DefaultSettingsFileLocation}");
} }
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void RaisePropertyChanged(string property)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property));
}
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -6,45 +6,24 @@
*/ */
using System.ComponentModel; using SPT.Launcher.Utilities;
namespace SPT.Launcher.Models.Launcher namespace SPT.Launcher.Models.Launcher
{ {
public class ConnectServerModel : INotifyPropertyChanged public class ConnectServerModel : NotifyPropertyChangedBase
{ {
private string _InfoText; private string _infoText;
public string InfoText public string InfoText
{ {
get => _InfoText; get => _infoText;
set set => SetProperty(ref _infoText, value);
{
if (_InfoText != value)
{
_InfoText = value;
RaisePropertyChanged(nameof(InfoText));
}
}
} }
private bool _ConnectionFailed; private bool _connectionFailed;
public bool ConnectionFailed public bool ConnectionFailed
{ {
get => _ConnectionFailed; get => _connectionFailed;
set set => SetProperty(ref _connectionFailed, value);
{
if(_ConnectionFailed != value)
{
_ConnectionFailed = value;
RaisePropertyChanged(nameof(ConnectionFailed));
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void RaisePropertyChanged(string property)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property));
} }
} }
} }

View File

@ -9,53 +9,32 @@
using SPT.Launcher.Models.SPT; using SPT.Launcher.Models.SPT;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.ComponentModel; using System.ComponentModel;
using SPT.Launcher.Utilities;
namespace SPT.Launcher.Models.Launcher namespace SPT.Launcher.Models.Launcher
{ {
public class EditionCollection : INotifyPropertyChanged public class EditionCollection : NotifyPropertyChangedBase
{ {
private bool _HasSelection; private bool _hasSelection;
public bool HasSelection public bool HasSelection
{ {
get => _HasSelection; get => _hasSelection;
set set => SetProperty(ref _hasSelection, value);
{
if(_HasSelection != value)
{
_HasSelection = value;
RaisePropertyChanged(nameof(HasSelection));
}
}
} }
private int _SelectedEditionIndex; private int _selectedEditionIndex;
public int SelectedEditionIndex public int SelectedEditionIndex
{ {
get => _SelectedEditionIndex; get => _selectedEditionIndex;
set set => SetProperty(ref _selectedEditionIndex, value);
{
if (_SelectedEditionIndex != value)
{
_SelectedEditionIndex = value;
RaisePropertyChanged(nameof(SelectedEditionIndex));
}
}
} }
private SPTEdition _SelectedEdition; private SPTEdition _selectedEdition;
public SPTEdition SelectedEdition public SPTEdition SelectedEdition
{ {
get => _SelectedEdition; get => _selectedEdition;
set set => SetProperty(ref _selectedEdition, value, () => HasSelection = _selectedEdition != null);
{
if (_SelectedEdition != value)
{
_SelectedEdition = value;
HasSelection = _SelectedEdition != null;
RaisePropertyChanged(nameof(SelectedEdition));
}
}
} }
public ObservableCollection<SPTEdition> AvailableEditions { get; private set; } = new ObservableCollection<SPTEdition>(); public ObservableCollection<SPTEdition> AvailableEditions { get; private set; } = [];
public EditionCollection() public EditionCollection()
{ {
@ -66,12 +45,5 @@ namespace SPT.Launcher.Models.Launcher
AvailableEditions.Add(new SPTEdition(edition)); AvailableEditions.Add(new SPTEdition(edition));
} }
} }
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void RaisePropertyChanged(string property)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property));
}
} }
} }

View File

@ -11,38 +11,24 @@ using SPT.Launcher.Helpers;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.ComponentModel; using System.ComponentModel;
using SPT.Launcher.Utilities;
namespace SPT.Launcher.Models.Launcher namespace SPT.Launcher.Models.Launcher
{ {
public class LocaleCollection : INotifyPropertyChanged public class LocaleCollection : NotifyPropertyChangedBase
{ {
private string _SelectedLocale; private string _selectedLocale;
public string SelectedLocale public string SelectedLocale
{ {
get => _SelectedLocale; get => _selectedLocale;
set set => SetProperty(ref _selectedLocale, value, () => LocalizationProvider.LoadLocalByName(value));
{
if (_SelectedLocale != value)
{
_SelectedLocale = value;
RaisePropertyChanged(nameof(SelectedLocale));
LocalizationProvider.LoadLocalByName(value);
}
}
} }
public ObservableCollection<string> AvailableLocales { get; set; } = LocalizationProvider.GetAvailableLocales(); public ObservableCollection<string> AvailableLocales { get; set; } = LocalizationProvider.GetAvailableLocales();
public event PropertyChangedEventHandler PropertyChanged;
public LocaleCollection() public LocaleCollection()
{ {
SelectedLocale = LocalizationProvider.LocaleNameDictionary.GetValueOrDefault(LauncherSettingsProvider.Instance.DefaultLocale, "English"); SelectedLocale = LocalizationProvider.LocaleNameDictionary.GetValueOrDefault(LauncherSettingsProvider.Instance.DefaultLocale, "English");
} }
protected virtual void RaisePropertyChanged(string property)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property));
}
} }
} }

View File

@ -2,25 +2,19 @@
using SPT.Launcher.Models.Launcher; using SPT.Launcher.Models.Launcher;
using System.ComponentModel; using System.ComponentModel;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using SPT.Launcher.Utilities;
namespace SPT.Launcher.Models namespace SPT.Launcher.Models
{ {
public class LocalizedLauncherAction : INotifyPropertyChanged public class LocalizedLauncherAction : NotifyPropertyChangedBase
{ {
public LauncherAction Action { get; set; } public LauncherAction Action { get; set; }
private string _Name; private string _name;
public string Name public string Name
{ {
get => _Name; get => _name;
set set => SetProperty(ref _name, value);
{
if(_Name != value)
{
_Name = value;
RaisePropertyChanged(nameof(Name));
}
}
} }
public void UpdateLocaleName() public void UpdateLocaleName()
@ -49,12 +43,5 @@ namespace SPT.Launcher.Models
UpdateLocaleName(); UpdateLocaleName();
} }
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void RaisePropertyChanged(string property)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property));
}
} }
} }

View File

@ -6,44 +6,24 @@
*/ */
using System.ComponentModel; using SPT.Launcher.Utilities;
namespace SPT.Launcher.Models.Launcher namespace SPT.Launcher.Models.Launcher
{ {
public class LoginModel : INotifyPropertyChanged public class LoginModel : NotifyPropertyChangedBase
{ {
private string _Username = ""; private string _username = "";
public string Username public string Username
{ {
get => _Username; get => _username;
set set => SetProperty(ref _username, value);
{
if (_Username != value)
{
_Username = value;
RaisePropertyChanged(nameof(Username));
}
}
} }
private string _Password = ""; private string _password = "";
public string Password public string Password
{ {
get => _Password; get => _password;
set set => SetProperty(ref _password, value);
{
if (_Password != value)
{
_Password = value;
RaisePropertyChanged(nameof(Password));
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void RaisePropertyChanged(string property)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property));
} }
} }
} }

View File

@ -9,62 +9,35 @@
using System; using System;
using System.ComponentModel; using System.ComponentModel;
using System.Threading.Tasks; using System.Threading.Tasks;
using SPT.Launcher.Utilities;
namespace SPT.Launcher.Models.Launcher namespace SPT.Launcher.Models.Launcher
{ {
public class MenuBarItem : INotifyPropertyChanged public class MenuBarItem : NotifyPropertyChangedBase
{ {
private string _Name; private string _name;
public string Name public string Name
{ {
get => _Name; get => _name;
set set => SetProperty(ref _name, value);
{
if (_Name != value)
{
_Name = value;
RaisePropertyChanged(nameof(Name));
}
}
} }
private bool _IsSelected; private bool _isSelected;
public bool IsSelected public bool IsSelected
{ {
get => _IsSelected; get => _isSelected;
set set => SetProperty(ref _isSelected, value);
{
if (_IsSelected != value)
{
_IsSelected = value;
RaisePropertyChanged(nameof(IsSelected));
}
}
} }
private Action _ItemAction; private Action _itemAction;
public Action ItemAction public Action ItemAction
{ {
get => _ItemAction; get => _itemAction;
set set => SetProperty(ref _itemAction, value);
{
if (_ItemAction != value)
{
_ItemAction = value;
RaisePropertyChanged(nameof(ItemAction));
}
}
} }
public Func<Task<bool>> CanUseAction = async () => await Task.FromResult(true); public Func<Task<bool>> CanUseAction = async () => await Task.FromResult(true);
public Action OnFailedToUseAction = null; public Action OnFailedToUseAction = null;
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void RaisePropertyChanged(string property)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property));
}
} }
} }

View File

@ -2,55 +2,35 @@
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.ComponentModel; using System.ComponentModel;
using System.Linq; using System.Linq;
using SPT.Launcher.Utilities;
namespace SPT.Launcher.Models.Launcher namespace SPT.Launcher.Models.Launcher
{ {
public class ModInfoCollection : INotifyPropertyChanged public class ModInfoCollection : NotifyPropertyChangedBase
{ {
private int _serverModsCount; private int _serverModsCount;
public int ServerModsCount public int ServerModsCount
{ {
get => _serverModsCount; get => _serverModsCount;
set set => SetProperty(ref _serverModsCount, value);
{
if (_serverModsCount != value)
{
_serverModsCount = value;
RaisePropertyChanged(nameof(ServerModsCount));
}
}
} }
private int _profileModsCount; private int _profileModsCount;
public int ProfileModsCount public int ProfileModsCount
{ {
get => _profileModsCount; get => _profileModsCount;
set set => SetProperty(ref _profileModsCount, value);
{
if (_profileModsCount != value)
{
_profileModsCount = value;
RaisePropertyChanged(nameof(ProfileModsCount));
}
}
} }
private bool _hasMods; private bool _hasMods;
public bool HasMods public bool HasMods
{ {
get => _hasMods; get => _hasMods;
set set => SetProperty(ref _hasMods, value);
{
if (_hasMods != value)
{
_hasMods = value;
RaisePropertyChanged(nameof(HasMods));
}
}
} }
public ObservableCollection<SPTMod> ActiveMods { get; private set; } = new ObservableCollection<SPTMod>(); public ObservableCollection<SPTMod> ActiveMods { get; private set; } = [];
public ObservableCollection<SPTMod> InactiveMods { get; private set; } = new ObservableCollection<SPTMod>(); public ObservableCollection<SPTMod> InactiveMods { get; private set; } = [];
public ModInfoCollection() public ModInfoCollection()
{ {
@ -68,7 +48,7 @@ namespace SPT.Launcher.Models.Launcher
foreach (var inactiveMod in profileMods) foreach (var inactiveMod in profileMods)
{ {
var existingMod = ActiveMods.Where(x => x.Name == inactiveMod.Name && x.Version == inactiveMod.Version && x.Author == inactiveMod.Author).FirstOrDefault(); var existingMod = ActiveMods.FirstOrDefault(x => x.Name == inactiveMod.Name && x.Version == inactiveMod.Version && x.Author == inactiveMod.Author);
if (existingMod != null) if (existingMod != null)
{ {
@ -82,11 +62,5 @@ namespace SPT.Launcher.Models.Launcher
HasMods = ActiveMods.Count > 0 || InactiveMods.Count > 0; HasMods = ActiveMods.Count > 0 || InactiveMods.Count > 0;
} }
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void RaisePropertyChanged(string property)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property));
}
} }
} }

View File

@ -9,75 +9,48 @@
using System; using System;
using System.ComponentModel; using System.ComponentModel;
using SPT.Launcher.Utilities;
namespace SPT.Launcher.Models.Launcher.Notifications namespace SPT.Launcher.Models.Launcher.Notifications
{ {
public class NotificationItem : INotifyPropertyChanged public class NotificationItem : NotifyPropertyChangedBase
{ {
private string _Message; private string _message;
public string Message public string Message
{ {
get => _Message; get => _message;
set set => SetProperty(ref _message, value);
{
if (_Message != value)
{
_Message = value;
RaisePropertyChanged(nameof(Message));
}
}
} }
private string _ButtonText; private string _buttonText;
public string ButtonText public string ButtonText
{ {
get => _ButtonText; get => _buttonText;
set set => SetProperty(ref _buttonText, value);
{
if (_ButtonText != value)
{
_ButtonText = value;
RaisePropertyChanged(nameof(ButtonText));
}
}
} }
private bool _HasButton; private bool _hasButton;
public bool HasButton public bool HasButton
{ {
get => _HasButton; get => _hasButton;
set set => SetProperty(ref _hasButton, value);
{
if (_HasButton != value)
{
_HasButton = value;
RaisePropertyChanged(nameof(HasButton));
}
}
} }
public Action ItemAction = null; public Action ItemAction = null;
public NotificationItem(string Message) public NotificationItem(string message)
{ {
this.Message = Message; Message = message;
ButtonText = string.Empty; ButtonText = string.Empty;
HasButton = false; HasButton = false;
} }
public NotificationItem(string Message, string ButtonText, Action ItemAction) public NotificationItem(string message, string buttonText, Action itemAction)
{ {
this.Message = Message; Message = message;
this.ButtonText = ButtonText; ButtonText = buttonText;
HasButton = true; HasButton = true;
this.ItemAction = ItemAction; ItemAction = itemAction;
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void RaisePropertyChanged(string property)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property));
} }
} }
} }

View File

@ -13,35 +13,29 @@ using System.Collections.ObjectModel;
using System.ComponentModel; using System.ComponentModel;
using System.Linq; using System.Linq;
using System.Timers; using System.Timers;
using SPT.Launcher.Utilities;
namespace SPT.Launcher.Models.Launcher.Notifications namespace SPT.Launcher.Models.Launcher.Notifications
{ {
public class NotificationQueue : INotifyPropertyChanged, IDisposable public class NotificationQueue : NotifyPropertyChangedBase, IDisposable
{ {
public Timer queueTimer = new Timer(); public Timer queueTimer = new Timer();
private Timer animateChangeTimer = new Timer(230); private Timer animateChangeTimer = new Timer(230);
private Timer animateCloseTimer = new Timer(230); private Timer animateCloseTimer = new Timer(230);
public ObservableCollection<NotificationItem> queue { get; set; } = new ObservableCollection<NotificationItem>(); public ObservableCollection<NotificationItem> queue { get; set; } = [];
private bool _ShowBanner; private bool _showBanner;
public bool ShowBanner public bool ShowBanner
{ {
get => _ShowBanner; get => _showBanner;
set set => SetProperty(ref _showBanner, value);
{
if (_ShowBanner != value)
{
_ShowBanner = value;
RaisePropertyChanged(nameof(ShowBanner));
}
}
} }
public NotificationQueue(int ShowTimeInMiliseconds) public NotificationQueue(int showTimeInMilliseconds)
{ {
ShowBanner = false; ShowBanner = false;
queueTimer.Interval = ShowTimeInMiliseconds; queueTimer.Interval = showTimeInMilliseconds;
queueTimer.Elapsed += QueueTimer_Elapsed; queueTimer.Elapsed += QueueTimer_Elapsed;
animateChangeTimer.Elapsed += AnimateChange_Elapsed; animateChangeTimer.Elapsed += AnimateChange_Elapsed;
@ -71,43 +65,43 @@ namespace SPT.Launcher.Models.Launcher.Notifications
} }
} }
public void Enqueue(string Message, bool AutowNext = false, bool NoDefaultButton = false) public void Enqueue(string message, bool autoNext = false, bool noDefaultButton = false)
{ {
if (queue.Where(x => x.Message == Message).Count() == 0) if (queue.All(x => x.Message != message))
{ {
if (NoDefaultButton) if (noDefaultButton)
{ {
queue.Add(new NotificationItem(Message)); queue.Add(new NotificationItem(message));
} }
else else
{ {
queue.Add(new NotificationItem(Message, LocalizationProvider.Instance.ok, () => { })); queue.Add(new NotificationItem(message, LocalizationProvider.Instance.ok, () => { }));
} }
CheckAndShowNotifications(); CheckAndShowNotifications();
if (AutowNext && queue.Count == 2) if (autoNext && queue.Count == 2)
{ {
Next(true); Next(true);
} }
} }
} }
public void Enqueue(string Message, string ButtonText, Action ButtonAction, bool AllowNext = false) public void Enqueue(string message, string buttonText, Action buttonAction, bool allowNext = false)
{ {
if (queue.Where(x => x.Message == Message && x.ButtonText == ButtonText).Count() == 0) if (queue.All(x=>x.Message != message && x.ButtonText != buttonText))
{ {
queue.Add(new NotificationItem(Message, ButtonText, ButtonAction)); queue.Add(new NotificationItem(message, buttonText, buttonAction));
CheckAndShowNotifications(); CheckAndShowNotifications();
if (AllowNext && queue.Count == 2) if (allowNext && queue.Count == 2)
{ {
Next(true); Next(true);
} }
} }
} }
public void Next(bool ResetTimer = false) public void Next(bool resetTimer = false)
{ {
if (queue.Count - 1 <= 0) if (queue.Count - 1 <= 0)
{ {
@ -115,7 +109,7 @@ namespace SPT.Launcher.Models.Launcher.Notifications
return; return;
} }
if (ResetTimer) if (resetTimer)
{ {
queueTimer.Stop(); queueTimer.Stop();
queueTimer.Start(); queueTimer.Start();
@ -142,13 +136,6 @@ namespace SPT.Launcher.Models.Launcher.Notifications
ShowBanner = true; ShowBanner = true;
} }
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void RaisePropertyChanged(string property)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property));
}
public void Dispose() public void Dispose()
{ {
queueTimer.Dispose(); queueTimer.Dispose();

View File

@ -12,210 +12,127 @@ using SPT.Launcher.Models.SPT;
using System; using System;
using System.ComponentModel; using System.ComponentModel;
using System.IO; using System.IO;
using SPT.Launcher.Utilities;
namespace SPT.Launcher.Models.Launcher namespace SPT.Launcher.Models.Launcher
{ {
public class ProfileInfo : INotifyPropertyChanged public class ProfileInfo : NotifyPropertyChangedBase
{ {
private string _Username; private string _username;
public string Username public string Username
{ {
get => _Username; get => _username;
set set => SetProperty(ref _username, value);
{
if(_Username != value)
{
_Username = value;
RaisePropertyChanged(nameof(Username));
}
}
} }
private string _Nickname; private string _nickname;
public string Nickname public string Nickname
{ {
get => _Nickname; get => _nickname;
set set => SetProperty(ref _nickname, value);
{
if (_Nickname != value)
{
_Nickname = value;
RaisePropertyChanged(nameof(Nickname));
}
}
} }
private string _SideImage; private string _sideImage;
public string SideImage public string SideImage
{ {
get => _SideImage; get => _sideImage;
set set => SetProperty(ref _sideImage, value);
{
if (_SideImage != value)
{
_SideImage = value;
RaisePropertyChanged(nameof(SideImage));
}
}
} }
private string _Side; private string _side;
public string Side public string Side
{ {
get => _Side; get => _side;
set set => SetProperty(ref _side, value);
{
if (_Side != value)
{
_Side = value;
RaisePropertyChanged(nameof(Side));
}
}
} }
private string _Level; private string _level;
public string Level public string Level
{ {
get => _Level; get => _level;
set set => SetProperty(ref _level, value);
{
if (_Level != value)
{
_Level = value;
RaisePropertyChanged(nameof(Level));
}
}
} }
private int _XPLevelProgress; private int _XPLevelProgress;
public int XPLevelProgress public int XPLevelProgress
{ {
get => _XPLevelProgress; get => _XPLevelProgress;
set set => SetProperty(ref _XPLevelProgress, value);
{
if (_XPLevelProgress != value)
{
_XPLevelProgress = value;
RaisePropertyChanged(nameof(XPLevelProgress));
}
}
} }
private long _CurrentXP; private long _currentXP;
public long CurrentExp public long CurrentExp
{ {
get => _CurrentXP; get => _currentXP;
set set => SetProperty(ref _currentXP, value);
{
if (_CurrentXP != value)
{
_CurrentXP = value;
RaisePropertyChanged(nameof(CurrentExp));
}
}
} }
private long _RemainingExp; private long _remainingExp;
public long RemainingExp public long RemainingExp
{ {
get => _RemainingExp; get => _remainingExp;
set set => SetProperty(ref _remainingExp, value);
{
if (_RemainingExp != value)
{
_RemainingExp = value;
RaisePropertyChanged(nameof(RemainingExp));
}
}
} }
private long _NextLvlExp; private long _nextLvlExp;
public long NextLvlExp public long NextLvlExp
{ {
get => _NextLvlExp; get => _nextLvlExp;
set set => SetProperty(ref _nextLvlExp, value);
{
if (_NextLvlExp != value)
{
_NextLvlExp = value;
RaisePropertyChanged(nameof(NextLvlExp));
}
}
} }
private bool _HasData; private bool _hasData;
public bool HasData public bool HasData
{ {
get => _HasData; get => _hasData;
set set => SetProperty(ref _hasData, value);
{
if (_HasData != value)
{
_HasData = value;
RaisePropertyChanged(nameof(HasData));
}
}
} }
public string MismatchMessage => VersionMismatch ? LocalizationProvider.Instance.profile_version_mismath : null; public string MismatchMessage => VersionMismatch ? LocalizationProvider.Instance.profile_version_mismath : null;
private bool _VersionMismatch; private bool _versionMismatch;
public bool VersionMismatch public bool VersionMismatch
{ {
get => _VersionMismatch; get => _versionMismatch;
set set => SetProperty(ref _versionMismatch, value);
{
if(_VersionMismatch != value)
{
_VersionMismatch = value;
RaisePropertyChanged(nameof(VersionMismatch));
}
}
} }
private SPTData _SPT; private SPTData _spt;
public SPTData SPT public SPTData SPT
{ {
get => _SPT; get => _spt;
set set => SetProperty(ref _spt, value);
{
if(_SPT != value)
{
_SPT = value;
RaisePropertyChanged(nameof(SPT));
}
}
} }
public void UpdateDisplayedProfile(ProfileInfo PInfo) public void UpdateDisplayedProfile(ProfileInfo pInfo)
{ {
if (PInfo.Side == null || string.IsNullOrWhiteSpace(PInfo.Side) || PInfo.Side == "unknown") return; if (pInfo.Side == null || string.IsNullOrWhiteSpace(pInfo.Side) || pInfo.Side == "unknown") return;
HasData = true; HasData = true;
Nickname = PInfo.Nickname; Nickname = pInfo.Nickname;
Side = PInfo.Side; Side = pInfo.Side;
SideImage = PInfo.SideImage; SideImage = pInfo.SideImage;
Level = PInfo.Level; Level = pInfo.Level;
CurrentExp = PInfo.CurrentExp; CurrentExp = pInfo.CurrentExp;
NextLvlExp = PInfo.NextLvlExp; NextLvlExp = pInfo.NextLvlExp;
RemainingExp = PInfo.RemainingExp; RemainingExp = pInfo.RemainingExp;
XPLevelProgress = PInfo.XPLevelProgress; XPLevelProgress = pInfo.XPLevelProgress;
SPT = PInfo.SPT; SPT = pInfo.SPT;
} }
/// <summary> /// <summary>
/// Checks if the SPT versions are compatible (non-major changes) /// Checks if the SPT versions are compatible (non-major changes)
/// </summary> /// </summary>
/// <param name="CurrentVersion"></param> /// <param name="currentVersion"></param>
/// <param name="ExpectedVersion"></param> /// <param name="expectedVersion"></param>
/// <returns></returns> /// <returns></returns>
private bool CompareVersions(string CurrentVersion, string ExpectedVersion) private bool CompareVersions(string currentVersion, string expectedVersion)
{ {
if (ExpectedVersion == "") return false; if (expectedVersion == "") return false;
SPTVersion v1 = new SPTVersion(CurrentVersion); var v1 = new SPTVersion(currentVersion);
SPTVersion v2 = new SPTVersion(ExpectedVersion); var v2 = new SPTVersion(expectedVersion);
// check 'X'.x.x // check 'X'.x.x
if (v1.Major != v2.Major) return false; if (v1.Major != v2.Major) return false;
@ -242,14 +159,7 @@ namespace SPT.Launcher.Models.Launcher
SideImage = Path.Combine(ImageRequest.ImageCacheFolder, $"side_{Side.ToLower()}.png"); SideImage = Path.Combine(ImageRequest.ImageCacheFolder, $"side_{Side.ToLower()}.png");
if (Side != null && !string.IsNullOrWhiteSpace(Side) && Side != "unknown") HasData = Side != null && !string.IsNullOrWhiteSpace(Side) && Side != "unknown";
{
HasData = true;
}
else
{
HasData = false;
}
Level = serverProfileInfo.currlvl.ToString(); Level = serverProfileInfo.currlvl.ToString();
CurrentExp = serverProfileInfo.currexp; CurrentExp = serverProfileInfo.currexp;
@ -269,12 +179,5 @@ namespace SPT.Launcher.Models.Launcher
XPLevelProgress = (int)Math.Floor((((double)currentLvlTotal) - RemainingExp) / currentLvlTotal * 100); XPLevelProgress = (int)Math.Floor((((double)currentLvlTotal) - RemainingExp) / currentLvlTotal * 100);
} }
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void RaisePropertyChanged(string property)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property));
}
} }
} }

View File

@ -6,47 +6,27 @@
*/ */
using System.ComponentModel; using SPT.Launcher.Utilities;
using SPT.Launcher.Models.Launcher;
namespace SPT.Launcher.Models.Launcher namespace SPT.Launch.Models.Launcher
{ {
public class RegisterModel : INotifyPropertyChanged public class RegisterModel : NotifyPropertyChangedBase
{ {
private string _Username; private string _username;
public string Username public string Username
{ {
get => _Username; get => _username;
set set => SetProperty(ref _username, value);
{
if (_Username != value)
{
_Username = value;
RaisePropertyChanged(nameof(Username));
}
}
} }
private string _Password; private string _password;
public string Password public string Password
{ {
get => _Password; get => _password;
set set => SetProperty(ref _password, value);
{
if (_Password != value)
{
_Password = value;
RaisePropertyChanged(nameof(Password));
}
}
} }
public EditionCollection EditionsCollection { get; set; } = new EditionCollection(); public EditionCollection EditionsCollection { get; set; } = new EditionCollection();
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void RaisePropertyChanged(string property)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property));
}
} }
} }

View File

@ -7,47 +7,26 @@
*/ */
using System.ComponentModel; using SPT.Launcher.Utilities;
namespace SPT.Launcher.Models.Launcher namespace SPT.Launcher.Models.Launcher
{ {
public class ServerSetting : INotifyPropertyChanged public class ServerSetting : NotifyPropertyChangedBase
{ {
public LoginModel AutoLoginCreds { get; set; } = null; public LoginModel AutoLoginCreds { get; set; } = null;
private string _Name; private string _name;
public string Name public string Name
{ {
get => _Name; get => _name;
set set => SetProperty(ref _name, value);
{
if (_Name != value)
{
_Name = value;
RaisePropertyChanged(nameof(Name));
}
}
} }
private string _Url; private string _url;
public string Url public string Url
{ {
get => _Url; get => _url;
set set => SetProperty(ref _url, value);
{
if (_Url != value)
{
_Url = value;
RaisePropertyChanged(nameof(Url));
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void RaisePropertyChanged(string property)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property));
} }
} }
} }

View File

@ -1,42 +1,34 @@
using System.ComponentModel; using SPT.Launcher.Utilities;
namespace SPT.Launcher.Models.SPT namespace SPT.Launcher.Models.SPT
{ {
public class SPTVersion : INotifyPropertyChanged public class SPTVersion : NotifyPropertyChangedBase
{ {
public int Major; public int Major;
public int Minor; public int Minor;
public int Build; public int Build;
public bool HasTag => Tag != null; public bool HasTag => Tag != string.Empty;
private string _Tag = null; private string _tag = string.Empty;
public string Tag public string Tag
{ {
get => _Tag; get => _tag;
set set => SetProperty(ref _tag, value, () => RaisePropertyChanged(nameof(HasTag)));
{
if(_Tag != value)
{
_Tag = value;
RaisePropertyChanged(nameof(Tag));
RaisePropertyChanged(nameof(HasTag));
}
}
} }
public void ParseVersionInfo(string SPTVersion) public void ParseVersionInfo(string sptVersion)
{ {
if (SPTVersion.Contains('-')) if (sptVersion.Contains('-'))
{ {
string[] versionInfo = SPTVersion.Split('-'); string[] versionInfo = sptVersion.Split('-');
SPTVersion = versionInfo[0]; sptVersion = versionInfo[0];
Tag = versionInfo[1]; Tag = versionInfo[1];
} }
string[] splitVersion = SPTVersion.Split('.'); string[] splitVersion = sptVersion.Split('.');
if (splitVersion.Length >= 3) if (splitVersion.Length >= 3)
{ {
@ -48,16 +40,9 @@ namespace SPT.Launcher.Models.SPT
public SPTVersion() { } public SPTVersion() { }
public SPTVersion(string SPTVersion) public SPTVersion(string sptVersion)
{ {
ParseVersionInfo(SPTVersion); ParseVersionInfo(sptVersion);
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void RaisePropertyChanged(string property)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property));
} }
public override string ToString() public override string ToString()

View File

@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace SPT.Launcher.Utilities;
public abstract class NotifyPropertyChangedBase : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected void RaisePropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
protected void SetProperty<T>(ref T field, T value, Action afterSetAction = null, [CallerMemberName] string propertyName = null)
{
if (!EqualityComparer<T>.Default.Equals(field, value))
{
field = value;
RaisePropertyChanged(propertyName);
afterSetAction?.Invoke();
}
}
protected void SetNotNullableProperty<T>(ref T field, T value, Action afterSetAction = null, [CallerMemberName] string propertyName = null)
{
if (value is not null)
{
SetProperty(ref field, value, afterSetAction, propertyName );
}
}
}