您好,登錄后才能下訂單哦!
本篇內(nèi)容介紹了“如何實(shí)現(xiàn)C#調(diào)用動(dòng)態(tài)unlha32.dll解壓Lha后綴的打包文件”的有關(guān)知識(shí),在實(shí)際案例的操作過程中,不少人都會(huì)遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)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;
}
}
}
“如何實(shí)現(xiàn)C#調(diào)用動(dòng)態(tài)unlha32.dll解壓Lha后綴的打包文件”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí)可以關(guān)注億速云網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。