Exemple #1
0
        /// <summary>
        ///   Checks a zip file to see if its directory is consistent,
        ///   and optionally fixes the directory if necessary.
        /// </summary>
        ///
        /// <remarks>
        ///
        /// <para>
        ///   In cases of data error, the directory within a zip file can get out of
        ///   synch with the entries in the zip file.  This method checks the given
        ///   zip file, and returns true if this has occurred. It also optionally
        ///   fixes the zipfile, saving the fixed copy in <em>Name</em>_Fixed.zip.
        /// </para>
        ///
        /// <para>
        ///   This method may take a long time to run for large zip files.  It
        ///   will take even longer if the file actually needs to be fixed, and if
        ///   <c>fixIfNecessary</c> is true.
        /// </para>
        ///
        /// <para>
        ///   This method is not supported in the Reduced or Compact
        ///   Framework versions of DotNetZip.
        /// </para>
        ///
        /// </remarks>
        ///
        /// <param name="zipFileName">The filename to of the zip file to check.</param>
        ///
        /// <param name="fixIfNecessary">If true, the method will fix the zip file if
        ///     necessary.</param>
        ///
        /// <param name="writer">
        /// a TextWriter in which messages generated while checking will be written.
        /// </param>
        ///
        /// <returns>true if the named zip is OK; false if the file needs to be fixed.</returns>
        ///
        /// <seealso cref="CheckZip(string)"/>
        /// <seealso cref="FixZipDirectory(string)"/>
        internal static bool CheckZip(string zipFileName, bool fixIfNecessary, TextWriter writer)
        {
            bool isOk = true;

            string fullPath = GetFullPath(zipFileName);

            // load the source file
            var file = FileSystem.Current.GetFileFromPathAsync(zipFileName).ExecuteSync();

            if (file == null)
            {
                throw new FileNotFoundException(string.Format("That file ({0}) does not exist!", zipFileName));
            }

            // create the "fixed" file location
            var dir     = FileSystem.Current.GetFolderFromPathAsync(Path.GetDirectoryName(fullPath)).ExecuteSync();
            var newFile = dir.CreateFileAsync(
                string.Format("{0}_fixed{1}", Path.GetFileNameWithoutExtension(zipFileName), Path.GetExtension(zipFileName)),
                CreationCollisionOption.FailIfExists).ExecuteSync();

            // do the check
            using (var stream = file.OpenAsync(FileAccess.Read).ExecuteSync())
                using (var newStream = newFile.OpenAsync(FileAccess.Read).ExecuteSync())
                {
                    isOk = ZipFile.CheckZip(stream, fixIfNecessary ? newStream : null, writer);
                }

            // delete the temporary file if there was no error
            if (isOk)
            {
                newFile.DeleteAsync().ExecuteSync();
            }

            return(isOk);
        }
Exemple #2
0
 /// <summary>
 ///  A wrapper for <see cref="ZipFile.CheckZip(string)">ZipFile.CheckZip(string)</see>
 /// </summary>
 /// <param name="filename">The filename to of the zip file to check.</param>
 ///
 /// <returns>true if the named zip file checks OK. Otherwise, false. </returns>
 public bool CheckZip(string filename)
 {
     return(ZipFile.CheckZip(filename));
 }
 /// <summary>
 ///   Checks a zip file to see if its directory is consistent.
 /// </summary>
 ///
 /// <remarks>
 ///
 /// <para>
 ///   In cases of data error, the directory within a zip file can get out
 ///   of synch with the entries in the zip file.  This method checks the
 ///   given zip file and returns true if this has occurred.
 /// </para>
 ///
 /// <para> This method may take a long time to run for large zip files.  </para>
 ///
 /// <para>
 ///   This method is not supported in the Reduced or Compact Framework
 ///   versions of DotNetZip.
 /// </para>
 ///
 /// <para>
 ///   Developers using COM can use the <see
 ///   cref="ComHelper.CheckZip(String)">ComHelper.CheckZip(String)</see>
 ///   method.
 /// </para>
 ///
 /// </remarks>
 ///
 /// <param name="zipFileName">The filename to of the zip file to check.</param>
 ///
 /// <returns>true if the named zip file checks OK. Otherwise, false. </returns>
 ///
 /// <seealso cref="FixZipDirectory(string)"/>
 /// <seealso cref="CheckZip(string,bool,System.IO.TextWriter)"/>
 public static bool CheckZip(Stream zipFileStream, Stream fixedZipFileStream)
 {
     return(ZipFile.CheckZip(zipFileStream, fixedZipFileStream));
 }
 /// <summary>
 ///   Checks a zip file to see if its directory is consistent,
 ///   and optionally fixes the directory if necessary.
 /// </summary>
 ///
 /// <remarks>
 ///
 /// <para>
 ///   In cases of data error, the directory within a zip file can get out of
 ///   synch with the entries in the zip file.  This method checks the given
 ///   zip file, and returns true if this has occurred. It also optionally
 ///   fixes the zipfile, saving the fixed copy in <em>Name</em>_Fixed.zip.
 /// </para>
 ///
 /// <para>
 ///   This method may take a long time to run for large zip files.  It
 ///   will take even longer if the file actually needs to be fixed, and if
 ///   <c>fixIfNecessary</c> is true.
 /// </para>
 ///
 /// <para>
 ///   This method is not supported in the Reduced or Compact
 ///   Framework versions of DotNetZip.
 /// </para>
 ///
 /// </remarks>
 ///
 /// <param name="zipFileName">The filename to of the zip file to check.</param>
 ///
 /// <param name="fixIfNecessary">If true, the method will fix the zip file if
 ///     necessary.</param>
 ///
 /// <param name="writer">
 /// a TextWriter in which messages generated while checking will be written.
 /// </param>
 ///
 /// <returns>true if the named zip is OK; false if the file needs to be fixed.</returns>
 ///
 /// <seealso cref="CheckZip(string)"/>
 /// <seealso cref="FixZipDirectory(string)"/>
 public static bool CheckZip(Stream zipFileStream, Stream fixedZipFileStream, TextWriter writer)
 {
     return(ZipFile.CheckZip(zipFileStream, fixedZipFileStream, writer));
 }