windows-pr 0.5.0-mswin32 → 0.5.1-mswin32

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,3 +1,8 @@
1
+ = 0.5.1 - 26-May-2006
2
+ * Minor updates and fixes for the Unicode and DeviceIO modules.
3
+ * Added some wide character support, based on $KCODE values (which should
4
+ not be used at this time).
5
+
1
6
  = 0.5.0 - 23-May-2006
2
7
  * Added the Registry module
3
8
  * Added the EventLog module
data/README CHANGED
@@ -45,6 +45,16 @@
45
45
  file contains clipboard related functions, such as CloseClipboard(), as
46
46
  well as constants such as CF_TEXT, CF_BITMAP, etc.
47
47
 
48
+ == Wide character functions - DO NOT USE
49
+ Because there's no way to "#define UNICODE" from outside of C, I have
50
+ instead taken the approach of defining the wide character functions and
51
+ automatically using those if $KCODE is set to anything other than "NONE".
52
+
53
+ However, support for this is very incomplete at the moment. In addition,
54
+ unpredictable segfaults occur with Ruby's string processing in some cases,
55
+ the cause of which is unknown at this time. The upshot of this is that you
56
+ should not use these modules with $KCODE set to anything other than "NONE".
57
+
48
58
  == Where are the tests, dude?
49
59
  While I've made some effort to test these functions, there are simply too
50
60
  many for me to effectively test them all. We're ultimately talking about
@@ -63,10 +63,26 @@ module Windows
63
63
  FILE_DEVICE_FIPS = 0x0000003A
64
64
  FILE_DEVICE_INFINIBAND = 0x0000003B
65
65
 
66
+ METHOD_BUFFERED = 0
67
+ FILE_ANY_ACCESS = 0
68
+
66
69
  DeviceIoControl = Win32API.new('kernel32', 'DeviceIoControl', 'LLPLPLPP', 'I')
67
70
 
68
71
  def DeviceIoControl(dev, code, in_buf, in_buf_size, out_buf, out_buf_size, bytes, overlapped)
69
- DeviceIoControl.call(dev, code, in_buf, in_buf_size, out_buf, out_buf_size, bytes, overlapped)
72
+ DeviceIoControl.call(dev, code, in_buf, in_buf_size, out_buf, out_buf_size, bytes, overlapped) > 0
73
+ end
74
+
75
+ # Macros from WinIoCtl.h
76
+ def CTL_CODE(device, function, method, access)
77
+ ((device) << 16) | ((access) << 14) | ((function) << 2) | (method)
78
+ end
79
+
80
+ def FSCTL_SET_COMPRESSION
81
+ CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 16, 0, FILE_READ_DATA | FILE_WRITE_DATA)
82
+ end
83
+
84
+ def FSCTL_SET_SPARSE
85
+ CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 49, 0, FILE_SPECIAL_ACCESS)
70
86
  end
71
87
  end
72
88
  end
@@ -1,8 +1,9 @@
1
- require 'Win32API'
1
+ require 'windows/unicode'
2
2
 
3
3
  module Windows
4
4
  module Directory
5
5
  CreateDirectory = Win32API.new('kernel32', 'CreateDirectory', 'PP', 'I')
6
+ CreateDirectoryW = Win32API.new('kernel32', 'CreateDirectoryW', 'PP', 'I')
6
7
  CreateDirectoryEx = Win32API.new('kernel32', 'CreateDirectoryEx', 'PPP', 'I')
7
8
  FindCloseChangeNotification = Win32API.new('kernel32', 'FindCloseChangeNotification', 'L', 'I')
8
9
  FindFirstChangeNotification = Win32API.new('kernel32', 'FindFirstChangeNotification', 'PIL', 'L')
@@ -10,10 +11,16 @@ module Windows
10
11
  GetCurrentDirectory = Win32API.new('kernel32', 'GetCurrentDirectory', 'LP', 'L')
11
12
  ReadDirectoryChangesW = Win32API.new('kernel32', 'ReadDirectoryChangesW', 'LPLILPPP', 'I')
12
13
  RemoveDirectory = Win32API.new('kernel32', 'RemoveDirectory', 'P', 'I')
14
+ RemoveDirectoryW = Win32API.new('kernel32', 'RemoveDirectoryW', 'P', 'I')
13
15
  SetCurrentDirectory = Win32API.new('kernel32', 'SetCurrentDirectory', 'P', 'I')
16
+ SetCurrentDirectoryW = Win32API.new('kernel32', 'SetCurrentDirectoryW', 'P', 'I')
14
17
 
15
- def CreateDirectory(path, attributes)
16
- CreateDirectory.call(path, attributes) != 0
18
+ def CreateDirectory(path, attributes = 0)
19
+ if $KCODE != 'NONE'
20
+ CreateDirectoryW.call(path, attributes) != 0
21
+ else
22
+ CreateDirectory.call(path, attributes) != 0
23
+ end
17
24
  end
