The main file :
Code: Select all
XIncludeFile "Rar.pbi"
File.s = OpenFileRequester("Select Rar file", "C:\", "Rar (*.rar)|*.rar", 0)
If File
unrar(File)
EndIf
and the include :
Code: Select all
;PB_unRAR - Paul Leischow, Sept.6, 2002
;RAR Archive extractor that uses the free UNRAR.DLL
#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
Structure RARHeaderData
ArcName.b[260]
FileName.b[260]
Flags.l
PackSize.l
UnpSize.l
HostOS.l
FileCRC.l
FileTime.l
UnpVer.l
Method.l
FileAttr.l
*CmtBuf.l
CmtBufSize.l
CmtSize.l
CmtState.l
EndStructure
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.l
CmtBufSize.l
CmtSize.l
CmtState.l
Reserved.l[1024]
EndStructure
Structure RAROpenArchiveData
*ArcName.l
OpenMode.l
OpenResult.l
*CmtBuf.l
CmtBufSize.l
CmtSize.l
CmtState.l
EndStructure
Structure RAROpenArchiveDataEx
*ArcName.l
*ArcNameW.l
OpenMode.l
OpenResult.l
*CmtBuf.l
CmtBufSize.l
CmtSize.l
CmtState.l
Flags.l
Reserved.l[32]
EndStructure
Global RarLib.l
Global RAROpenArchive.l
Global RARCloseArchive.l
Global RARReadHeader.l
Global RARProcessFile.l
Global RARSetCallback.l
Global RARSetChangeVolProc.l
Global RARSetProcessDataProc.l
Global RARSetPassword.l
Global RARGetDllVersion.l
Prototype.l Prot_RAROpenArchive(a.l)
Prototype.l Prot_RARCloseArchive(a.l)
Prototype.l Prot_RARReadHeader(a.l,b.l)
CompilerIf #PB_Compiler_Unicode=0
Prototype.l Prot_RARProcessFile(a.l,b.l,c.p-ascii,d.p-ascii)
CompilerElse
Prototype.l Prot_RARProcessFile(a.l,b.l,c.p-unicode,d.p-unicode)
CompilerEndIf
Prototype.l Prot_RARSetCallback(a.l,b.l,c.l)
Prototype.l Prot_RARSetChangeVolProc(a.l,b.l)
Prototype.l Prot_RARSetProcessDataProc(a.l,b.l)
CompilerIf #PB_Compiler_Unicode=0
Prototype.l Prot_RARSetPassword(a.l,b.p-ascii)
CompilerElse
Prototype.l Prot_RARSetPassword(a.l,b.p-unicode)
CompilerEndIf
Prototype.l Prot_RARGetDllVersion()
ProcedureDLL Rar_Init()
RarLib=OpenLibrary(#PB_Any,"unrar.dll")
If RarLib
CompilerIf #PB_Compiler_Unicode=0
RAROpenArchive.Prot_RAROpenArchive = GetFunction(RarLib, "RAROpenArchive")
RARReadHeader.Prot_RARReadHeader = GetFunction(RarLib, "RARReadHeader")
RARProcessFile.Prot_RARProcessFile = GetFunction(RarLib, "RARProcessFile")
CompilerElse
RAROpenArchive.Prot_RAROpenArchive = GetFunction(RarLib, "RAROpenArchiveEx")
RARReadHeader.Prot_RARReadHeader = GetFunction(RarLib, "RARReadHeaderEx")
RARProcessFile.Prot_RARProcessFile = GetFunction(RarLib, "RARProcessFileW")
CompilerEndIf
RARCloseArchive.Prot_RARCloseArchive = GetFunction(RarLib, "RARCloseArchive")
RARSetCallback.Prot_RARSetCallback = GetFunction(RarLib, "RARSetCallback")
RARSetChangeVolProc.Prot_RARSetChangeVolProc = GetFunction(RarLib, "RARSetChangeVolProc")
RARSetProcessDataProc.Prot_RARSetProcessDataProc = GetFunction(RarLib, "RARSetProcessDataProc")
RARSetPassword.Prot_RARSetPassword = GetFunction(RarLib, "RARSetPassword")
RARGetDllVersion.Prot_RARGetDllVersion = GetFunction(RarLib, "RARGetDllVersion")
Else
MessageRequester("Erreur", "unrar.dll est introuvable.", #MB_ICONERROR)
End
EndIf
EndProcedure
ProcedureDLL Rar_End()
If RarLib
CloseLibrary(RarLib)
RarLib=0
EndIf
EndProcedure
Procedure UnRar(File$)
CompilerIf #PB_Compiler_Unicode=0
rarheader.RARHeaderData
raropen.RAROpenArchiveData
raropen\ArcName= @File$
CompilerElse
rarheader.RARHeaderDataEx
raropen.RAROpenArchiveDataEx
raropen\ArcNameW = @File$
CompilerEndIf
raropen\CmtBuf = 0
raropen\CmtBufSize = 0
raropen\OpenMode=#RAR_OM_EXTRACT
hRAR=RAROpenArchive(@raropen)
file.s=""
filelist.s=""
If raropen\OpenResult
MessageRequester("Error","Could Not Open RAR File",#MB_ICONERROR)
ProcedureReturn
EndIf
While RARReadHeader(hRAR,@rarheader)=0
CompilerIf #PB_Compiler_Unicode=0
file=PeekS(@rarheader\FileName)
CompilerElse
file=PeekS(@rarheader\FileNameW)
CompilerEndIf
Debug "File:"+file
filelist+file+Chr(10)
If rarheader\flags & #RAR_HEADERFLAG_ENCRYPTED
;Debug "#RAR_HEADERFLAG_ENCRYPTED"
RARSetPassword(hRAR,"free")
;MessageRequester("Error","file is password protected",#MB_ICONERROR)
EndIf
res=RARProcessFile(hRAR,#RAR_EXTRACT,"",file)
Select res
Case #ERAR_BAD_DATA
Debug "File CRC error"
Case #ERAR_BAD_ARCHIVE
Debug "Volume is not valid RAR archive"
Case #ERAR_UNKNOWN_FORMAT
Debug "Unknown archive format"
Case #ERAR_EOPEN
Debug "Volume open error"
Case #ERAR_ECREATE
Debug "File create error"
Case #ERAR_ECLOSE
Debug "File close error"
Case #ERAR_EREAD
Debug "Read error"
Case #ERAR_EWRITE
Debug "Write error"
EndSelect
Wend
If RARCloseArchive(hRAR)=#ERAR_ECLOSE
MessageRequester("RARCloseArchive","Archive close error",#MB_ICONINFORMATION)
EndIf
EndProcedure
Rar_Init()
It should work but you must have the unrar.dll.