示例#1
0
        private ZipOptions CreateZipOptionsForMove()
        {
            ZipOptions zopt = CreateZipOptions();

            zopt.fMove = 1;
            return(zopt);
        }
示例#2
0
        private ZipOptions CreateZipOptionsForFreshen()
        {
            ZipOptions zopt = CreateZipOptions();

            zopt.fFreshen = 1;
            return(zopt);
        }
示例#3
0
        /// <summary>
        /// Creates the zip options for update files in zip archive.
        /// </summary>
        /// <returns>ZipOptions structure, prepared for files update operation</returns>
        private ZipOptions CreateZipOptionsForUpdate()
        {
            ZipOptions zopt = CreateZipOptions();

            zopt.fUpdate = 1;
            return(zopt);
        }
示例#4
0
        /// <summary>
        /// Creates the zip options for delete files opration.
        /// </summary>
        /// <returns>ZipOptions structure prepared for deleting files opration</returns>
        private ZipOptions CreateZipOptionsForDelete()
        {
            ZipOptions zopt = CreateZipOptions();

            zopt.fDeleteEntries = 1;
            return(zopt);
        }
示例#5
0
        internal bool ProcessFiles(string[] fileMask, ZipOptions zopt)
        {
            int      iret;
            ZipError zipError;

            if (string.IsNullOrEmpty(FileName))
            {
                return(false);
            }

            if (fileMask.Length == 0)
            {
                return(false);
            }

            ZipUserFunctions zuf = PrepareCallBack();

            try
            {
                iret = NativeMethods.ZpInit(ref zuf);
            }
            catch (DllNotFoundException)
            {
                return(false);
            }

            if (iret == 0)
            {
                return(false);
            }


            try
            {
                zipError = NativeMethods.ZpSetOptions(ref zopt);
                zipError = NativeMethods.ZpArchive(fileMask.Length, fileName, fileMask);
            }
            catch (DllNotFoundException)
            {
                return(false);
            }
            return(zipError == ZipError.ZE_OK);
        }
示例#6
0
        /// <summary>
        /// Creates the zip options.
        /// </summary>
        /// <returns></returns>
        private ZipOptions CreateZipOptions()
        {
            ZipOptions zopt = new ZipOptions();

            zopt.Date          = string.Empty;
            zopt.szRootDir     = rootFolder;
            zopt.szTempDir     = temporaryFolder;
            zopt.fTemp         = (string.IsNullOrEmpty(temporaryFolder)) ? 0 : 1;
            zopt.fEncrypt      = (string.IsNullOrEmpty(password)) ? 0 : 1;
            zopt.fSystem       = InternalHelper.BoolToInt(SystemFilesIgnored);
            zopt.fVolume       = InternalHelper.BoolToInt(VolumeLabelStored);
            zopt.fExtra        = InternalHelper.BoolToInt(ExtraAttributesExcluded);
            zopt.fNoDirEntries = InternalHelper.BoolToInt(DirEntriesIgnored);
            zopt.fVerbose      = InternalHelper.BoolToInt(VerboseMessages);
            zopt.fQuiet        = InternalHelper.BoolToInt(QuietMessages);

            //Do not translate CR/LF to LF
            zopt.fCRLF_LF = 0;
            //Do not translate LF to CR/LF
            zopt.fLF_CRLF = 0;

            zopt.fGrow       = InternalHelper.BoolToInt(GrowZipFile);
            zopt.fLatestTime = InternalHelper.BoolToInt(setLatestTime);
            zopt.fComment    = (string.IsNullOrEmpty(comment)) ? 0 : 1;
            zopt.fPrivilege  = InternalHelper.BoolToInt(usePrivileges);
            zopt.fRecurse    = (int)(recurse);
            zopt.fLevel      = (byte)CompressionLevel;

            zopt.fJunkDir     = 0;
            zopt.fExcludeDate = 0;
            zopt.fIncludeDate = 0;
            zopt.fForce       = 0;
            zopt.fOffsets     = 0;
            zopt.fSuffix      = 0;
            zopt.fJunkSFX     = 0;
            zopt.fEncryption  = 0;
            return(zopt);
        }
示例#7
0
        /// <summary>
        /// Adds the files that match file mask to the archive.
        /// </summary>
        /// <param name="fileMask">The file name mask, for example <c>"*.txt"</c>
        /// The wild card characters '*' and '?' are allowed in file mask
        /// </param>
        /// <returns><c>true</c>, if files successfully added to the archive</returns>
        /// <example>
        /// <code>
        /// string[] content = { "*.jpg" };
        /// KarnaZip zip = new KarnaZip();
        /// zip.PrintMessage += new EventHandler&lt;CompressionEventArgs&gt;(zip_PrintMessage);
        /// zip.ServiceMessage += new EventHandler&lt;CompressionServiceEventArgs&gt;(zip_ServiceMessage);
        /// zip.FileName = "test.zip";
        /// zip.Password = "******";
        /// zip.Comment = "This is just a test archive";
        /// zip.AddFiles(content);
        /// </code>
        /// </example>
        public bool AddFiles(string[] fileMask)
        {
            ZipOptions zopt = CreateZipOptions();

            return(ProcessFiles(fileMask, zopt));
        }
示例#8
0
        /// <summary>
        /// Moves the specified files to ZIP archive.
        /// </summary>
        /// <param name="fileMask">The file name mask.
        /// The wild card characters '*' and '?' are allowed in file mask</param>
        /// <returns>Returns <c>true</c> if successful, or <c>false</c> otherwise.</returns>
        public bool MoveFiles(string[] fileMask)
        {
            ZipOptions zopt = CreateZipOptionsForMove();

            return(ProcessFiles(fileMask, zopt));
        }
示例#9
0
        /// <summary>
        /// Freshens the specified files in the archive.
        /// </summary>
        /// <param name="fileMask">The file mask.
        /// The wild card characters '*' and '?' are allowed in file mask
        /// </param>
        /// <returns>Returns <c>true</c> if successful, or <c>false</c> otherwise.</returns>
        public bool FreshenFiles(string[] fileMask)
        {
            ZipOptions zopt = CreateZipOptionsForFreshen();

            return(ProcessFiles(fileMask, zopt));
        }
 public static extern ZipError ZpSetOptions(ref ZipOptions zopts);