mirror of
https://git.ryujinx.app/ryubing/ryujinx.git
synced 2025-07-09 13:36:27 +02:00
Automatically remove invalid dlc and updates as part of auto load (#42)
* Automatically remove invalid dlc and updates as part of auto load Fixed some minor label spacing issues in options dialog Removal of unused variable in input view model * Fixed missing french message for AutoloadDlcAddedMessage
This commit is contained in:
parent
6be8838043
commit
7038a902c3
8 changed files with 109 additions and 43 deletions
|
@ -1,5 +1,6 @@
|
|||
using DynamicData;
|
||||
using DynamicData.Kernel;
|
||||
using Gommon;
|
||||
using LibHac;
|
||||
using LibHac.Common;
|
||||
using LibHac.Fs;
|
||||
|
@ -801,17 +802,31 @@ namespace Ryujinx.UI.App.Common
|
|||
|
||||
// Searches the provided directories for DLC NSP files that are _valid for the currently detected games in the
|
||||
// library_, and then enables those DLC.
|
||||
public int AutoLoadDownloadableContents(List<string> appDirs)
|
||||
public int AutoLoadDownloadableContents(List<string> appDirs, out int numDlcRemoved)
|
||||
{
|
||||
_cancellationToken = new CancellationTokenSource();
|
||||
|
||||
List<string> dlcPaths = new();
|
||||
int newDlcLoaded = 0;
|
||||
numDlcRemoved = 0;
|
||||
|
||||
try
|
||||
{
|
||||
// Remove any downloadable content which can no longer be located on disk
|
||||
Logger.Notice.Print(LogClass.Application, $"Removing non-existing Title DLCs");
|
||||
var dlcToRemove = _downloadableContents.Items
|
||||
.Where(dlc => !File.Exists(dlc.Dlc.ContainerPath))
|
||||
.ToList();
|
||||
dlcToRemove.ForEach(dlc =>
|
||||
Logger.Warning?.Print(LogClass.Application, $"Title DLC removed: {dlc.Dlc.ContainerPath}")
|
||||
);
|
||||
numDlcRemoved += dlcToRemove.Distinct().Count();
|
||||
_downloadableContents.RemoveKeys(dlcToRemove.Select(dlc => dlc.Dlc));
|
||||
|
||||
foreach (string appDir in appDirs)
|
||||
{
|
||||
Logger.Notice.Print(LogClass.Application, $"Auto loading DLC from: {appDir}");
|
||||
|
||||
if (_cancellationToken.Token.IsCancellationRequested)
|
||||
{
|
||||
return newDlcLoaded;
|
||||
|
@ -900,17 +915,37 @@ namespace Ryujinx.UI.App.Common
|
|||
// Searches the provided directories for update NSP files that are _valid for the currently detected games in the
|
||||
// library_, and then applies those updates. If a newly-detected update is a newer version than the currently
|
||||
// selected update (or if no update is currently selected), then that update will be selected.
|
||||
public int AutoLoadTitleUpdates(List<string> appDirs)
|
||||
public int AutoLoadTitleUpdates(List<string> appDirs, out int numUpdatesRemoved)
|
||||
{
|
||||
_cancellationToken = new CancellationTokenSource();
|
||||
|
||||
List<string> updatePaths = new();
|
||||
int numUpdatesLoaded = 0;
|
||||
numUpdatesRemoved = 0;
|
||||
|
||||
try
|
||||
{
|
||||
var titleIdsToSave = new HashSet<ulong>();
|
||||
var titleIdsToRefresh = new HashSet<ulong>();
|
||||
|
||||
// Remove any updates which can no longer be located on disk
|
||||
Logger.Notice.Print(LogClass.Application, $"Removing non-existing Title Updates");
|
||||
var updatesToRemove = _titleUpdates.Items
|
||||
.Where(it => !File.Exists(it.TitleUpdate.Path))
|
||||
.ToList();
|
||||
|
||||
numUpdatesRemoved += updatesToRemove.Select(it => it.TitleUpdate).Distinct().Count();
|
||||
updatesToRemove.ForEach(ti =>
|
||||
Logger.Warning?.Print(LogClass.Application, $"Title update removed: {ti.TitleUpdate.Path}")
|
||||
);
|
||||
_titleUpdates.RemoveKeys(updatesToRemove.Select(it => it.TitleUpdate));
|
||||
titleIdsToSave.UnionWith(updatesToRemove.Select(it => it.TitleUpdate.TitleIdBase));
|
||||
titleIdsToRefresh.UnionWith(updatesToRemove.Where(it => it.IsSelected).Select(update => update.TitleUpdate.TitleIdBase));
|
||||
|
||||
foreach (string appDir in appDirs)
|
||||
{
|
||||
Logger.Notice.Print(LogClass.Application, $"Auto loading updates from: {appDir}");
|
||||
|
||||
if (_cancellationToken.Token.IsCancellationRequested)
|
||||
{
|
||||
return numUpdatesLoaded;
|
||||
|
@ -979,27 +1014,21 @@ namespace Ryujinx.UI.App.Common
|
|||
{
|
||||
if (!_titleUpdates.Lookup(update).HasValue)
|
||||
{
|
||||
var currentlySelected = TitleUpdates.Items.FirstOrOptional(it =>
|
||||
it.TitleUpdate.TitleIdBase == update.TitleIdBase && it.IsSelected);
|
||||
|
||||
var shouldSelect = !currentlySelected.HasValue ||
|
||||
currentlySelected.Value.TitleUpdate.Version < update.Version;
|
||||
_titleUpdates.AddOrUpdate((update, shouldSelect));
|
||||
|
||||
if (currentlySelected.HasValue && shouldSelect)
|
||||
_titleUpdates.AddOrUpdate((currentlySelected.Value.TitleUpdate, false));
|
||||
|
||||
SaveTitleUpdatesForGame(update.TitleIdBase);
|
||||
bool shouldSelect = AddAndAutoSelectUpdate(update);
|
||||
titleIdsToSave.Add(update.TitleIdBase);
|
||||
numUpdatesLoaded++;
|
||||
|
||||
if (shouldSelect)
|
||||
{
|
||||
RefreshApplicationInfo(update.TitleIdBase);
|
||||
titleIdsToRefresh.Add(update.TitleIdBase);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
titleIdsToSave.ForEach(titleId => SaveTitleUpdatesForGame(titleId));
|
||||
titleIdsToRefresh.ForEach(titleId => RefreshApplicationInfo(titleId));
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
@ -1010,6 +1039,24 @@ namespace Ryujinx.UI.App.Common
|
|||
return numUpdatesLoaded;
|
||||
}
|
||||
|
||||
private bool AddAndAutoSelectUpdate(TitleUpdateModel update)
|
||||
{
|
||||
var currentlySelected = TitleUpdates.Items.FirstOrOptional(it =>
|
||||
it.TitleUpdate.TitleIdBase == update.TitleIdBase && it.IsSelected);
|
||||
|
||||
var shouldSelect = !currentlySelected.HasValue ||
|
||||
currentlySelected.Value.TitleUpdate.Version < update.Version;
|
||||
|
||||
_titleUpdates.AddOrUpdate((update, shouldSelect));
|
||||
|
||||
if (currentlySelected.HasValue && shouldSelect)
|
||||
{
|
||||
_titleUpdates.AddOrUpdate((currentlySelected.Value.TitleUpdate, false));
|
||||
}
|
||||
|
||||
return shouldSelect;
|
||||
}
|
||||
|
||||
protected void OnApplicationCountUpdated(ApplicationCountUpdatedEventArgs e)
|
||||
{
|
||||
ApplicationCountUpdated?.Invoke(null, e);
|
||||
|
@ -1394,8 +1441,8 @@ namespace Ryujinx.UI.App.Common
|
|||
if (TryGetTitleUpdatesFromFile(application.Path, out var bundledUpdates))
|
||||
{
|
||||
var savedUpdateLookup = savedUpdates.Select(update => update.Item1).ToHashSet();
|
||||
bool updatesChanged = false;
|
||||
|
||||
bool addedNewUpdate = false;
|
||||
foreach (var update in bundledUpdates.OrderByDescending(bundled => bundled.Version))
|
||||
{
|
||||
if (!savedUpdateLookup.Contains(update))
|
||||
|
@ -1404,17 +1451,19 @@ namespace Ryujinx.UI.App.Common
|
|||
if (!selectedUpdate.HasValue || selectedUpdate.Value.Item1.Version < update.Version)
|
||||
{
|
||||
shouldSelect = true;
|
||||
selectedUpdate = Optional<(TitleUpdateModel, bool IsSelected)>.Create((update, true));
|
||||
if (selectedUpdate.HasValue)
|
||||
_titleUpdates.AddOrUpdate((selectedUpdate.Value.Item1, false));
|
||||
selectedUpdate = DynamicData.Kernel.Optional<(TitleUpdateModel, bool IsSelected)>.Create((update, true));
|
||||
}
|
||||
|
||||
modifiedVersion = modifiedVersion || shouldSelect;
|
||||
it.AddOrUpdate((update, shouldSelect));
|
||||
|
||||
addedNewUpdate = true;
|
||||
updatesChanged = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (addedNewUpdate)
|
||||
if (updatesChanged)
|
||||
{
|
||||
var gameUpdates = it.Items.Where(update => update.TitleUpdate.TitleIdBase == application.IdBase).ToList();
|
||||
TitleUpdatesHelper.SaveTitleUpdatesJson(_virtualFileSystem, application.IdBase, gameUpdates);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue