Skip to content

Commit

Permalink
UI: Extract the 256x256 thumbnail too when extracting the logo.
Browse files Browse the repository at this point in the history
  • Loading branch information
GreemDev committed Oct 11, 2024
1 parent 17e259b commit 335eed7
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 23 deletions.
45 changes: 25 additions & 20 deletions src/Ryujinx/Common/ApplicationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,20 +141,8 @@ public static void OpenSaveDir(ulong saveDataId)
}
}

public static async Task ExtractSection(IStorageProvider storageProvider, NcaSectionType ncaSectionType, string titleFilePath, string titleName, int programIndex = 0)
public static void ExtractSection(string destination, NcaSectionType ncaSectionType, string titleFilePath, string titleName, int programIndex = 0)
{
var result = await storageProvider.OpenFolderPickerAsync(new FolderPickerOpenOptions
{
Title = LocaleManager.Instance[LocaleKeys.FolderDialogExtractTitle],
AllowMultiple = false,
});

if (result.Count == 0)
{
return;
}

var destination = result[0].Path.LocalPath;
var cancellationToken = new CancellationTokenSource();

UpdateWaitWindow waitingDialog = new(
Expand All @@ -172,11 +160,11 @@ public static async Task ExtractSection(IStorageProvider storageProvider, NcaSec
Nca patchNca = null;
string extension = Path.GetExtension(titleFilePath).ToLower();
if (extension == ".nsp" || extension == ".pfs0" || extension == ".xci")
if (extension is ".nsp" or ".pfs0" or ".xci")
{
IFileSystem pfs;
if (extension == ".xci")
if (extension is ".xci")
{
pfs = new Xci(_virtualFileSystem.KeySet, file.AsStorage()).OpenPartition(XciPartitionType.Secure);
}
Expand All @@ -194,7 +182,7 @@ public static async Task ExtractSection(IStorageProvider storageProvider, NcaSec
pfs.OpenFile(ref ncaFile.Ref, fileEntry.FullPath.ToU8Span(), OpenMode.Read).ThrowIfFailure();
Nca nca = new(_virtualFileSystem.KeySet, ncaFile.Get.AsStorage());
if (nca.Header.ContentType == NcaContentType.Program)
if (nca.Header.ContentType is NcaContentType.Program)
{
int dataIndex = Nca.GetSectionIndexFromType(NcaSectionType.Data, NcaContentType.Program);
if (nca.SectionExists(NcaSectionType.Data) && nca.Header.GetFsHeader(dataIndex).IsPatchSection())
Expand All @@ -208,12 +196,12 @@ public static async Task ExtractSection(IStorageProvider storageProvider, NcaSec
}
}
}
else if (extension == ".nca")
else if (extension is ".nca")
{
mainNca = new Nca(_virtualFileSystem.KeySet, file.AsStorage());
}
if (mainNca == null)
if (mainNca is null)
{
Logger.Error?.Print(LogClass.Application, "Extraction failure. The main NCA was not present in the selected file");
Expand All @@ -232,7 +220,7 @@ public static async Task ExtractSection(IStorageProvider storageProvider, NcaSec
: IntegrityCheckLevel.None;
(Nca updatePatchNca, _) = mainNca.GetUpdateData(_virtualFileSystem, checkLevel, programIndex, out _);
if (updatePatchNca != null)
if (updatePatchNca is not null)
{
patchNca = updatePatchNca;
}
Expand All @@ -242,7 +230,7 @@ public static async Task ExtractSection(IStorageProvider storageProvider, NcaSec
try
{
bool sectionExistsInPatch = false;
if (patchNca != null)
if (patchNca is not null)
{
sectionExistsInPatch = patchNca.CanOpenSection(index);
}
Expand Down Expand Up @@ -309,6 +297,23 @@ public static async Task ExtractSection(IStorageProvider storageProvider, NcaSec
extractorThread.Start();
}


public static async Task ExtractSection(IStorageProvider storageProvider, NcaSectionType ncaSectionType, string titleFilePath, string titleName, int programIndex = 0)
{
var result = await storageProvider.OpenFolderPickerAsync(new FolderPickerOpenOptions
{
Title = LocaleManager.Instance[LocaleKeys.FolderDialogExtractTitle],
AllowMultiple = false,
});

if (result.Count == 0)
{
return;
}

ExtractSection(result[0].Path.LocalPath, ncaSectionType, titleFilePath, titleName, programIndex);
}

public static (Result? result, bool canceled) CopyDirectory(FileSystemClient fs, string sourcePath, string destPath, CancellationToken token)
{
Result rc = fs.OpenDirectory(out DirectoryHandle sourceHandle, sourcePath.ToU8Span(), OpenDirectoryMode.All);
Expand Down
23 changes: 20 additions & 3 deletions src/Ryujinx/UI/Controls/ApplicationContextMenu.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Markup.Xaml;
using Avalonia.Platform.Storage;
using LibHac.Fs;
using LibHac.Tools.FsSystem.NcaUtils;
using Ryujinx.Ava.Common;
Expand Down Expand Up @@ -325,13 +326,29 @@ public async void ExtractApplicationLogo_Click(object sender, RoutedEventArgs ar
{
var viewModel = (sender as MenuItem)?.DataContext as MainWindowViewModel;

if (viewModel?.SelectedApplication != null)
if (viewModel?.SelectedApplication is { } selectedApp)
{
await ApplicationHelper.ExtractSection(
viewModel.StorageProvider,
var result = await viewModel.StorageProvider.OpenFolderPickerAsync(new FolderPickerOpenOptions
{
Title = LocaleManager.Instance[LocaleKeys.FolderDialogExtractTitle],
AllowMultiple = false,
});

if (result.Count == 0)
{
return;
}

ApplicationHelper.ExtractSection(
result[0].Path.LocalPath,
NcaSectionType.Logo,
viewModel.SelectedApplication.Path,
viewModel.SelectedApplication.Name);

var iconFile = await result[0].CreateFileAsync(selectedApp.IdString + ".png");
await using var fileStream = await iconFile.OpenWriteAsync();

fileStream.Write(selectedApp.Icon);
}
}

Expand Down

0 comments on commit 335eed7

Please sign in to comment.