Ejemplo n.º 1
0
        public async Task Initialize(IReadOnlyBinaryDataAccessor data)
        {
            this.RawData = data;
            if (Header != null && Header.RomFsSize > 0)
            {
                if (Header.ExeFsOffset > 0 && Header.ExeFsSize > 0)
                {
                    ExeFs = await ExeFs.Load(data.Slice((long)Header.ExeFsOffset *MediaUnitSize, (long)Header.ExeFsSize *MediaUnitSize));
                }
                if (Header.RomFsOffset > 0 && Header.RomFsOffset > 0)
                {
                    RomFs = await RomFs.Load(data.Slice((long)Header.RomFsOffset *MediaUnitSize, (long)Header.RomFsSize *MediaUnitSize));
                }
                if (Header.ExHeaderSize > 0)
                {
                    ExHeader = await NcchExtendedHeader.Load(data.Slice(0x200, Header.ExHeaderSize));
                }

                PlainRegion = await data.ReadStringAsync(Header.PlainRegionOffset *MediaUnitSize, Header.PlainRegionSize *MediaUnitSize, Encoding.ASCII);

                Logo = await data.ReadArrayAsync(Header.LogoRegionOffset *MediaUnitSize, Header.LogoRegionSize *MediaUnitSize);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Builds a new NCCH partition from the given directory
        /// </summary>
        /// <param name="fileSystem">File system from which to load the files</param>
        /// <returns>A newly built NCCH partition</returns>
        public static async Task <NcchPartition> Build(string headerFilename, string exHeaderFilename, string?exeFsDirectory, string?romFsDiretory, string?plainRegionFilename, string?logoFilename, IFileSystem fileSystem, ProcessingProgressedToken?progressToken = null)
        {
            ProcessingProgressedToken?exefsToken = null;
            ProcessingProgressedToken?romfsToken = null;

            void ReportProgress()
            {
                if (progressToken != null)
                {
                    progressToken.TotalFileCount     = (exefsToken?.TotalFileCount + romfsToken?.TotalFileCount).GetValueOrDefault();
                    progressToken.ProcessedFileCount = (exefsToken?.ProcessedFileCount + romfsToken?.ProcessedFileCount).GetValueOrDefault();
                }
            };

            Task <ExeFs?> exeFsTask;

            if (!string.IsNullOrEmpty(exeFsDirectory))
            {
                if (progressToken != null)
                {
                    exefsToken = new ProcessingProgressedToken();
                    exefsToken.FileCountChanged += (sender, e) => ReportProgress();
                }
                exeFsTask = Task.Run <ExeFs?>(async() => await ExeFs.Build(exeFsDirectory, fileSystem, exefsToken).ConfigureAwait(false));
            }
            else
            {
                exeFsTask = Task.FromResult <ExeFs?>(null);
            }

            Task <RomFs?> romFsTask;

            if (!string.IsNullOrEmpty(romFsDiretory))
            {
                if (progressToken != null)
                {
                    romfsToken = new ProcessingProgressedToken();
                    romfsToken.FileCountChanged += (sender, e) => ReportProgress();
                }
                romFsTask = Task.Run <RomFs?>(async() => await RomFs.Build(romFsDiretory, fileSystem, romfsToken).ConfigureAwait(false));
            }
            else
            {
                romFsTask = Task.FromResult <RomFs?>(null);
            }

            var header = new NcchHeader(fileSystem.ReadAllBytes(headerFilename));

            NcchExtendedHeader?exHeader = null;

            if (!string.IsNullOrEmpty(exHeaderFilename))
            {
                using var exHeaderData = new BinaryFile(fileSystem.ReadAllBytes(exHeaderFilename));
                exHeader = await NcchExtendedHeader.Load(exHeaderData);
            }

            string?plainRegion = null;

            if (!string.IsNullOrEmpty(plainRegionFilename))
            {
                plainRegion = fileSystem.ReadAllText(plainRegionFilename);
            }

            byte[]? logo = null;
            if (!string.IsNullOrEmpty(logoFilename))
            {
                logo = fileSystem.ReadAllBytes(logoFilename);
            }

            return(new NcchPartition(await romFsTask, await exeFsTask, header, exHeader, plainRegion, logo));
        }