C calls dynamic ES1en32.dll to extract the Lha suffix for packaged file sharing
- 2020-07-21 07:30:09
- OfStack
public class LhaUtity
{
/// achieve DLL The version of the
[DllImport("unlha32")]
private static extern UInt16 UnlhaGetVersion();
/// <summary>
/// ' achieve DLL Implementation of
/// </summary>
/// <returns> The success of </returns>
[DllImport("unlha32")]
private static extern Boolean UnlhaGetRunning();
/// <summary>
/// ' File check
/// </summary>
/// <param name="szFileName"></param>
/// <param name="iMode"></param>
/// <returns></returns>
[DllImport("unlha32")]
private static extern Boolean UnlhaCheckArchive(String szFileName, Int32 iMode);
/// <summary>
/// File decompression
/// </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>
/// Files to unzip
/// </summary>
/// <param name="archiveFile"> Unzip file path </param>
/// <param name="extractDir"> Unzip to the path </param>
/// <param name="isDeleteFile"> Whether or not to delete </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))
{
// Determine whether the file to be unzipped is saved or not
throw new Exception(string.Format(" It needs to be uncompressed {0} There is no ", archiveFile));
}
try
{
UInt16 ver = LhaUtity.UnlhaGetVersion();
}
catch (Exception ex)
{
throw new Exception(" Did not find Unlha32.dll file ");
}
if (UnlhaGetRunning())
{
throw new Exception("DLL Being performed ");
}
if (!UnlhaCheckArchive(archiveFile, 0))
{
throw new Exception(" The file cannot be decompressed ");
}
// Unzip the path
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(" File unzip and cancel ");
}
else
{
throw new Exception(" File decompression exception ends ");
}
}
else
{
if (isDeleteFile)
{
System.IO.File.Delete(archiveFile);
}
return true;
}
}
}
In the project, I need to decompress this type of file, so I have no way to start. I find that it is one of the commonly used compression algorithms in Japan by looking at data on the Internet.
Looking up a lot of information, there is no good way to unpack,
Later I found this dll can be unpacked
But the code on the web is VB or C
Only the C# version itself, even though C# calls the dynamic linking library
Download the dll and place the DLL in the C:\Windows\System32 directory