mirror of
https://git.ryujinx.app/ryubing/ryujinx.git
synced 2025-06-28 08:56:24 +02:00
Add ability to trim and untrim XCI files from the application context menu AND in Bulk (#105)
This commit is contained in:
parent
47b8145809
commit
4831965404
23 changed files with 2095 additions and 3 deletions
|
@ -22,6 +22,7 @@ using Ryujinx.Ava.UI.Windows;
|
|||
using Ryujinx.Common;
|
||||
using Ryujinx.Common.Configuration;
|
||||
using Ryujinx.Common.Logging;
|
||||
using Ryujinx.Common.Utilities;
|
||||
using Ryujinx.Cpu;
|
||||
using Ryujinx.HLE;
|
||||
using Ryujinx.HLE.FileSystem;
|
||||
|
@ -84,6 +85,8 @@ namespace Ryujinx.Ava.UI.ViewModels
|
|||
private bool _isAppletMenuActive;
|
||||
private int _statusBarProgressMaximum;
|
||||
private int _statusBarProgressValue;
|
||||
private string _statusBarProgressStatusText;
|
||||
private bool _statusBarProgressStatusVisible;
|
||||
private bool _isPaused;
|
||||
private bool _showContent = true;
|
||||
private bool _isLoadingIndeterminate = true;
|
||||
|
@ -391,6 +394,8 @@ namespace Ryujinx.Ava.UI.ViewModels
|
|||
|
||||
public bool OpenDeviceSaveDirectoryEnabled => !SelectedApplication.ControlHolder.ByteSpan.IsZeros() && SelectedApplication.ControlHolder.Value.DeviceSaveDataSize > 0;
|
||||
|
||||
public bool TrimXCIEnabled => Ryujinx.Common.Utilities.XCIFileTrimmer.CanTrim(SelectedApplication.Path, new Common.XCIFileTrimmerMainWindowLog(this));
|
||||
|
||||
public bool OpenBcatSaveDirectoryEnabled => !SelectedApplication.ControlHolder.ByteSpan.IsZeros() && SelectedApplication.ControlHolder.Value.BcatDeliveryCacheStorageSize > 0;
|
||||
|
||||
public bool CreateShortcutEnabled => !ReleaseInformation.IsFlatHubBuild;
|
||||
|
@ -505,6 +510,28 @@ namespace Ryujinx.Ava.UI.ViewModels
|
|||
}
|
||||
}
|
||||
|
||||
public bool StatusBarProgressStatusVisible
|
||||
{
|
||||
get => _statusBarProgressStatusVisible;
|
||||
set
|
||||
{
|
||||
_statusBarProgressStatusVisible = value;
|
||||
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public string StatusBarProgressStatusText
|
||||
{
|
||||
get => _statusBarProgressStatusText;
|
||||
set
|
||||
{
|
||||
_statusBarProgressStatusText = value;
|
||||
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public string FifoStatusText
|
||||
{
|
||||
get => _fifoStatusText;
|
||||
|
@ -1834,6 +1861,98 @@ namespace Ryujinx.Ava.UI.ViewModels
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async void ProcessTrimResult(String filename, Ryujinx.Common.Utilities.XCIFileTrimmer.OperationOutcome operationOutcome)
|
||||
{
|
||||
string notifyUser = operationOutcome.ToLocalisedText();
|
||||
|
||||
if (notifyUser != null)
|
||||
{
|
||||
await ContentDialogHelper.CreateWarningDialog(
|
||||
LocaleManager.Instance[LocaleKeys.TrimXCIFileFailedPrimaryText],
|
||||
notifyUser
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (operationOutcome)
|
||||
{
|
||||
case Ryujinx.Common.Utilities.XCIFileTrimmer.OperationOutcome.Successful:
|
||||
if (Avalonia.Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
||||
{
|
||||
if (desktop.MainWindow is MainWindow mainWindow)
|
||||
mainWindow.LoadApplications();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async Task TrimXCIFile(string filename)
|
||||
{
|
||||
if (filename == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var trimmer = new XCIFileTrimmer(filename, new Common.XCIFileTrimmerMainWindowLog(this));
|
||||
|
||||
if (trimmer.CanBeTrimmed)
|
||||
{
|
||||
var savings = (double)trimmer.DiskSpaceSavingsB / 1024.0 / 1024.0;
|
||||
var currentFileSize = (double)trimmer.FileSizeB / 1024.0 / 1024.0;
|
||||
var cartDataSize = (double)trimmer.DataSizeB / 1024.0 / 1024.0;
|
||||
string secondaryText = LocaleManager.Instance.UpdateAndGetDynamicValue(LocaleKeys.TrimXCIFileDialogSecondaryText, currentFileSize, cartDataSize, savings);
|
||||
|
||||
var result = await ContentDialogHelper.CreateConfirmationDialog(
|
||||
LocaleManager.Instance[LocaleKeys.TrimXCIFileDialogPrimaryText],
|
||||
secondaryText,
|
||||
LocaleManager.Instance[LocaleKeys.Continue],
|
||||
LocaleManager.Instance[LocaleKeys.Cancel],
|
||||
LocaleManager.Instance[LocaleKeys.TrimXCIFileDialogTitle]
|
||||
);
|
||||
|
||||
if (result == UserResult.Yes)
|
||||
{
|
||||
Thread XCIFileTrimThread = new(() =>
|
||||
{
|
||||
Dispatcher.UIThread.Post(() =>
|
||||
{
|
||||
StatusBarProgressStatusText = LocaleManager.Instance.UpdateAndGetDynamicValue(LocaleKeys.StatusBarXCIFileTrimming, Path.GetFileName(filename));
|
||||
StatusBarProgressStatusVisible = true;
|
||||
StatusBarProgressMaximum = 1;
|
||||
StatusBarProgressValue = 0;
|
||||
StatusBarVisible = true;
|
||||
});
|
||||
|
||||
try
|
||||
{
|
||||
XCIFileTrimmer.OperationOutcome operationOutcome = trimmer.Trim();
|
||||
|
||||
Dispatcher.UIThread.Post(() =>
|
||||
{
|
||||
ProcessTrimResult(filename, operationOutcome);
|
||||
});
|
||||
}
|
||||
finally
|
||||
{
|
||||
Dispatcher.UIThread.Post(() =>
|
||||
{
|
||||
StatusBarProgressStatusVisible = false;
|
||||
StatusBarProgressStatusText = string.Empty;
|
||||
StatusBarVisible = false;
|
||||
});
|
||||
}
|
||||
})
|
||||
{
|
||||
Name = "GUI.XCIFileTrimmerThread",
|
||||
IsBackground = true,
|
||||
};
|
||||
XCIFileTrimThread.Start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue