Exemplo n.º 1
0
 public ContentSection(ZipEntry entry)
 {
     Id = Path.GetFileNameWithoutExtension(entry.FileName);
     ArchivePath = entry.FileName;
     using (Stream s = entry.OpenReader())
     {
         using (StreamReader sr = new StreamReader(s))
         {
             Content = sr.ReadToEnd();
         }
     }
 }
Exemplo n.º 2
0
 public OpfMetadataFile(ZipEntry file, string password)
 {
     try
     {
         using (Stream s = (String.IsNullOrEmpty(password) ? file.OpenReader() : file.OpenReader(password)))
         {
             using (StreamReader sr = new StreamReader(s))
             {
                 try
                 {
                     content = XDocument.Parse(sr.ReadToEnd());
                 }
                 catch (Exception ex)
                 {
                     throw new MetadataParseException(ex, "Nie można było otworzyć pliku z metadanymi. Może to być spowodowane uszkodzeniem jego struktury XMLowej, niewłaściwym kodowaniem, albo brakiem dostępu.");
                 }
             }
         }
     }
     catch (Exception ex)
     {
         throw new EpubFileException(ex, "Błąd w rozpakowywaniu pliku ePub. Może to być spowodowane uszkodzeniem pliku, brakiem plików z metadanymi bądź brakiem dostępu.");
     }
 }
Exemplo n.º 3
0
        public static string GetStringFile(ZipEntry zipEntry)
        {
            if (zipEntry != null)
            {
                using (var stream = zipEntry.OpenReader())
                {
                    using (StreamReader sr = new StreamReader(stream, KPGenericUtil.GetDefaultEncoding()))
                    {
                        string fileString = sr.ReadToEnd();
                        return fileString;
                    }
                }
            }

            return String.Empty;
        }
        private static void Save(ZipEntry entry, string outputFilePath)
        {
            using (var input = entry.OpenReader())
            {
                var folderPath = Path.GetDirectoryName(outputFilePath);
                if (!Directory.Exists(folderPath))
                {
                    Directory.CreateDirectory(folderPath);
                }

                using (Stream output = File.OpenWrite(outputFilePath))
                {
                    CopyStream(input, output);
                }
            }
        }
Exemplo n.º 5
0
 protected void IterateOverCSVZipEntry(ZipEntry entry, Func<GenericParserAdapter, bool> func)
 {
     using (var reader = new StreamReader(entry.OpenReader())) {
         using (var parser = new GenericParserAdapter(reader)) {
             parser.ColumnDelimiter = ',';
             parser.FirstRowHasHeader = true;
             parser.TextQualifier = '\"';
             parser.FirstRowSetsExpectedColumnCount = true;
             while (parser.Read()) {
                 if (func != null) {
                     if (!func(parser)) {
                         return;
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 6
0
        /// <summary>
        /// Provide Entry Content
        /// </summary>
        /// <param name="ze"></param>
        /// <returns></returns>
        private List<string> Input2String(ZipEntry ze)
        {
            List<string> result = new List<string>();
            try
            {
                using (var s = ze.OpenReader())
                {
                    var sr = new StreamReader(s);
                    string line = sr.ReadLine();
                    while (line != null)
                    {
                        result.Add(line);
                        line = sr.ReadLine();
                    }
                    
                }
                //using (var ms = new MemoryStream())
                //{
                //    int n;
                //    var buffer = new byte[1024];
                //    while ((n = s.Read(buffer, 0, buffer.Length)) > 0)
                //        ms.Write(buffer, 0, n);
                //    ms.Seek(0, SeekOrigin.Begin);

                //    var sr = new StreamReader(ms);
                //    result = sr.ReadToEnd();

                //    sr.Close();
                //    sr.Dispose();
                //}
            }
            catch (Exception ex)
            { throw ex; }

            return result;
        }
Exemplo n.º 7
0
 private void ExtractTestStepIndex(ZipEntry entry)
 {
     using (var reader = new StreamReader(entry.OpenReader()))
     {
         var text = reader.ReadToEnd();
         TestStepIndex = int.Parse(text);
     }
 }
Exemplo n.º 8
0
 static ErrorLog ErrorLog(ZipEntry entry)
 {
     using(var reader = entry.OpenReader())
     using(var stream = new StreamReader(reader))
         return (ErrorLog) serializer.Deserialize(stream);
 }
 private void ExtractEnvironmentName(ZipEntry entry)
 {
     using (var reader = new StreamReader(entry.OpenReader()))
     {
         Environment = reader.ReadToEnd();
     }
 }
Exemplo n.º 10
0
		private static void UpdateXmlEntity(ZipEntry entry, string selector, Action<XElement> update, ZipFile zip, IXmlNamespaceResolver nsResolver)
		{
			var output = new MemoryStream();
			using (var entryStream = entry.OpenReader())
			{
				var xml = XDocument.Load(entryStream);
				update(xml.XPathSelectElement(selector, nsResolver));
				xml.Save(output);
			}
			zip.UpdateEntry(entry.FileName, output.GetBuffer());
			zip.Save();
		}
Exemplo n.º 11
0
		private static void UpdateCsFiles(ZipEntry entry, string slideId, ZipFile zip)
		{
			string code;
			using (var entryStream = entry.OpenReader())
			{
				code = new StreamReader(entryStream).ReadToEnd();
			}
			code = Regex.Replace(code, "(?<=\\[Slide\\(\".*\",\\s*\").+(?=\"\\)\\])", slideId);
			zip.UpdateEntry(entry.FileName, code, Encoding.UTF8);
			zip.Save();
		}
Exemplo n.º 12
0
 public void AddModFile(ZipEntry ModFile)
 {
     AddModFile(ModFile.OpenReader(), ModFile.FileName);
 }
Exemplo n.º 13
0
		private void CopyFileInZipToLocation(ZipEntry entry)
		{
			string targetFilePath = CreateTargetPathForZipEntry(entry);
			if (File.Exists(targetFilePath))
				return;
			using (var stream = entry.OpenReader())
			using (var memoryStream = new MemoryStream())
			{
				stream.CopyTo(memoryStream);
				File.WriteAllBytes(targetFilePath, memoryStream.ToArray());
			}
		}