AutoHotkey Community

It is currently May 26th, 2012, 5:35 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 97 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6, 7  Next
Author Message
 Post subject:
PostPosted: March 3rd, 2008, 9:52 pm 
Offline

Joined: April 22nd, 2007, 6:33 pm
Posts: 1833
i would like the ahk solution, but would also like to see a dll version. is it written by you? i had written a program a while ago that i discontinued as i couldnt get multiple drives to be checked.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 3rd, 2008, 11:46 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8775
tic wrote:
is it written by you?


I got it from net and that found that it was not working in AHK.
Luckily, the source code was included and so, I investigated - fixed - recompiled it ( VC++ 6 ) and to my joy, it is working now.

As of now, the function does not accept enough parameters to make things really flexible and I am trying to work it out.

:)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 4th, 2008, 2:20 pm 
Offline

Joined: December 19th, 2006, 2:14 pm
Posts: 72
Location: France
Hi

Just my 2 cents :

*) Don't count on CreateSymbolicLink : it's not the right use, it's use is meant to create "soft" or "symbolic" links (unix-like, google "man ls" : symbolic links [new to Vista] are created using "ln -s" whereas "hard" links are created using "ln" without "-s" under unix, and with "linkd" on MS OS'es)

*) "junctions" are like mount points under unix (google "man mount").

*) the best way to spy multiple dirs (to my mind) should be : call as often as needed ReadDirectoryChangesW() specifying no LPOVERLAPPED_COMPLETION_ROUTINE, but giving a different hEvent associated to each spyed dir - create them using CreateEvent()). Once finished, enter an infinite loop (or with a boolean if clean exit might be needed) which in it's beginning calls WaitForMultipleEvents() with an array containing the handles to the events created before. When given back hand, the signaled event tells which dir has changed for an appropriate processing. Finally, when over with spying, if loop is conditioned by a boolean, you just have to change it's value during this processing. You can even use a timeout to stop waiting prematurely or to have a regularly scheduled process while waiting.
=> WaitForMultipleEvents has a limit of 64 entries in it's waiting array.

*) No sample - I got no time (sorry)

Wish you all good luck :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 4th, 2008, 3:46 pm 
Don't push too far the analogy with Unix. And linkd is not for hardlink, it's for junction. Use fsutil for hardlink. By the way, there is no API like WaitForMultipleEvents.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 4th, 2008, 4:05 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8775
Anonymous wrote:
By the way, there is no API like WaitForMultipleEvents.


It is obvious Azerty meant WaitForMultipleObjects :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 11th, 2008, 5:43 pm 
Offline

Joined: December 19th, 2006, 2:14 pm
Posts: 72
Location: France
SKAN wrote:
Anonymous wrote:
By the way, there is no API like WaitForMultipleEvents.


It is obvious Azerty meant WaitForMultipleObjects :)


that's exactly it. Thanks for correction (wrote it fast :wink: )


Report this post
Top
 Profile  
Reply with quote  
PostPosted: April 9th, 2008, 11:55 pm 
Offline

Joined: April 9th, 2008, 11:46 pm
Posts: 14
I'm a newbie and I'm trying to learn AutoHotKey. So forgive me if I make some trivial questions.
Code:
Loop %WatchFolder%, 1
      WatchFolder := A_LoopFileLongPath
DllCall( "shlwapi\PathAddBackslashA", UInt,&Watchfolder )

Which is the meaning of the previous three code lines?

Moreover, once launched Folderspy advises several times for each file modification. Why?


Report this post
Top
 Profile  
Reply with quote  
PostPosted: April 10th, 2008, 12:06 am 
Offline

Joined: April 22nd, 2007, 6:33 pm
Posts: 1833
caterva wrote:
I'm a newbie and I'm trying to learn AutoHotKey. So forgive me if I make some trivial questions.
Code:
Loop %WatchFolder%, 1
      WatchFolder := A_LoopFileLongPath
