Check if game directories have been updated before refreshing GUI (#3607)

* Check if game directories have been updated before refreshing list on save.

* Cleanup spacing

* Add Avalonia and reset value after saving

* Fix Avalonia

* Fix multiple directories not being added in GTK
This commit is contained in:
MutantAura 2022-08-21 14:07:28 +01:00 committed by GitHub
parent 88a0e720cb
commit 54421760c3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 15 deletions

View file

@ -49,6 +49,7 @@ namespace Ryujinx.Ava.Ui.ViewModels
private float _previousVolumeLevel; private float _previousVolumeLevel;
private float _volume; private float _volume;
private bool _isVulkanAvailable = true; private bool _isVulkanAvailable = true;
private bool _directoryChanged = false;
private List<string> _gpuIds = new List<string>(); private List<string> _gpuIds = new List<string>();
private KeyboardHotkeys _keyboardHotkeys; private KeyboardHotkeys _keyboardHotkeys;
private int _graphicsBackendIndex; private int _graphicsBackendIndex;
@ -112,6 +113,17 @@ namespace Ryujinx.Ava.Ui.ViewModels
} }
} }
public bool DirectoryChanged
{
get => _directoryChanged;
set
{
_directoryChanged = value;
OnPropertyChanged();
}
}
public bool EnableDiscordIntegration { get; set; } public bool EnableDiscordIntegration { get; set; }
public bool CheckUpdatesOnStart { get; set; } public bool CheckUpdatesOnStart { get; set; }
public bool ShowConfirmExit { get; set; } public bool ShowConfirmExit { get; set; }
@ -397,10 +409,14 @@ namespace Ryujinx.Ava.Ui.ViewModels
public async Task SaveSettings() public async Task SaveSettings()
{ {
List<string> gameDirs = new List<string>(GameDirectories);
ConfigurationState config = ConfigurationState.Instance; ConfigurationState config = ConfigurationState.Instance;
if (_directoryChanged)
{
List<string> gameDirs = new List<string>(GameDirectories);
config.Ui.GameDirs.Value = gameDirs;
}
if (_validTzRegions.Contains(TimeZone)) if (_validTzRegions.Contains(TimeZone))
{ {
config.System.TimeZone.Value = TimeZone; config.System.TimeZone.Value = TimeZone;
@ -465,7 +481,6 @@ namespace Ryujinx.Ava.Ui.ViewModels
config.System.SystemTimeOffset.Value = systemTimeOffset.Seconds; config.System.SystemTimeOffset.Value = systemTimeOffset.Seconds;
config.Graphics.ShadersDumpPath.Value = ShaderDumpPath; config.Graphics.ShadersDumpPath.Value = ShaderDumpPath;
config.Ui.GameDirs.Value = gameDirs;
config.System.FsGlobalAccessLogMode.Value = FsGlobalAccessLogMode; config.System.FsGlobalAccessLogMode.Value = FsGlobalAccessLogMode;
config.System.MemoryManagerMode.Value = (MemoryManagerMode)MemoryMode; config.System.MemoryManagerMode.Value = (MemoryManagerMode)MemoryMode;

View file

@ -162,6 +162,7 @@ namespace Ryujinx.Ava.Ui.Windows
if (!string.IsNullOrWhiteSpace(path) && Directory.Exists(path) && !ViewModel.GameDirectories.Contains(path)) if (!string.IsNullOrWhiteSpace(path) && Directory.Exists(path) && !ViewModel.GameDirectories.Contains(path))
{ {
ViewModel.GameDirectories.Add(path); ViewModel.GameDirectories.Add(path);
ViewModel.DirectoryChanged = true;
} }
else else
{ {
@ -170,6 +171,7 @@ namespace Ryujinx.Ava.Ui.Windows
if (!string.IsNullOrWhiteSpace(path)) if (!string.IsNullOrWhiteSpace(path))
{ {
ViewModel.GameDirectories.Add(path); ViewModel.GameDirectories.Add(path);
ViewModel.DirectoryChanged = true;
} }
} }
} }
@ -181,6 +183,7 @@ namespace Ryujinx.Ava.Ui.Windows
foreach (string path in selected) foreach (string path in selected)
{ {
ViewModel.GameDirectories.Remove(path); ViewModel.GameDirectories.Remove(path);
ViewModel.DirectoryChanged = true;
} }
} }
@ -232,10 +235,12 @@ namespace Ryujinx.Ava.Ui.Windows
ControllerSettings?.SaveCurrentProfile(); ControllerSettings?.SaveCurrentProfile();
if (Owner is MainWindow window) if (Owner is MainWindow window && ViewModel.DirectoryChanged)
{ {
window.ViewModel.LoadApplications(); window.ViewModel.LoadApplications();
} }
ViewModel.DirectoryChanged = false;
} }
protected override void OnClosed(EventArgs e) protected override void OnClosed(EventArgs e)

View file

