Psibernetic Posted January 16, 2007 Share Posted January 16, 2007 (edited) I need some help, when I try to "secure" a folder, it is supposeed to encrypt the PsiE_******.zp, it doesnt....works fine with files any ideas? I kno I am asking alit..but I am out of options.. I am including the files... Securacy runs the program others are includes...(problem could be in the includes) Edited January 16, 2007 by Psibernetic [sup]Psibernetic[/sup]My Creations:X-HideSecuracy Link to comment Share on other sites More sharing options...
Somerset Posted January 16, 2007 Share Posted January 16, 2007 I need some help, when I try to "secure" a folder, it is supposeed to encrypt the PsiE_******.zp, it doesnt....works fine with files any ideas? I kno I am asking alit..but I am out of options..I am including the files... Securacy runs the program others are includes...(problem could be in the includes)your thread here is kind of confusing... please clear this up. Link to comment Share on other sites More sharing options...
Psibernetic Posted January 16, 2007 Author Share Posted January 16, 2007 sorry uploading issues... [sup]Psibernetic[/sup]My Creations:X-HideSecuracy Link to comment Share on other sites More sharing options...
Psibernetic Posted January 16, 2007 Author Share Posted January 16, 2007 Ok RE-cap...(sorry it is very confusing to me so I am trying to explain my own confusion...) When I run my script Securacy, it is supposed to take the file or folder, make a zip file out of it, and then encrypt the zip, this one adds the prefix PsiE_ (which means psibernetic encrypt)...it works fine with files, but if u attempt it on a folder, the file that is supposed to be encrypted will not encrypt [sup]Psibernetic[/sup]My Creations:X-HideSecuracy Link to comment Share on other sites More sharing options...
Somerset Posted January 16, 2007 Share Posted January 16, 2007 ok thanks for clearing up your post, but why not post your script here... so we can have a look at it, so it can be diagnosed easily... files being uploaded by people whom i don't know is kind of ehhhhh. It could be infected with a virus for all o know. so please just post the script... that is the preffered method. Link to comment Share on other sites More sharing options...
Psibernetic Posted January 16, 2007 Author Share Posted January 16, 2007 umm.. there is alot of code.... in multiple files... it'll be a mess but ill try.... [sup]Psibernetic[/sup]My Creations:X-HideSecuracy Link to comment Share on other sites More sharing options...
Psibernetic Posted January 16, 2007 Author Share Posted January 16, 2007 Securacy.au3CODE;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;~~~~~~~~~~~~~~~~~~~(Psibernetic Computing's X- AutoIt3 Special Edition)~~~~~~~~~~~~~~~;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(01/03/07 - 1/10/07)~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#include <GUIConstants.au3>#include <File.au3>#include <Array.au3>#Include <String.au3>#Include <GuiListView.au3>#include <FileEncryption.au3>#include <xZipUDF.au3>#Include <PsiberneticUDF.au3> #NoTrayIcon;Initial Variables$xHSpath=@ScriptDir & "\HSlog\logHSfiles.log" ;Path to the Entry Database$xEncryptPath=@scriptDir &"\HSlog\PSIFR.log" ;Path to the first time run and password file$xFirstRun=FileReadLine($xEncryptPath, 1) ;is it the first run?;This Code Executes on user's first run of the program, sets the password for encryption and decryptionIf $xFirstRun<>1 then ;execute if first run $xEncryptPassword=InputBox("Password Set","Please set your password to encrypt your database","","*M") ;ask what to set the password as If @error=1 then exit $xSetEncryptedPass=_StringEncrypt(1,$xEncryptPassword,"PsiPhi",2) ;Encrypt it FileWriteLine($xEncryptPath, 1) ;Write on the first line 1 telling x-hide it has been ran before (set this to zero manually to change pass) FileWriteLine($xEncryptPath, $xSetEncryptedPass) ;Write the encrypted passwaord ;Log Encryption $xDatabaseCrypt=_FileCountLines($xHSpath) ;See how many lines there are If $xDatabaseCrypt<>0 Then ; If there are any entries, do following: dim $ArrayToClearLog[1] ;make an array for clearing file $ArrayToClearLog[0]="" ;set the array's only element to nothing $xHS_Database=FileRead($xHSpath) ; read the log into $xHS_Database $xHS_Database_En=_StringEncrypt(1,$xHS_Database,$xDecryptPassword,2) ;Save the encrypted log into $xHS_Database_En _FileWriteFromArray ($xHSpath, $ArrayToClearLog) ;Clear the log FileWrite($xHSpath, $xHS_Database_En) ;Write the encrypted log back EndIfEndIf$xPasswordEncrypted=FileReadLine($xEncryptPath, 2)$xPasswordDecrypted=_StringEncrypt(0,$xPasswordEncrypted,"PsiPhi",2)$xDecryptPassword=InputBox("Password Required", "Please enter the password to decrypt your database", "","*M")If @error=1 then exit If $xDecryptPassword<>$xPasswordDecrypted Then msgbox(0,"ERROR","Incorrect Password, Good-Bye") ExitElse ;Log Decryption $xDatabaseCrypt=_FileCountLines($xHSpath) ;See how many lines there are If $xDatabaseCrypt<>0 Then ; If there are any entries, do following: dim $ArrayToClearLog[1] ;make an array for clearing file $ArrayToClearLog[0]="" ;set the array's only element to nothing $xHS_Database=FileRead($xHSpath) ; read the log into $xHS_Database $xHS_Database_De=_StringEncrypt(0,$xHS_Database,$xDecryptPassword,2) ;Save the decrypted log into $xHS_Database_De _FileWriteFromArray ($xHSpath, $ArrayToClearLog) ;Clear the log FileWrite($xHSpath, $xHS_Database_De) ;Write the Decrypted log back EndIfEndIf;Define GUI type and specifics$xMainWin=GUICreate("Securacy Beta R1", 300, 242) GUISetIcon ("Xau3.ico") GUISetBkColor(0x000000);Picture CTRLs$xLogoPic=GUICtrlCreatePic(@ScriptDir & "\button\securacy.bmp", 63,0, 172, 63) ;$xLogoPic Construction$xFilePic=GUICtrlCreatePic(@ScriptDir & "\button\file.bmp",-10,122,75,30) ;$xFilePic Construction$xFolderPic=GUICtrlCreatePic(@ScriptDir & "\button\folder.bmp",215,122,75,30) ;$xFolderPic Construction$xHide=GUICtrlCreatepic(@scriptDir & "\Button\secure.bmp", 2, 32, 59, 30) ;xHide Construction$xBrowse=GUICtrlCreatepic(@scriptDir & "\Button\browse.bmp", 120, 68, 59, 30) ;xBrowse Construction$xUnHide=GUICtrlCreatepic(@scriptDir & "\Button\unsecure.bmp", 239, 32, 59, 30) ;xUnHide Construction ;Input CTRLs$xFilePath=GUICtrlCreateInput("",41,103,216,20) ;xFilePath Construction GUICtrlSetBkColor($xFilePath, 0x000000) ;xFilePath Background Color: 000000(Black) GUICtrlSetColor($xFilePath, 0x00FF00) ;xFilePath Font Color: 00FF00(lime);Slider CTRLs$xBrowseType=GUICtrlCreateSlider(65,127,150) ;xBrowseType Construction GUICtrlSetLimit($xBrowseType,2,1) ; change min/max value;ListView CTRLs$xHiddenListView=GUICtrlCreateListView ("File|Path",0,154,300,88,$LVS_NOSORTHEADER) ;xHiddenListView Construction GUICtrlSetBkColor($xHiddenListView, 0x000000) ;xHiddenListView Background Color: 000000(Black) GUICtrlSetColor($xHiddenListView, 0x00FF00) ;xHiddenListView Font Color: 00FF00(lime) _GUICtrlListViewSetColumnWidth ( $xHiddenListView, 0, 70 ) ;set "File" column width to 70 _GUICtrlListViewSetColumnWidth ( $xHiddenListView, 1, 226 ) ;set "Path" column width to 226;ListView Item CTRLspsi_LoadList($xHSpath, $xHiddenListView) ;Call the xLoadList function exports control IDs to the array $xListItems[];GUI activateGUISetState(@SW_SHOW);Program Event Checking loopWhile 1 $Event=GUIGetMsg() Select case $Event=$GUI_EVENT_CLOSE ExitLoop case $Event=$xBrowse $xBrowseMethod=GUICtrlRead($xBrowseType) Select case $xBrowseMethod=1 $xRetrievedPath=FileOpenDialog("Choose your file to hide/unhide...", "C:\", "All (*.*)", 1+2+4+8) ControlSetText("","",$xFilePath, $xRetrievedPath) case $xBrowseMethod=2 $xRetrievedPath=FileSelectFolder("", "C:\" & @CommonFilesDir) ControlSetText("","",$xFilePath, $xRetrievedPath) EndSelect case $Event=$xHide ;If Hide is clicked execute following $xFile=ControlGetText ("","",$xFilePath) ;get the path returned by Browse $xFileCol=psi_PathManipulate($xFile, "F") ;retreive the file portion of the fullpath $xPathCol=psi_PathManipulate($xFile, "P") ;retreive the path portion of the fullpath Select ;if no Filename, do not include it in new path case $xFileCol<>"N/A" Dim $xFullPath[1] $xFullPath[0]=$xPathCol & $xFileCol ;Essentially the same as $xFile, but $xFile may cause a conflict so remade variable ensure proper execution $xZippedFilePath=$xFullPath[0] & ".zip" _ZipOpen($xZippedFilePath) _ZipPackGroup($xFullPath, False) _ZipClose() $xFileCol="PsiE_" & $xFileCol ;If selected file/folder is a folder path then do not add prefix PsiE_ $xFileAndPathCols=$xFileCol & "|" & $xPathCol ;format the path and filename as reurned by psi_PathManipulate $xEncryptedFilePath=$xPathCol & $xFileCol & ".zip" case Else Dim $xFullPathDir[1] $xFolderDir=psi_PathManipulate($xFile & ".", "F") ;retreive the final dir portion of the fullpath (added decimal to trick function into treating it as a file) $xFolderDir=StringLeft($xFolderDir,stringlen($xFolderDir)-1) ;get rid of the decimal $xPathFolder=psi_PathManipulate($xFile & ".", "P") ;retreive the path portion of the fullpath (added decimal to trick function to returning the path -1 directory) $xFullPathDir[0]=$xPathFolder & $xFolderDir ;Essentially the same as $xFile, but $xFile may cause a conflict so remade variable ensure proper execution $xZippedFilePath=$xPathFolder & $xFolderDir & ".zip" _ZipOpen($xZippedFilePath) _ZipPackGroup($xFullPathDir, False) _ZipClose() $xFileAndPathCols=$xFileCol & "|" & $xPathCol ;format the path and filename as reurned by psi_PathManipulate $xEncryptedFilePath=$xPathFolder & "PsiE_" & $xFolderDir & ".zip" EndSelect _FileEncrypt($xZippedFilePath, $xEncryptedFilePath, $xDecryptPassword & "@1") ; IDEA Encrypt File psi_Hide($xEncryptedFilePath, "hide") ;make "Superhidden" (Hidden System files) psi_AddListItem($xHSpath, $xFileAndPathCols, $xHiddenListView) ; add new file to the log and ListView ControlSetText("","",$xFilePath,"") ;empty the input boxes content _FileDecrypt($xEncryptedFilePath,"C:\DE.zip",$xDecryptPassword & "@1") ; IDEA Encrypt File case $Event=$xUnHide ;If UnHide is clicked execute following $xFile=ControlGetText ("","",$xFilePath) psi_Hide($xFile, "unhide") $xPrefixCheck=stringleft(psi_PathManipulate($xFile, "F"), 4) If StringLower($xPrefixCheck)="psie" Then $xOriginalFileName=stringright(psi_PathManipulate($xFile, "F"), stringlen(psi_PathManipulate($xFile, "F"))-5) $xOriginalPath=psi_PathManipulate($xFile, "P") $xOriginalFilePath=$xOriginalPath & $xOriginalFilename _FileDecrypt($xFile, $xOriginalFilePath, $xDecryptPassword & "@1") FileDelete($xFile) EndIf psi_RemoveListItem($xHiddenListView, $xHSpath) ControlSetText("","",$xFilePath,"") case $Event=$GUI_EVENT_PRIMARYDOWN psi_DetectDblClick() case $Event=$xFilePic GUICtrlSetData($xBrowseType,1) case $Event=$xFolderPic GUICtrlSetData($xBrowseType, 2) EndSelectwend;ReEnccrypt Entry DataBase$xDatabaseCrypt=_FileCountLines($xHSpath) ;See how many lines there areIf $xDatabaseCrypt<>0 Then ; If there is any entries, do following: dim $ArrayToClearLog[1] ;make an array for clearing file $ArrayToClearLog[0]="" ;set the array's only element to nothing $xHS_Database=FileRead($xHSpath) ; read the log into $xHS_Database $xHS_Database_En=_StringEncrypt(1,$xHS_Database,$xDecryptPassword,2) ;Save the encrypted log into $xHS_Database_En _FileWriteFromArray ($xHSpath, $ArrayToClearLog) ;Clear the log FileWrite($xHSpath, $xHS_Database_En) ;Write the encrypted log backEndIf;End Executionexitfunc psi_DetectDblClick() $psi_SelectedItemListView=_GUICtrlListViewGetCurSel($xHiddenListView) Select Case $psi_SelectedItemListView<>-1 $psi_LonePath=_GUICtrlListViewGetItemText($xHiddenListView, $psi_SelectedItemListView,1) $psi_Filename=_GUICtrlListViewGetItemText($xHiddenListView, $psi_SelectedItemListView,0) If $psi_Filename<>"N/A" Then $psi_FullPath=$psi_LonePath & $psi_Filename GUICtrlSetData($xFilePath, $psi_FullPath) Else GUICtrlSetData($xFilePath, $psi_LonePath) EndIf EndSelectEndFunc FileEncryption.au3:CODE;===============================================================================;; Function Name: _FileEncrypt(); Description: Encrypts a file using the IDEA Algorithm; Parameter(s): $FileInput - File to encrypt; $FileOutput - Where to save encrypted file; $sKey - Key to encrypt file with; Requirement(s): File.au3; Return Value(s): On Success - Returns 1; On Failure - Sets @error to 1 if input file does not exist; - Sets @error to 2 if writing new file fails; Author(s): RazerM;===============================================================================;Func _FileEncrypt($FileInput, $FileOutput, $sKey) Select Case Not FileExists(@TempDir & "\encrypt.com") _WriteEncryptCom() Case Not FileExists($FileInput) Return SetError(1, 0, 0) EndSelect $FileTemp = __FileCopy($FileInput, $FileOutput) If @extended = 0 Then Return SetError(2, 0, 0) RunWait(@ComSpec & " /c echo " & $sKey & "|" & FileGetShortName(@TempDir & "\encrypt.com") & " + " & FileGetShortName($FileOutput), "", @SW_HIDE) FileDelete(@TempDir & "\encrypt.com") FileDelete($FileTemp)EndFunc ;==>_FileEncrypt;===============================================================================;; Function Name: _FileDecrypt(); Description: Decrypt a file using the IDEA Algorithm; Parameter(s): $FileInput - File to decrypt; $FileOutput - Where to save decrypted file; $sKey - Key to decrypt file with; Requirement(s): File.au3; Return Value(s): On Success - Returns 1; On Failure - Sets @error to 1 if input file does not exist; - Sets @error to 2 if writing new file fails; Author(s): RazerM;===============================================================================;Func _FileDecrypt($FileInput, $FileOutput, $sKey) Select Case Not FileExists(@TempDir & "\encrypt.com") _WriteEncryptCom() Case Not FileExists($FileInput) Return SetError(1, 0, 0) EndSelect If Not FileExists(@TempDir & "\encrypt.com") Then _WriteEncryptCom() $FileTemp = __FileCopy($FileInput, $FileOutput) If @extended = 0 Then Return SetError(2, 0, 0) RunWait(@ComSpec & " /c echo " & $sKey & "|" & FileGetShortName(@TempDir & "\encrypt.com") & " - " & FileGetShortName($FileOutput), "", @SW_HIDE) FileDelete(@TempDir & "\encrypt.com") FileDelete($FileTemp)EndFunc ;==>_FileDecryptFunc __FileCopy($FileInput, $FileOutput) Local $NULL, $szDrive, $szDir, $szFName, $szExt _PathSplit($FileOutput, $szDrive, $szDir, $szFName, $szExt) FileCopy($FileInput, @TempDir & "\" & $szFName & $szExt, 9) Return SetError(0, FileMove(@TempDir & "\" & $szFName & $szExt, $FileOutput, 9), @TempDir & "\" & $szFName & $szExt)EndFunc ;==>__FileCopyFunc _WriteEncryptCom() Local $com = "0x" $com &= "E81A01BAE402BE8000AC0AC0740AACAC3C2D74073C2B7407E9FE00FE06DD01AD" $com &= "AC3C2077FB884CFFB2F0B409CD21B2F6B40ACD21B110BEF8025156B104BE8203" $com &= "BF9A03F3A55E56E8DC00BE9A03568BFEE8E600B104BE7A03BF8A0357F3A55F5E" $com &= "56E802018BF7BF7A03E8C3005F5E5657E8B300B104BE8A03F3A55E8BFEE8B900" $com &= "B104BE8203BF92035657F3A55F57BE9A03E8D2005E5FE896005E83C60859E299" $com &= "BF7A03E89300BA8400B8023DCD21720B93B90080BA0A04B43FCD2172590BC074" $com &= "5C5250538BFA050700B103D3E891BE7A035157BF0204E88D00B904005EF8720F" $com &= "AD86E03305AB86E08944FEE2F3EB0F8B1DAD86E0AB33D886FB895CFEE2F18BFE" $com &= "59E2CB5B5A52F7DA49B80142CD21595AB440CD21739BBADE02B409CD21BFF702" $com &= "B91381F3AAC3B104AD86E0ABE2FAC3B90400AD3305ABE2FAC383C710B3088BC3" $com &= "24073C068B45F28B55F472088B55E474038B45E2B109D3E0B107D3EA0BC2AB43" $com &= "80FB3475D9C3C606780308578B158B4D028B6D048B7D06E8500093AD03C8AD03" $com &= "E88BD7E8440097515533EB33CF8BD5E8380003C8958BD1E8300003E89133D933" $com &= "FD5A5833CA33E88BD3FE0E780375C8E8180093AD03E8AD03C88BD7E80C005F57" $com &= "93AB95AB91AB93AB5FC352ADF7E22BC25A7507402B44FE2BC2C3150000C34572" $com &= "726F72094944454120F12046696C65244B65793A202480" FileDelete(@TempDir & "\encrypt.com") Return FileWrite(@TempDir & "\encrypt.com", BinaryString($com))EndFunc ;==>_WriteEncryptComPsiberneticUDF.au3:CODE#include-once;Hide/UnHide FunctionFunc psi_Hide($psi_File, $psi_Action) select case $psi_Action="hide" ;if action is hide execute FileSetAttrib($psi_File, "+SH") ;Hide chosen file case $psi_Action="unhide" ;if action is unhide execute FileSetAttrib($psi_File, "-SH") ;UnHide chosen file EndSelectEndFunc ;==>psi_Hide()#cs=========================================================================================Function Referencepsi_LoadList--------------------------------------------------------------------------------Loads a set of ListViewItems into a ListView box from a file#Include <PsiberneticUDF.au3>psi_loadlist ( $psi_Path, $psi_ListViewCTRL )Parameters$psi_Path Indicates path of log $psi_ListViewCTRL Indicates the ID of the ListView CTRL the items will be placed intoReturn ValueSuccess: Returns the global array $psi_ListViewItems[] which contains the control IDs of each item.Failure: Returns program run-time error. RemarksThis function will read from the file indicated, each line is considered an entry. Relatedpsi_AddListItem, psi_RemoveListItem=========================================================================================#cefunc psi_LoadList($psi_Path, $psi_ListViewCTRL) $psi_FilesContainer=FileOpen($psi_Path,0) ;Open the log $psi_logEntries=_FileCountLines($psi_Path) ;Count the entries in the log Dim $psi_FileEntry[1] ;Set the log importing array (integer indexed) $psi_ImportIndex=0 ;set the counter at 0 while $psi_ImportIndex < $psi_LogEntries ;Log import loop beginning $psi_ImportIndex=$psi_ImportIndex+1 ;Increase counter _ArrayAdd($psi_FileEntry, FileReadLine($psi_FilesContainer, $psi_ImportIndex)) ;import an entry from the log into $psi_FileEntry[] WEnd ;Log import loop ending FileClose($psi_FilesContainer) ;Close the log Global $psi_ListViewItems[1] ;set the array containing the handles of the ListView Items (integer indexed) Global $psi_ImportIndex $psi_ImportIndex=0 ;set the counter at 0 While $psi_ImportIndex < $psi_LogEntries ;Item add loop beginning $psi_ImportIndex=$psi_ImportIndex+1 ;Increase counter _ArrayAdd($psi_ListViewItems, GUICtrlCreateListViewItem($psi_FileEntry[$psi_ImportIndex], $psi_ListViewCTRL)) ;addListView entry to the specified ListView CTRL Wend ;Item add loop ending return endfunc ;==>psi_LoadList();===============================================================================;; Function Name: psi_PathManipulate ( $psi_PathToEval, $psi_Action ); Description: Retrieve the filename or path from a file or folder path; Parameter(s): $psi_PathToEval -The path to retrieve the filename from; $psi_Action -Retrieve filename or path correct values: F or P; Requirement(s): #include <PsiberneticUDF.au3>; Return Value(s): On Success - Returns the filename; On Failure - Returns N/A as filename; @ERROR = 1 Not a file path; @ERROR = 2 Not a valid path; Author(s): Psibernetic;;===============================================================================func psi_PathManipulate($psi_PathToEval, $psi_Action) Select case StringInStr($psi_PathToEval, ".")=0 SetError(1) $psi_Filename="N/A" $psi_Path=$psi_PathToEval select case StringUpper($psi_Action)="F" Return $psi_Filename case StringUpper($psi_Action)="P" Return $psi_Path EndSelect case StringInStr($psi_PathToEval, "\")=0 SetError(2) $psi_Filename="N/A" $psi_Path="N/A" Return $psi_Filename Return $psi_Path select case StringUpper($psi_Action)="F" Return $psi_Filename case StringUpper($psi_Action)="P" Return $psi_Path EndSelect case Else $psi_Filename="" While StringRight($psi_PathToEval,1)<>"\" $psi_Filename=StringRight($psi_PathToEval,1) & $psi_Filename $psi_PathToEval=StringLeft($psi_PathToEval, (StringLen($psi_PathToEval)-1)) WEnd $psi_Path=$psi_PathToEval select case StringUpper($psi_Action)="F" Return $psi_Filename case StringUpper($psi_Action)="P" Return $psi_Path EndSelect EndSelect ;==>psi_PathManipulate()EndFuncfunc psi_AddListItem($psi_Path, $psi_Data, $psi_ListViewCTRL) FileWriteLine($psi_Path, $psi_Data) ;Add the entry _ArrayAdd($psi_ListViewItems, GUICtrlCreateListViewItem($psi_Data, $psi_ListViewCTRL)) Global $psi_ImportIndex $psi_ImportIndex=$psi_ImportIndex+1EndFunc ;==>psi_AddListItem()func psi_RemoveListItem($psi_ListViewID, $psi_File) $psi_SelectedItem=_GUICtrlListViewGetCurSel($psi_ListViewID) $psi_SelectedItem=$psi_SelectedItem+1 Dim $psi_FileRW[1] _FileReadToArray($psi_File, $psi_FileRW) _ArrayDelete($psi_FileRW, $psi_SelectedItem) _FileWriteFromArray($psi_File, $psi_FileRW, 1) GUICtrlDelete($psi_ListViewItems[$psi_SelectedItem]) _ArrayDelete($psi_ListViewItems, $psi_SelectedItem)EndFunc ;==>psi_RemoveListItem()xZipUDF.au3:CODE; ======================================================================================; Zip UDFs based on standared fileOpen()/fileClose() system; Based on other people's work.;; Only the more basic functions of XZip are represnted (poorly);; Requires: XZip.dll:; http://xstandard.com/printer-friendly.asp?...60-2267ED6763A7; ======================================================================================#include-once#include <array.au3>#include <file.au3>Global $oXZip_UDFGlobal, $sZipPath_UDFGlobal, $oComError_UDFGlobal, $sDllLoc_UDFGlobal, $iRegDelay_UDFGlobal; ============================================================================; Turned off COM erroring; I don't think it's needed if the scripter is not directly interacting with; the object, plus it causes an error with my choosen exit(_ZipClose) method; ============================================================================;$oComError_UDFGlobal = ObjEvent("AutoIt.Error", "__XZip_COM_Error");===============================================================================;; Description: :Open ZIP file, and load XZip.dll as a service; Parameter(s): :Archive path, (Opt)XZip.dll path (default to @ScriptDir),; (opt)Delay between regsrv, and objcreate (default 150 ms); Requirement: :XZip.dll, XZip.au3; Return Value(s): :True/False (error #); User CallTip: :_ZipOpen(ArchivePath, XZipDllPath, Delay in MS);;===============================================================================;Func _ZipOpen($sNewArchivePath, $sDllPath = '', $iDelay = 200) If $sDllPath = '' Then $sDllPath = @ScriptDir & '\XZip.dll' ;some error checking If Not FileExists($sDllPath) Then SetError(1) Return False ElseIf Not IsInt($iDelay) Then SetError(2) Return False EndIf ;set the globals $sZipPath_UDFGlobal = $sNewArchivePath $sDllLoc_UDFGlobal = $sDllPath $iRegDelay_UDFGlobal = $iDelay __DOSStart('regsvr32 /s "' & $sDllLoc_UDFGlobal & '"') Sleep($iRegDelay_UDFGlobal);needs a sec when loaded silent. $oXZip_UDFGlobal = ObjCreate('XStandard.Zip') If IsObj($oXZip_UDFGlobal) Then;make sure it's opened Return True Else SetError(3) Return False EndIfEndFunc ;==>_ZipOpen;===============================================================================;; Description: :List items in given Zip file; Parameter(s): :None (see _ZipOpen); Requirement: :XZip.dll, XZip.au3; Return Value(s): :Array contaning archive contents; User CallTip: :_ZipContents();;===============================================================================;Func _ZipContents();this func needs some more work Local $oItem Local $aRet[1] If Not IsObj($oXZip_UDFGlobal) Then SetError(1) Return False EndIf For $oItem In $oXZip_UDFGlobal.Contents ($sZipPath_UDFGlobal) _ArrayAdd($aRet, $oItem.Path & $oItem.Name) Next $aRet[0] = UBound($aRet) Return $aRetEndFunc ;==>_ZipContents;===============================================================================;; Description: :Add items to opened Zip file; Parameter(s): :Array contaning item paths, (opt)Retain dir structure; Requirement: :XZip.dll, XZip.au3; Return Value(s): :True/False (error #); User CallTip: :_ZipPack(array of item paths, Bool);;===============================================================================;Func _ZipPackGroup(ByRef $aItems, $bKeepPath = True);this func needs some more work If Not IsObj($oXZip_UDFGlobal) Then SetError(1) Return False EndIf Local $x For $x = 0 To UBound($aItems) - 1 If Not FileExists($aItems[$x]) Then SetError(2) SetExtended($aItems[$x]) Return False EndIf $oXZip_UDFGlobal.Pack ($aItems[$x], $sZipPath_UDFGlobal, $bKeepPath) Next Return TrueEndFunc ;==>_ZipPackGroup;;===============================================================================;; Description: :Add all items in a dir to opened Zip file; Parameter(s): :String dir path; Requirement: :XZip.dll, XZip.au3; Return Value(s): :True/False (error #); User CallTip: :_ZipPackDir(DirPath);;===============================================================================;Func _ZipPackDir($sDirPath);this is the one that I needed, so it works well Local $aFiles, $x, $i, $aDirs[1], $sStartDir, $sWorkingDir, $sNewDirPath, $iInsert, $sDirInZip If Not IsObj($oXZip_UDFGlobal) Then SetError(1) Return False ElseIf Not StringInStr(FileGetAttrib($sDirPath), 'D') Then SetError(2) Return False EndIf $sStartDir = $sDirPath $aDirs[0] = $sDirPath $i = 0 ; ===========================================================; This loop might have some unneeded code, because it took a; lot of trys to get it right. Also some error more checking,; optimization and clean couldn't hurt. But it works!; =========================================================== Do $sWorkingDir = $aDirs[$i] & '\' $aFiles = _FileListToArray ($aDirs[$i]) For $x = 1 To UBound($aFiles) - 1 If StringInStr(FileGetAttrib($aFiles[$x]), 'D') Then $sNewDirPath = $sDirPath & '\' & $aFiles[$x] $iInsert = $i + 1 _ArrayInsert($aDirs, $iInsert, $sNewDirPath) Else $sDirInZip = StringReplace($sWorkingDir, $sDirPath, '') $oXZip_UDFGlobal.Pack ($sWorkingDir & $aFiles[$x], $sZipPath_UDFGlobal, 1, $sDirInZip) EndIf Next $i = $i + 1 $aFiles = '' Until UBound($aDirs) = $i Return TrueEndFunc ;==>_ZipPackDir;===============================================================================;; Description: :Unpack a zip file; Parameter(s): :String: Path to extract Zip file to; Requirement: :XZip.dll, XZip.au3; Return Value(s): :True/False (error #); User CallTip: :_ZipUnpack(ExtractPath);;===============================================================================;Func _ZipUnpack($sDestPath) If Not IsObj($oXZip_UDFGlobal) Then SetError(1) Return False EndIf If Not FileExists($sDestPath) Then DirCreate($sDestPath) $oXZip_UDFGlobal.UnPack ($sZipPath_UDFGlobal, $sDestPath) Return TrueEndFunc ;==>_ZipUnpack;===============================================================================;; Description: :Close ZIP file, and unload XZip.dll as a service; Parameter(s): :None, based on _ZipOpen globals; Requirement: :XZip.dll, XZip.au3; Return Value(s): :True/False (error #); User CallTip: :_ZipClose(XZipDllPath, Delay in MS);;===============================================================================;Func _ZipClose();some error checking If Not FileExists($sDllLoc_UDFGlobal) Then SetError(1) Return False EndIf __DOSStart('regsvr32 /s /u "' & $sDllLoc_UDFGlobal & '"') Sleep($iRegDelay_UDFGlobal);needs a sec when unloaded silently. ; =====================================================; This way of checking will cause a COM error; but I like to confirm that the object's been closed; ===================================================== $oXZip_UDFGlobal = ObjCreate('XStandard.Zip') If Not IsObj($oXZip_UDFGlobal) Then;make sure it's closed ;reset globals, for next call $sZipPath_UDFGlobal = '' $sDllLoc_UDFGlobal = '' $iRegDelay_UDFGlobal = 0 $oXZip_UDFGlobal = '' Return True Else SetError(2) Return False EndIf EndFunc ;==>_ZipClose;helper functionsFunc __XZip_COM_Error() Local $hNumber = Hex($oComError_UDFGlobal.number, 8) ;blantly stolen from SvenP (We'll call it a 'port') MsgBox(0, 'XZip Com Error', 'There was COM Error!' & @CRLF & @CRLF & _ 'description is: ' & @TAB & $oComError_UDFGlobal.description & @CRLF & _ 'windescription:' & @TAB & $oComError_UDFGlobal.windescription & @CRLF & _ 'number is: ' & @TAB & $hNumber & @CRLF & _ 'lastdllerror is: ' & @TAB & $oComError_UDFGlobal.lastdllerror & @CRLF & _ 'scriptline is: ' & @TAB & $oComError_UDFGlobal.scriptline & @CRLF & _ 'source is: ' & @TAB & $oComError_UDFGlobal.source & @CRLF & _ 'helpfile is: ' & @TAB & $oComError_UDFGlobal.helpfile & @CRLF & _ 'helpcontext is: ' & @TAB & $oComError_UDFGlobal.helpcontext _ ) SetError(1)EndFunc ;==>__XZip_COM_ErrorFunc __DOSStart($sStart) Run(@ComSpec & ' /c start ' & $sStart, '', @SW_HIDE)EndFunc ;==>__DOSStart#cs UserCalltips _ZipOpen($sNewArchivePath, $sDllPath = '', $iDelay = 150) _ZipContents() _ZipPackGroup(ByRef $aItems, $bKeepPath = True);this func needs some more work _ZipPackDir(DirPath) _ZipUnpack($sDestPath) _ZipClose($sDllPath = '', $iDelay = 150)#ceEnjoy... told you alot of code.... [sup]Psibernetic[/sup]My Creations:X-HideSecuracy Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now