18
25
 
19
26
  def CreateDirectoryEx(template, new, attributes)
@@ -41,11 +48,19 @@ module Windows
41
48
  end
42
49
 
43
50
  def RemoveDirectory(path)
44
- RemoveDirectory.call(path) != 0
51
+ if $KCODE != 'NONE'
52
+ RemoveDirectoryW.call(path) != 0
53
+ else
54
+ RemoveDirectory.call(path) != 0
55
+ end
45
56
  end
46
57
 
47
58
  def SetCurrentDirectory(path)
48
- SetCurrentDirectory.call(path) != 0
59
+ if $KCODE != 'NONE'
60
+ SetCurrentDirectoryW.call(path) != 0
61
+ else
62
+ SetCurrentDirectory.call(path) != 0
63
+ end
49
64
  end
50
65
  end
51
66
  end
@@ -8,7 +8,7 @@
8
8
  # get_last_error - Returns a human readable string for the error returned
9
9
  # by the GetLastError() function.
10
10
  ############################################################################
11
- require 'Win32API'
11
+ require 'windows/unicode'
12
12
 
13
13
  module Windows
14
14
  module Error
@@ -273,6 +273,7 @@ module Windows
273
273
  SetLastErrorEx = Win32API.new('kernel32', 'GetLastError', 'LL', 'V')
274
274
  SetErrorMode = Win32API.new('kernel32', 'SetErrorMode', 'I', 'I')
275
275
  FormatMessage = Win32API.new('kernel32', 'FormatMessage', 'LLLLPLP', 'L')
276
+ FormatMessageW = Win32API.new('kernel32', 'FormatMessageW', 'LLLLPLP', 'L')
276
277
 
277
278
  def GetLastError
278
279
  GetLastError.call
@@ -298,17 +299,15 @@ module Windows
298
299
  # returns a human readable string.
299
300
  #
300
301
  def get_last_error(err_num = GetLastError.call)
301
- buf = 0.chr * 260
302
- FormatMessage.call(
303
- FORMAT_MESSAGE_FROM_SYSTEM + FORMAT_MESSAGE_ARGUMENT_ARRAY,
304
- 0,
305
- err_num,
306
- 0,
307
- buf,
308
- buf.length,
309
- 0
310
- )
311
- buf.split(0.chr).first.chomp
302
+ buf = 0.chr * 260
303
+ flags = FORMAT_MESSAGE_FROM_SYSTEM + FORMAT_MESSAGE_ARGUMENT_ARRAY
304
+
305
+ if $KCODE != 'NONE'
306
+ FormatMessageW.call(flags, 0, err_num, 0, buf, buf.length, 0)
307
+ else
308
+ FormatMessage.call(flags, 0, err_num, 0, buf, buf.length, 0)
309
+ end
310
+ buf.split(0.chr).first.chomp
312
311
  end
313
312
  end
314
313
  end
@@ -1,4 +1,4 @@
1
- require 'Win32API'
1
+ require 'windows/unicode'
2
2
 
3
3
  module Windows
4
4
  module File
@@ -146,6 +146,7 @@ module Windows
146
146
  CopyFile = Win32API.new('kernel32', 'CopyFile', 'PPI', 'I')
147
147
  CopyFileEx = Win32API.new('kernel32', 'CopyFileEx', 'PPPPPL', 'I')
148
148
  CreateFile = Win32API.new('kernel32', 'CreateFile', 'PLLPLLL', 'L')
149
+ CreateFileW = Win32API.new('kernel32', 'CreateFileW', 'PLLPLLL', 'L')
149
150
  CreateHardLink = Win32API.new('kernel32', 'CreateHardLink', 'PPP', 'I')
150
151
  DecryptFile = Win32API.new('advapi32', 'DecryptFile', 'PL', 'I')
151
152
  DeleteFile = Win32API.new('kernel32', 'DeleteFile', 'P', 'I')
@@ -157,6 +158,8 @@ module Windows
157
158
  GetFileSize = Win32API.new('kernel32', 'GetFileSize', 'LP', 'L')
158
159
  GetFileSizeEx = Win32API.new('kernel32', 'GetFileSizeEx', 'LP', 'L')
159
160
  GetFileType = Win32API.new('kernel32', 'GetFileType', 'L', 'L')
161
+ GetFullPathName = Win32API.new('kernel32', 'GetFullPathName', 'PLPP', 'L')
162
+ GetFullPathNameW = Win32API.new('kernel32', 'GetFullPathNameW', 'PLPP', 'L')
160
163
  GetLongPathName = Win32API.new('kernel32', 'GetLongPathName', 'PPL', 'L')
161
164
  GetShortPathName = Win32API.new('kernel32', 'GetShortPathName', 'PPL', 'L')
162
165
 
@@ -181,7 +184,11 @@ module Windows
181
184
  end
