[Win32utils-devel] Need some help with pure Ruby win32-changenotify

Daniel Berger djberg96 at gmail.com
Sun Aug 5 16:09:37 EDT 2007


Ok, solved the remaining issues. I had to move the CloseHandle call in
the wait method above the yield/return. Also, I had to increase the
buffer size for the final string name.

Now I'm wondering if I should automatically prepend the @path to the
file name in the final struct. We could use File.expand_path for
relative paths.

What do you think?

Thanks,

Dan

On 8/5/07, Daniel Berger <djberg96 at gmail.com> wrote:
> Nevermind. The break condition needs to be moved to the end of the
> loop. But, I think there's another issue. Researching further....
>
> Dan
>
> On 8/5/07, Daniel Berger <djberg96 at gmail.com> wrote:
> > Hi again,
> >
> > Yep, forgot about the variable length, thanks. I've committed your
> > changes. I also increased the buffer to 64k.
> >
> > The problem now seems to be that it detects an event, but the
> > NextEntryOffset is 0. The result is that I see an empty array yielded
> > back most of the time when an event occurs. The C version works fine.
> >
> > Here's a simple script I'm using for testing:
> >
> > Thread.new{ loop { sleep 0.1 } } # So ctrl-c works (might take 10 seconds)
> >
> > filter = ChangeNotify::FILE_NAME | ChangeNotify::DIR_NAME
> > cn = ChangeNotify.new("C:\\", true, filter)
> > cn.wait(10){ |x|
> >    p x
> > } while true
> >
> > Any ideas?
> >
> > Thanks,
> >
> > Dan
> >
> > On 8/5/07, Heesob Park <phasis at gmail.com> wrote:
> > > Hi,
> > >
> > >
> > > 2007/8/4, Daniel Berger <djberg96 at gmail.com>:
> > >
> > > > Hi all,
> > > >
> > > > I know it's deprecated, but people seem to still be using
> > > > win32-changenotify, so I thought I'd see if I could make it pure Ruby.
> > > > Also, I thought it would be a good opportunity to test passing a custom
> > > > Win32::Event object.
> > > >
> > > > I'm mostly done I think, but I'm having trouble unraveling the
> > > > FILE_NOTIFY_INFORMATION struct buffer. Please check out the latest
> > > > lib/win32/changenotify.rb from CVS and take a look at both the custom
> > > > wait method and the get_file_action private method.
> > > >
> > > > The notification is clearly getting picked up, but I'm just not
> > > > unraveling the struct properly.
> > > >
> > > > Here's a little sample program you can use to test:
> > > >
> > > > require 'win32/changenotify'
> > > > include Win32
> > > >
> > > > filter = ChangeNotify::FILE_NAME | ChangeNotify::DIR_NAME
> > > > cn = ChangeNotify.new("C:\\", true, filter)
> > > > cn.wait(15){ |x|
> > > >    p x
> > > > } while true
> > > >
> > > > Then, just make sure to modify some file within the 15 second wait period.
> > > >
> > > > Thanks,
> > > >
> > > > Dan
> > >
> > >
> > > You may overlooked the API document that says the FileName field is a
> > > variable-length field.
> > >
> > > Here is working version of get_file_action:
> > >
> > >      def get_file_action(fni)
> > >          array  = []
> > >          while true
> > >             break if fni.nil? || fni[0,4].unpack('L')[0] == 0
> > >             int_action = fni[4,4].unpack('L')[0]
> > >             str_action = 'unknown'
> > >             case int_action
> > >                when FILE_ACTION_ADDED
> > >                   str_action = 'added'
> > >                when FILE_ACTION_REMOVED
> > >                    str_action = 'removed'
> > >                when FILE_ACTION_MODIFIED
> > >                   str_action = 'modified'
> > >                when FILE_ACTION_RENAMED_OLD_NAME
> > >                   str_action = 'renamed old name'
> > >                when FILE_ACTION_RENAMED_NEW_NAME
> > >                   str_action = 'renamed new name'
> > >             end
> > >             len = fni[8,4].unpack('L').first
> > >             buf = fni[12,len]
> > >             file = wide_to_multi(buf)
> > >             struct = ChangeNotifyStruct.new(str_action, file)
> > >             array.push(struct)
> > >             fni = fni[fni[0,4].unpack('L').first, -1] # Next offset
> > >          end
> > >
> > >          array
> > >       end
> > >
> > > Regards,
> > >
> > > Park Heesob
> > >
> > > _______________________________________________
> > > win32utils-devel mailing list
> > > win32utils-devel at rubyforge.org
> > > http://rubyforge.org/mailman/listinfo/win32utils-devel
> > >
> >
>


More information about the win32utils-devel mailing list