module Winhelper

Public Class Methods

GetWindowsUniqueFileIdentifier(path) click to toggle source
# File lib/filewatch/winhelper.rb, line 47
def self.GetWindowsUniqueFileIdentifier(path)
        handle = GetOpenFileHandle(path, 0, 7, nil, 3, 128, nil)
        fileInfo = Winhelper::FileInformation.new
        success = GetFileInformationByHandle(handle, fileInfo)
        CloseHandle(handle)
        if  success == 1
                #args = [
                #            fileInfo[:fileAttributes], fileInfo[:volumeSerialNumber], fileInfo[:fileSizeHigh], fileInfo[:fileSizeLow],
                #            fileInfo[:numberOfLinks], fileInfo[:fileIndexHigh], fileInfo[:fileIndexLow]
                #    ]
                #p "Information: %u %u %u %u %u %u %u " % args
                #this is only guaranteed on NTFS, for ReFS on windows 2012, GetFileInformationByHandleEx should be used with FILE_ID_INFO, which returns a 128 bit identifier
                return "#{fileInfo[:volumeSerialNumber]}-#{fileInfo[:fileIndexLow]}-#{fileInfo[:fileIndexHigh]}"
        else
                #p "cannot retrieve file information, returning path"
                return path;
        end
end