mirror of
https://git.ryujinx.app/projects/Kenji-NX.git
synced 2026-09-26 21:50:05 +02:00
misc: chore: Fix possible System.NullReferenceExceptions
This commit is contained in:
@@ -46,7 +46,6 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
|
||||
private PlayerIndex _playerId;
|
||||
private PlayerIndex _playerIdChoose;
|
||||
private int _controller;
|
||||
private int _controllerNumber;
|
||||
private string _controllerImage;
|
||||
private int _device;
|
||||
private object _configViewModel;
|
||||
@@ -247,8 +246,8 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
|
||||
if (Program.PreviewerDetached)
|
||||
{
|
||||
_mainWindow =
|
||||
(MainWindow)((IClassicDesktopStyleApplicationLifetime)Application.Current
|
||||
.ApplicationLifetime).MainWindow;
|
||||
(MainWindow)((IClassicDesktopStyleApplicationLifetime)Application.Current?
|
||||
.ApplicationLifetime)?.MainWindow;
|
||||
|
||||
AvaloniaKeyboardDriver = new AvaloniaKeyboardDriver(owner);
|
||||
|
||||
@@ -519,7 +518,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
|
||||
{
|
||||
ProfilesList.Clear();
|
||||
|
||||
string basePath = GetProfileBasePath();
|
||||
string basePath = GetProfileBasePath() ?? string.Empty;
|
||||
|
||||
if (!Directory.Exists(basePath))
|
||||
{
|
||||
@@ -773,11 +772,11 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
|
||||
|
||||
if (IsKeyboard)
|
||||
{
|
||||
config = (ConfigViewModel as KeyboardInputViewModel).Config.GetConfig();
|
||||
config = (ConfigViewModel as KeyboardInputViewModel)?.Config.GetConfig();
|
||||
}
|
||||
else if (IsController)
|
||||
{
|
||||
config = (ConfigViewModel as ControllerInputViewModel).Config.GetConfig();
|
||||
config = (ConfigViewModel as ControllerInputViewModel)?.Config.GetConfig();
|
||||
}
|
||||
|
||||
config.ControllerType = Controllers[_controller].Type;
|
||||
@@ -842,18 +841,18 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
|
||||
|
||||
if (device.Type == DeviceType.Keyboard)
|
||||
{
|
||||
var inputConfig = (ConfigViewModel as KeyboardInputViewModel).Config;
|
||||
var inputConfig = ((KeyboardInputViewModel)ConfigViewModel).Config;
|
||||
inputConfig.Id = device.Id;
|
||||
}
|
||||
else
|
||||
{
|
||||
var inputConfig = (ConfigViewModel as ControllerInputViewModel).Config;
|
||||
var inputConfig = ((ControllerInputViewModel)ConfigViewModel).Config;
|
||||
inputConfig.Id = device.Id.Split(" ")[0];
|
||||
}
|
||||
|
||||
var config = !IsController
|
||||
? (ConfigViewModel as KeyboardInputViewModel).Config.GetConfig()
|
||||
: (ConfigViewModel as ControllerInputViewModel).Config.GetConfig();
|
||||
? ((KeyboardInputViewModel)ConfigViewModel).Config.GetConfig()
|
||||
: ((ControllerInputViewModel)ConfigViewModel).Config.GetConfig();
|
||||
config.ControllerType = Controllers[_controller].Type;
|
||||
config.PlayerIndex = _playerId;
|
||||
|
||||
|
||||
@@ -2251,7 +2251,7 @@ namespace Ryujinx.Ava.UI.ViewModels
|
||||
switch (operationOutcome)
|
||||
{
|
||||
case XCIFileTrimmer.OperationOutcome.Successful:
|
||||
if (Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
||||
if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
||||
{
|
||||
if (desktop.MainWindow is MainWindow mainWindow)
|
||||
mainWindow.LoadApplications();
|
||||
|
||||
@@ -93,9 +93,9 @@ namespace Ryujinx.Ava.UI.ViewModels
|
||||
|
||||
_modJsonPath = Path.Combine(AppDataManager.GamesDirPath, applicationId.ToString("x16"), "mods.json");
|
||||
|
||||
if (Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
||||
if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
||||
{
|
||||
_storageProvider = desktop.MainWindow.StorageProvider;
|
||||
_storageProvider = desktop.MainWindow?.StorageProvider;
|
||||
}
|
||||
|
||||
LoadMods(applicationId, _installedDlcIds);
|
||||
@@ -117,8 +117,8 @@ namespace Ryujinx.Ava.UI.ViewModels
|
||||
|
||||
foreach (var mod in modCache.RomfsDirs)
|
||||
{
|
||||
var modModel = new ModModel(mod.Path.Parent.FullName, mod.Name, mod.Enabled, inSd);
|
||||
if (Mods.All(x => x.Path != mod.Path.Parent.FullName))
|
||||
var modModel = new ModModel(mod.Path.Parent?.FullName, mod.Name, mod.Enabled, inSd);
|
||||
if (Mods.All(x => x.Path != mod.Path.Parent?.FullName))
|
||||
{
|
||||
Mods.Add(modModel);
|
||||
}
|
||||
@@ -131,8 +131,8 @@ namespace Ryujinx.Ava.UI.ViewModels
|
||||
|
||||
foreach (var mod in modCache.ExefsDirs)
|
||||
{
|
||||
var modModel = new ModModel(mod.Path.Parent.FullName, mod.Name, mod.Enabled, inSd);
|
||||
if (Mods.All(x => x.Path != mod.Path.Parent.FullName))
|
||||
var modModel = new ModModel(mod.Path.Parent?.FullName, mod.Name, mod.Enabled, inSd);
|
||||
if (Mods.All(x => x.Path != mod.Path.Parent?.FullName))
|
||||
{
|
||||
Mods.Add(modModel);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user