Auto-load bundled DLC on startup

This commit is contained in:
Jimmy Reichley 2024-08-17 15:18:08 -04:00
parent 57de6a7dc5
commit 867bc7021f
No known key found for this signature in database
GPG key ID: 67715DC5A329803C
2 changed files with 27 additions and 15 deletions

View file

@ -786,12 +786,33 @@ namespace Ryujinx.UI.App.Common
foreach (ApplicationData application in Applications.Items) foreach (ApplicationData application in Applications.Items)
{ {
var res = DownloadableContentsHelper.LoadDownloadableContentsJson(_virtualFileSystem, application.IdBase); var savedDlc = DownloadableContentsHelper.LoadDownloadableContentsJson(_virtualFileSystem, application.IdBase);
it.AddOrUpdate(res); it.AddOrUpdate(savedDlc);
if(TryGetDownloadableContentFromFile(application.Path, out var bundledDlc))
{
var savedDlcLookup = savedDlc.Select(dlc => dlc.Item1).ToHashSet();
bool addedNewDlc = false;
foreach (var dlc in bundledDlc)
{
if (!savedDlcLookup.Contains(dlc))
{
addedNewDlc = true;
it.AddOrUpdate((dlc, true));
}
}
if (addedNewDlc)
{
var gameDlcs = it.Items.Where(dlc => dlc.Dlc.TitleIdBase == application.IdBase).ToList();
DownloadableContentsHelper.SaveDownloadableContentsJson(_virtualFileSystem, application.IdBase, gameDlcs);
}
}
} }
}); });
} }
public void SaveDownloadableContentsForGame(ApplicationData application, List<(DownloadableContentModel, bool IsEnabled)> dlcs) public void SaveDownloadableContentsForGame(ApplicationData application, List<(DownloadableContentModel, bool IsEnabled)> dlcs)
{ {
_downloadableContents.Edit(it => _downloadableContents.Edit(it =>

View file

@ -21,8 +21,8 @@ namespace Ryujinx.Ava.UI.ViewModels
{ {
private readonly ApplicationLibrary _applicationLibrary; private readonly ApplicationLibrary _applicationLibrary;
private AvaloniaList<DownloadableContentModel> _downloadableContents = new(); private AvaloniaList<DownloadableContentModel> _downloadableContents = new();
private AvaloniaList<DownloadableContentModel> _views = new();
private AvaloniaList<DownloadableContentModel> _selectedDownloadableContents = new(); private AvaloniaList<DownloadableContentModel> _selectedDownloadableContents = new();
private AvaloniaList<DownloadableContentModel> _views = new();
private string _search; private string _search;
private readonly ApplicationData _applicationData; private readonly ApplicationData _applicationData;
@ -106,14 +106,6 @@ namespace Ryujinx.Ava.UI.ViewModels
OnPropertyChanged(nameof(UpdateCount)); OnPropertyChanged(nameof(UpdateCount));
} }
// NOTE: Try to load downloadable contents from PFS last to preserve enabled state.
if (AddDownloadableContent(_applicationData.Path, out var newDlc) && newDlc > 0)
{
ShowNewDlcAddedDialog(newDlc);
}
// NOTE: Save the list again to remove leftovers.
Save();
Sort(); Sort();
} }
@ -182,7 +174,7 @@ namespace Ryujinx.Ava.UI.ViewModels
if (totalDlcAdded > 0) if (totalDlcAdded > 0)
{ {
await ShowNewDlcAddedDialog(0); await ShowNewDlcAddedDialog(totalDlcAdded);
} }
} }
@ -205,7 +197,7 @@ namespace Ryujinx.Ava.UI.ViewModels
if (!DownloadableContents.Contains(dlc)) if (!DownloadableContents.Contains(dlc))
{ {
DownloadableContents.Add(dlc); DownloadableContents.Add(dlc);
Dispatcher.UIThread.InvokeAsync(() => SelectedDownloadableContents.ReplaceOrAdd(dlc, dlc)); SelectedDownloadableContents.ReplaceOrAdd(dlc, dlc);
numDlcAdded++; numDlcAdded++;
} }
@ -276,6 +268,5 @@ namespace Ryujinx.Ava.UI.ViewModels
await ContentDialogHelper.ShowTextDialog(LocaleManager.Instance[LocaleKeys.DialogConfirmationTitle], msg, "", "", "", LocaleManager.Instance[LocaleKeys.InputDialogOk], (int)Symbol.Checkmark); await ContentDialogHelper.ShowTextDialog(LocaleManager.Instance[LocaleKeys.DialogConfirmationTitle], msg, "", "", "", LocaleManager.Instance[LocaleKeys.InputDialogOk], (int)Symbol.Checkmark);
}); });
} }
} }
} }