예제 #1
0
        private async Task LoadCBRComic(StorageFile storageFile)
        {
            try
            {
                using (var zipStream = await storageFile.OpenStreamForReadAsync())
                    using (var memoryStream = new MemoryStream((int)zipStream.Length))
                    {
                        await zipStream.CopyToAsync(memoryStream);

                        memoryStream.Position = 0;

                        var rarArchive = RarArchive.Open(memoryStream);

                        if (rarArchive == null)
                        {
                            return;
                        }

                        var comic = new DisplayComic
                        {
                            File     = storageFile,
                            FullPath = storageFile.Name,
                            Name     = storageFile.DisplayName,
                            Pages    = rarArchive.Entries.Count
                        };

                        foreach (var entry in rarArchive.Entries)
                        {
                            if (IsValidEntry(entry))
                            {
                                continue;
                            }

                            using (var entryStream = new MemoryStream((int)entry.Size))
                            {
                                entry.WriteTo(entryStream);
                                entryStream.Position = 0;

                                using (var binaryReader = new BinaryReader(entryStream))
                                {
                                    var bytes = binaryReader.ReadBytes((int)entryStream.Length);

                                    comic.CoverageImageBytes = bytes;

                                    break;
                                }
                            }
                        }

                        comics.Add(comic);
                    }
            }
            catch (Exception ex)
            {
                // Do nothing
            }
        }
예제 #2
0
        private async Task LoadCBZComic(StorageFile storageFile)
        {
            try
            {
                using (var zipStream = await storageFile.OpenStreamForReadAsync())
                    using (var memoryStream = new MemoryStream((int)zipStream.Length))
                    {
                        zipStream.Position = 0;

                        await zipStream.CopyToAsync(memoryStream);

                        using (var archive = new ZipArchive(memoryStream, ZipArchiveMode.Read))
                        {
                            foreach (var entry in archive.Entries)
                            {
                                if (IsValidEntry(entry))
                                {
                                    continue;
                                }

                                var stream = entry.Open();

                                using (var binaryReader = new BinaryReader(stream))
                                {
                                    var bytes = binaryReader.ReadBytes(2245999);

                                    var comic = new DisplayComic
                                    {
                                        File               = storageFile,
                                        FullPath           = storageFile.Name,
                                        Name               = storageFile.DisplayName,
                                        Pages              = archive.Entries.Count,
                                        CoverageImageBytes = bytes
                                    };

                                    comics.Add(comic);

                                    return;
                                }
                            }
                        }
                    }
            }
            catch (Exception ex)
            {
                // Do nothing
            }
        }