Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 02/02/2013 in all areas

  1. wraithdu

    _LargeFileCopy UDF

    Several people have had problems with their GUIs freezing when they try to copy large files using FileCopy(). This is because FileCopy() is a blocking function, and the GUI stops responding to messages from the OS during the operation. If that goes on long enough, the OS thinks it is hung and you get the (Not Responding) thing going on. Here's a function that copies large files using Windows API calls in 8MB 2 MB chunks. This keeps the GUI alive and responsive. I've added additional copy verification functionality as well (disabled by default). Take a look at my A3COPY project for a great usage example of this UDF. Update: 1/31/13 - Moved a few more functions into _FileEx. - Fixed a bug in GetDiskClusterSize function. Update: 10/8/12 - Fixed bug due to missing RtlCopyMemory and RtlCompareMemory exports in x86 kernel32.dll. Now uses RtlMoveMemory and RtlCompareMemory from ntdll.dll (sorry). Update: 10/4/12 Read NOTES at top of UDF - Reduced default buffer size to 2 MB - Added flags for copying source file attributes, all three file times individually, ACL security descriptors and ownership, and NTFS specific compression and encryption - Optimized buffer creation - Enhanced path handling to fully support UNC and network conventions ( C:... , ?C:... , srvshare... , ?UNCsrvshare... ) - Removed C runtime functions (msvcrt.dll) in favor of native kernel32 functions - Code cleanup and many optimizations in LFC and the accompanying _FileEx UDF Update: 4/15/11 - Added additional verification methods - bit by bit, and size only - The default verification method (ie iFlag 8) is now bit by bit - it is faster and less computationally intensive than MD5 hashing, it also allows the function to bail out early in the case of a failed copy operation Update: 3/9/11 SCRIPT BREAKING CHANGES - Combined some parameters into one iFlags parameter - Re-ordered some parameters based on priority - Added a parameter to specify a different read buffer size - Destination file is now opened with GENERIC_READ | GENERIC_WRITE per MSDN for better compatibility copying files across a network - No longer create destination directory structure unless specified in iFlags parameter Update: 9/20/10 - Removed tracexxx's hashing functions (sorry!) in favor of a different method which is not RAM limited - Hashing algorithm can be specified (those supported by Crypt.au3: CALG_MD2, CALG_MD4, CALG_MD5, CALG_SHA1) Update: 8/26/10 - Fix for failed verification of 0 byte files - Added check for 0 byte source in RAW functions Update: 8/22/10 - Small change to CreateFile function to avoid errors when opening SYSTEM or HIDDEN files when specifying CREATE_ALWAYS. Update: 8/10/10 - Added _LargeFileCopyUnbuffered and _LargeRawCopyUnbuffered which will copy files using unbuffered I/O. - MD5 hashing of the source file / memory block is now done on the fly from the memory buffer. This avoids an additional read of the source file later on and saves time. - Destination file MD5 hashing is now done with trancexxx's nice hashing UDF. It uses the Windows API and is really fast. Update: 7/9/2010 - Added _LargeRawCopy which will copy large memory blocks (usually from an embedded resource) to a file in the same manner as _LargeFileCopy. This function also has the verify functionality via MD5 hash. Update: 7/8/2010 - Added optional user function and variable parameters. This function, if given, will be called after each write operation with the total bytes written, total file size in bytes, and the user given variable. This is perfect for a copy-with-progess type of function call. Example #NoTrayIcon #AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #include <_LargeFileCopy.au3> _Main() Func _Main() Local $msg, $timer, $ret Local $src = "ubuntu-10.04-desktop-i386.iso" ; <---- path to a really large file goes here, recommended 600MB+ Local $destpath = @DesktopDir & "testdir" ; <---- destination path goes here GUICreate("File Copy Test", 250, 150) GUICtrlCreateLabel("Try to interact with the GUI during file copy...", 20, 15) Local $go = GUICtrlCreateButton("Copy Large File", 50, 50, 150, 50) Local $doing = GUICtrlCreateLabel("Ready...", 20, 120, 200) GUISetState() Do $msg = GUIGetMsg() If $msg = $go Then ; create destination path DirCreate($destpath) ; internal FileCopy() function GUICtrlSetData($doing, "FileCopy()...") $timer = TimerInit() ConsoleWrite("FileCopy:" & @CRLF) $ret = FileCopy($src, $destpath, 1) ConsoleWrite("return: " & $ret & @CRLF & "error: " & @error & @CRLF & "time: " & TimerDiff($timer) & " ms" & @CRLF) ConsoleWrite("====================" & @CRLF) ; _LargeFileCopy() UDF function GUICtrlSetData($doing, "_LargeFileCopy()...") $timer = TimerInit() ConsoleWrite("_LargeFileCopy:" & @CRLF) $ret = _LargeFileCopy($src, $destpath, 1) ConsoleWrite("return: " & $ret & @CRLF & "error: " & @error & @CRLF & "time: " & TimerDiff($timer) & " ms" & @CRLF) ConsoleWrite("====================" & @CRLF) GUICtrlSetData($doing, "Ready...") EndIf Until $msg = -3 EndFuncLargeFileCopy.zip
    1 point
  2. I would imagine that using Const is useful when working alongside other coders or if someone else decides to update or modify your code. This way they will be less likely to make a mistake. I would always use Const to declare a mathematical constant, or any variable used as some kind of standardized unit calibration or ratio. Pi would fall into this category. Regarding other uses, I'm not really sure if you can give a clear set of rules, since it can be applied in so many different situations. I'm also not sure about handles, since I don't know if Windows will reassign the same handle to another control under certain circumstances. Then again. perhaps that's just me being paranoid. I don't think the keyword should be used willy nilly. Of course it makes sense to use it for things like Windows control styles (already defined as constants) etc...
    1 point
  3. My "final" version #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Global $CHECKBOX_CHECKED = "ü" $Form = GUICreate("", 140, 70, -1, -1) $Checkbox = _GUICtrlCreateCheckBox("", 8, 8, 16, 16, 0xFFFFFF, 0x0000FF) $Button = GUICtrlCreateButton("IsChecked", 48, 8, 81, 33) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Checkbox If GUICtrlRead($Checkbox) <> $CHECKBOX_CHECKED Then GUICtrlSetData($Checkbox, $CHECKBOX_CHECKED) Else GUICtrlSetData($Checkbox, "") EndIf Case $Button If GUICtrlRead($Checkbox) <> $CHECKBOX_CHECKED Then MsgBox(0, 0, "IsChecked") Else MsgBox(0, 0, "NOT Checked") EndIf EndSwitch WEnd Func _GUICtrlCreateCheckBox($title, $left, $top, $width, $height, $checkcolor, $checkbk, $style = 513, $exstyle = 0x00020000) $handle = GUICtrlCreateLabel($title, $left, $top, $width, $height, $style, $exstyle) GUICtrlSetColor($handle, $checkcolor) GUICtrlSetBkColor($handle, $checkbk) GUICtrlSetFont($handle, $height, 600, "", "Wingdings") Return $handle EndFunc The bad thing, you need to add a Case for ever "Checkbox", and also is not totally centered...but wait some other expert like Melba, guinness, BrewManNH and many many other, i'm sure can find a better solution for you
    1 point
  4. This is the best solution i have think: #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("Form1", 150, 150, -1, -1) $Label = GUICtrlCreateLabel("", 8, 8, 16, 16, BitOR($SS_CENTERIMAGE, $SS_CENTER), $WS_EX_STATICEDGE) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlSetBkColor(-1, 0x0000FF) GUICtrlSetFont(-1, 15, 600, "", "Wingdings") GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Label If GUICtrlRead($Label) = "" Then GUICtrlSetData($Label, "ü") Else GUICtrlSetData($Label, "") EndIf EndSwitch WEnd I'll modify a little...wait some minute
    1 point
  5. Well i guess it doesn't really matter that much in interpreted/dynamic languages, besides compile-time checking of assignment to constant variables (does autoitcheck do this?). It's useful to avoid name clashing and give symbolic meaning / clues to what a variable does. Also, of course, it should be used on constants, which autoit, to my understanding, is able to optimize. In compiled languages, if you explicitly state the constness of variables (and the compiler can guarantee this), the compiler is able to do a lot of optimizations on code, registers, memory layouts, copying (specifically able to do reference passing instead of copying parameters) etc. I do think it's an excellent coding practice in dynamic languages though, to make everything you don't intend to change immutable, both because of symbolism but also transitions to/from other languages.
    1 point
  6. So you basically want to set the text to white? No clue as to why it's grey'ish. Sorry.
    1 point
  7. Example 2: Using a non-native AutoIt GUI. #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include '_GUIDisable.au3' Example_2() Func Example_2() ; Run Notepad Run('notepad.exe') ; Wait 10 seconds for the Notepad window to appear. Local $hWnd = WinWait('[CLASS:Notepad]', '', 5) ; Apply the dimmed effect. Local $hGUIDisable = _GUIDisable($hWnd, 1, 25) ; Get the position of the dimmed effect and adjust accordingly. Local $aWinGetPos = WinGetPos($hGUIDisable) If @error = 0 Then WinMove($hGUIDisable, '', $aWinGetPos[0] - 5, $aWinGetPos[1] - 5) EndIf ; Wait for 2 seconds to display the Notepad window. Sleep(2000) ; Destroy the dimmed effect. _GUIDisable($hWnd, 1) ; Wait for 1/2 second. Sleep(500) ; Close the Notepad window using the classname of Notepad. WinClose($hWnd) EndFunc ;==>Example_2
    1 point
  8. I have a modified version of the standard Array.au3 file that comes with AutoIt3. Most of the original _Arrayxxx functions didn't/don't support 2D arrays when using them. I have welded on the ability to use most of the existing functions with a 1 or 2D array. There are a couple of the _Array functions that I have not added this functionality to, mostly because I don't think it would be necessary and/or helpful for them to have it. Here is a list of the functions included in the Array.au3 file that have been added and modified, taken from the header of the file These modified functions are a drop in replacement for the original functions, they are backwards compatible with all scripts written to use the functions as originally written, but I have added the ability to use them with 2D arrays, as well as with 1D arrays. 2 of the new functions weren't written by me, _ArrayAddColumns and _ArrayDeleteColumn, but I have them in my arsenal of array functions so I figured it couldn't hurt to include them here as well. If anyone finds these useful, please let me know. If anyone finds any problems or bugs, I'd like to know that as well. Hopefully I have updated all of the function comment headers to reflect the changes, but if I have missed something let me know about that too so I can correct it. As an added bonus, I am also posting an array related function called _FileWriteFromArray2D, which will write a 2D array to a file and is a modified version of _FileWriteFromArray that only works with 1D arrays. This could probably be incorporated into the _FileWriteFromArray function so that it would be able to handle 1D and 2D arrays natively pretty easily. 11/10/2011 - Updated attachment Ran #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w 7 on the contents of the file to eliminate any warning messages that might be popping up. No functional changes to the functions, just cleaning up the mess of warning messages that didn't affect the working of the script, but might make the unwary nervous about them. All warnings have been fixed by declaring the variables correctly. _Array.au3
    1 point
×
×
  • Create New...