How to implement C # calling dynamic unlha32.dll to decompress the package file of Lha suffix
This article introduces the knowledge of "how to implement C # calling dynamic unlha32.dll to decompress the package file of Lha suffix". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
The copy code is as follows:
Public class LhaUtity
{
/ get the version of DLL
[DllImport ("unlha32")]
Private static extern UInt16 UnlhaGetVersion ()
/ / /
/ 'get the implementation of DLL
/ / /
/ / whether it is successful or not
[DllImport ("unlha32")]
Private static extern Boolean UnlhaGetRunning ()
/ / /
/ / 'File check
/ / /
/ / /
/ / /
/ / /
[DllImport ("unlha32")]
Private static extern Boolean UnlhaCheckArchive (String szFileName, Int32 iMode)
/ / /
/ / decompress the file
/ / /
/ / /
/ / /
/ / /
/ / /
/ / /
[DllImport ("unlha32")]
Private static extern int Unlha (int hwnd, string szCmdLine, string szOutput, int dwSize)
/ / /
/ / Files that need to be extracted
/ / /
/ / decompress the file path
/ / decompress to the path
/ / whether to delete or not
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))
{
/ / decide whether to save the files that need to be unzipped
Throw new Exception (string.Format ("{0} that needs to be extracted 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 executing")
}
If (! UnlhaCheckArchive (archiveFile, 0))
{
Throw new Exception ("File cannot be extracted")
}
/ / the path of decompression
If (string.IsNullOrEmpty (extractDir))
{
ExtractFullPath = string.Format (@ "{0} {1}\", startPath,archiveFile.Substring (archiveFile.LastIndexOf ("\") + 1 Magneto 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 unzipping cancel")
}
Else
{
Throw new Exception ("abnormal end of file extraction")
}
}
Else
{
If (isDeleteFile)
{
System.IO.File.Delete (archiveFile)
}
Return true
}
}
}
This is the end of the content of "how to implement C # calling dynamic unlha32.dll to decompress the package file of Lha suffix". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!