예제 #1
0
        /// <summary>
        /// This method decompresses a file
        /// </summary>
        /// <param name="sourceFolderOrFile">File or folder to be decompressed</param>
        /// <param name="destinationCompressFile">Resultant file or folder to created after decompression</param>
        /// <param name="isItAFolder">Used as <c>isItAFolder?</c> flag</param>
        /// <param name="xceedLicenseKey">License Key for Xceed Library</param>
        /// <returns>Returns if file or decompression was successful or not</returns>
        public bool CompressFileOrFolder(string sourceFolderOrFile, string destinationCompressFile, bool isItAFolder, string xceedLicenseKey)
        {
            if (string.IsNullOrWhiteSpace(sourceFolderOrFile))
            {
                throw new ArgumentNullException("sourceFolderOrFile");
            }
            if (string.IsNullOrWhiteSpace(destinationCompressFile))
            {
                throw new ArgumentNullException("destinationCompressFile");
            }
            Licenser.LicenseKey = xceedLicenseKey;

            try
            {
                if (isItAFolder)
                {
                    QuickZip.Zip(destinationCompressFile, false, false, false, Directory.EnumerateFiles(sourceFolderOrFile).ToArray());
                }
                else
                {
                    QuickZip.Zip(destinationCompressFile, false, false, false, sourceFolderOrFile);
                }

                return(true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// This private method uses XCeed library to compress the folder or file
        /// </summary>
        /// <param name="sourceFolderOrFile">Folder or file to be compressed</param>
        /// <param name="destinationCompressFile">Name of the resultant compressed file</param>
        /// <param name="blnCompressFolder">It indicate whether to compress a folder or a file</param>
        /// <returns></returns>
        private static bool DoCompress(string sourceFolderOrFile, string destinationCompressFile, bool blnCompressFolder, string XceedLicenseKey)
        {
            if (string.IsNullOrWhiteSpace(sourceFolderOrFile))
            {
                throw new ArgumentNullException("sourceFolderOrFile");
            }
            if (string.IsNullOrWhiteSpace(destinationCompressFile))
            {
                throw new ArgumentNullException("destinationCompressFile");
            }

            Xceed.Zip.Licenser.LicenseKey = XceedLicenseKey;

            try
            {
                if (blnCompressFolder)
                {
                    QuickZip.Zip(destinationCompressFile,
                                 false,
                                 false,
                                 false,
                                 Directory.EnumerateFiles(sourceFolderOrFile).ToArray());
                }
                else
                {
                    QuickZip.Zip(destinationCompressFile, false, false, false, sourceFolderOrFile);
                }
                return(true);
            }
            catch
            {
                throw;
            }
        }
예제 #3
0
        /// <summary>
        /// Unzip a file and any zip files contained within it.
        /// </summary>
        /// <param name="zipFile">path of zipfile</param>
        /// <returns>true if file successfully unzipped, false if it failed</returns>
        private bool UnzipFile(string zipFile)
        {
            try
            {
                //Unzip the zip file
                string zipFileName = Path.GetFileName(zipFile);

                //DV NT Re-eng Phase 1 set as a public for use elsewhere
                _zipFileName = zipFileName;
                // create a public guid for the big zip file - not working as this is called for each little zip
                _guid = Guid.NewGuid().ToString();

                string zipFilePath   = zipFile.Replace(zipFileName, "");
                string zipFileSubDir = zipFilePath + zipFileName.Substring(0, zipFileName.Length - 4);
                Directory.CreateDirectory(zipFileSubDir);
                QuickZip.Unzip(zipFile, zipFileSubDir, new string[] { "*" });

                //Scan the unipped contents for input files
                ScanForInputFiles(zipFileSubDir);
                //DirectoryInfo dirInfo = new DirectoryInfo(zipFileSubDir);
                //dirInfo.Delete(true);
            }
            catch (Exception e)
            {
                NexdoxMessaging.SendMessage("Failed to unzip file: " + zipFile + " error message: " + e.Message, true, this);

                //_errorFiles.Add();
                return(false);
            }

            return(true);
        }
        public static void ZipDownloadHandler(IHttpContext context)
        {
            var path = new BackSlashPath(ExamplesConfiguration.UnprotectString(context.Request["path"])).RemoveTrailingSlash();

            var fileResponse = new FileResponse(context, 0);

            fileResponse.Transmit((targetStream) =>
            {
                QuickZip.Zip(targetStream, Directory.EnumerateFileSystemEntries(path));
            }, path.FileName + ".zip", 0);
        }
예제 #5
0
        /// <summary>
        /// This private method uses XCeed library to decompress the folder or file
        /// </summary>
        /// <param name="compressedFile">Name of the file to be decompressed</param>
        /// <param name="destinationPath">Path where ExtractToFolder will be created</param>
        /// <param name="extractToFolder">ExtractToFolder contains all the decompressed files</param>
        /// <param name="emailInterchangeId">Email Interchange ID</param>
        /// <param name="requestType">Request Type</param>
        /// <param name="isItAFolder">It indicate whether to decompress a folder or a file, since we made this as Optional parameter by default it will takes true</param>
        /// <param name="canDeleteCompressedfile">It indicate whether to delete the compressed folder after the decompression or not, if true it will delete the compressed fodler</param>
        /// <returns></returns>
        public bool DecompressFileOrFolder(string compressedFile, string destinationPath, string extractToFolder, string xceedLicenseKey, bool isItAFolder = true, bool canDeleteCompressedfile = false)
        {
            if (string.IsNullOrWhiteSpace(compressedFile))
            {
                throw new ArgumentNullException("compressedFile");
            }
            Xceed.Zip.Licenser.LicenseKey = xceedLicenseKey;

            try
            {
                if (isItAFolder)
                {
                    if (string.IsNullOrWhiteSpace(destinationPath))
                    {
                        throw new ArgumentNullException("destinationPath");
                    }
                    if (string.IsNullOrWhiteSpace(extractToFolder))
                    {
                        throw new ArgumentNullException("extractToFolder");
                    }

                    destinationPath = Path.Combine(destinationPath, extractToFolder);
                    if (!Directory.Exists(destinationPath))
                    {
                        Directory.CreateDirectory(destinationPath);
                    }
                    QuickZip.Unzip(compressedFile, destinationPath, "*");
                }
                else
                {
                    var compressedFileInfo = new FileInfo(compressedFile);
                    QuickZip.Unzip(compressedFile, compressedFileInfo.Directory.FullName, "*");
                }

                if (canDeleteCompressedfile && File.Exists(compressedFile))
                {
                    System.IO.File.Delete(compressedFile);
                }
                return(true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #6
0
        protected string ExtractContents(FileInfo fileInfo)
        {
            var freeDiskSpace = fileInfo.Directory.Root.Name.GetFreeDiskSpace();

            if (3.0 * fileInfo.Length > freeDiskSpace)
            {
                throw new ApplicationException(string.Format(@"--- The current free disk space <{0}> of drive <{1}> is not enough to extracting the contents!", freeDiskSpace, fileInfo.Directory.Root));
            }

            var extractedFolder = Path.Combine(_extractingResultsDir, fileInfo.MD5().ToString());

            CreateSubfolder(extractedFolder, fileInfo.Name);

            fileInfo.FullName.RemoveFileReadOnlyAttribute();
            QuickZip.Unzip(fileInfo.FullName, extractedFolder, _password, true, true, true, "*");
            //File.Delete(fileInfo.FullName);

            return(extractedFolder);
        }
예제 #7
0
 public void Zip(string zipFile, string[] files)
 {
     QuickZip.Zip(zipFile, true, true, false, files);
 }
예제 #8
0
 public void ExtractArchiveTo(string distinationFolder, string password = null)
 {
     QuickZip.Unzip(_sourceArchiveFile, distinationFolder, password, true, true, true, "*");
 }