public override void Rebuild(string outputFolder)
        {
            var outputPath = System.IO.Path.Combine(outputFolder, RelativePath);

            Directory.CreateDirectory(System.IO.Path.GetDirectoryName(outputPath));

            var subtitles = GetSubtitles();

            using (var fsInput = new FileStream(Path, FileMode.Open))
                using (var input = new ExtendedBinaryReader(fsInput, FileEncoding))
                    using (var fsOutput = new FileStream(outputPath, FileMode.Create))
                        using (var output = new ExtendedBinaryWriter(fsOutput, FileEncoding))
                        {
                            var tableEnd = input.PeekUInt16();

                            long outputOffset = tableEnd;

                            while (input.Position < tableEnd)
                            {
                                var item = ReadItem(input);

                                outputOffset = WriteItem(output, subtitles, item, outputOffset);
                            }
                        }
        }
        public override void Rebuild(string outputFolder)
        {
            var outputPath = System.IO.Path.Combine(outputFolder, RelativePath);

            Directory.CreateDirectory(System.IO.Path.GetDirectoryName(outputPath));

            var subtitles = GetSubtitles();

            using (var fsInput = new FileStream(Path, FileMode.Open))
                using (var input = new ExtendedBinaryReader(fsInput, FileEncoding))
                    using (var fsOutput = new FileStream(outputPath, FileMode.Create))
                        using (var output = new ExtendedBinaryWriter(fsOutput, FileEncoding))
                        {
                            var  tableEnd     = input.PeekUInt16();
                            long outputOffset = tableEnd;

                            var itemOffsets = new List <ushort>(tableEnd / 2);

                            for (var i = 0; i < tableEnd / 2; i++)
                            {
                                var offset = input.ReadUInt16();
                                itemOffsets.Add(offset);
                            }

                            itemOffsets.Sort();

                            var dictionary = new Dictionary <ushort, int>();

                            for (var i = 0; i < itemOffsets.Count - 1; i++)
                            {
                                dictionary.Add(itemOffsets[i], itemOffsets[i + 1] - itemOffsets[i]);
                            }

                            dictionary.Add(itemOffsets[itemOffsets.Count - 1], (int)(input.Length - itemOffsets[itemOffsets.Count - 1]));

                            input.Seek(0, SeekOrigin.Begin);
                            for (var i = 0; i < itemOffsets.Count; i++)
                            {
                                var offset = input.ReadUInt16();
                                var size   = dictionary[offset];

                                var item = ReadItem(input, offset, size);
                                outputOffset = WriteItem(output, subtitles, item, outputOffset);
                            }
                        }
        }
        protected override IList <Subtitle> GetSubtitles()
        {
            var result = new List <Subtitle>();

            using (var fs = new FileStream(Path, FileMode.Open))
                using (var input = new ExtendedBinaryReader(fs, FileEncoding))
                {
                    var tableEnd = input.PeekUInt16();

                    var itemOffsets = new List <ushort>(tableEnd / 2);
                    var itemLengths = new int[tableEnd / 2];

                    for (var i = 0; i < tableEnd / 2; i++)
                    {
                        var offset = input.ReadUInt16();
                        itemOffsets.Add(offset);
                    }

                    itemOffsets.Sort();

                    for (var i = 0; i < itemOffsets.Count - 1; i++)
                    {
                        itemLengths[i] = itemOffsets[i + 1] - itemOffsets[i];
                    }

                    itemLengths[itemLengths.Length - 1] = (int)(input.Length - itemOffsets[itemOffsets.Count - 1]);

                    input.Seek(0, SeekOrigin.Begin);
                    for (var i = 0; i < itemOffsets.Count; i++)
                    {
                        var item = ReadItem(input, itemOffsets[i], itemLengths[i]);

                        item.Title.PropertyChanged += SubtitlePropertyChanged;

                        result.Add(item.Title);
                    }
                }

            LoadChanges(result);

            return(result);
        }
예제 #4
0
        protected override IList <Subtitle> GetSubtitles()
        {
            var result = new List <Subtitle>();

            using (var fs = new FileStream(Path, FileMode.Open))
                using (var input = new ExtendedBinaryReader(fs, FileEncoding))
                {
                    var tableEnd = input.PeekUInt16();
                    while (input.Position < tableEnd)
                    {
                        var subtitle = ReadSubtitle(input);
                        subtitle.PropertyChanged += SubtitlePropertyChanged;
                        result.Add(subtitle);
                    }
                }

            LoadChanges(result);

            return(result);
        }