C\#압축,압축 풀기 파일(클립)(rar,zip)

70944 단어 zip
주로 Rar.exe 압축 해제 파일(클립)(*.rar)을 사용 하 며,SevenZipSharp.dll,zLib1.dll,7z.dll 압축 해제 파일(클립)(*.zip)도 사용 합 니 다.주의해 야 할 몇 가 지 는 다음 과 같다.
1.Rar.exe 소프트웨어 가 저 장 된 위 치 를 주의 하고 이번에 Debug 디 렉 터 리 에 두 었 습 니 다.
2.SevenZipSharp.dll,zLib 1.dll,7z.dll 이 동시에 존재 해 야 합 니 다.그렇지 않 으 면"7z.dll 오류 불 러 오기"를 자주 보고 합 니 다.항목 참조 시 SevenZipSharp.dll 만 참조 하면 됩 니 다.
3.7z.dll 파일 을 찾 지 못 해도 오류 가 발생 할 수 있 습 니 다.테스트 를 할 때@"..\.\..\dll\7z.dll"만 사용 하 는 것 을 발견 합 니 다.상대 경로 가 바 뀌 었 을 때 경로 가 바 뀌 었 기 때문에 여기 서 string libPath=System.AppDomain.CurrentDomain.BaseDirectory+@"..\..\dll\\7z.dll"을 사 용 했 습 니 다.                SevenZip.SevenZipCompressor.SetLibraryPath(libPath);



구체 적 인 코드 는 다음 과 같다.
Enums.cs
using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;



namespace CompressProj

{

    /// <summary>

    ///         

    /// </summary>

    public enum CompressResults

    {

        Success,

        SourceObjectNotExist,

        UnKnown

    }



    /// <summary>

    ///          

    /// </summary>

    public enum UnCompressResults

    {

        Success,

        SourceObjectNotExist,

        PasswordError,

        UnKnown

    }

    /// <summary>

    ///       

    /// </summary>

    public enum ProcessResults

    { 

        Success,

        Failed

    }

}

 
CommonFunctions.cs
using System;

using System.Collections.Generic;

using System.Diagnostics;

using System.IO;

using System.Linq;

using System.Text;

using System.Threading.Tasks;



namespace CompressProj

{

    class CommonFunctions

    {

        #region     



        private static CommonFunctions uniqueInstance;

        private static object _lock = new object();



        private CommonFunctions() { }

        public static CommonFunctions getInstance() 

        {

           if (null == uniqueInstance)      //            ,         。

           {

               lock (_lock)

               {

                   if (null == uniqueInstance) 

                   {

                       uniqueInstance = new CommonFunctions();

                   }

               }      

           }

           return uniqueInstance;

        }



        #endregion



        #region   



        /// <summary>

        ///          

        /// </summary>

        /// <param name="exe">     (  + )</param>

        /// <param name="commandInfo">    </param>

        /// <param name="workingDir">        </param>

        /// <param name="processWindowStyle">      </param>

        /// <param name="isUseShellExe">Shell    </param>

        public void ExecuteProcess(string exe, string commandInfo, string workingDir = "", ProcessWindowStyle processWindowStyle = ProcessWindowStyle.Hidden,bool isUseShellExe = false)

        {

            ProcessStartInfo startInfo = new ProcessStartInfo();

            startInfo.FileName = exe;

            startInfo.Arguments = commandInfo;

            startInfo.WindowStyle = processWindowStyle;

            startInfo.UseShellExecute = isUseShellExe;

            if (!string.IsNullOrWhiteSpace(workingDir))

            {

                startInfo.WorkingDirectory = workingDir;

            }



            ExecuteProcess(startInfo);

        }



        /// <summary>

        ///          

        /// </summary>

        /// <param name="startInfo">           </param>

        public void ExecuteProcess(ProcessStartInfo startInfo)

