Exemple #1
0
 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);
 }
Exemple #2
0
        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);
            }
        }
Exemple #3
0
 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;
         }
     }
 }
Exemple #4
0
 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);
             }
         }
     }
 }
Exemple #5
0
 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);
 }