DllCall( "shlwapi\PathAddBackslashA", UInt,&Watchfolder )

Which is the meaning of the previous three code lines?

Moreover, once launched Folderspy advises several times for each file modification. Why?


You can see what
Code:
Loop %WatchFolder%, 1
      WatchFolder := A_LoopFileLongPath


does in the docs for looping a folder

and

Code:
DllCall( "shlwapi\PathAddBackslashA", UInt,&Watchfolder )


is similar to:

Code:
If (SubStr(WatchFolder, 0) != "")
WatchFolder .= ""


I think.

Whens the asynchronous one coming Skan!? :D Really been looking forward to it.


Report this post
Top
 Profile  
Reply with quote  
PostPosted: April 10th, 2008, 9:34 am 
Offline

Joined: April 9th, 2008, 11:46 pm
Posts: 14
Thanks for your reply. I'm having some doubts yet.
Quote:
You can see what
Code:
Loop %WatchFolder%, 1
      WatchFolder := A_LoopFileLongPath


does in the docs for looping a folder

Which is the aim of this loop? It seems to me that the variable %WatchFolder% is overwritten at every step.
Quote:
Code:
DllCall( "shlwapi\PathAddBackslashA", UInt,&Watchfolder )


is similar to:

Code:
If (SubStr(WatchFolder, 0) != "\")
WatchFolder .= "\"


Is this line inside or outside the loop? It seems to me the latter case. So, %WatchFolder% (or its address?) assumes the last value of previous loop. Sorry, I do not understand the need of the loop yet... :(

Quote:
Whens the asynchronous one coming Skan!? :D Really been looking forward to it.

Me too. His explanation of the functioning ReadDirectoryChangesW was very very useful, so I wish to ask if he can describe the difference between using it in synchronous and asymchronous mode.
Thanks to all your indications.


Report this post
Top
 Profile  
Reply with quote  
PostPosted: April 10th, 2008, 10:40 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7501
Location: Australia
caterva wrote:
Which is the aim of this loop?
To execute code for each file or folder matching the input pattern. In this case it expects there to be only one matching folder; i.e. it uses the loop only to get the full path of the file (A_LoopFileLongPath.)
Quote:
It seems to me that the variable %WatchFolder% is overwritten at every step.
It is. However, the file pattern is retrieved from %WatchFolder% before the loop begins.
Quote:
... the difference between using it in synchronous and asymchronous mode.
I presume asynchronous mode would allow the script to do other things (like respond to user input) while waiting for an event, whereas synchronous mode does not.
SKAN wrote:
The problem with synchronous mode in AHK is that AHK is single threaded and ReadDirectoryChangesW can halt/freeze every other operation when it is waiting for an event in the watched folder. Halt means: you cannot start an another thread via hotkey /settimer .. the GUI ( if any ) would not respond for any messages ( including mouse ).. not even a right click on tray icon would work!

Btw, I think
Code:
DllCall( "shlwapi\PathAddBackslashA", UInt,&Watchfolder )
is not safe since there is no assurance that WatchFolder has the capacity to hold another character. The script equivalent tic mentioned is safe, since AutoHotkey will expand the variable if necessary.


Report this post
Top
 Profile  
Reply with quote  
PostPosted: April 10th, 2008, 10:59 am 
Offline

Joined: April 9th, 2008, 11:46 pm
Posts: 14
Lexikos wrote:
In this case it expects there to be only one matching folder; i.e. it uses the loop only to get the full path of the file (A_LoopFileLongPath.)

Oh, at last I think to have understood! Equivalently, I could have written
Code:
Loop %WatchFolder%, 1
{
}
      WatchFolder := A_LoopFileLongPath

Isn't it?
Many thanks to all you for your patience and kindness.

I'm very interested in an example of asynchronous mode!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 10th, 2008, 11:11 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7501
Location: Australia
No, A_LoopFileLongPath is only valid inside a loop.

I noticed "asynchronous" mode is actually achieved via an "overlapped operation." Since I have written code for such before, I thought I'd apply it to FolderSpy.

The modified ReadDirectoryChanges():
Code:
ReadDirectoryChanges() {       ;    http://msdn2.microsoft.com/en-us/library/aa365465.aspx

    Global hDir,PointerFNI, Sizeof_FNI, WatchSubdirs
   
    ; Create an event object and OVERLAPPED structure.
    hEvent := DllCall("CreateEvent", UInt, 0, Int, true, Int, false, UInt, 0)
    VarSetCapacity(Overlapped, 20, 0), NumPut(hEvent, Overlapped, 16)
   
    ; Call ReadDirectoryChangesW in overlapped/asynchronous mode.
    if !DllCall( "ReadDirectoryChangesW"
                , UInt , hDir
                , UInt , PointerFNI
                , UInt , SizeOf_FNI
                , UInt , WatchSubDirs
                , UInt , ( FILE_NOTIFY_CHANGE_FILE_NAME   := 0x1   )
                       | ( FILE_NOTIFY_CHANGE_DIR_NAME    := 0x2   )
                       | ( FILE_NOTIFY_CHANGE_ATTRIBUTES  := 0x4   )
                       | ( FILE_NOTIFY_CHANGE_SIZE        := 0x8   )
                       | ( FILE_NOTIFY_CHANGE_LAST_WRITE  := 0x10  )
                       | ( FILE_NOTIFY_CHANGE_LAST_ACCESS := 0x20  )
                       | ( FILE_NOTIFY_CHANGE_CREATION    := 0x40  )
                       | ( FILE_NOTIFY_CHANGE_SECURITY    := 0x100 )
                , UIntP, nReadLen
                , UInt , &Overlapped
                , UInt , 0  )
        return false ; error?
   
    Loop {
        ; Wait for the event to be signaled, or any window message received.
        r := DllCall("MsgWaitForMultipleObjectsEx", UInt, 1, UIntP, hEvent
                                            , UInt, -1, UInt, 0x4FF, UInt, 0x6)
        if (r = 0) || (r = -1) ; WAIT_OBJECT_0 or WAIT_FAILED
            break
        Sleep, 1 ; Allow AutoHotkey to process/dispatch messages.
    }
   
    DllCall( "CloseHandle", UInt,hEvent )

    return DllCall( "GetOverlappedResult", UInt, hDir
                    , UInt, &Overlapped, UIntP, nReadLen, Int, true )
}
...and simplified loop in WatchFolder:
Code:
  Loop {
    ReadDirectoryChanges()
    GoSub, Decode_FILE_NOTIFY_INFORMATION
    Sleep 100
    If !Watch
        Break
  }

Btw, it seems FolderSpy does not allow the user (me) to select the root of a drive. (File/folder loops don't seem to consider it a folder...)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 10th, 2008, 5:07 pm 
Offline

Joined: April 9th, 2008, 11:46 pm
Posts: 14
Lexikos wrote:
No, A_LoopFileLongPath is only valid inside a loop.

Damn, you are right, I'm a stupid man. So, when there are not brackets, I must assume that the loop involves the following only one line?

And what about the several notifications I receive for each file change once FolderSpy is executed?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 10th, 2008, 5:27 pm 
Offline

Joined: April 22nd, 2007, 6:33 pm
Posts: 1833
Lexikos is that function you posted above the asynchronous version (by this I mean we can watch several folders/drives "simultaneously"). If so, please could you show how the function should be used if more than 1 folder is to be watched. Thanks


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 10th, 2008, 5:40 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8775
tic wrote:
please could you show how the function should be used if more than 1 folder is to be watched.


+1

I too have been successful with asynchronous method.. but I failed miserably trying to make this work for multiple folders.

so, please Lexikos.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 97 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6, 7  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Stigg and 7 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group