佳木斯湛栽影视文化发展公司

主頁 > 知識庫 > C#調(diào)用動態(tài)unlha32.dll解壓Lha后綴的打包文件分享

C#調(diào)用動態(tài)unlha32.dll解壓Lha后綴的打包文件分享

熱門標簽:電銷業(yè)務(wù) 網(wǎng)站排名優(yōu)化 科大訊飛語音識別系統(tǒng) 電商新玩法 百度AI接口 客戶服務(wù) 人工智能 國美全國運營中心

復(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;
            }


        }

}


項目中需要到解壓這類型的文件,無從下手,上網(wǎng)看資料發(fā)現(xiàn)是日本常用的壓縮算法之一,

查了很多資料,都沒有好的辦法解包,

后來找到這個dll可以解包的

但是網(wǎng)上的代碼都是VB或者C的

唯有自己寫成C#版本的,其實即使C#調(diào)用動態(tài)鏈接庫

先到網(wǎng)上下載這個dll,然后把這個DLL放到C:\Windows\System32目錄下

您可能感興趣的文章:
  • C#將dll打包到程序中的具體實現(xiàn)
  • C#服務(wù)端圖片打包下載實現(xiàn)代碼解析
  • C#使用InstallerProjects打包桌面應(yīng)用程序的完整步驟
  • Unity C#打包AssetBundle與場景詳解
  • C#利用VS中插件打包并發(fā)布winfrom程序
  • c#打包文件解壓縮的實例
  • C#打包應(yīng)用程序,與.NETFramework介紹
  • 將c#編寫的程序打包成應(yīng)用程序的實現(xiàn)步驟分享(安裝,卸載) 圖文
  • 使用VS2010 C#開發(fā)ActiveX控件(下),完整代碼打包下載
  • c#項目將dll打包到exe中的步驟

標簽:益陽 棗莊 咸寧 廈門 南平 拉薩 攀枝花 POS機

巨人網(wǎng)絡(luò)通訊聲明:本文標題《C#調(diào)用動態(tài)unlha32.dll解壓Lha后綴的打包文件分享》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266
    儋州市| 卢湾区| 邢台市| 浦城县| 婺源县| 崇文区| 南华县| 阿克陶县| 丹东市| 洛宁县| 外汇| 聊城市| 翼城县| 城口县| 文化| 海盐县| 松潘县| 新平| 巍山| 博客| 紫阳县| 新竹市| 洪洞县| 积石山| 额敏县| 加查县| 历史| 丹巴县| 通江县| 汝南县| 太仓市| 曲水县| 桐柏县| 虹口区| 舟曲县| 湟源县| 绍兴市| 尉氏县| 玉溪市| 澜沧| 汤原县|