예제 #1
0
파일: NKitForm.cs 프로젝트: skudi/NKit
        private void saveFile(string path, string imageName, ExtractedFile f, Stream s)
        {
            path = Path.Combine(path, f.DiscType.ToString(), imageName + "_" + f.DiscId8);
            if (f.PartitionId != null)
            {
                path = Path.Combine(path, f.PartitionId);
            }
            path = Path.Combine(path, SourceFiles.PathFix(f.Path.TrimStart('/')));
            Directory.CreateDirectory(path);

            using (Stream b = File.OpenWrite(Path.Combine(path, f.Name)))
                s.Copy(b, f.Length);
        }
예제 #2
0
        private ExtractResult ExtractFilesWiiNkit(Func <ExtractedFile, bool> filter, Action <Stream, ExtractedFile> extract)
        {
            WiiDiscHeaderSection hdr    = (WiiDiscHeaderSection)Header;
            ExtractedFile        exFile = new ExtractedFile(IsGameCube ? DiscType.GameCube : DiscType.Wii,
                                                            NStream.Id8, null, 0, hdr.Size, "", "hdr.bin", ExtractedFileType.WiiDiscItem);
            long srcPos = hdr.Size;

            if (filter(exFile))
            {
                using (MemoryStream ms = new MemoryStream(hdr.Data))
                {
                    extract(ms, exFile);
                }
            }

            foreach (WiiPartitionInfo part in hdr.Partitions) //already sorted
            {
                if (NStream.Position < part.DiscOffset)
                {
                    NStream.Copy(Stream.Null, part.DiscOffset - NStream.Position);
                }

                long          prtPos     = NStream.Position;
                MemorySection prtHdr     = MemorySection.Read(NStream, 0x20000);
                MemorySection prtDataHdr = MemorySection.Read(NStream, 0x440);
                string        prtId      = prtDataHdr.ReadString(0, 4);
                if (prtId != "\0\0\0\0")
                {
                    srcPos += prtHdr.Size + prtDataHdr.Size;
                    exFile  = new ExtractedFile(IsGameCube ? DiscType.GameCube : DiscType.Wii,
                                                NStream.Id8, null, prtPos, prtHdr.Size, "", prtId + "hdr.bin", ExtractedFileType.WiiDiscItem);
                    if (filter(exFile))
                    {
                        using (MemoryStream ms = new MemoryStream(prtHdr.Data))
                        {
                            extract(ms, exFile);
                        }
                    }

                    extractFiles(prtId, prtDataHdr, NStream, filter, extract);
                }
            }
            return(createExtractResult((Region)Header.ReadUInt32B(0x4e000), null));
        }
예제 #3
0
        public ExtractResult ExtractFilesWii(Func <ExtractedFile, bool> filter, Action <Stream, ExtractedFile> extract)
        {
            List <ExtractResult>    result    = new List <ExtractResult>();
            List <WiiPartitionInfo> toExtract = new List <WiiPartitionInfo>();
            WiiDiscHeaderSection    hdr       = null;
            bool seekMode = !NStream.IsIsoDec; //experimental as iso.dec may not be able to seek to group start, archives will read ahead not seek

            ExtractedFile exFile;

            foreach (IWiiDiscSection s in this.EnumerateSectionsFix(false, true, false))
            {
                if (s is WiiDiscHeaderSection)
                {
                    hdr    = (WiiDiscHeaderSection)s;
                    exFile = new ExtractedFile(this.IsGameCube ? DiscType.GameCube : DiscType.Wii,
                                               this.NStream.Id8, null, 0, hdr.Size, "", "hdr.bin", ExtractedFileType.WiiDiscItem);
                    if (filter(exFile))
                    {
                        using (MemoryStream ms = new MemoryStream(hdr.Data))
                            extract(ms, exFile);
                    }
                }
                else if (s is WiiPartitionSection)
                {
                    WiiPartitionSection ps = (WiiPartitionSection)s;

                    if (ps.Header.Id != "\0\0\0\0")
                    {
                        exFile = new ExtractedFile(this.IsGameCube ? DiscType.GameCube : DiscType.Wii,
                                                   this.NStream.Id8, null, ps.Header.DiscOffset, ps.Header.Size, "", ps.Header.Id + "hdr.bin", ExtractedFileType.WiiDiscItem);
                        if (filter(exFile))
                        {
                            using (MemoryStream ms = new MemoryStream(ps.Header.Data))
                                extract(ms, exFile);
                        }
                    }

                    using (StreamCircularBuffer decrypted = new StreamCircularBuffer(ps.PartitionDataLength, null, null, output =>
                    {
                        foreach (WiiPartitionGroupSection pg in ps.Sections)
                        {
                            for (int i = 0; i < pg.Size / 0x8000; i++)
                            {
                                output.Write(pg.Decrypted, (i * 0x8000) + 0x400, 0x7c00);
                            }
                        }
                    }))
                    {
                        if (ps.Header.Id == "\0\0\0\0")
                        {
                            decrypted.Copy(Stream.Null, ps.PartitionDataLength);
                        }
                        else
                        {
                            extractFiles(ps.Id, new MemorySection(ps.Header.Data), decrypted, filter, extract);
                        }
                    }
                }
                else if (s is WiiFillerSection)
                {
                }
            }
            return(createExtractResult((Region)hdr.ReadUInt32B(0x4e000), null));
        }