示例#1
0
        private Stream GetTableDataStream()
        {
            var stream    = _stream;
            var offset    = _offset;
            var tableSize = (int)_utfReader.PeekUInt32(stream, offset, 4) + 8;

            if (!IsEncrypted)
            {
                return(AcbHelper.ExtractToNewStream(stream, offset, tableSize));
            }
            // Another reading process. Unlike the one with direct reading, this may encounter UTF table decryption.
            var originalPosition = stream.Position;
            var totalBytesRead   = 0;
            var memory           = new byte[tableSize];
            var currentIndex     = 0;
            var currentOffset    = offset;

            do
            {
                var shouldRead = tableSize - totalBytesRead;
                var buffer     = _utfReader.PeekBytes(stream, currentOffset, shouldRead, totalBytesRead);
                Array.Copy(buffer, 0, memory, currentIndex, buffer.Length);
                currentOffset  += buffer.Length;
                currentIndex   += buffer.Length;
                totalBytesRead += buffer.Length;
            } while (totalBytesRead < tableSize);
            stream.Position = originalPosition;
            var memoryStream = new MemoryStream(memory, false)
            {
                Capacity = tableSize
            };

            memoryStream.Seek(0, SeekOrigin.Begin);
            return(memoryStream);
        }
示例#2
0
        private Stream GetDataStreamFromCueInfo(AcbCueRecord cue, string fileNameForErrorInfo)
        {
            if (!cue.IsWaveformIdentified)
            {
                throw new InvalidOperationException($"File '{fileNameForErrorInfo}' is not identified.");
            }

            Stream result;

            if (cue.IsStreaming)
            {
                var externalAwb = ExternalAwb;
                if (externalAwb == null)
                {
                    throw new InvalidOperationException($"External AWB does not exist for streaming file '{fileNameForErrorInfo}'.");
                }

                if (!externalAwb.Files.ContainsKey(cue.WaveformId))
                {
                    throw new InvalidOperationException($"Waveform ID {cue.WaveformId} is not found in AWB file {externalAwb.FileName}.");
                }

                var targetExternalFile = externalAwb.Files[cue.WaveformId];

                using (var fs = File.Open(externalAwb.FileName, FileMode.Open, FileAccess.Read, FileShare.Read)) {
                    result = AcbHelper.ExtractToNewStream(fs, targetExternalFile.FileOffsetAligned, (int)targetExternalFile.FileLength);
                }
            }
            else
            {
                var internalAwb = InternalAwb;

                if (internalAwb == null)
                {
                    throw new InvalidOperationException($"Internal AWB is not found for memory file '{fileNameForErrorInfo}' in '{AcbFileName}'.");
                }

                if (!internalAwb.Files.ContainsKey(cue.WaveformId))
                {
                    throw new InvalidOperationException($"Waveform ID {cue.WaveformId} is not found in internal AWB in {AcbFileName}.");
                }

                var targetInternalFile = internalAwb.Files[cue.WaveformId];

                result = AcbHelper.ExtractToNewStream(Stream, targetInternalFile.FileOffsetAligned, (int)targetInternalFile.FileLength);
            }

            return(result);
        }
示例#3
0
        public Stream OpenDataStream(string fileName)
        {
            AcbCueRecord cue;

            try {
                cue = Cues.Single(c => c.CueName == fileName);
            } catch (InvalidOperationException ex) {
                throw new InvalidOperationException($"File '{fileName}' is not found or it has multiple entries.", ex);
            }
            if (!cue.IsWaveformIdentified)
            {
                throw new InvalidOperationException($"File '{fileName}' is not identified.");
            }
            if (cue.IsStreaming)
            {
                var externalAwb = ExternalAwb;
                if (externalAwb == null)
                {
                    throw new InvalidOperationException($"External AWB does not exist for streaming file '{fileName}'.");
                }
                if (!externalAwb.Files.ContainsKey(cue.WaveformId))
                {
                    throw new InvalidOperationException($"Waveform ID {cue.WaveformId} is not found in AWB file {externalAwb.FileName}.");
                }
                var targetExternalFile = externalAwb.Files[cue.WaveformId];
                using (var fs = File.Open(externalAwb.FileName, FileMode.Open, FileAccess.Read)) {
                    return(AcbHelper.ExtractToNewStream(fs, targetExternalFile.FileOffsetAligned, (int)targetExternalFile.FileLength));
                }
            }
            else
            {
                var internalAwb = InternalAwb;
                if (internalAwb == null)
                {
                    throw new InvalidOperationException($"Internal AWB is not found for memory file '{fileName}' in '{AcbFileName}'.");
                }
                if (!internalAwb.Files.ContainsKey(cue.WaveformId))
                {
                    throw new InvalidOperationException($"Waveform ID {cue.WaveformId} is not found in internal AWB in {AcbFileName}.");
                }
                var targetInternalFile = internalAwb.Files[cue.WaveformId];
                return(AcbHelper.ExtractToNewStream(Stream, targetInternalFile.FileOffsetAligned, (int)targetInternalFile.FileLength));
            }
        }