예제 #1
0
        private void _Check_ZIP(string pathFileZip, IDTSComponentEvents componentEvents)
        {
            bool b = false;

            if (_testarchive)
            {
                using (ICSharpCode.SharpZipLib.Zip.ZipInputStream fz = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(System.IO.File.OpenRead(pathFileZip)))
                {
                    if (!string.IsNullOrEmpty(_password))
                    {
                        fz.Password = _password;
                    }

                    try
                    {
                        ICSharpCode.SharpZipLib.Zip.ZipEntry ze = fz.GetNextEntry();
                        componentEvents.FireInformation(1, "UnZip SSIS", "Start verify file ZIP (" + _folderSource + _fileZip + ")", null, 0, ref b);

                        while (ze != null)
                        {
                            componentEvents.FireInformation(1, "UnZip SSIS", "Verifying Entry: " + ze.Name, null, 0, ref b);

                            fz.CopyTo(System.IO.MemoryStream.Null);
                            fz.Flush();

                            fz.CloseEntry();
                            ze = fz.GetNextEntry();
                        }
                        componentEvents.FireInformation(1, "UnZip SSIS", "File ZIP verified ZIP (" + _folderSource + _fileZip + ")", null, 0, ref b);
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("Verify file: " + _fileZip + " failed. (" + ex.Message + ")");
                    }
                    finally
                    {
                        fz.Close();
                    }
                }
            }
        }
예제 #2
0
        private void _DeCompressZIP(string pathFileZip, IDTSComponentEvents componentEvents)
        {
            bool b = false;

            _Check_ZIP(pathFileZip, componentEvents);

            using (ICSharpCode.SharpZipLib.Zip.ZipInputStream fz = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(System.IO.File.OpenRead(pathFileZip)))
            {
                if (!string.IsNullOrEmpty(_password))
                {
                    fz.Password = _password;
                }

                ICSharpCode.SharpZipLib.Zip.ZipEntry ze = fz.GetNextEntry();

                while (ze != null)
                {
                    string             fn = ze.Name.Replace("/", "\\");
                    System.IO.FileInfo fi = null;

                    if ((!System.Text.RegularExpressions.Regex.Match(fn, _fileFilter).Success) || (ze.IsDirectory && ze.Size == 0))
                    {
                        if (!System.Text.RegularExpressions.Regex.Match(fn, _fileFilter).Success)
                        {
                            componentEvents.FireInformation(1, "UnZip SSIS", _typeCompression.ToString() + ": file " + fn + " doesn't match regex filter '" + _fileFilter + "'", null, 0, ref b); //  Added information display when regex doesn't match (Updated on 2015-12-30 by Nico_FR75)
                        }

                        fz.CloseEntry();
                        ze = fz.GetNextEntry();
                        continue;
                    }

                    componentEvents.FireInformation(1, "UnZip SSIS", _typeCompression.ToString() + ": De-Compress (with '" + _storePaths.ToString() + "') file: " + fn, null, 0, ref b);

                    if (_storePaths == Store_Paths.Absolute_Paths || _storePaths == Store_Paths.Relative_Paths)
                    {
                        //Absolute / Relative Path
                        fi = new System.IO.FileInfo(_folderDest + fn);
                        if (!System.IO.Directory.Exists(fi.DirectoryName))
                        {
                            System.IO.Directory.CreateDirectory(fi.DirectoryName);
                        }
                    }
                    else if (_storePaths == Store_Paths.No_Paths)
                    {
                        //No Path
                        fi = new System.IO.FileInfo(_folderDest + System.IO.Path.GetFileName(fn));
                    }
                    else
                    {
                        throw new Exception("Please select type Store Paths (No_Paths / Relative_Paths / Absolute_Paths).");
                    }

                    using (System.IO.FileStream fs = new System.IO.FileStream(fi.FullName, System.IO.FileMode.Create, System.IO.FileAccess.Write))
                    {
                        fz.CopyTo(fs);
                        fs.Flush();
                    }

                    fz.CloseEntry();
                    ze = fz.GetNextEntry();
                }

                fz.Close();
            }
        }