lib/windows/file.rb in windows-pr-0.6.6 vs lib/windows/file.rb in windows-pr-0.7.0

- old
+ new

@@ -1,10 +1,16 @@ require 'windows/unicode' +include Windows module Windows module File include Windows::Unicode + + API.auto_namespace = 'Windows::File' + API.auto_constant = true + API.auto_method = true + API.auto_unicode = true # File Attributes FILE_ATTRIBUTE_READONLY = 0x00000001 FILE_ATTRIBUTE_HIDDEN = 0x00000002 FILE_ATTRIBUTE_SYSTEM = 0x00000004 @@ -81,20 +87,32 @@ FILE_TRAVERSE = 32 FILE_DELETE_CHILD = 64 FILE_READ_ATTRIBUTES = 128 FILE_WRITE_ATTRIBUTES = 256 - FILE_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|0x1ff) + FILE_ALL_ACCESS = STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 0x1ff - FILE_GENERIC_READ = (STANDARD_RIGHTS_READ|FILE_READ_DATA| - FILE_READ_ATTRIBUTES|FILE_READ_EA|SYNCHRONIZE) + FILE_GENERIC_READ = + STANDARD_RIGHTS_READ | + FILE_READ_DATA | + FILE_READ_ATTRIBUTES | + FILE_READ_EA | + SYNCHRONIZE - FILE_GENERIC_WRITE = (STANDARD_RIGHTS_WRITE|FILE_WRITE_DATA| - FILE_WRITE_ATTRIBUTES|FILE_WRITE_EA|FILE_APPEND_DATA|SYNCHRONIZE) + FILE_GENERIC_WRITE = + STANDARD_RIGHTS_WRITE | + FILE_WRITE_DATA | + FILE_WRITE_ATTRIBUTES | + FILE_WRITE_EA | + FILE_APPEND_DATA | + SYNCHRONIZE - FILE_GENERIC_EXECUTE = (STANDARD_RIGHTS_EXECUTE|FILE_READ_ATTRIBUTES| - FILE_EXECUTE|SYNCHRONIZE) + FILE_GENERIC_EXECUTE = + STANDARD_RIGHTS_EXECUTE | + FILE_READ_ATTRIBUTES | + FILE_EXECUTE | + SYNCHRONIZE FILE_SHARE_READ = 1 FILE_SHARE_WRITE = 2 FILE_SHARE_DELETE = 4 FILE_NOTIFY_CHANGE_FILE_NAME = 1 @@ -144,303 +162,49 @@ SECTION_MAP_WRITE = 0x0002 SECTION_MAP_READ = 0x0004 SECTION_MAP_EXECUTE = 0x0008 SECTION_EXTEND_SIZE = 0x0010 - SECTION_ALL_ACCESS = STANDARD_RIGHTS_REQUIRED | SECTION_QUERY | - SECTION_MAP_WRITE | SECTION_MAP_READ | SECTION_MAP_EXECUTE | + SECTION_ALL_ACCESS = + STANDARD_RIGHTS_REQUIRED | + SECTION_QUERY | + SECTION_MAP_WRITE | + SECTION_MAP_READ | + SECTION_MAP_EXECUTE | SECTION_EXTEND_SIZE # Errors - INVALID_FILE_ATTRIBUTES = -1 - INVALID_HANDLE_VALUE = -1 - INVALID_FILE_SIZE = 0xFFFFFFFF + INVALID_FILE_ATTRIBUTES = -1 + INVALID_HANDLE_VALUE = -1 + INVALID_FILE_SIZE = 0xFFFFFFFF # Misc LOCKFILE_EXCLUSIVE_LOCK = 0x00000001 LOCKFILE_FAIL_IMMEDIATELY = 0x00000002 - CopyFile = Win32API.new('kernel32', 'CopyFile', 'PPI', 'I') - CopyFileA = Win32API.new('kernel32', 'CopyFileA', 'PPI', 'I') - CopyFileW = Win32API.new('kernel32', 'CopyFileW', 'PPI', 'I') - - CopyFileEx = Win32API.new('kernel32', 'CopyFileEx', 'PPPPPL', 'I') - CopyFileExA = Win32API.new('kernel32', 'CopyFileExA', 'PPPPPL', 'I') - CopyFileExW = Win32API.new('kernel32', 'CopyFileExW', 'PPPPPL', 'I') - - CreateFile = Win32API.new('kernel32', 'CreateFile', 'PLLPLLL', 'L') - CreateFileA = Win32API.new('kernel32', 'CreateFileA', 'PLLPLLL', 'L') - CreateFileW = Win32API.new('kernel32', 'CreateFileW', 'PLLPLLL', 'L') - - CreateHardLink = Win32API.new('kernel32', 'CreateHardLink', 'PPP', 'I') - CreateHardLinkA = Win32API.new('kernel32', 'CreateHardLinkA', 'PPP', 'I') - CreateHardLinkW = Win32API.new('kernel32', 'CreateHardLinkW', 'PPP', 'I') - - DecryptFile = Win32API.new('advapi32', 'DecryptFile', 'PL', 'I') - DecryptFileA = Win32API.new('advapi32', 'DecryptFileA', 'PL', 'I') - DecryptFileW = Win32API.new('advapi32', 'DecryptFileW', 'PL', 'I') - - DeleteFile = Win32API.new('kernel32', 'DeleteFile', 'P', 'I') - DeleteFileA = Win32API.new('kernel32', 'DeleteFileA', 'P', 'I') - DeleteFileW = Win32API.new('kernel32', 'DeleteFileW', 'P', 'I') - - EncryptFile = Win32API.new('advapi32', 'EncryptFile', 'P', 'I') - EncryptFileA = Win32API.new('advapi32', 'EncryptFileA', 'P', 'I') - EncryptFileW = Win32API.new('advapi32', 'EncryptFileW', 'P', 'I') - - GetBinaryType = Win32API.new('kernel32', 'GetBinaryType', 'PP', 'I') - GetBinaryTypeA = Win32API.new('kernel32', 'GetBinaryTypeA', 'PP', 'I') - GetBinaryTypeW = Win32API.new('kernel32', 'GetBinaryTypeW', 'PP', 'I') - - GetFileAttributes = Win32API.new('kernel32', 'GetFileAttributes', 'P', 'L') - GetFileAttributesA = Win32API.new('kernel32', 'GetFileAttributesA', 'P', 'L') - GetFileAttributesW = Win32API.new('kernel32', 'GetFileAttributesW', 'P', 'L') - - GetFileAttributesEx = Win32API.new('kernel32', 'GetFileAttributesEx', 'PPP', 'I') - GetFileAttributesExA = Win32API.new('kernel32', 'GetFileAttributesExA', 'PPP', 'I') - GetFileAttributesExW = Win32API.new('kernel32', 'GetFileAttributesExW', 'PPP', 'I') - - GetFileSize = Win32API.new('kernel32', 'GetFileSize', 'LP', 'L') - GetFileSizeEx = Win32API.new('kernel32', 'GetFileSizeEx', 'LP', 'L') - GetFileType = Win32API.new('kernel32', 'GetFileType', 'L', 'L') - - GetFullPathName = Win32API.new('kernel32', 'GetFullPathName', 'PLPP', 'L') - GetFullPathNameA = Win32API.new('kernel32', 'GetFullPathNameA', 'PLPP', 'L') - GetFullPathNameW = Win32API.new('kernel32', 'GetFullPathNameW', 'PLPP', 'L') - - GetLongPathName = Win32API.new('kernel32', 'GetLongPathName', 'PPL', 'L') - GetLongPathNameA = Win32API.new('kernel32', 'GetLongPathNameA', 'PPL', 'L') - GetLongPathNameW = Win32API.new('kernel32', 'GetLongPathNameW', 'PPL', 'L') - - GetShortPathName = Win32API.new('kernel32', 'GetShortPathName', 'PPL', 'L') - GetShortPathNameA = Win32API.new('kernel32', 'GetShortPathNameA', 'PPL', 'L') - GetShortPathNameW = Win32API.new('kernel32', 'GetShortPathNameW', 'PPL', 'L') - - LockFile = Win32API.new('kernel32', 'LockFile', 'LLLLL', 'I') - LockFileEx = Win32API.new('kernel32', 'LockFileEx', 'LLLLLL', 'I') - - ReadFile = Win32API.new('kernel32', 'ReadFile', 'LPLPP', 'I') - ReadFileEx = Win32API.new('kernel32', 'ReadFileEx', 'LPLPP', 'I') - - SetFileAttributes = Win32API.new('kernel32', 'SetFileAttributes', 'PL', 'I') - SetFileAttributesA = Win32API.new('kernel32', 'SetFileAttributesA', 'PL', 'I') - SetFileAttributesW = Win32API.new('kernel32', 'SetFileAttributesW', 'PL', 'I') - - UnlockFile = Win32API.new('kernel32', 'UnlockFile', 'LLLLL', 'I') - UnlockFileEx = Win32API.new('kernel32', 'UnlockFileEx', 'LLLLL', 'I') - - WriteFile = Win32API.new('kernel32', 'WriteFile', 'LPLPP', 'I') - WriteFileEx = Win32API.new('kernel32', 'WriteFileEx', 'LPLPP', 'I') - - def CopyFile(curr_file, new_file, bail) - CopyFile.call(curr_file, new_file, bail) > 0 - end - - def CopyFileA(curr_file, new_file, bail) - CopyFileA.call(curr_file, new_file, bail) > 0 - end - - def CopyFileW(curr_file, new_file, bail) - CopyFileW.call(curr_file, new_file, bail) > 0 - end - - def CopyFileEx(curr_file, new_file, routine, data, cancel, flags) - CopyFileEx.call(curr_file, new_file, routine, data, cancel, flags) > 0 - end - - def CopyFileExA(curr_file, new_file, routine, data, cancel, flags) - CopyFileExA.call(curr_file, new_file, routine, data, cancel, flags) > 0 - end - - def CopyFileExW(curr_file, new_file, routine, data, cancel, flags) - CopyFileExW.call(curr_file, new_file, routine, data, cancel, flags) > 0 - end - - def CreateFile(file, access, share, sec, disp, flags, template) - CreateFile.call(file, access, share, sec, disp, flags, template) - end - - def CreateFileA(file, access, share, sec, disp, flags, template) - CreateFileA.call(file, access, share, sec, disp, flags, template) - end - - def CreateFileW(file, access, share, sec, disp, flags, template) - CreateFileW.call(file, access, share, sec, disp, flags, template) - end - - def CreateHardLink(new_file, old_file, attributes) - CreateHardLink.call(new_file, old_file, attributes) > 0 - end - - def CreateHardLinkA(new_file, old_file, attributes) - CreateHardLinkA.call(new_file, old_file, attributes) > 0 - end - - def CreateHardLinkW(new_file, old_file, attributes) - CreateHardLinkW.call(new_file, old_file, attributes) > 0 - end - - def DecryptFile(file, res = 0) - DecryptFile.call(file, res) - end - - def DecryptFileA(file, res = 0) - DecryptFileA.call(file, res) - end - - def DecryptFileW(file, res = 0) - DecryptFileW.call(file, res) - end - - def DeleteFile(file) - DeleteFile.call(file) > 0 - end - - def DeleteFileA(file) - DeleteFileA.call(file) > 0 - end - - def DeleteFileW(file) - DeleteFileW.call(file) > 0 - end - - def EncryptFile(file) - EncryptFile.call(file) > 0 - end - - def EncryptFileA(file) - EncryptFileA.call(file) > 0 - end - - def EncryptFileW(file) - EncryptFileW.call(file) > 0 - end - - def GetBinaryType(file, type) - GetBinaryType.call(file, type) > 0 - end - - def GetBinaryTypeA(file, type) - GetBinaryTypeA.call(file, type) > 0 - end - - def GetBinaryTypeW(file, type) - GetBinaryTypeW.call(file, type) > 0 - end - - def GetFileAttributes(file) - GetFileAttributes.call(file) - end - - def GetFileAttributesA(file) - GetFileAttributesA.call(file) - end - - def GetFileAttributesW(file) - GetFileAttributesW.call(file) - end - - def GetFileAttributesEx(file, level_id, info) - GetFileAttributesEx.call(file, level_id, info) - end - - def GetFileAttributesExA(file, level_id, info) - GetFileAttributesExA.call(file, level_id, info) - end - - def GetFileAttributesExW(file, level_id, info) - GetFileAttributesExW.call(file, level_id, info) - end - - def GetFileSize(handle, size) - GetFileSize.call(handle, size) - end - - def GetFileSizeEx(handle, size) - GetFileSizeEx.call(handle, size) > 0 - end - - def GetFileType(handle) - GetFileType.call(handle) - end - - def GetFullPathName(file, buf, buf_size, part) - GetFullPathName.call(file, buf, buf_size, part) - end - - def GetFullPathNameA(file, buf, buf_size, part) - GetFullPathNameA.call(file, buf, buf_size, part) - end - - def GetFullPathNameW(file, buf, buf_size, part) - GetFullPathNameW.call(file, buf, buf_size, part) - end - - def GetLongPathName(short, buf, buf_size) - GetLongPathName.call(short, buf, buf_size) - end - - def GetLongPathNameA(short, buf, buf_size) - GetLongPathNameA.call(short, buf, buf_size) - end - - def GetLongPathNameW(short, buf, buf_size) - GetLongPathNameW.call(short, buf, buf_size) - end - - def GetShortPathName(long, buf, buf_size) - GetShortPathName.call(long, buf, buf_size) - end - - def GetShortPathNameA(long, buf, buf_size) - GetShortPathNameA.call(long, buf, buf_size) - end - - def GetShortPathNameW(long, buf, buf_size) - GetShortPathNameW.call(long, buf, buf_size) - end - - def LockFile(handle, off_low, off_high, lock_low, lock_high) - LockFile.call(handle, off_low, off_high, lock_low, lock_high) > 0 - end - - def LockFileEx(handle, flags, res, low, high, overlapped) - LockFileEx.call(handle, flags, res, low, high, overlapped) > 0 - end - - def ReadFile(file, buf, bytes, bytes_read, overlapped) - ReadFile.call(file, buf, bytes, bytes_read, overlapped) > 0 - end - - def ReadFileEx(file, buf, bytes, overlapped, routine) - ReadFileEx.call(file, buf, bytes, overlapped, routine) > 0 - end - - def SetFileAttributes(file, attributes) - SetFileAttributes.call(file, attributes) > 0 - end - - def SetFileAttributesA(file, attributes) - SetFileAttributesA.call(file, attributes) > 0 - end - - def SetFileAttributesW(file, attributes) - SetFileAttributesW.call(file, attributes) > 0 - end - - def UnlockFile(handle, off_low, off_high, bytes_low, bytes_high) - UnlockFile.call(handle, off_low, off_high, bytes_low, bytes_high) > 0 - end - - def UnlockFileEx(handle, res, low, high, overlapped) - UnlockFileEx.call(handle, res, low, high, overlapped) > 0 - end - - def WriteFile(handle, buf, bytes, overlapped) - WriteFile.call(handle, buf, bytes, overlapped) > 0 - end - - def WriteFileEx(handle, buf, bytes, overlapped, routine) - WriteFileEx.call(handle, buf, bytes, overlapped, routine) > 0 - end + API.new('CopyFile', 'PPI', 'B') + API.new('CopyFileEx', 'PPPPPL', 'B') + API.new('CreateFile', 'PLLPLLL', 'L') + API.new('CreateHardLink', 'PPP', 'B') + API.new('DecryptFile', 'PL', 'B', 'advapi32') + API.new('DeleteFile', 'P', 'B') + API.new('EncryptFile', 'P', 'B', 'advapi32') + API.new('GetBinaryType', 'PP', 'B') + API.new('GetFileAttributes', 'P', 'L') + API.new('GetFileAttributesEx', 'PPP', 'I') + API.new('GetFileSize', 'LP', 'L') + API.new('GetFileSizeEx', 'LP', 'B') + API.new('GetFileType', 'L', 'L') + API.new('GetFullPathName', 'PLPP', 'L') + API.new('GetLongPathName', 'PPL', 'L') + API.new('GetShortPathName', 'PPL', 'L') + API.new('LockFile', 'LLLLL', 'B') + API.new('LockFileEx', 'LLLLLL', 'B') + API.new('ReadFile', 'LPLPP', 'B') + API.new('ReadFileEx', 'LPLPP', 'B') + API.new('SetFileAttributes', 'PL', 'B') + API.new('UnlockFile', 'LLLLL', 'B') + API.new('UnlockFileEx', 'LLLLL', 'B') + API.new('WriteFile', 'LPLPP', 'B') + API.new('WriteFileEx', 'LPLPP', 'B') end end