        {

            try

            {

                Process process = new Process();

                process.StartInfo = startInfo;

                process.Start();

                process.WaitForExit();

                process.Close();

                process.Dispose();

            }

            catch(Exception ex)

            {

                throw new Exception("
\r
" + startInfo.FileName + "
\r
" + ex.Message); } } /// <summary> /// /// </summary> /// <param name="objectPathName"> </param> public void Attribute2Normal(string objectPathName) { if (true == Directory.Exists(objectPathName)) { System.IO.DirectoryInfo directoryInfo = new System.IO.DirectoryInfo(objectPathName); directoryInfo.Attributes = FileAttributes.Normal; } else { File.SetAttributes(objectPathName,FileAttributes.Normal); } } #endregion } }

 
RarOperate.cs
using System;

using System.Collections.Generic;

using System.Diagnostics;

using System.IO;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;



namespace CompressProj

{

    class RarOperate

    {



        private CommonFunctions commFuncs = CommonFunctions.getInstance();

        

        #region     



        private static RarOperate uniqueInstance;

        private static object _lock = new object();



        private RarOperate() { }

        public static RarOperate getInstance() 

        {

           if (null == uniqueInstance)      //            ,         。

           {

               lock (_lock)

               {

                   if (null == uniqueInstance) 

                   {

                       uniqueInstance = new RarOperate();

                   }

               }      

           }

           return uniqueInstance;

        }



        #endregion



        #region   



        /// <summary>

        ///   Rar.exe    

        /// </summary>

        /// <param name="rarRunPathName">Rar.exe  +   </param>

        /// <param name="objectPathName">       +   </param>

        /// <param name="objectRarPathName">       +   </param>

        /// <returns></returns>

        public CompressResults CompressObject(string rarRunPathName, string objectPathName, string objectRarPathName,string password)

        {

            try

            {

                //         

                int beforeObjectNameIndex = objectPathName.LastIndexOf('\\');

                string objectPath = objectPathName.Substring(0, beforeObjectNameIndex);

                //System.IO.DirectoryInfo directoryInfo = new System.IO.DirectoryInfo(objectPathName);

                if (Directory.Exists(objectPathName)/*directoryInfo.Exists*/ == false && System.IO.File.Exists(objectPathName) == false)

                {

                    return CompressResults.SourceObjectNotExist;

                }



                //              

                string rarCommand = "\"" + rarRunPathName + "\"";

                string objectPathNameCommand = "\"" + objectPathName + "\"";

                int beforeObjectRarNameIndex = objectRarPathName.LastIndexOf('\\');

                int objectRarNameIndex = beforeObjectRarNameIndex + 1;

                string objectRarName = objectRarPathName.Substring(objectRarNameIndex);

                string rarNameCommand = "\"" + objectRarName + "\"";

                string objectRarPath = objectRarPathName.Substring(0, beforeObjectRarNameIndex);

                //

                if (System.IO.Directory.Exists(objectRarPath) == false)

                {

                    System.IO.Directory.CreateDirectory(objectRarPath);

                }

                else if (System.IO.File.Exists(objectRarPathName) == true)

                {

                    System.IO.File.Delete(objectRarPathName);

                }

                //Rar    

                string commandInfo = "a " + rarNameCommand + " " + objectPathNameCommand + " -y -p" + password + " -ep1 -r -s- -rr ";

                //       

                commFuncs.ExecuteProcess(rarCommand, commandInfo, objectRarPath, ProcessWindowStyle.Hidden);



                CompressRarTest(rarCommand, objectRarPathName, password);

                CorrectConfusedRar(objectRarPathName);

            }

            catch (Exception ex)

            {

                MessageBox.Show(ex.Message);

                return CompressResults.UnKnown;

            }

            return CompressResults.Success;

        }

        

        #endregion



        #region   



        /// <summary>

        ///   :            。   :         ,        , rar     

        /// </summary>

        /// <param name="rarRunPath">rar.exe      </param>

        /// <param name="fromRarPath">    rar    </param>

        /// <param name="toRarPath">          </param>

        /// <returns></returns>

        public UnCompressResults unCompressRAR(String rarRunPath, String objectRarPathName, String objectPath, string password)

        {

            try

            {

                bool isFileExist = File.Exists(objectRarPathName);

                if (false == isFileExist)

                {

                    MessageBox.Show("" + objectRarPathName);

                    return UnCompressResults.SourceObjectNotExist;

                }

                File.SetAttributes(objectRarPathName, FileAttributes.Normal);     //      



                if (Directory.Exists(objectPath) == false)

                {

                    Directory.CreateDirectory(objectPath);

                }



                String rarCommand = "\"" + rarRunPath + "\"";

                String objectPathCommand = "\"" + objectPath + "\\\"";

                String commandInfo = "x \"" + objectRarPathName + "\" " + objectPath + " -y -p" + password;



                commFuncs.ExecuteProcess(rarCommand, commandInfo, objectPath, ProcessWindowStyle.Hidden);



                MessageBox.Show("" + objectRarPathName);

                return UnCompressResults.Success;

            }

            catch

            {

                MessageBox.Show( "" + objectRarPathName);

                return UnCompressResults.UnKnown;

            }

        }





        #endregion



        #region   







        #endregion



        #region       



        /// <summary>

        ////// </summary>

        /// <param name="rarRunPath"></param>

        /// <param name="rarFilePathName"></param>

        public bool CompressRarTest(String rarRunPath, String rarFilePathName,string password)

        {

            bool isOk = false;

            String commandInfo = "t -p" + password + " \"" + rarFilePathName + "\"";



            ProcessStartInfo startInfo = new ProcessStartInfo();

            startInfo.FileName = rarRunPath;

            startInfo.Arguments = commandInfo;

            startInfo.WindowStyle = ProcessWindowStyle.Hidden;

            startInfo.UseShellExecute = false;

            startInfo.RedirectStandardOutput = true;

            startInfo.CreateNoWindow = true;



            Process process = new Process();

            process.StartInfo = startInfo;

            process.Start();



            StreamReader streamReader = process.StandardOutput;



            process.WaitForExit();



            if (streamReader.ReadToEnd().ToLower().IndexOf("error") >= 0)

            {

                MessageBox.Show("");

                isOk = false;

            }

            else

            {

                MessageBox.Show("");

                isOk = true;

            }

            process.Close();

            process.Dispose();

            return isOk;

        }





        /// <summary>

        ///   Rar

        /// </summary>

        /// <param name="objectRarPathName">rar  + </param>

        /// <returns></returns>

        public bool ConfusedRar(string objectRarPathName)

        {

            try

            {

                //  

                System.IO.FileStream fs = new FileStream(objectRarPathName, FileMode.Open);

                fs.WriteByte(0x53);

                fs.Close();

                return true;

            }

            catch (Exception ex)

            {

                MessageBox.Show("  Rar  !" + ex.Message);

                return false;

            }

        }



        /// <summary>

        ///      Rar

        /// </summary>

        /// <param name="objectRarPathName">rar  + </param>

        /// <returns></returns>

        public bool CorrectConfusedRar(string objectRarPathName)

        {

            bool isCorrect = false;

            try

            {

                //                

                FileStream fsRar = new FileStream(objectRarPathName, FileMode.Open, FileAccess.Read);

                int b = fsRar.ReadByte();

                fsRar.Close();

                if (b != 0x52)     //R:0x52      

                {

                    string strTempFile = System.IO.Path.GetTempFileName();

                    File.Copy(objectRarPathName, strTempFile, true);

                    File.SetAttributes(strTempFile, FileAttributes.Normal);     //      

                    FileStream fs = new FileStream(strTempFile, FileMode.Open);

                    fs.WriteByte(0x52);

                    fs.Close();

                    System.IO.File.Delete(objectRarPathName);

                    File.Copy(strTempFile, objectRarPathName, true);

                }

                isCorrect = true;

                return isCorrect;

             }

            catch

            {

                MessageBox.Show("" + objectRarPathName);

                return isCorrect;

            }

        }





        #endregion



        #region 



        



        #endregion

    }

}

ZipOperate.cs
using SevenZip;

using System;

using System.Collections.Generic;

using System.IO;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;



namespace CompressProj

{

    class ZipOperate

    {

        

        #region     



        private static ZipOperate uniqueInstance;

        private static object _lock = new object();



        private ZipOperate() { }

        public static ZipOperate getInstance() 

        {

           if (null == uniqueInstance)      //            ,         。

           {

               lock (_lock)

               {

                   if (null == uniqueInstance) 

                   {

                       uniqueInstance = new ZipOperate();

                   }

               }      

           }

           return uniqueInstance;

        }



        #endregion



        #region 7zZip  、    

        /// <summary>

        ///       

        /// </summary>

        /// <param name="objectPathName">    (       |      )</param>

        /// <param name="objectZipPathName">         </param>

        /// <param name="strPassword">   </param>

        ///        :    (objectZipPathName)         (objectPathName) ,   “           ”  。

        /// <returns></returns>

        public CompressResults Compress7zZip(String objectPathName, String objectZipPathName, String strPassword)

        {

            try

            {

                //http://sevenzipsharp.codeplex.com/releases/view/51254   sevenzipsharp.dll

                //SevenZipSharp.dll、zLib1.dll、7z.dll      ,    “  7z.dll  ”

                string libPath = System.AppDomain.CurrentDomain.BaseDirectory + @"..\..\dll\7z.dll";

                SevenZip.SevenZipCompressor.SetLibraryPath(libPath);

                SevenZip.SevenZipCompressor sevenZipCompressor = new SevenZip.SevenZipCompressor();

                sevenZipCompressor.CompressionLevel = SevenZip.CompressionLevel.Fast;

                sevenZipCompressor.ArchiveFormat = SevenZip.OutArchiveFormat.Zip;

                

                //         

                int beforeObjectNameIndex = objectPathName.LastIndexOf('\\');

                string objectPath = objectPathName.Substring(0, beforeObjectNameIndex);

                //System.IO.DirectoryInfo directoryInfo = new System.IO.DirectoryInfo(objectPathName);

                if (Directory.Exists(objectPathName)/*directoryInfo.Exists*/ == false && System.IO.File.Exists(objectPathName) == false)

                {

                    return CompressResults.SourceObjectNotExist;

                }

                int beforeObjectRarNameIndex = objectZipPathName.LastIndexOf('\\');

                int objectRarNameIndex = beforeObjectRarNameIndex + 1;

                //string objectZipName = objectZipPathName.Substring(objectRarNameIndex);

                string objectZipPath = objectZipPathName.Substring(0, beforeObjectRarNameIndex);

                //    、      

                if (System.IO.Directory.Exists(objectZipPath) == false)

                {

                    System.IO.Directory.CreateDirectory(objectZipPath);

                }

                else if (System.IO.File.Exists(objectZipPathName) == true)

                {

                    System.IO.File.Delete(objectZipPathName);

                }



                if (Directory.Exists(objectPathName))       //        

                {

                    if (String.IsNullOrEmpty(strPassword))

                    {

                        sevenZipCompressor.CompressDirectory(objectPathName, objectZipPathName);

                    }

                    else

                    { 

                        sevenZipCompressor.CompressDirectory(objectPathName, objectZipPathName, strPassword);

                    }

                }

                else        //             

                {

                    sevenZipCompressor.CompressFiles(objectZipPathName, objectPathName);

                }



                return CompressResults.Success;

            }

            catch(Exception ex)

            {

                MessageBox.Show("      !" + ex.Message);

                return CompressResults.UnKnown;

            }

        }



        /// <summary>

        ///       

        /// </summary>

        /// <param name="zipFilePathName">zip      + </param>

        /// <param name="unCompressDir">    </param>

        /// <param name="strPassword">   </param>

        /// <returns></returns>

        public UnCompressResults UnCompress7zZip(String zipFilePathName, String unCompressDir, String strPassword)

        {

            try

            {

                //SevenZipSharp.dll、zLib1.dll、7z.dll      ,    “  7z.dll  ”      ,   SevenZipSharp.dll    

                string libPath = System.AppDomain.CurrentDomain.BaseDirectory + @"..\..\dll\7z.dll";

                SevenZip.SevenZipCompressor.SetLibraryPath(libPath);



                bool isFileExist = File.Exists(zipFilePathName);

                if (false == isFileExist)

                {

                    MessageBox.Show("       !" + zipFilePathName);

                    return UnCompressResults.SourceObjectNotExist;

                }

                File.SetAttributes(zipFilePathName, FileAttributes.Normal);     //      



                if (Directory.Exists(unCompressDir) == false)

                {

                    Directory.CreateDirectory(unCompressDir);

                }



                SevenZip.SevenZipExtractor sevenZipExtractor;

                if (String.IsNullOrEmpty(strPassword))

                {

                    sevenZipExtractor = new SevenZip.SevenZipExtractor(zipFilePathName);

                }

                else

                {

                    sevenZipExtractor = new SevenZip.SevenZipExtractor(zipFilePathName, strPassword);

                }



                sevenZipExtractor.ExtractArchive(unCompressDir);

                sevenZipExtractor.Dispose();

                return UnCompressResults.Success;

            }

            catch(Exception ex)

            {

                MessageBox.Show("       !" + ex.Message);

                return UnCompressResults.UnKnown;

            }

        }

        #endregion

    }

}


FileOperate.cs
using System;

using System.Collections.Generic;

using System.IO;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;



namespace CompressProj

{

    class FileOperate

    {

        private RarOperate rarOperate = RarOperate.getInstance();



        #region     



        private static FileOperate uniqueInstance;

        private static object _lock = new object();



        private FileOperate() { }

        public static FileOperate getInstance() 

        {

           if (null == uniqueInstance)      //            ,         。

           {

               lock (_lock)

               {

                   if (null == uniqueInstance) 

                   {

                       uniqueInstance = new FileOperate();

                   }

               }      

           }

           return uniqueInstance;

        }



        #endregion



        /// <summary>

        ///     

        /// </summary>

        /// <param name="openFileDialog"></param>

        /// <param name="filter"></param>

        /// <param name="isReadOnly"></param>

        /// <returns></returns>

        public string OpenFile(OpenFileDialog openFileDialog,string filter,string openFileDialogTitle = "    ",bool isReadOnly = false)

        {

            string filePathName = string.Empty;

            if (string.IsNullOrEmpty(filter))

            {

                filter = "AllFiles(*.*)|*.*";   //TXT(*.txt)|*.txt|Word(*.doc,*.docx)|*.doc;*.docx|    (*.gif;*.jpg;*.jpeg;*.png;*.psd)|*.gif;*.jpg;*.jpeg;*.png;*.psd|

            }

            openFileDialog.Filter = filter;

            DialogResult dResult = openFileDialog.ShowDialog();

            if (dResult == DialogResult.OK)

            {

                string defaultExt = ".docx";

                //string filter = string.Empty;

                //openFileDialog.ReadOnlyChecked = isReadOnly;

                openFileDialog.SupportMultiDottedExtensions = true;

                openFileDialog.AutoUpgradeEnabled = true;

                openFileDialog.AddExtension = true;

                openFileDialog.CheckPathExists = true;

                openFileDialog.CheckFileExists = true;

                openFileDialog.DefaultExt = defaultExt;

                openFileDialog.Multiselect = true;

                openFileDialog.ShowReadOnly = true;

                openFileDialog.Title = openFileDialogTitle;

                openFileDialog.ValidateNames = true;

                openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Templates);

                //         Win7 + VS11

                openFileDialog.ShowHelp = true;

                filePathName = openFileDialog.FileName;

                if (true == isReadOnly)

                {

                    openFileDialog.OpenFile();    //      ,           ,           

                }



                openFileDialog.Dispose();

            }

            return filePathName;

        }



        /// <summary>

        ///     

        /// </summary>

        /// <param name="saveFileDialog"></param>

        /// <param name="filter"></param>

        /// <param name="isReadOnly"></param>

        /// <returns></returns>

        public string SaveFile(SaveFileDialog saveFileDialog, string filter,string saveFileDialogTitle = "    ", bool isReadOnly = false)

        {

            string filePathName = string.Empty;

            if (string.IsNullOrEmpty(filter))

            {

                filter = "AllFiles(*.*)|*.*";   //TXT(*.txt)|*.txt|Word(*.doc,*.docx)|*.doc;*.docx|    (*.gif;*.jpg;*.jpeg;*.png;*.psd)|*.gif;*.jpg;*.jpeg;*.png;*.psd|

            }

            saveFileDialog.Filter = filter;

            DialogResult dResult = saveFileDialog.ShowDialog();

            if (dResult == DialogResult.OK)

            {

                string defaultExt = ".docx";

                //string filter = string.Empty;

                //string saveFileDialogTitle = "    ";

                saveFileDialog.SupportMultiDottedExtensions = true;

                saveFileDialog.AutoUpgradeEnabled = true;

                saveFileDialog.AddExtension = true;

                saveFileDialog.CheckPathExists = true;

                saveFileDialog.CheckFileExists = true;

                saveFileDialog.DefaultExt = defaultExt;

                saveFileDialog.RestoreDirectory = true;

                saveFileDialog.OverwritePrompt = true;

                saveFileDialog.Title = saveFileDialogTitle;

                saveFileDialog.ValidateNames = true;

                saveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Templates);

                //         Win7 + VS11

                saveFileDialog.ShowHelp = true;

                filePathName = saveFileDialog.FileName;

                if (true == isReadOnly)

                {

                    saveFileDialog.OpenFile();  //      ,           ,           

                }

                saveFileDialog.Dispose();

            }

            return filePathName;

        }



    }

}

 
테스트 호출 코드 는 다음 과 같 습 니 다:
RarForm.cs
using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Diagnostics;

using System.Drawing;

using System.IO;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;



namespace CompressProj

{

    public partial class RarForm : Form

    {

        private FileOperate fileOperate = FileOperate.getInstance();

        private RarOperate rarOperate = RarOperate.getInstance();

        private ZipOperate zipOperate = ZipOperate.getInstance();



        public RarForm()

        {

            InitializeComponent();

        }



        private void btnCompress_Click(object sender, EventArgs e)

        {

            string filter = "TXT(*.txt)|*.txt|Word(*.doc,*.docx)|*.doc;*.docx|AllFiles(*.*)|*.*";

            string openFileDialogTitle = "    ";

            string compressFilePathName = fileOperate.OpenFile(this.openFileDialog1, filter, openFileDialogTitle,true);

            if (string.IsNullOrEmpty(compressFilePathName) || string.IsNullOrWhiteSpace(compressFilePathName))

            {

                return;

            }

            this.openFileDialog1.HelpRequest += new EventHandler(openFileDialog1_HelpRequest);

            string objectRarPathName = compressFilePathName.Substring(0,compressFilePathName.LastIndexOf('.')) + ".rar";

            string rarPathName = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Rar.exe";

            string password = string.Empty;//"shenc";

            CompressResults compressResult = rarOperate.CompressObject(rarPathName, compressFilePathName, objectRarPathName, password);

            if (CompressResults.Success == compressResult)

            {

                MessageBox.Show(objectRarPathName);

            }

        }



        private void openFileDialog1_HelpRequest(object sender, EventArgs e)

        {

            MessageBox.Show("HelpRequest!");

        }



        private void btnUncompress_Click(object sender, EventArgs e)

        {

            string filter = "Rar(*.rar)|*.rar";

            string openFileDialogTitle = "    ";

            string unCompressFilePathName = fileOperate.OpenFile(this.openFileDialog1, filter, openFileDialogTitle, false);

            if (string.IsNullOrEmpty(unCompressFilePathName) || string.IsNullOrWhiteSpace(unCompressFilePathName))

            {

                return;

            }

            string objectPath = unCompressFilePathName.Substring(0, unCompressFilePathName.LastIndexOf('.'));

            string rarPathName = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Rar.exe";

            string password = string.Empty;//"shenc";

            UnCompressResults unCompressResult = rarOperate.unCompressRAR(rarPathName, unCompressFilePathName, objectPath, password);

            if (UnCompressResults.Success == unCompressResult)

            {

                MessageBox.Show(objectPath);

            }

        }



        private void btnCompressZip_Click(object sender, EventArgs e)

        {

            string filter = "TXT(*.txt)|*.txt|Word(*.doc,*.docx)|*.doc;*.docx|AllFiles(*.*)|*.*";

            string openFileDialogTitle = "    ";

            string compressFilePathName = fileOperate.OpenFile(this.openFileDialog1, filter, openFileDialogTitle, false);

            if (string.IsNullOrEmpty(compressFilePathName) || string.IsNullOrWhiteSpace(compressFilePathName))

            {

                return;

            }

            //this.openFileDialog1.HelpRequest += new EventHandler(openFileDialog1_HelpRequest);

            string password = string.Empty;//"shenc";

            string objectZipPathName = compressFilePathName.Substring(0, compressFilePathName.LastIndexOf('.')) + ".zip";

            CompressResults compressResult = zipOperate.Compress7zZip(compressFilePathName, objectZipPathName, password); //    



            ////       :              ,   “           ”  。

            //string objectPath = compressFilePathName.Substring(0, compressFilePathName.LastIndexOf('\\'));

            //objectZipPathName = objectPath + ".zip";

            //CompressResults compressResult = zipOperate.Compress7zZip(objectPath, objectZipPathName, password);   //     



            if (CompressResults.Success == compressResult)

            {

                MessageBox.Show(objectZipPathName);

            }

        }



        private void btnUnCompressZip_Click(object sender, EventArgs e)

        {

            string filter = "Zip(*.zip)|*.zip";

            string openFileDialogTitle = "    ";

            string unCompressFilePathName = fileOperate.OpenFile(this.openFileDialog1, filter, openFileDialogTitle, false);

            if (string.IsNullOrEmpty(unCompressFilePathName) || string.IsNullOrWhiteSpace(unCompressFilePathName))

            {

                return;

            }

            string objectPath = unCompressFilePathName.Substring(0, unCompressFilePathName.LastIndexOf('.'));

            string password = string.Empty;//"shenc";

            UnCompressResults unCompressResult = zipOperate.UnCompress7zZip(unCompressFilePathName, objectPath, password);

            if (UnCompressResults.Success == unCompressResult)

            {

                MessageBox.Show(objectPath);

            }

        }

    }

}

좋은 웹페이지 즐겨찾기