Opinions and Feedback welcome
File Guard
Started by
Meerecat
, Jun 12 2011 05:16 PM
6 replies to this topic
#1
Posted 12 June 2011 - 05:16 PM
With the help of some of the guys on this forum, I have finished my second script. This one is designed for encrypting confidential documents before you email them. Special thanks to Smartee, Mat and MHz.
Opinions and Feedback welcome
Opinions and Feedback welcome
Lack of planning on your part does not constitute an emergency on my part.-The biggest idiot can ask questions the smartest man cannot answer.
#2
Posted 12 June 2011 - 05:51 PM
Quick look.
In all your functions you run the Main function in case of back button
I'm not sure if this causes recursion even though you delete the gui (whatever gui that may be.
Would it make more sense to just Return from the function, or GUIDelete() and then return in those functions which create GUIs.
In all your functions you run the Main function in case of back button
I'm not sure if this causes recursion even though you delete the gui (whatever gui that may be.
Would it make more sense to just Return from the function, or GUIDelete() and then return in those functions which create GUIs.
AutoIt Absolute Beginners Require a serial
Run('hh mk:@MSITStore:'&StringReplace(@AutoItExe,'.exe','.chm')&'::/html/tutorials/helloworld/helloworld.htm','',@SW_MAXIMIZE)
#3
Posted 12 June 2011 - 06:00 PM
How do I return from a function?
I thought I was deleting the gui's. There is only one gui on screen at any one time.
I'm not disagreeing with you, I just don't want to misunderstand. I want to learn
Many Thanks
Lee
I thought I was deleting the gui's. There is only one gui on screen at any one time.
I'm not disagreeing with you, I just don't want to misunderstand. I want to learn
Many Thanks
Lee
Lack of planning on your part does not constitute an emergency on my part.-The biggest idiot can ask questions the smartest man cannot answer.
#4
Posted 12 June 2011 - 07:15 PM
I'm not sure what you mean. A function is a function, gui doesn't matter.I'm not sure if this causes recursion even though you delete the gui (whatever gui that may be.
Either let the function end naturally or use the "Return" keyword (as JohnOne said), see helpfileHow do I return from a function?
How To Ask Questions The Smart WayHow to Report Bugs EffectivelySome of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface
#5
Posted 12 June 2011 - 07:21 PM
What I mean is, each time a function ends, or its task is complete, it returns to the last function it was called from.
When you hit the back button in your case, it sort of calls the function again while the function called from it never ended (if you get me) this is called recursion (I think)
Just an example of what I mean using extract from your code.
In this case, your main GUI is always there and will never need to be re-drawn , just the called functions gui will be deleted
When you hit the back button in your case, it sort of calls the function again while the function called from it never ended (if you get me) this is called recursion (I think)
Just an example of what I mean using extract from your code.
AutoIt
_main() Func _main() ;GUIDelete() $Form1 = GUICreate("Meerecat File Guard", 288, 287) GUISetBkColor(0xFFFFFF) $MainMenu = GUICtrlCreateMenu("&Main Menu") $encrypt_menu = GUICtrlCreateMenuItem("&Encrypt File", $MainMenu) $decrypt_menu = GUICtrlCreateMenuItem("&Decrypt File", $MainMenu) $exit_menu = GUICtrlCreateMenuItem("E&xit", $MainMenu) $HelpMenu = GUICtrlCreateMenu("&Help") $contact_menu = GUICtrlCreateMenuItem("&Contact Us", $HelpMenu) $about_menu = GUICtrlCreateMenuItem("&About", $HelpMenu) $Pic1 = GUICtrlCreatePic($IMG_DIR & '\meerecat.jpg', 8, 58, 113, 150) $Label2 = GUICtrlCreateLabel("Meerecat File Guard", 66, 8, 155, 23) GUICtrlSetFont(-1, 12, 800, 0, "Leelawadee") $Pic2 = GUICtrlCreatePic($IMG_DIR & 'meerecat.jpg', 408, 45, 113, 150) $encrypt = GUICtrlCreateButton("Encrypt File", 155, 86, 100, 30) GUICtrlSetFont(-1, 10, 800, 0, "Leelawadee") $decrypt = GUICtrlCreateButton("Decrypt File", 155, 135, 100, 30) GUICtrlSetFont(-1, 10, 800, 0, "Leelawadee") GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $encrypt _encrypt() Case $decrypt _decrypt() Case $encrypt_menu _encrypt() Case $decrypt_menu _decrypt() Case $contact_menu ShellExecute("<a href='http://www.meerecat-itservices.co.uk/contact-us' class='bbc_url' title='External link' rel='nofollow external'>http://www.meerecat-itservices.co.uk/contact-us"</a>) Case $exit_menu Exit Case $about_menu _about() EndSwitch WEnd EndFunc ;==>_main Func _encrypt() ;GUIDelete() $hWnd = GUICreate("Meerecat File Guard", 288, 287) GUISetBkColor(0xFFFFFF) $MainMenu = GUICtrlCreateMenu("&Main Menu") $encrypt_menu = GUICtrlCreateMenuItem("Encrypt File", $MainMenu) $decrypt_menu = GUICtrlCreateMenuItem("Decrypt File", $MainMenu) $exit_menu = GUICtrlCreateMenuItem("Exit", $MainMenu) $HelpMenu = GUICtrlCreateMenu("&Help") $contact_menu = GUICtrlCreateMenuItem("Contact Us", $HelpMenu) $about_menu = GUICtrlCreateMenuItem("About", $HelpMenu) $Label2 = GUICtrlCreateLabel("Meerecat File Guard", 66, 8, 155, 23) GUICtrlSetFont(-1, 12, 800, 0, "Leelawadee") $Label3 = GUICtrlCreateLabel("Meerecat IT Services ©2011", 376, 224, 145, 17) GUICtrlSetFont(-1, 6, 400, 0, "MS Sans Serif") $back = GUICtrlCreateButton("Back", 155, 231, 100, 30) GUICtrlSetFont(-1, 10, 800, 0, "Leelawadee") $InFileLabel = GUICtrlCreateLabel("Input File", 8, 56, 56, 19) GUICtrlSetFont(-1, 10, 400, 0, "Leelawadee") $InFileInput = GUICtrlCreateInput("", 8, 72, 225, 21) $OutFileLabel = GUICtrlCreateLabel("Output File", 8, 110, 67, 19) GUICtrlSetFont(-1, 10, 400, 0, "Leelawadee") $OutFileInput = GUICtrlCreateInput("", 8, 123, 225, 21) $InFileButton = GUICtrlCreateButton(". . .", 240, 72, 30, 25) $OutFileButton = GUICtrlCreateButton(". . .", 240, 123, 30, 25) $PasswordLabel = GUICtrlCreateLabel("Encryption Password", 8, 159, 125, 19) GUICtrlSetFont(-1, 10, 400, 0, "Leelawadee") $PasswordInput = GUICtrlCreateInput("", 7, 175, 225, 21) $EncryptButton = GUICtrlCreateButton("Encrypt", 35, 230, 100, 30) GUICtrlSetFont(-1, 10, 800, 0, "Leelawadee") If ($CmdLine[0] > 0) Then ;Used to prefill input areas GUICtrlSetData($InFileInput, $CmdLine[1]) GUICtrlSetData($OutFileInput, $CmdLine[1] & $Extension) EndIf GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $back GUIDelete($hWnd) Return Case $encrypt_menu _encrypt() Case $decrypt_menu _decrypt() Case $contact_menu ShellExecute("<a href='http://www.meerecat-itservices.co.uk/contact-us' class='bbc_url' title='External link' rel='nofollow external'>http://www.meerecat-itservices.co.uk/contact-us"</a>) Case $exit_menu Exit Case $about_menu _about() Case $InFileButton $file = FileOpenDialog("Input File", "", "All files (*.*;)") If $file <> "" Then GUICtrlSetData($InFileInput, $file) GUICtrlSetData($OutFileInput, $file & $Extension) EndIf Case $OutFileButton $file = FileSaveDialog("Output file", "", "Any file (*.*;)") If $file <> "" Then GUICtrlSetData($OutFileInput, $file) Case $EncryptButton $infile = GUICtrlRead($InFileInput) If Not FileExists($infile) Then MsgBox(16, "Error", "Input file doesn't exists!") ContinueLoop EndIf $outfile = GUICtrlRead($OutFileInput) If $outfile = "" Then MsgBox(16, "Error", "Please input a output file") ContinueLoop EndIf $password = GUICtrlRead($PasswordInput) If $password = "" Then MsgBox(16, "Error", "Please input a password") ContinueLoop EndIf AdlibRegister("Update", 333) $success = _Crypt_EncryptFile($infile, $outfile, $password, $CALG_RC4) If $success Then MsgBox(0, "Success", "Operation succeeded") Else Switch @error Case 1 MsgBox(16, "Fail", "Failed to create key") Case 2 MsgBox(16, "Fail", "Couldn't open source file") Case 3 MsgBox(16, "Fail", "Couldn't open destination file") Case 4 Or 5 MsgBox(16, "Fail", "Encryption error") EndSwitch EndIf AdlibUnRegister("Update") WinSetTitle($hWnd, "", "File Encrypter") EndSwitch WEnd EndFunc ;==>_encrypt
In this case, your main GUI is always there and will never need to be re-drawn , just the called functions gui will be deleted
Edited by JohnOne, 12 June 2011 - 07:23 PM.
AutoIt Absolute Beginners Require a serial
Run('hh mk:@MSITStore:'&StringReplace(@AutoItExe,'.exe','.chm')&'::/html/tutorials/helloworld/helloworld.htm','',@SW_MAXIMIZE)
#6
Posted 12 June 2011 - 08:16 PM
Thanks JohnOne
Currently rewriting (or trying to) both the folder lock and file guard with this in mind
Currently rewriting (or trying to) both the folder lock and file guard with this in mind
Lack of planning on your part does not constitute an emergency on my part.-The biggest idiot can ask questions the smartest man cannot answer.
#7
Posted 21 April 2012 - 12:08 PM
Nice Work!
I'm new to AutoIt!! so tell me how do you do it?!
tnx
I'm new to AutoIt!! so tell me how do you do it?!
tnx
Edited by n1maS, 21 April 2012 - 12:09 PM.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users





