public static NacpItem?FindNacpItem(this NcaItem ncaItem) { foreach (var sectionItem in ncaItem.ChildItems) { foreach (var dirEntry in sectionItem.ChildItems) { if (dirEntry is NacpItem nacpItem) { return(nacpItem); } } } return(null); }
public NcaItemViewModel(NcaItem ncaItem, IServiceProvider serviceProvider) : base(ncaItem, serviceProvider) { _ncaItem = ncaItem; _ncaItem.PropertyChanged += OnNcaItemPropertyChanged; var savePartitionFileCommand = serviceProvider.GetRequiredService <ISavePartitionFileCommand>(); savePartitionFileCommand.PartitionFileItem = ncaItem; _menuItemSaveNcaRaw = CreateLocalizedMenuItem(nameof(ILocalizationKeys.ContextMenu_SaveNcaFileRaw), savePartitionFileCommand); var savePlaintextNcaFileCommand = serviceProvider.GetRequiredService <ISavePlaintextNcaFileCommand>(); savePlaintextNcaFileCommand.NcaItem = ncaItem; _menuItemSavePlaintextNca = CreateLocalizedMenuItem(nameof(ILocalizationKeys.ContextMenu_SaveNcaFilePlaintext), savePlaintextNcaFileCommand); }
private void BuildChildItems(NcaItem parentItem) { try { var nca = parentItem.Nca; for (var sectionIndex = 0; sectionIndex < NcaItem.MaxSections; sectionIndex++) { try { if (!nca.Header.IsSectionEnabled(sectionIndex)) { continue; } } catch (Exception ex) { OnLoadingException(ex, parentItem); var message = LocalizationManager.Instance.Current.Keys.LoadingError_FailedToCheckIfSectionCanBeOpened.SafeFormat(ex.Message); parentItem.Errors.Add(TREE_LOADING_CATEGORY, message); _logger.LogError(ex, message); continue; } NcaFsHeader ncaFsHeader; try { ncaFsHeader = nca.GetFsHeader(sectionIndex); } catch (Exception ex) { OnLoadingException(ex, parentItem); var message = LocalizationManager.Instance.Current.Keys.LoadingError_FailedToGetNcaSectionFsHeader.SafeFormat(sectionIndex, ex.Message); parentItem.Errors.Add(TREE_LOADING_CATEGORY, message); _logger.LogError(ex, message); continue; } var sectionItem = new SectionItem(sectionIndex, ncaFsHeader, parentItem); parentItem.ChildItems.Add(sectionItem); IFileSystem?fileSystem = null; try { fileSystem = nca.OpenFileSystem(sectionIndex, IntegrityCheckLevel.ErrorOnInvalid); } catch (Exception ex) { OnLoadingException(ex, sectionItem); var message = LocalizationManager.Instance.Current.Keys.LoadingError_FailedToOpenNcaSectionFileSystem.SafeFormat(sectionIndex, ex.Message); sectionItem.Errors.Add(TREE_LOADING_CATEGORY, message); _logger.LogError(ex, message); } sectionItem.FileSystem = fileSystem; BuildChildItems(sectionItem); } } catch (Exception ex) { OnLoadingException(ex, parentItem); var message = LocalizationManager.Instance.Current.Keys.LoadingError_FailedToLoadNcaContent.SafeFormat(ex.Message); parentItem.Errors.Add(TREE_LOADING_CATEGORY, message); _logger.LogError(ex, message); } }
private void BuildChildItems(PartitionFileSystemItemBase parentItem) { try { var partitionFileSystem = parentItem.PartitionFileSystem; var remainingEntries = new List <PartitionFileEntry>(); // First loop on *.tik files to inject title keys in KeySet foreach (var partitionFileEntry in partitionFileSystem.Files) { var fileName = partitionFileEntry.Name; if (!fileName.EndsWith(".tik", StringComparison.OrdinalIgnoreCase)) { remainingEntries.Add(partitionFileEntry); continue; } IFile file; try { file = partitionFileSystem.OpenFile(partitionFileEntry, OpenMode.Read); } catch (Exception ex) { OnLoadingException(ex, parentItem); var message = LocalizationManager.Instance.Current.Keys.LoadingError_FailedToOpenPartitionFile.SafeFormat(ex.Message); parentItem.Errors.Add(TREE_LOADING_CATEGORY, message); _logger.LogError(ex, message); continue; } Ticket ticket; try { using var asStream = file.AsStream(); ticket = new Ticket(asStream); } catch (Exception ex) { OnLoadingException(ex, parentItem); var message = LocalizationManager.Instance.Current.Keys.LoadingError_FailedToLoadTicketFile.SafeFormat(ex.Message); parentItem.Errors.Add(TREE_LOADING_CATEGORY, message); _logger.LogError(ex, message); continue; } var ticketItem = new TicketItem(ticket, partitionFileEntry, file, parentItem); try { var rightsId = new RightsId(ticket.RightsId); var accessKey = new AccessKey(ticket.TitleKeyBlock); ticketItem.RightsId = rightsId; ticketItem.AccessKey = accessKey; if (parentItem.KeySet.ExternalKeySet.Get(rightsId, out var existingAccessKey) == Result.Success) { // Here RightID key is already defined if (existingAccessKey != accessKey) { // Replaces the RightID key with the one defined in the ticket parentItem.KeySet.ExternalKeySet.Remove(rightsId); parentItem.KeySet.ExternalKeySet.Add(rightsId, accessKey).ThrowIfFailure(); _logger.LogWarning(LocalizationManager.Instance.Current.Keys.LoadingWarning_TitleIdKeyReplaced.SafeFormat(rightsId.ToString(), accessKey.ToString(), fileName, existingAccessKey)); } else { _logger.LogDebug(LocalizationManager.Instance.Current.Keys.LoadingDebug_TitleIdKeyAlreadyExists.SafeFormat(rightsId.ToString(), accessKey.ToString(), fileName)); } } else { parentItem.KeySet.ExternalKeySet.Add(rightsId, accessKey).ThrowIfFailure(); _logger.LogInformation(LocalizationManager.Instance.Current.Keys.LoadingInfo_TitleIdKeySuccessfullyInjected.SafeFormat(rightsId.ToString(), accessKey.ToString(), fileName)); } } catch (Exception ex) { _logger.LogError(ex, LocalizationManager.Instance.Current.Keys.LoadingError_FailedToLoadTitleIdKey.SafeFormat(fileName, ex.Message)); } parentItem.TicketChildItems.Add(ticketItem); } foreach (var partitionFileEntry in remainingEntries) { IFile file; try { file = partitionFileSystem.OpenFile(partitionFileEntry, OpenMode.Read); } catch (Exception ex) { OnLoadingException(ex, parentItem); var message = LocalizationManager.Instance.Current.Keys.LoadingError_FailedToOpenPartitionFile.SafeFormat(ex.Message); parentItem.Errors.Add(TREE_LOADING_CATEGORY, message); _logger.LogError(ex, message); continue; } var fileName = partitionFileEntry.Name; if (fileName.EndsWith(".nca", StringComparison.OrdinalIgnoreCase) || fileName.EndsWith(".ncz", StringComparison.OrdinalIgnoreCase)) { Nca nca; try { nca = new Nca(parentItem.KeySet, new FileStorage(file)); } catch (Exception ex) { OnLoadingException(ex, parentItem); var message = LocalizationManager.Instance.Current.Keys.LoadingError_FailedToLoadNcaFile.SafeFormat(ex.Message); parentItem.Errors.Add(TREE_LOADING_CATEGORY, message); _logger.LogError(ex, message); continue; } var ncaItem = new NcaItem(nca, partitionFileEntry, file, parentItem); BuildChildItems(ncaItem); parentItem.NcaChildItems.Add(ncaItem); } else { var partitionFileEntryItem = new PartitionFileEntryItem(partitionFileEntry, file, parentItem); parentItem.PartitionFileEntryChildItems.Add(partitionFileEntryItem); } } } catch (Exception ex) { OnLoadingException(ex, parentItem); var message = LocalizationManager.Instance.Current.Keys.LoadingError_FailedToLoadPartitionFileSystemContent.SafeFormat(ex.Message); parentItem.Errors.Add(TREE_LOADING_CATEGORY, message); _logger.LogError(ex, message); } }