Copy codeThe Code is as follows:
Public class LhaUtity
{
/// Obtain the DLL version
[DllImport ("unlha32")]
Private static extern UInt16 UnlhaGetVersion ();
/// <Summary>
/// 'Obtain the DLL execution status
/// </Summary>
/// <Returns> Successful </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>
/// Decompress the file
/// </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 sz1_line, string szOutput, int dwSize );
/// <Summary>
/// The file to be decompressed
/// </Summary>
/// <Param name = "archiveFile"> decompress the file path </param>
/// <Param name = "extractDir"> extract the package to the path </param>
/// <Param name = "isDeleteFile"> whether 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 files to be decompressed are saved
Throw new Exception (string. Format ("the {0} To be decompressed does not exist", archiveFile ));
}
Try
{
UInt16 ver = LhaUtity. UnlhaGetVersion ();
}
Catch (Exception ex)
{
Throw new Exception ("Unlha32.dll file not found ");
}
If (UnlhaGetRunning ())
{
Throw new Exception ("DLL is being executed ");
}
If (! UnlhaCheckArchive (archiveFile, 0 ))
{
Throw new Exception ("files cannot be decompressed ");
}
// Decompressed 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 ("unzipping an object ");
}
Else
{
Throw new Exception ("file decompression ends abnormally ");
}
}
Else
{
If (isDeleteFile)
{
System. IO. File. Delete (archiveFile );
}
Return true;
}
}
}
Files of this type need to be decompressed in the project. It is one of the common compression algorithms in Japan to view data online,
I checked a lot of information and couldn't unpack it,
Later, I found this dll to unpackage.
However, the Code on the internet is VB or C.
Only the C # version can be written by yourself. In fact, even if C # Calls the dynamic link library
First download the dll from the Internet and put it in the C: \ Windows \ System32 directory.