unRAR wrapper/include
Posted: Fri Jan 27, 2012 6:23 pm
New Version of my unRAR-wrapper/include.
Support ASCII/Unicode/x86/x64 Windows Only
please download the unrar DLL here: http://www.rarlab.com/rar/UnRARDLL.exe
Unpack or Execute the exe und put the libs and dlls in the same directory as this inlclude.
// edit
added callback support to RAR_Unpack()
Support ASCII/Unicode/x86/x64 Windows Only
please download the unrar DLL here: http://www.rarlab.com/rar/UnRARDLL.exe
Unpack or Execute the exe und put the libs and dlls in the same directory as this inlclude.
Code: Select all
; The unrar.dll library is freeware. This means:
;
; 1. All copyrights To RAR And the unrar.dll are exclusively
; owned by the author - Alexander Roshal.
;
; 2. The unrar.dll library may be used in any software To handle
; RAR archives without limitations free of charge.
;
; 3. THE RAR ARCHIVER And THE UNRAR.DLL LIBRARY ARE DISTRIBUTED "AS IS".
; NO WARRANTY OF ANY KIND IS EXPRESSED Or IMPLIED. YOU USE AT
; YOUR OWN RISK. THE AUTHOR WILL Not BE LIABLE For Data LOSS,
; DAMAGES, LOSS OF PROFITS Or ANY OTHER KIND OF LOSS While USING
; Or MISUSING THIS SOFTWARE.
;
; Thank you For your interest in RAR And unrar.dll.
;
;
; Alexander L. Roshal
; you can download the required lib and dll at:
; http://www.rarlab.com/rar/UnRARDLL.exe
; the wrapper/include for purebasic is written by Thomas 'ts-soft' Schulz, Berlin Germany
EnableExplicit
CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
#unRARlib$ = "unrar.lib"
CompilerElse
#unRARlib$ = "unrar64.lib"
CompilerEndIf
#ERAR_END_ARCHIVE = 10
#ERAR_NO_MEMORY = 11
#ERAR_BAD_DATA = 12
#ERAR_BAD_ARCHIVE = 13
#ERAR_UNKNOWN_FORMAT = 14
#ERAR_EOPEN = 15
#ERAR_ECREATE = 16
#ERAR_ECLOSE = 17
#ERAR_EREAD = 18
#ERAR_EWRITE = 19
#ERAR_SMALL_BUF = 20
#ERAR_UNKNOWN = 21
#ERAR_MISSING_PASSWORD = 22
#RAR_HEADERFLAG_ENCRYPTED = %00000100
#RAR_OM_LIST = 0
#RAR_OM_EXTRACT = 1
#RAR_OM_LIST_INCSPLIT = 2
#RAR_SKIP = 0
#RAR_TEST = 1
#RAR_EXTRACT = 2
#RAR_VOL_ASK = 0
#RAR_VOL_NOTIFY = 1
#RAR_DLL_VERSION = 4
Enumeration ; UNRARCALLBACK_MESSAGES
#UCM_CHANGEVOLUME
#UCM_PROCESSDATA
#UCM_NEEDPASSWORD
EndEnumeration
Prototype UNRARCALLBACK(msg, UserData, P1, P2)
Prototype CHANGEVOLPROC(ArcName.s, Mode)
Prototype PROCESSDATAPROC(*Addr, Size)
Structure RARHeaderDataEx
ArcName.b[1024]
ArcNameW.w[1024]
FileName.b[1024]
FileNameW.w[1024]
Flags.l
PackSize.l
PackSizeHigh.l
UnpSize.l
UnpSizeHigh.l
HostOS.l
FileCRC.l
FileTime.l
UnpVer.l
Method.l
FileAttr.l
*CmtBuf
CmtBufSize.l
CmtSize.l
CmtState.l
Reserved.l[1024]
EndStructure
Structure RAROpenArchiveDataEx
*ArcName
*ArcNameW
OpenMode.l
OpenResult.l
*CmtBuf
CmtBufSize.l
CmtSize.l
CmtState.l
Flags.l
*Callback.UNRARCALLBACK
*UserData
Reserved.l[28]
EndStructure
Import #unRARlib$
RAROpenArchiveEx(*ArchiveData.RAROpenArchiveDataEx)
RARCloseArchive(hArcData)
RARReadHeaderEx(hArcData, *HeaderData.RARHeaderDataEx)
RARProcessFile(hArcData, Operation, DestPath.s, DestName.s)
RARProcessFileW(hArcData, Operation, DestPath.s, DestName.s)
RARSetCallback(hArcData, *Callback.UNRARCALLBACK, UserData)
RARSetChangeVolProc(hArcData, *ChangeVolProc.CHANGEVOLPROC)
RARSetProcessDataProc(hArcData, *ProcessDataProc.PROCESSDATAPROC)
RARSetPassword(hArcData, Password.p-ascii)
RARGetDllVersion()
EndImport
Structure RarInfos
filename.s
PackSize.l
UnpSize.l
EndStructure
Procedure RAR_GetInfo(File.s, List rarfiles.RarInfos())
Protected hRAR, fFile.s
Protected rarheader.RARHeaderDataEx
Protected raropen.RAROpenArchiveDataEx
ClearList(rarfiles())
CompilerIf #PB_Compiler_Unicode
raropen\ArcNameW = @File
CompilerElse
raropen\ArcName= @File
CompilerEndIf
raropen\OpenMode = #RAR_OM_LIST
hRAR = RAROpenArchiveEx(@raropen)
If hRAR
While Not RARReadHeaderEx(hRAR, @rarheader)
CompilerIf #PB_Compiler_Unicode
fFile = PeekS(@rarheader\FileNameW)
CompilerElse
fFile =PeekS(@rarheader\FileName)
CompilerEndIf
AddElement(rarfiles())
rarfiles()\filename = fFile
rarfiles()\PackSize = rarheader\PackSize
rarfiles()\UnpSize = rarheader\UnpSize
RARProcessFile(hRAR, #RAR_OM_LIST, "", File)
Wend
RARCloseArchive(hRAR)
ProcedureReturn #True
EndIf
ProcedureReturn #False
EndProcedure
Procedure RAR_Unpack(rarfile.s, destpath.s = "", password.s = "", *callback = 0, *userdata = 0)
Protected hRAR
Protected rarheader.RARHeaderDataEx
Protected raropen.RAROpenArchiveDataEx
CompilerIf #PB_Compiler_Unicode
raropen\ArcNameW = @rarfile
CompilerElse
raropen\ArcName= @rarfile
If destpath
CharToOem_(destpath, destpath)
EndIf
CompilerEndIf
raropen\OpenMode = #RAR_OM_EXTRACT
raropen\Callback = *callback
raropen\UserData = *userdata
hRAR = RAROpenArchiveEx(@raropen)
If hRAR
RARSetPassword(hRAR, password)
While Not RARReadHeaderEx(hRAR, @rarheader)
CompilerIf #PB_Compiler_Unicode
RARProcessFileW(hRAR, #RAR_EXTRACT, destpath, #NULL$)
CompilerElse
RARProcessFile(hRAR, #RAR_EXTRACT, destpath, #NULL$)
CompilerEndIf
Wend
RARCloseArchive(hRAR)
ProcedureReturn #True
EndIf
ProcedureReturn #False
EndProcedure
; test
CompilerIf #PB_Compiler_Debugger
NewList rar.RarInfos()
Define File.s = OpenFileRequester("", "", "RAR-Archiv (*.rar)|*.rar", 0)
If File
If RAR_GetInfo(File, rar())
ForEach rar()
Debug rar()\filename
Debug rar()\PackSize
Debug rar()\UnpSize
Debug "-----------------"
Next
EndIf
EndIf
CompilerEndIf
added callback support to RAR_Unpack()