Hi Superfraggle and everyone,
I've been learning from this a lot, I have hundreds of Rar file compressed with one of 3 different passwords or none. I would like some help to:
1) Pass a password parameter as:
pass1|pass2|passN
and a loopparse inside the function that tries them showing the input box only after the last one fails.
2) How can I tell when the extraction was completely successful?
I;ve notice that If (FileResult = 10) in line 138 does not mean that was OK???
Here is the funcion I slitly modify. NOt a big thing:
The style (so I can readit

)
The input box
I declare global Password_Saved as the last password entered with success, which may not be necessary if a loop parse can be done. (still not working)
file is full path
If ExPath not exist the same rar folder will be use
If ExPath = propt you choose the folder.
Add if conditions to show progress on RarCallback function (avoid show an empty progress on errors)
Some comments (please correct me if Im wrong)
Bellow is a piece of how I use the function from my main script.
NOt working example, but the function should work!
Thanks!!!
Code:
File := WE_CURRENT_SELECTED_ITEM_FULL_PATH_%A_Index%
If A_ThisMenuItem = Extract &to...
ExPath = Propt
Else
ExPath = ;WILL USE THE ROOT DIR
ExPaths = 1
ShowProg = 1
Password = %password1%|%password2%|%password3% ;This is how I want it to be
ExtractFileResult := ExtractRAR(File,ExPath,ExPaths,ShowProg,Password)
If ExtractFileResult <> FAIL
If ExtractFileResult <>
If A_ThisMenuItem = Extract Here && &Recycle
filedelete, %File%
Return
ExtractRAR(File,ExPath ="",ExPaths=1,ShowProg=1,Password="")
{
Global Prog,UnpackedFS,ExtractFileResult,Password_Saved
If Password = ;Update If Blank
Password := Password_Saved
If Password_Saved = ;Update If Blank
Password_Saved := Password
IfNotExist, %File% ;CHECK FILE EXIST
{
MsgBox , 262160, %A_ScriptName% ,`n`nPlease Set a Valid File to Extract.`n`nCureent Value: %File%`n`nPress OK to Close`n`n
ExtractFileResult = FAIL
Return ExtractFileResult
}
IfNotExist, %ExPath%
{
If ExPath = Propt
FileSelectFolder, ExPath, %A_Desktop%, 3 ;SELECT PATH OR EXTACT ON SOURCE PARENT DIRR
Else
SplitPath, File, , ExPath
ExPath := RegExReplace(ExPath, "\\$") ; Removes the trailing backslash, if present.
}
IfNotExist, %ExPath% ;CHECK DIRR EXIST
{
MsgBox , 262160, %A_ScriptName%,`n`nPlease Select a Valid Directory to Extract.`n`nPress OK to Close`n`n
ExtractFileResult = FAIL
Return ExtractFileResult
}
Fname := File
varsetcapacity(ArchiveData,32,0)
Numput(&File,ArchiveData)
Numput(1,ArchiveData,4)
hModule := DllCall("LoadLibrary", "str", "unrar.dll")
if (!hModule)
{
MsgBox , 262160 , %A_ScriptName% ,Could not Load Library
ExtractFileResult = FAIL
Goto, Sub_Return
}
hArchive:=DLLCall("unrar.dll\RAROpenArchive","Uint",&ArchiveData) ;OPEN ARCHIVE
Result:=Numget(&ArchiveData,8)
If (Result = 11)
{
MsgBox , 262160 , %A_ScriptName% ,Not enough Memory
ExtractFileResult = FAIL
Goto, Sub_Return
}
If (Result = 12)
{
MsgBox , 262160 , %A_ScriptName% ,Archive Header Broken
ExtractFileResult = FAIL
Goto, Sub_Return
}
If (Result = 13)
{
MsgBox , 262160 , %A_ScriptName% ,Invalid Archive Type
ExtractFileResult = FAIL
Goto, Sub_Return
}
If (Result = 14)
{
MsgBox , 262160 , %A_ScriptName% ,Unknown encryption
ExtractFileResult = FAIL
Goto, Sub_Return
}
If (Result = 15)
{
MsgBox , 262160 , %A_ScriptName% ,Error Opening File
ExtractFileResult = FAIL
Goto, Sub_Return
}
If (ShowProg)
{
Address:=registercallback("RarCallback","",4,1)
If (Address = "")
{
Msgbox , 262160 , %A_ScriptName% , Error extracting archive!`n`nReturned adress to machine-code function was empty.
ExtractFileResult = FAIL
Goto, Sub_Return
}
}
Else
{
Address:=registercallback("RarCallback","",4,0)
If (Address = "")
{
Msgbox , 262160 , %A_ScriptName% , Error extracting archive!`n`nReturned adress to machine-code function was empty.
ExtractFileResult = FAIL
Goto, Sub_Return
}
}
DLLCall("unrar.dll\RARSetCallback","UInt",hArchive,"Uint",Address,"Uint",0) ;READ ARCHIVE
Varsetcapacity(ArchiveHeader,572,0)
Loop
{
FileResult:=DLLCall("unrar.dll\RARReadHeader","UInt",hArchive,"Uint",&ArchiveHeader)
If (FileResult = 12)
{
Progress, Off
MsgBox, 262160, %A_ScriptName% ,File Header Currupt - Incorrect Password????
ExtractFileResult = FAIL
Goto, Sub_Return
}
If (FileResult = 10) ;FNISH READING
{
ExtractFileResult = OK ;NOT SURE HOW TO TELL OK OR FAIL
Goto, Sub_Return
}
Varsetcapacity(CurFile,260,0)
DllCall("lstrcpynA", "Str", CurFile, "UInt", &ArchiveHeader+260, "int", 260)
UnpackedFS:=Numget(&ArchiveHeader,528)
If (ShowProg)
If A_Index > 1 ;DO NOT SHOW THE FIRST FILE IN CASE GIVES ERROR
{
Progress,R0-%UnpackedFS% M P0 Y600 w1100,%CurFile%,Source: %Fname%, Compressed File Extraction in Progress... ;THIS PROGRESS TITLE MUST MACH THE ONE ON THE OTHER FUNCTION
Prog:=0
}
Sleep, 300 / A_Index ;Sleep more at the begining just in case is a one or just a few files to extract
If (substr(ExPath,0,1) != "\")
{
Expath.="\"
}
If (ExPaths)
{
File:=ExPath . CurFile
}
Else
{
File:=ExPath . Regexreplace(CurFile,".*\\","")
}
ExResult:=DLLCall("unrar.dll\RARProcessFile","UInt",hArchive,"Uint",2,"Uint",0,"Uint",&File)
If (ExResult != 0)
{
Progress,Off
MsgBox , 262160 , %A_ScriptName% ,`nError Extracting Compressed File.
ExtractFileResult = FAIL
Goto, Sub_Return
}
Sleep 10 ;CPU
}
;____________________________________________CLOSE PROGRESS, RELEASE FILE, CLOSE LIBRERY AND Return Result
Sub_Return:
Progress,Off
DLLCall("unrar.dll\RARCloseArchive","Uint",hArchive)
DllCall("FreeLibrary ", "UInt", hModule)
Return ExtractFileResult
}
;___________________________________________________FUNCTION CALL BACK
RarCallback(Message,User,P1,P2)
{
Global Prog,ShowProg,ExtractFileResult,Password,Password_Saved
If Message = 2
{
InputBox, Password, Please enter Compresed Rar File Password, Please enter Compresed File Password, , 550, 130, , , , , %Password%
If ErrorLevel <> 0 ;CANCEL OR TIME OUT
{
ExtractFileResult = FAIL
Progress,Off
DLLCall("unrar.dll\RARCloseArchive","Uint",hArchive)
DllCall("FreeLibrary ", "UInt", hModule)
Return ExtractFileResult
}
DllCall("lstrcpynA","Uint",P1+0, "STR",Password,"int", P2)
}
If Message = 1
If a_eventinfo = 1
If ShowProg = 1 ;SOME HOW REDUNDANT
IfWinExist, Compressed File Extraction in Progress... ahk_class AutoHotkey2 ;PROGRESS BAR MUST EXIST, THIS PROGRESS TITLE MUST MACH THE ONE ON THE OTHER FUNCTION
{
Prog+=P2
Progress,%Prog%
}
return,1
}