Leaderboard
Popular Content
Showing content with the highest reputation on 06/20/2013 in all areas
-
New release. 19 June 2013 (1.0.0.4) There is a relation with this topic SQLite ListView and BLOB demo but I decided to start a completely new Topic because the approach is considerably different from the two previous examples which were only kick-offs to this demo. This example shows how binary objects can be recognized natively in a database BLOB field without having to link to other fields that may contain information of the data object. In the demo I used 2 approaches for native recognition 1. For multi-type binary objects, the file name is added in the header of the BLOB Multi-type object can be images or any other kind of file. Because of the object header data, there is no need to identify the object in the binary code 2. Objects without header data, this works only for images, an algorithm will identify the type of image. The demo shows what happens whit objects which are not identifiable, see example 5. Credits to: 1. trancexx: GIFAnimation.au3 '?do=embed' frameborder='0' data-embedContent>> 2. smashly: _ImageResize() Resizes and converts different graphicformats 3. rover: Customize Draw of Listview rows Optimizations of WS_NOTIFY I also thank rover for giving a second method to resolve the image space issue. I implemented the one proposed by KaFu, because very simple to implement 4. KaFu: Solved the Listview issue with image space in Columns one. 5. jchd: For some hints and background info on SQLite 6. Yashied: WinAPIEx.au3 '?do=embed' frameborder='0' data-embedContent>> new release. Version 1.0.0.4 What's new: - added fully generic Add, Edit, Add/Copy, Delete and Find buttons. With fully generic I mean, you don't have to bother about the table content, GUI field inputs will populate accoring to the table definition. - Added Field validation, also according to how the columns were defined in the table. (see GUI dynamic input validation for more information) tested a thousand times... on W7 and WXP 32/64 For a working example you have to download 2 files (see links in between the horizontal lines: SQLite GreenCan_demo BLOB in Listview 1.0.0.4.zip GreenCan_demo2.zip (if you already did, don't mind downloading it again) Note: For the Edit GUI, you will notice that sometimes one field is not editable, marked as (*PK) in the description. The field is a 'Primary Key autoincrement'. When appending the row, the PK will automatically increment, therefore it is not allowed to edit the field. Other fields mared (*) cannot be empty, you can only save the row if these fields contain data. In the case (*PK) is editable, you have to put unique data for the Primary key. If you do a copy/add without changing the field content, you will get a not unique Error. Special case: I don't allow empty primary key (NULL), while SQLite does, but it's pretty useless anyhow because you can only have 1 NULL in a Primary key. I have also included a very small non BLOB database, for example 0, to show that the generic edit/add works also here. SQLite GreenCan_demo BLOB in Listview 1.0.0.4.zip and don't forget to download this zip file to complete the required files for the demo http://users.telenet.be/GreenCan/AutoIt/GreenCan_demo2.zip I let you explore the demo and please give me feedback. GreenCan1 point
-
I've had this thing I wrote up laying around for a while now and decided I'd comment the heck out of it and post it here for others to enjoy as well. It's a multi-client TCP server "base" that has all the boilerplate code done, the only thing that one needs to do is just whip their protocol code in to it and it's ready to go. I've included a little few-line example bit in it (in the #region stuff) for a simple echo server. A quick way to see the example work is to just start this up and use a telnet client to connect to it on the port that you chose to have it bind (default in the one I'm posting is port 8080), typing a sentence, and pressing enter. This server makes use of setting the TCPTimeout option to 0, making it quite efficient when a high number of clients are connected and making it faster at accepting new connections. It does not use a fixed-size array for storing client connections, but instead dynamically re-sizes the client array when clients disconnect or connect (Setting $MaxClients to 0 makes the number of simultaneous clients only limited by RAM or AutoIt internal limits, whatever is reached first. I've tested this at 10,000 concurrent connections successfully, albeit with some slightly elevated CPU usage ). The server also implements a simple per-client packet buffer (as shown in the little echo example) which can come in handy for things such as large packets from file transferring and such. Instead of only relying on checking @error after a TCPRecv call to determine if a client disconnected (which can lie in certain cases), this uses a checking function which implements both that @error check and an idle timeout check that disconnects the client if they have not sent anything in a certain period of time. This is not really aimed at people who are unfamiliar with sockets work in AutoIt, as this provides no real application layer protocol, you must make that yourself. The only thing this does is do all the hard and/or tedious work of managing what happens when clients try connecting, how packet data should be buffered, and when a connection should be considered "dead". If you use this in a project, a simple little comment saying you used it would be nice #cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.8.1 (Or greater) Author: Ken Piper Script Function: Template multi-client server base code. Use as a base for making an efficient server program. This base will just accept connections and echo back what it receives, and kill the connection if it is dead or inactive for x seconds. It will not do any other work, that must be added seperately! #ce ---------------------------------------------------------------------------- TCPStartup() Opt("TCPTimeout", 0) #region ;Safe-to-edit things are below Global $BindIP = "0.0.0.0" ;Listen on all addresses Global $BindPort = 8080 ;Listen on port 8080 Global $Timeout = 15000 ;Max idle time is 15 seconds before calling a connection "dead" Global $PacketSize = 2048 ;Max packet size per-check is 2KB Global $MaxClients = 50 ;Max simultaneous clients is 50 #endregion ;Stuff you shouldn't touch is below Global $Listen Global $Clients[1][4] ;[Index][Socket, IP, Timestamp, Buffer] Global $Ws2_32 = DllOpen("Ws2_32.dll") ;Open Ws2_32.dll, it might get used a lot Global $NTDLL = DllOpen("ntdll.dll") ;Open ntdll.dll, it WILL get used a lot Global $CleanupTimer = TimerInit() ;This is used to time when things should be cleaned up OnAutoItExitRegister("Close") ;Register this function to be called if the server needs to exit $Clients[0][0] = 0 $Listen = TCPListen($BindIP, $BindPort, $MaxClients) ;Start listening on the given IP/port If @error Then Exit 1 ;Exit with return code 1 if something was already bound to that IP and port While 1 USleep(5000, $NTDLL) ;This is needed because TCPTimeout is disabled. Without this it will run one core at ~100%. ;The USleep function takes MICROseconds, not milliseconds, so 1000 = 1ms delay. ;When working with this granularity, you have to take in to account the time it takes to complete USleep(). ;1000us (1ms) is about as fast as this should be set. If you need more performance, set this from 5000 to 1000, ;but doing so will make it consume a bit more CPU time to get that extra bit of performance. Check() ;Check recv buffers and do things If TimerDiff($CleanupTimer) > 1000 Then ;If it has been more than 1000ms since Cleanup() was last called, call it now $CleanupTimer = TimerInit() ;Reset $CleanupTimer, so it is ready to be called again Cleanup() ;Clean up the dead connections EndIf Local $iSock = TCPAccept($Listen) ;See if anything wants to connect If $iSock = -1 Then ContinueLoop ;If nothing wants to connect, restart at the top of the loop Local $iSize = UBound($Clients, 1) ;Something wants to connect, so get the number of people currently connected here If $iSize - 1 > $MaxClients And $MaxClients > 0 Then ;If $MaxClients is greater than 0 (meaning if there is a max connection limit) then check if that has been reached TCPCloseSocket($iSock) ;It has been reached, close the new connection and continue back at the top of the loop ContinueLoop EndIf ReDim $Clients[$iSize + 1][4] ;There is room for a new connection, allocate space for it here $Clients[0][0] = $iSize ;Update the number of connected clients $Clients[$iSize][0] = $iSock ;Set the socket ID of the connection $Clients[$iSize][1] = SocketToIP($iSock, $Ws2_32) ;Set the IP Address the connection is from $Clients[$iSize][2] = TimerInit() ;Set the timestamp for the last known activity timer $Clients[$iSize][3] = "" ;Blank the recv buffer WEnd Func Check() ;Function for processing If $Clients[0][0] < 1 Then Return ;If there are no clients connected, stop the function right now For $i = 1 To $Clients[0][0] ;Loop through all connected clients $sRecv = TCPRecv($Clients[$i][0], $PacketSize) ;Read $PacketSize bytes from the current client's buffer If $sRecv <> "" Then $Clients[$i][3] &= $sRecv ;If there was more data sent from the client, add it to the buffer If $Clients[$i][3] = "" Then ContinueLoop ;If the buffer is empty, stop right here and check more clients $Clients[$i][2] = TimerInit() ;If it got this far, there is data to be parsed, so update the activity timer #region ;Example packet processing stuff here. This is handling for a simple "echo" server with per-packet handling $sRecv = StringLeft($Clients[$i][3], StringInStr($Clients[$i][3], @CRLF, 0, -1)) ;Pull all data to the left of the last @CRLF in the buffer ;This does NOT pull the first complete packet, this pulls ALL complete packets, leaving only potentially incomplete packets in the buffer If $sRecv = "" Then ContinueLoop ;Check if there were any complete "packets" $Clients[$i][3] = StringTrimLeft($Clients[$i][3], StringLen($sRecv) + 1) ;remove what was just read from the client's buffer $sPacket = StringSplit($sRecv, @CRLF, 1) ;Split all complete packets up in to an array, so it is easy to work with them For $j = 1 To $sPacket[0] ;Loop through each complete packet; This is where any packet processing should be done TCPSend($Clients[$i][0], "Echoing line: " & $sPacket[$j] & @CRLF) ;Echo back the packet the client sent Next #endregion ;Example Next EndFunc Func Cleanup() ;Clean up any disconnected clients to regain resources If $Clients[0][0] < 1 Then Return ;If no clients are connected then return Local $iNewSize = 0 For $i = 1 To $Clients[0][0] ;Loop through all connected clients $Clients[$i][3] &= TCPRecv($Clients[$i][0], $PacketSize) ;Dump any data not-yet-seen in to their recv buffer If @error > 0 Or TimerDiff($Clients[$i][2]) > $Timeout Then ;Check to see if the connection has been inactive for a while or if there was an error TCPCloseSocket($Clients[$i][0]) ;If yes, close the connection $Clients[$i][0] = -1 ;Set the socket ID to an invalid socket Else $iNewSize += 1 EndIf Next If $iNewSize < $Clients[0][0] Then ;If any dead connections were found, drop them from the client array and resize the array Local $iSize = UBound($Clients, 2) - 1 Local $aTemp[$iNewSize + 1][$iSize + 1] Local $iCount = 1 For $i = 1 To $Clients[0][0] If $Clients[$i][0] = -1 Then ContinueLoop For $j = 0 To $iSize $aTemp[$iCount][$j] = $Clients[$i][$j] Next $iCount += 1 Next $aTemp[0][0] = $iNewSize $Clients = $aTemp EndIf EndFunc Func Close() DllClose($Ws2_32) ;Close the open handle to Ws2_32.dll DllClose($NTDLL) ;Close the open handle to ntdll.dll For $i = 1 To $Clients[0][0] ;Loop through the connected clients TCPCloseSocket($Clients[$i][0]) ;Force the client's connection closed Next TCPShutdown() ;Shut down networking stuff EndFunc Func SocketToIP($iSock, $hDLL = "Ws2_32.dll") ;A rewrite of that _SocketToIP function that has been floating around for ages Local $structName = DllStructCreate("short;ushort;uint;char[8]") Local $sRet = DllCall($hDLL, "int", "getpeername", "int", $iSock, "ptr", DllStructGetPtr($structName), "int*", DllStructGetSize($structName)) If Not @error Then $sRet = DllCall($hDLL, "str", "inet_ntoa", "int", DllStructGetData($structName, 3)) If Not @error Then Return $sRet[0] EndIf Return "0.0.0.0" ;Something went wrong, return an invalid IP EndFunc Func USleep($iUsec, $hDLL = "ntdll.dll") ;A rewrite of the _HighPrecisionSleep function made by monoceres (Thanks!) Local $hStruct = DllStructCreate("int64") DllStructSetData($hStruct, 1, -1 * ($iUsec * 10)) DllCall($hDLL, "dword", "ZwDelayExecution", "int", 0, "ptr", DllStructGetPtr($hStruct)) EndFunc Comments, questions, and criticisms are appreciated! Changelog: Cleared up formatting a bit in the [autoit] tags Fixed a bug in how it cleaned up the connection, and fixed a spelling error in the post Fixed a very rare corner-case that could cause a crash when getting many connections and disconnections in a short amount of time Changed a bit of code to fix issues with reading multiple buffered packets Fixed some spelling in the post and clean the code a bit; I try to keep this code up-to-date with the source file on my computer Fixed to add a massive performance increase when handling large numbers of connected clients and the client array needs to be trimmed. (I've seen up to a 500x speed increase on my computer!) Quick fix, apparently I forgot to set the max pending connections in TCPListen, leading for some pretty slow connection-accepting! Sorry about that. Fixed the problem of the latest AutoIt version causing "If @error Then" type statements to fail for TCPRecv, as TCPRecv now sets @error to -1 if the socket is alive but idle. This fixes the problem of clients getting instantly disconnected, sorry about not updating the code here with this sooner.1 point
-
You spend a lot of time to create mus++ and for this tool to arrange "Für Elise" - it would have been not fair to your efforts to use something else instead! AND I LIKE IT THIS WAY! Thx a lot. Br, UEZ1 point
-
Hey UEZ I'm happy you decided to use this. I think the tune works nicely with the graphics. There are still several optimizations need doing to the mus++ interpreter. It's still in experimental phase, although I have solutions for most of the problems. When I have finished it will be much easier to implement than it is at present.1 point
-
Update to v0.9.8.0 build 2013-06-20 beta! Many thanks to Ascend4nt for shorter CPU usage code and czardas for mus++ and arranging "Für Elise". To play the midi I used a different technique which let the music sometime play not in time. If somebody knows a simple way to check whether any network traffic (bytes sent / received) is made, please let me know. Br, UEZ1 point
-
MSSQL Connection
Hallistorm1989 reacted to ZombieKillz for a topic
Hallistorm, I'm not sure about that UDF. Please have a look at this one -> '?do=embed' frameborder='0' data-embedContent>> Then check out this post () by llewxam explaining how to put it together. At least that's how I got mine working.1 point -
Right to Left texts in menus
Mat reacted to mohammadezazi for a topic
Thank you all a bilion ! Everything works wel now.1 point -
r3b, No, your last topic got locked because you said it was a game: Which part of the rules to which I linked you is unclear about our policy on game automation? Furthermore we do not like automation of any "click to gain" sites - regardless of whether they are game-related. And finally, we do not write code "on request" - we help you get the script you write running correctly. I suggest you try o-desk if you want it written for you. So guess what - this thread gets locked too and I strongly suggest you do NOT open a third or the decision to go elsewhere will become a necessity rather than a choice. M231 point
-
New to AutoIt - Display data into one MSG box
ZombieKillz reacted to jdelaney for a topic
You can add all the services into an array...then do loops. It will clean up the code and allow dynamic gui re-sizes...adding any number of processes, will expand the gui to the necessary height and create all the labels...I also added a timer to check status every 5 seconds: #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= Global Enum $iProcess_1D_RSMS, _ $iProcess_1D_EAFRCS, _ $iProcess_1D_RSS, _ $iProcess_1D_EACS, _ $iProcess_1D_EAFRCM, _ $iProcess_1D_RSGUIP, _ $iProcess_1D_UBound Global Enum $iProcess_2d_Name, _ $iProcess_2d_Label, _ $iProcess_2d_Status, _ $iProcess_2d_UBound Global $aProcess[$iProcess_1D_UBound][$iProcess_2d_UBound] $aProcess[$iProcess_1D_RSMS][$iProcess_2d_Name] = "RemovableStorageMgmtService.exe" $aProcess[$iProcess_1D_EAFRCS][$iProcess_2d_Name] = "EAFRCliStart.exe" $aProcess[$iProcess_1D_RSS][$iProcess_2d_Name] = "RemovableStorageService.exe" $aProcess[$iProcess_1D_EACS][$iProcess_2d_Name] = "EACommunicatorSrv.exe" $aProcess[$iProcess_1D_EAFRCM][$iProcess_2d_Name] = "EAFRCliManager.exe" $aProcess[$iProcess_1D_RSGUIP][$iProcess_2d_Name] = "RSGUIProvider.exe" $iStaticHeight = 15 $iStaticSpace = 10 $YourGUIForm = GUICreate("Processes Running?", 300,($iProcess_1D_UBound*$iStaticHeight)+(($iProcess_1D_UBound+1)*$iStaticSpace)) ; the "hidden" labels, until check if processes exists below For $i = 0 To UBound($aProcess)-1 $aProcess[$i][$iProcess_2d_Label] = GUICtrlCreateLabel($aProcess[$i][$iProcess_2d_Name], $iStaticSpace, ($iStaticSpace*($i+1))+$iStaticHeight*$i) $aProcess[$i][$iProcess_2d_Status] = GUICtrlCreateLabel("", 200, ($iStaticSpace*($i+1))+$iStaticHeight*$i, 100, $iStaticHeight) Next CheckStatus() GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Func CheckStatus() ConsoleWrite("Checking status" & @CRLF) ; loop through, get statuses For $i = 0 To UBound($aProcess)-1 If ProcessExists($aProcess[$i][$iProcess_2d_Name]) Then GUICtrlSetData($aProcess[$i][$iProcess_2d_Status], "running") GUICtrlSetColor($aProcess[$i][$iProcess_2d_Status], 0x66CD00) ; sets font to green Else GUICtrlSetData($aProcess[$i][$iProcess_2d_Status], "not running") GUICtrlSetColor($aProcess[$i][$iProcess_2d_Status], 0xFF0000) ; sets font to red EndIf Next EndFunc $bCheckStatus = True $iTimer = TimerInit() $iCheckSeconds = 5000 While 1 If TimerDiff($iTimer) > $iCheckSeconds Then $iTimer = TimerInit() CheckStatus() EndIf $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd1 point -
Crop image search
Tenderfoot reacted to PhoenixXL for a topic
Check this HotKeySet("b", "HotKEY_Func_") ;use this when only an interval of two is required. Func HotKEY_Func_() ;we would use boolean values in this case. ;this Static variable is a Global Variable which only has scope inside this funciton Static $fCount = True $fCount = Not $fCount ;change True to False and vice-versa. ;if true If $fCount Then ConsoleWrite(">Execute Function no. 1 now." & @CRLF) ;if false If Not $fCount Then ConsoleWrite(">Execute Function no. 2 now." & @CRLF) EndFunc HotKeySet("a", "HotKEY_Func") ;use this when more than two intervals are required. Func HotKEY_Func() ;we would use integer values in this case. ;this Static variable is a Global Variable which only has scope inside this funciton Static $iCount = 0 ;base your functions under a specific interval integer. ;assuming we have four functions ;each would be executed according to its number. Local $iFunction_Index = Mod($iCount, 4) + 1 ;added "1" so that there is no "0"th func. ConsoleWrite("+Execute Function no. " & $iFunction_Index & " now." & @CRLF) ;increment the count by one. $iCount += 1 EndFunc ;==>HotKEY_Func Do Sleep(10) Until 0 Regards1 point -
How do I create a dynamic array?
Keith_Greenberg reacted to BugFix for a topic
Another way: use array alternatives (object) like i.e. System.Collections.ArrayList or Scripting.Dictionary. So you can increase/decrease your array object without ReDim. Here an example: $ObjList = ObjCreate("System.Collections.ArrayList") ; create $ObjList.Add($VALUE) ; add value $VALUE = $ObjList.Item($Index) ; get value $ObjList.Remove($VALUE) ; delete by name $ObjList.RemoveAt($Index) ; delete by index $Array = $ObjList.ToArray ; list to array ; and more... $oDICT = ObjCreate('Scripting.Dictionary') $oDICT.Add($KEY, $VALUE) ; add pair (key/value) $VALUE = $oDICT.Item($KEY) ; get value $oDICT.Item($KEY) = $VALUE ; set value $oDICT.Remove($KEY) ; delete key $oDICT.RemoveAll ; delete all keys ; and more...1 point