public async Task AppendAsync(string fileName, IProgress <int> progress) { using (EnterSingleOperation()) using (Images.EnterUnnotifiedSection()) using (var bookmarks = new BookmarkCollection()) await ReadFileAsync(fileName, bookmarks, progress).ConfigureAwait(false); }
async Task <FileHeader> ReadFileAsync(string fileName, BookmarkCollection bookmarks, IProgress <int> progress) { using (FileStream readStream = new FileStream(fileName, FileMode.Open, FileAccess.Read)) { var cic = FileHeader.Load(readStream); // ID確認 if (cic == null) { throw new ArgumentException(Properties.Resources.InvalidFileFormat); } bookmarks.Load(readStream); // 目次 await Images.LoadAsync(readStream, cic.FileVersion, progress).ConfigureAwait(false); // 画像 return(cic); } }
protected virtual void Dispose(bool disposing) { if (disposing) { using (EnterUndirtiableSection()) { if (_images != null) { _images.Clear(); _images.Dispose(); _images = null; } if (_bookmarks != null) { _bookmarks.Clear(); _bookmarks.Dispose(); _bookmarks = null; } Thumbnail = null; Title = Author = string.Empty; IsDirty = false; } } }
static async Task WriteFileAsync(string fileName, IReadOnlyList <ImageReference> images, FileHeader cic, BookmarkCollection bookmarks, IProgress <int> progress) { using (FileStream writeStream = new FileStream(fileName, FileMode.Create, FileAccess.Write)) { cic.Save(writeStream); bookmarks.Save(writeStream); using (BinaryWriter writer = new BinaryWriter(writeStream, System.Text.Encoding.Unicode, true)) { writer.Write(images.Count); // 画像数 for (int i = 0; i < images.Count; i++) { await images[i].SaveAsync(writer).ConfigureAwait(false); progress?.Report((i + 1) * 100 / images.Count); } } } }
public async Task ExtractAsync(string fileName, IEnumerable <ImageReference> images, IProgress <int> progress) { using (EnterSingleOperation()) using (var bookmarks = new BookmarkCollection()) await WriteFileAsync(fileName, images.ToArray(), new FileHeader(string.Empty, Author, null, PageTurningDirection, null), bookmarks, progress).ConfigureAwait(false); }