如何實(shí)現(xiàn)C#調(diào)用動態(tài)unlha32.dll解壓Lha后綴的打包文件-創(chuàng)新互聯(lián)

本篇內(nèi)容介紹了“如何實(shí)現(xiàn)C#調(diào)用動態(tài)unlha32.dll解壓Lha后綴的打包文件”的有關(guān)知識,在實(shí)際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!

目前創(chuàng)新互聯(lián)已為上千余家的企業(yè)提供了網(wǎng)站建設(shè)、域名、虛擬空間、綿陽服務(wù)器托管、企業(yè)網(wǎng)站設(shè)計(jì)、潛江網(wǎng)站維護(hù)等服務(wù),公司將堅(jiān)持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長,共同發(fā)展。

復(fù)制代碼 代碼如下:

public class LhaUtity
    {
        ///取得DLL的版本
        [DllImport("unlha32")]
        private static extern UInt16 UnlhaGetVersion();

        /// <summary>
        /// '取得DLL的執(zhí)行情況
        /// </summary>
        /// <returns>是否成功</returns>
        [DllImport("unlha32")]
        private static extern  Boolean UnlhaGetRunning();

        /// <summary>
        /// '文件檢查
        /// </summary>
        /// <param name="szFileName"></param>
        /// <param name="iMode"></param>
        /// <returns></returns>
        [DllImport("unlha32")]
        private static extern Boolean UnlhaCheckArchive(String szFileName, Int32 iMode);

        /// <summary>
        /// 文件解壓縮
        /// </summary>
        /// <param name="hwnd"></param>
        /// <param name="szCmdLine"></param>
        /// <param name="szOutput"></param>
        /// <param name="dwSize"></param>
        /// <returns></returns>
        [DllImport("unlha32")]
        private static extern int Unlha(int hwnd, string szCmdLine, string szOutput, int dwSize);

        /// <summary>
        /// 需要解壓的文件
        /// </summary>
        /// <param name="archiveFile">解壓文件路徑</param>
        /// <param name="extractDir">解壓到路徑</param>
        /// <param name="isDeleteFile">是否刪除</param>
        public static bool UnCompress(string archiveFile, string extractDir,bool  isDeleteFile)
        {
            string extractFullPath = string.Empty;
            string startPath = AppDomain.CurrentDomain.BaseDirectory;

            if (!System.IO.File.Exists(archiveFile))
            {
                //判斷需要解壓的文件存不存
                throw new Exception(string.Format("需要解壓的{0}不存在", archiveFile));
            }

            try
            {
                UInt16 ver = LhaUtity.UnlhaGetVersion();
            }
            catch (Exception ex)
            {
                throw new Exception("沒找到Unlha32.dll文件");
            }

            if (UnlhaGetRunning())
            {
                throw new Exception("DLL正在執(zhí)行");
            }


            if (!UnlhaCheckArchive(archiveFile, 0))
            {
                throw new Exception("文件不能被解壓縮");
            }

            //解壓的路徑
            if (string.IsNullOrEmpty(extractDir))
            {
                extractFullPath =string.Format(@"{0}{1}\", startPath,archiveFile.Substring(archiveFile.LastIndexOf("\\")+1,archiveFile.IndexOf(".lha")-1-archiveFile.LastIndexOf("\\")));
            }
            else
            {
                extractFullPath = extractDir;
            }

            if (!System.IO.Directory.Exists(extractFullPath))
            {
                System.IO.Directory.CreateDirectory(extractFullPath);
            }
        


            int ret = Unlha(0, string.Format("x \"{0}\" \"{1}\"", archiveFile, extractFullPath), null, 0);

            if (ret != 0)
            {


                if (ret == 32800)
                {
                    throw new Exception("文件解壓縮取消");
                }
                else
                {
                    throw new Exception("文件解壓縮異常結(jié)束");

                }

            }
            else
            {
                if (isDeleteFile)
                {
                    System.IO.File.Delete(archiveFile);
                }

                return true;
            }


        }

}


“如何實(shí)現(xiàn)C#調(diào)用動態(tài)unlha32.dll解壓Lha后綴的打包文件”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識可以關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!

本文標(biāo)題:如何實(shí)現(xiàn)C#調(diào)用動態(tài)unlha32.dll解壓Lha后綴的打包文件-創(chuàng)新互聯(lián)
文章URL:http://muchs.cn/article46/ddsshg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站維護(hù)、云服務(wù)器、網(wǎng)站策劃、定制開發(fā)、Google虛擬主機(jī)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站制作