コード例 #1
0
ファイル: BookSaver.cs プロジェクト: cupa/Bookinator
        public void Save(Book book)
        {
            var file     = book.File;
            var bookZip  = ZipFile.Open(file, ZipArchiveMode.Update);
            var tempFile = @"C:\Users\pgathany\Desktop\Personal\Books\tempDirectory" + Path.GetFileNameWithoutExtension(file);

            bookZip.ExtractToDirectory(tempFile);

            var tempBookFiles    = directory.GetFiles(tempFile, "*.opf", SearchOption.AllDirectories);
            var opf              = tempBookFiles.FirstOrDefault(f => f.EndsWith(".opf"));
            var doc              = XDocument.Load(opf);
            var elements         = doc.Root.Elements();
            var metadata         = elements.Where(e => e.Name.LocalName == "metadata").FirstOrDefault();
            var metaDataElements = metadata.Elements();

            var title = metaDataElements.Where(e => e.Name.LocalName == "title").FirstOrDefault();

            title.Value = book.Title;

            var creator = metaDataElements.Where(e => e.Name.LocalName == "creator").FirstOrDefault();

            creator.Value = book.Creator;
            File.Delete(opf);
            doc.Save(opf);
            File.Delete(file);
            ZipFile.CreateFromDirectory(tempFile, file);
            directory.Delete(tempFile, true);
        }
コード例 #2
0
 /// <summary>
 /// Cleans up coverage report directory
 /// </summary>
 private void CleanupReportDirectory()
 {
     try
     {
         if (_directoryHelper.Exists(_reportDirectory))
         {
             _directoryHelper.Delete(_reportDirectory, true);
             _eqtTrace.Verbose("{0}: Deleted report directory: '{1}'", CoverletConstants.DataCollectorName, _reportDirectory);
         }
     }
     catch (Exception ex)
     {
         string errorMessage = string.Format(Resources.FailedToCleanupReportDirectory, CoverletConstants.DataCollectorName, _reportDirectory);
         throw new CoverletDataCollectorException(errorMessage, ex);
     }
 }
コード例 #3
0
ファイル: BookSaver.cs プロジェクト: cupa/Bookinator
 private void OverwriteEpub(string file, string tempFile)
 {
     File.Delete(file);
     using (var zip = new Ionic.Zip.ZipFile())
     {
         var mime = zip.AddEntry("mimetype", "application/epub+zip", Encoding.ASCII);
         zip.UseZip64WhenSaving = Ionic.Zip.Zip64Option.Never;
         mime.CompressionLevel  = Ionic.Zlib.CompressionLevel.None;
         mime.CompressionMethod = Ionic.Zip.CompressionMethod.None;
         var metaDir = Path.Combine(tempFile, "META-INF");
         var meta    = zip.AddDirectory(metaDir, "META-INF");
         meta.CompressionLevel = Ionic.Zlib.CompressionLevel.None;
         var contentDir = Path.Combine(tempFile, "OEBPS");
         var content    = zip.AddDirectory(contentDir, "OEBPS");
         content.CompressionLevel = Ionic.Zlib.CompressionLevel.None;
         zip.Save(file);
     }
     directory.Delete(tempFile, true);
 }