Example #1
0
        /// <summary>
        /// Generate a list of DatItem objects from the header values in an archive
        /// </summary>
        /// <returns>List of DatItem objects representing the found data</returns>
        public override List <BaseFile> GetChildren()
        {
            if (_children == null || _children.Count == 0)
            {
                _children = new List <BaseFile>();

                string gamename = Path.GetFileNameWithoutExtension(this.Filename);

                BaseFile possibleTgz = GetTorrentGZFileInfo();

                // If it was, then add it to the outputs and continue
                if (possibleTgz != null && possibleTgz.Filename != null)
                {
                    _children.Add(possibleTgz);
                }
                else
                {
                    try
                    {
                        // Create a blank item for the entry
                        BaseFile gzipEntryRom = new BaseFile();

                        // Perform a quickscan, if flagged to
                        if (this.AvailableHashes == Hash.CRC)
                        {
                            gzipEntryRom.Filename = gamename;
                            using (BinaryReader br = new BinaryReader(FileExtensions.TryOpenRead(this.Filename)))
                            {
                                br.BaseStream.Seek(-8, SeekOrigin.End);
                                gzipEntryRom.CRC  = br.ReadBytesBigEndian(4);
                                gzipEntryRom.Size = br.ReadInt32BigEndian();
                            }
                        }
                        // Otherwise, use the stream directly
                        else
                        {
                            var       gz  = new gZip();
                            ZipReturn ret = gz.ZipFileOpen(this.Filename);
                            ret                   = gz.ZipFileOpenReadStream(0, out Stream gzstream, out ulong streamSize);
                            gzipEntryRom          = gzstream.GetInfo(hashes: this.AvailableHashes);
                            gzipEntryRom.Filename = gz.Filename(0);
                            gzipEntryRom.Parent   = gamename;
                            gzipEntryRom.Date     = (gz.TimeStamp > 0 ? gz.TimeStamp.ToString() : null);
                            gzstream.Dispose();
                        }

                        // Fill in comon details and add to the list
                        gzipEntryRom.Parent = gamename;
                        _children.Add(gzipEntryRom);
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex);
                        return(null);
                    }
                }
            }

            return(_children);
        }