182
185
 
183
186
  def CreateFile(file, access, share, sec, disp, flags, template)
184
- CreateFile.call(file, access, share, sec, disp, flags, template)
187
+ if $KCODE != 'NONE'
188
+ CreateFileW.call(file, access, share, sec, disp, flags, template)
189
+ else
190
+ CreateFile.call(file, access, share, sec, disp, flags, template)
191
+ end
185
192
  end
186
193
 
187
194
  def CreateHardLink(new_file, old_file, attributes)
@@ -224,6 +231,14 @@ module Windows
224
231
  GetFileType.call(handle)
225
232
  end
226
233
 
234
+ def GetFullPathName(file, buf, buf_size, part)
235
+ if $KCODE != 'NONE'
236
+ GetFullPathNameW.call(file, buf, buf_size, part)
237
+ else
238
+ GetFullPathName.call(file, buf, buf_size, part)
239
+ end
240
+ end
241
+
227
242
  def GetLongPathName(short, buf, buf_size)
228
243
  GetLongPathName.call(short, buf, buf_size)
229
244
  end
@@ -66,8 +66,8 @@ module Windows
66
66
  E_INVALIDARG = 2147483651
67
67
 
68
68
  # Flags
69
- SHGFP_TYPE_CURRENT
70
- SHGFP_TYPE_DEFAULT
69
+ SHGFP_TYPE_CURRENT = 0
70
+ SHGFP_TYPE_DEFAULT = 1
71
71
 
72
72
  SHGetFolderPath = Win32API.new('shell32', 'SHGetFolderPath', 'LLLLP', 'L')
73
73
  SHGetSpecialFolderLocation = Win32API.new('shell32', 'SHGetSpecialFolderLocation', 'LIP', 'L')
@@ -68,7 +68,7 @@ module Windows
68
68
  IsDBCSLeadByteEx = Win32API.new('kernel32', 'IsDBCSLeadByteEx', 'IP', 'I')
69
69
  IsTextUnicode = Win32API.new('advapi32', 'IsTextUnicode', 'PIP', 'I')
70
70
  MultiByteToWideChar = Win32API.new('kernel32', 'MultiByteToWideChar', 'ILPIPI', 'I')
71
- TranslateCharsetInfo = Win32API.new('kernel32', 'TranslateCharsetInfo', 'PPL', 'I')
71
+ TranslateCharsetInfo = Win32API.new('gdi32', 'TranslateCharsetInfo', 'PPL', 'I')
72
72
  WideCharToMultiByte = Win32API.new('kernel32', 'WideCharToMultiByte', 'ILPIPIPP', 'I')
73
73
 
74
74
  def GetTextCharset(hdc)
@@ -87,7 +87,7 @@ module Windows
87
87
  IsDBCSLeadByteEx.call(code_pag, char) != 0
88
88
  end
89
89
 
90
- def IsTextUnicode(buf, size, options)
90
+ def IsTextUnicode(buf, size = buf.size, options = 0)
91
91
  IsTextUnicode.call(buf, size, options) != 0
92
92
  end
93
93
 
@@ -102,5 +102,37 @@ module Windows
102
102
  def WideCharToMultiByte(page, flags, str, str_size, buf, buf_size, defchar, used_def)
103
103
  WideCharToMultiByte.call(page, flags, str, str_size, buf, buf_size, defchar, used_def)
104
104
  end
105
+
106
+ # Convenient wrapper methods
107
+
108
+ # Maps a string to a wide (unicode) string using UTF8. If the function
109
+ # fails it just returns the string as is.
110
+ #
111
+ def multi_to_wide(str)
112
+ cp = ($KCODE == 'UTF8') ? CP_UTF8 : CP_ACP
113
+ buf = 0.chr * str.size * 2 # sizeof(WCHAR)
114
+ int = MultiByteToWideChar(cp, 0, str, str.size, buf, buf.size)
115
+
116
+ if int > 0
117
+ buf[0, int*2]
118
+ else
119
+ str
120
+ end
121
+ end
122
+
123
+ # Maps a wide character string to a new character string. If the
124
+ # function fails it just returns the string as is.
125
+ #
126
+ def wide_to_multi(str)
127
+ cp = ($KCODE == 'UTF8') ? CP_UTF8 : CP_ACP
128
+ buf = 0.chr * str.size
129
+ int = WideCharToMultiByte(cp, 0, str, str.size/2, buf, buf.size, 0, 0)
130
+
131
+ if int > 0
132
+ buf[0, int]
133
+ else
134
+ str
135
+ end
136
+ end
105
137
  end
106
138
  end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: windows-pr
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.5.0
7
- date: 2006-05-23 00:00:00 -06:00
6
+ version: 0.5.1
7
+ date: 2006-05-28 00:00:00 -06:00
8
8
  summary: Windows functions and constants predefined via Win32API
9
9
  require_paths:
10
10
  - lib