@ -34,6 +34,7 @@ namespace Ryujinx.Ui.Windows
private long _systemTimeOffset; private long _systemTimeOffset;
private float _previousVolumeLevel; private float _previousVolumeLevel;
private bool _directoryChanged = false;
#pragma warning disable CS0649, IDE0044 #pragma warning disable CS0649, IDE0044
[GUI] CheckButton _traceLogToggle; [GUI] CheckButton _traceLogToggle;
@ -501,14 +502,22 @@ namespace Ryujinx.Ui.Windows
private void SaveSettings() private void SaveSettings()
{ {
List<string> gameDirs = new List<string>(); if (_directoryChanged)
_gameDirsBoxStore.GetIterFirst(out TreeIter treeIter);
for (int i = 0; i < _gameDirsBoxStore.IterNChildren(); i++)
{ {
gameDirs.Add((string)_gameDirsBoxStore.GetValue(treeIter, 0)); List<string> gameDirs = new List<string>();
_gameDirsBoxStore.IterNext(ref treeIter); _gameDirsBoxStore.GetIterFirst(out TreeIter treeIter);
for (int i = 0; i < _gameDirsBoxStore.IterNChildren(); i++)
{
gameDirs.Add((string)_gameDirsBoxStore.GetValue(treeIter, 0));
_gameDirsBoxStore.IterNext(ref treeIter);
}
ConfigurationState.Instance.Ui.GameDirs.Value = gameDirs;
_directoryChanged = false;
} }
if (!float.TryParse(_resScaleText.Buffer.Text, out float resScaleCustom) || resScaleCustom <= 0.0f) if (!float.TryParse(_resScaleText.Buffer.Text, out float resScaleCustom) || resScaleCustom <= 0.0f)
@ -571,7 +580,6 @@ namespace Ryujinx.Ui.Windows
ConfigurationState.Instance.System.SystemTimeOffset.Value = _systemTimeOffset; ConfigurationState.Instance.System.SystemTimeOffset.Value = _systemTimeOffset;
ConfigurationState.Instance.Ui.CustomThemePath.Value = _custThemePath.Buffer.Text; ConfigurationState.Instance.Ui.CustomThemePath.Value = _custThemePath.Buffer.Text;
ConfigurationState.Instance.Graphics.ShadersDumpPath.Value = _graphicsShadersDumpPath.Buffer.Text; ConfigurationState.Instance.Graphics.ShadersDumpPath.Value = _graphicsShadersDumpPath.Buffer.Text;
ConfigurationState.Instance.Ui.GameDirs.Value = gameDirs;
ConfigurationState.Instance.System.FsGlobalAccessLogMode.Value = (int)_fsLogSpinAdjustment.Value; ConfigurationState.Instance.System.FsGlobalAccessLogMode.Value = (int)_fsLogSpinAdjustment.Value;
ConfigurationState.Instance.Graphics.MaxAnisotropy.Value = float.Parse(_anisotropy.ActiveId, CultureInfo.InvariantCulture); ConfigurationState.Instance.Graphics.MaxAnisotropy.Value = float.Parse(_anisotropy.ActiveId, CultureInfo.InvariantCulture);
ConfigurationState.Instance.Graphics.AspectRatio.Value = Enum.Parse<AspectRatio>(_aspectRatio.ActiveId); ConfigurationState.Instance.Graphics.AspectRatio.Value = Enum.Parse<AspectRatio>(_aspectRatio.ActiveId);
@ -655,27 +663,27 @@ namespace Ryujinx.Ui.Windows
if (fileChooser.Run() == (int)ResponseType.Accept) if (fileChooser.Run() == (int)ResponseType.Accept)
{ {
_directoryChanged = false;
foreach (string directory in fileChooser.Filenames) foreach (string directory in fileChooser.Filenames)
{ {
bool directoryAdded = false;
if (_gameDirsBoxStore.GetIterFirst(out TreeIter treeIter)) if (_gameDirsBoxStore.GetIterFirst(out TreeIter treeIter))
{ {
do do
{ {
if (directory.Equals((string)_gameDirsBoxStore.GetValue(treeIter, 0))) if (directory.Equals((string)_gameDirsBoxStore.GetValue(treeIter, 0)))
{ {
directoryAdded = true;
break; break;
} }
} while(_gameDirsBoxStore.IterNext(ref treeIter)); } while(_gameDirsBoxStore.IterNext(ref treeIter));
} }
if (!directoryAdded) if (!_directoryChanged)
{ {
_gameDirsBoxStore.AppendValues(directory); _gameDirsBoxStore.AppendValues(directory);
} }
} }
_directoryChanged = true;
} }
fileChooser.Dispose(); fileChooser.Dispose();
@ -693,6 +701,8 @@ namespace Ryujinx.Ui.Windows
if (selection.GetSelected(out TreeIter treeIter)) if (selection.GetSelected(out TreeIter treeIter))
{ {
_gameDirsBoxStore.Remove(ref treeIter); _gameDirsBoxStore.Remove(ref treeIter);
_directoryChanged = true;
} }
((ToggleButton)sender).SetStateFlags(StateFlags.Normal, true); ((ToggleButton)sender).SetStateFlags(StateFlags.Normal, true);