win32-dir 0.4.1 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGES CHANGED
@@ -1,3 +1,7 @@
1
+ == 0.4.2 - 8-Apr-2013
2
+ * Fixed the HANDLE function prototypes in the underlying FFI code and added
3
+ some custom typedefs for convenience. This affects 64 bit Ruby code.
4
+
1
5
  == 0.4.1 - 2-Oct-2012
2
6
  * Added the Dir.read_junction method. Thanks go to Gabriel Wilkins for the patch.
3
7
 
data/lib/win32/dir.rb CHANGED
@@ -26,7 +26,7 @@ class Dir
26
26
  )
27
27
 
28
28
  # The version of the win32-dir library.
29
- VERSION = '0.4.1'
29
+ VERSION = '0.4.2'
30
30
 
31
31
  # CSIDL constants
32
32
  csidl = Hash[
@@ -194,11 +194,8 @@ class Dir
194
194
  # Dir.create_junction('C:/to', 'C:/from')
195
195
  #
196
196
  def self.create_junction(to, from)
197
- to = to.tr(File::SEPARATOR, File::ALT_SEPARATOR) + "\0" # Normalize path
198
- from = from.tr(File::SEPARATOR, File::ALT_SEPARATOR) + "\0" # Normalize path
199
-
200
- to.encode!('UTF-16LE')
201
- from.encode!('UTF-16LE')
197
+ to = to.wincode
198
+ from = from.wincode
202
199
 
203
200
  from_path = 0.chr * 1024
204
201
  from_path.encode!('UTF-16LE')
@@ -212,7 +209,6 @@ class Dir
212
209
  end
213
210
 
214
211
  to_path = 0.chr * 1024
215
- to.encode!('UTF-16LE')
216
212
  to_path.encode!('UTF-16LE')
217
213
 
218
214
  length = GetFullPathNameW(to, to_path.size, to_path, nil)
@@ -303,9 +299,9 @@ class Dir
303
299
  #
304
300
  def self.read_junction(junction)
305
301
  return false unless Dir.junction?(junction)
306
- junction = junction.tr(File::SEPARATOR, File::ALT_SEPARATOR) + "\0" # Normalize path
307
302
 
308
- junction.encode!('UTF-16LE')
303
+ junction = junction.wincode
304
+
309
305
  junction_path = 0.chr * 1024
310
306
  junction_path.encode!('UTF-16LE')
311
307
 
@@ -379,19 +375,15 @@ class Dir
379
375
  # a directory, or contains any files other than '.' or '..'.
380
376
  #
381
377
  def self.empty?(path)
382
- path = path + "\0"
383
- path = path.encode('UTF-16LE')
384
- PathIsDirectoryEmptyW(path)
378
+ PathIsDirectoryEmptyW(path.wincode)
385
379
  end
386
380
 
387
381
  # Returns whether or not +path+ is a junction.
388
382
  #
389
383
  def self.junction?(path)
390
384
  bool = true
391
- path = path + "\0"
392
- path.encode!('UTF-16LE')
393
385
 
394
- attrib = GetFileAttributesW(path)
386
+ attrib = GetFileAttributesW(path.wincode)
395
387
 
396
388
  # Only directories with a reparse point attribute can be junctions
397
389
  if attrib == INVALID_FILE_ATTRIBUTES ||
@@ -9,11 +9,16 @@ require 'ffi'
9
9
  module Dir::Functions
10
10
  extend FFI::Library
11
11
 
12
+ typedef :ulong, :dword
13
+ typedef :uintptr_t, :handle
14
+ typedef :uintptr_t, :hwnd
15
+ typedef :pointer, :ptr
16
+
12
17
  ffi_lib :shell32
13
18
 
14
- attach_function :SHGetFolderPathW, [:ulong, :int, :ulong, :ulong, :buffer_out], :ulong
15
- attach_function :SHGetFolderLocation, [:ulong, :int, :ulong, :ulong, :pointer], :ulong
16
- attach_function :SHGetFileInfo, [:ulong, :ulong, :pointer, :uint, :uint], :ulong
19
+ attach_function :SHGetFolderPathW, [:hwnd, :int, :handle, :dword, :buffer_out], :dword
20
+ attach_function :SHGetFolderLocation, [:hwnd, :int, :handle, :dword, :ptr], :dword
21
+ attach_function :SHGetFileInfo, [:dword, :dword, :ptr, :uint, :uint], :dword
17
22
 
18
23
  ffi_lib :shlwapi
19
24
 
@@ -21,15 +26,23 @@ module Dir::Functions
21
26
 
22
27
  ffi_lib :kernel32
23
28
 
24
- attach_function :CloseHandle, [:ulong], :bool
25
- attach_function :CreateDirectoryW, [:buffer_in, :pointer], :bool
26
- attach_function :CreateFileW, [:buffer_in, :ulong, :ulong, :pointer, :ulong, :ulong, :ulong], :ulong
27
- attach_function :DeviceIoControl, [:ulong, :ulong, :pointer, :ulong, :pointer, :ulong, :pointer, :pointer], :bool
28
- attach_function :GetCurrentDirectoryW, [:ulong, :buffer_out], :ulong
29
- attach_function :GetFileAttributesW, [:buffer_in], :ulong
30
- attach_function :GetLastError, [], :ulong
31
- attach_function :GetShortPathNameW, [:buffer_in, :buffer_out, :ulong], :ulong
32
- attach_function :GetLongPathNameW, [:buffer_in, :buffer_out, :ulong], :ulong
33
- attach_function :GetFullPathNameW, [:buffer_in, :ulong, :buffer_out, :pointer], :ulong
29
+ attach_function :CloseHandle, [:handle], :bool
30
+ attach_function :CreateDirectoryW, [:buffer_in, :ptr], :bool
31
+ attach_function :CreateFileW, [:buffer_in, :dword, :dword, :ptr, :dword, :dword, :handle], :handle
32
+ attach_function :DeviceIoControl, [:handle, :dword, :ptr, :dword, :ptr, :dword, :ptr, :ptr], :bool
33
+ attach_function :GetCurrentDirectoryW, [:dword, :buffer_out], :dword
34
+ attach_function :GetFileAttributesW, [:buffer_in], :dword
35
+ attach_function :GetLastError, [], :dword
36
+ attach_function :GetShortPathNameW, [:buffer_in, :buffer_out, :dword], :dword
37
+ attach_function :GetLongPathNameW, [:buffer_in, :buffer_out, :dword], :dword
38
+ attach_function :GetFullPathNameW, [:buffer_in, :dword, :buffer_out, :ptr], :dword
34
39
  attach_function :RemoveDirectoryW, [:buffer_in], :bool
35
40
  end
41
+
42
+ class String
43
+ # Convenience method for converting strings to UTF-16LE for wide character
44
+ # functions that require it.
45
+ def wincode
46
+ (self.tr(File::SEPARATOR, File::ALT_SEPARATOR) + 0.chr).encode('UTF-16LE')
47
+ end
48
+ end
@@ -25,7 +25,7 @@ class TC_Win32_Dir < Test::Unit::TestCase
25
25
  end
26
26
 
27
27
  test "version number is set to expected value" do
28
- assert_equal('0.4.1', Dir::VERSION)
28
+ assert_equal('0.4.2', Dir::VERSION)
29
29
  end
30
30
 
31
31
  test 'glob handles backslashes' do
data/win32-dir.gemspec CHANGED
@@ -2,11 +2,11 @@ require 'rubygems'
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'win32-dir'
5
- spec.version = '0.4.1'
5
+ spec.version = '0.4.2'
6
6
  spec.authors = ['Daniel J. Berger', 'Park Heesob']
7
7
  spec.license = 'Artistic 2.0'
8
8
  spec.email = 'djberg96@gmail.com'
9
- spec.homepage = 'http://www.rubyforge.org/projects/win32utils'
9
+ spec.homepage = 'http://github.com/djberg96/win32-dir'
10
10
  spec.summary = 'Extra constants and methods for the Dir class on Windows.'
11
11
  spec.test_file = 'test/test_win32_dir.rb'
12
12
  spec.files = Dir['**/*'].reject{ |f| f.include?('git') }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: win32-dir
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-10-02 00:00:00.000000000 Z
13
+ date: 2013-04-08 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: ffi
@@ -68,7 +68,7 @@ files:
68
68
  - README
69
69
  - test/test_win32_dir.rb
70
70
  - win32-dir.gemspec
71
- homepage: http://www.rubyforge.org/projects/win32utils
71
+ homepage: http://github.com/djberg96/win32-dir
72
72
  licenses:
73
73
  - Artistic 2.0
74
74
  post_install_message: