/// <summary> /// Extract files from the input PPTX zip archive to the specified physical directory /// The source archive is handled by the resolver, while the destination correspond to physical dir /// </summary> /// <param name="source">Relative path inside the source archive</param> /// <param name="destination">Destination folder name and file name seperated by '|' character</param> private void extractFile(string destination, string source) { // Retrive the Target folder name and Filename string targetFolderName = destination.Substring(0, destination.IndexOf('|')); string targetFileName = destination.Substring(destination.IndexOf('|') + 1); //GetOutputFilepath - gets the path where the output ODP file will be copied string strCurrentDirectory = getOutputFilePath(); string strDestinationFilePath = strCurrentDirectory.Replace("\\", "//") + "//" + targetFolderName; //get the zipArchive stream try { Stream inputStream = getStream(source); if (inputStream != null) { Directory.CreateDirectory(strDestinationFilePath); strDestinationFilePath = strDestinationFilePath + "//" + targetFileName; if (!File.Exists(strDestinationFilePath)) { FileStream fsFile = new FileStream(strDestinationFilePath, FileMode.Create); streamCopy(inputStream, fsFile); fsFile.Close(); } } } catch (IOException e) { ZipException exZip = new ZipException(e.Message); throw exZip; } }
/// <summary> /// Imoprt files from the specified physical directory to otuput PPTX zip archive /// The destination archive is handled by the resolver, while the source corresponds to physical dir /// </summary> /// <param name="source">Source file pysical path - Relative/absolute </param> /// <param name="destination">Destination path inside zip archive</param> private void importFile(string destination, string source) { string inputFilePath = ""; //Resolve relative path if (source.StartsWith("../")) { inputFilePath = Path.GetFullPath(Path.Combine(getInputFilePath(), source.Remove(0, 3))).Replace("/", "//").Replace("%20", " "); } else { inputFilePath = source.Replace("/", "//").Replace("%20", " "); } try { //Copy referd audio fiels from external directory to ppt/media if (_zipOutputStream != null) { if (File.Exists(inputFilePath)) { _zipOutputStream.AddEntry(destination); FileStream fsSourceFile = new FileStream(inputFilePath, FileMode.Open, FileAccess.Read); int bytesCopied = streamCopy(fsSourceFile, _zipOutputStream); Debug.WriteLine("CopyBinary : " + inputFilePath + " --> " + destination + ", bytes copied = " + bytesCopied); } else { _zipOutputStream.AddEntry(destination); string CurrDir = Environment.CurrentDirectory; inputFilePath = Path.GetFullPath(Path.Combine(CurrDir + "\\", source.Remove(0, 3))).Replace("/", "//").Replace("%20", " "); if (File.Exists(inputFilePath)) { FileStream fsSourceFile = new FileStream(inputFilePath, FileMode.Open, FileAccess.Read); int bytesCopied = streamCopy(fsSourceFile, _zipOutputStream); Debug.WriteLine("CopyBinary : " + inputFilePath + " --> " + destination + ", bytes copied = " + bytesCopied); } } } } catch (IOException e) { ZipException exZip = new ZipException(e.Message); throw exZip; } }