win32_filetime 0.0.4 → 0.0.5
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.
- checksums.yaml +4 -4
- data/lib/win32_filetime/version.rb +1 -1
- data/lib/win32ft.rb +23 -21
- data/specs/win32ft.spec.rb +6 -6
- data/win32_filetime.gemspec +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 70b017261f7dbbe2b16694d91f7a11a5e312c228
|
4
|
+
data.tar.gz: cbf648e30b528a910672494885338ca52db80100
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0988a7b478f4be845ed72105d99ed5a534e6de7d1d083ed174059ce96d9466918f1acb1ffac6e25418967f2a41c781f3f3586e6fa92fd2ab55644549c5d97019
|
7
|
+
data.tar.gz: 4531d8cb04df6b9a80c60198b72fa942396e8e320325e5359e6b62de60c1c9091c87af971ef737c2ae384ebe25f7dddf26d0f1c251ae357bac2d92db8f3fcbfb
|
data/lib/win32ft.rb
CHANGED
@@ -149,6 +149,8 @@ module CFflag
|
|
149
149
|
FILE_FLAG_OPEN_REPARSE_POINT =0x00200000
|
150
150
|
FILE_FLAG_OPEN_NO_RECALL =0x00100000
|
151
151
|
FILE_FLAG_FIRST_PIPE_INSTANCE =0x00080000
|
152
|
+
|
153
|
+
INVALID_HANDLE_VALUE =0xFFFFFFFF
|
152
154
|
end
|
153
155
|
|
154
156
|
module FA
|
@@ -174,9 +176,9 @@ module Win32ft
|
|
174
176
|
ffi_lib 'msvcrt', 'kernel32'
|
175
177
|
ffi_convention :stdcall
|
176
178
|
|
177
|
-
attach_function :GetFileType, [:
|
178
|
-
attach_function :GetLastError, [], :
|
179
|
-
attach_function :FormatMessageA, [:
|
179
|
+
attach_function :GetFileType, [:ulong], :int
|
180
|
+
attach_function :GetLastError, [], :uint
|
181
|
+
attach_function :FormatMessage, :FormatMessageA, [:uint, :pointer, :uint, :uint, :string, :uint, :pointer], :int
|
180
182
|
|
181
183
|
attach_function :FileTimeToLocalFileTime, [FileTime.by_ref, FileTime.by_ref], :bool
|
182
184
|
attach_function :LocalFileTimeToFileTime, [FileTime.by_ref, FileTime.by_ref], :bool
|
@@ -228,12 +230,12 @@ module Win32ft
|
|
228
230
|
GetLocalTime(lt)
|
229
231
|
lt
|
230
232
|
end
|
231
|
-
attach_function :GetFileAttributes, :GetFileAttributesA, [:string], :
|
232
|
-
attach_function :SetFileAttributes, :SetFileAttributesA, [:string, :
|
233
|
+
attach_function :GetFileAttributes, :GetFileAttributesA, [:string], :uint
|
234
|
+
attach_function :SetFileAttributes, :SetFileAttributesA, [:string, :uint], :bool
|
233
235
|
|
234
236
|
=begin
|
235
|
-
|
236
|
-
|
237
|
+
CreateFile("", GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0)
|
238
|
+
CreateFile("", GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0)
|
237
239
|
|
238
240
|
LPCSTR lpFileName, # "filename"
|
239
241
|
DWORD dwDesiredAccess, # GENERIC_READ / GENERIC_WRITE / GENERIC_EXECUTE / GENERIC_ALL
|
@@ -265,22 +267,22 @@ FlushFileBuffers(HANDLE)
|
|
265
267
|
|
266
268
|
CloseHandle(HANDLE)
|
267
269
|
=end
|
268
|
-
attach_function :CreateFileA, [:string, :uint, :uint, :pointer, :uint, :uint, :int], :
|
269
|
-
attach_function :ReadFile, [:
|
270
|
-
attach_function :WriteFile, [:
|
270
|
+
attach_function :CreateFile, :CreateFileA, [:string, :uint, :uint, :pointer, :uint, :uint, :int], :ulong
|
271
|
+
attach_function :ReadFile, [:ulong, :pointer, :uint, :pointer, :pointer], :bool
|
272
|
+
attach_function :WriteFile, [:ulong, :pointer, :uint, :pointer, :pointer], :bool
|
271
273
|
attach_function :DeleteFile, :DeleteFileA, [:string], :bool
|
272
|
-
attach_function :FlushFileBuffers, [:
|
273
|
-
attach_function :CloseHandle, [:
|
274
|
+
attach_function :FlushFileBuffers, [:ulong], :bool
|
275
|
+
attach_function :CloseHandle, [:ulong], :bool
|
274
276
|
|
275
|
-
attach_function :GetFileTime, [:
|
276
|
-
attach_function :SetFileTime, [:
|
277
|
+
attach_function :GetFileTime, [:ulong, FileTime.by_ref, FileTime.by_ref, FileTime.by_ref], :bool
|
278
|
+
attach_function :SetFileTime, [:ulong, FileTime.by_ref, FileTime.by_ref, FileTime.by_ref], :bool
|
277
279
|
def self.getfiletime(fn, getsize: false)
|
278
280
|
size = Large_Integer.new if getsize
|
279
281
|
tc, ta, tm = FileTime.new, FileTime.new, FileTime.new
|
280
282
|
ttts = [tc, ta, tm]
|
281
|
-
hf =
|
283
|
+
hf = CreateFile(fn, CFflag::GENERIC_READ, CFflag::FILE_SHARE_READ | CFflag::FILE_SHARE_WRITE,
|
282
284
|
nil, CFflag::OPEN_EXISTING, CFflag::FILE_FLAG_BACKUP_SEMANTICS, 0)
|
283
|
-
raise "getfiletime: Can not open file \"#{fn}\"" if hf ==
|
285
|
+
raise "getfiletime: Can not open file \"#{fn}\"" if hf == CFflag::INVALID_HANDLE_VALUE
|
284
286
|
res = GetFileTime(hf, tc, ta, tm)
|
285
287
|
raise "getfiletime: GetFileTime error." if !res
|
286
288
|
if getsize
|
@@ -294,9 +296,9 @@ CloseHandle(HANDLE)
|
|
294
296
|
def self.setfiletime(fn, tc, ta, tm)
|
295
297
|
fattr = GetFileAttributes(fn)
|
296
298
|
SetFileAttributes(fn, fattr & ~FA::FILE_ATTRIBUTE_READONLY) if fattr & FA::FILE_ATTRIBUTE_READONLY
|
297
|
-
hf =
|
299
|
+
hf = CreateFile(fn, CFflag::GENERIC_WRITE, CFflag::FILE_SHARE_READ | CFflag::FILE_SHARE_WRITE,
|
298
300
|
nil, CFflag::OPEN_EXISTING, CFflag::FILE_FLAG_BACKUP_SEMANTICS, 0)
|
299
|
-
raise "setfiletime: Can not open file \"#{fn}\"" if hf ==
|
301
|
+
raise "setfiletime: Can not open file \"#{fn}\"" if hf == CFflag::INVALID_HANDLE_VALUE
|
300
302
|
tc = str2ft(tc) if String === tc
|
301
303
|
ta = str2ft(ta) if String === ta
|
302
304
|
tm = str2ft(tm) if String === tm
|
@@ -323,11 +325,11 @@ CloseHandle(HANDLE)
|
|
323
325
|
tt
|
324
326
|
end
|
325
327
|
|
326
|
-
attach_function :GetFileSizeEx, [:
|
328
|
+
attach_function :GetFileSizeEx, [:ulong, Large_Integer.by_ref], :bool
|
327
329
|
def self.getfilesize(fn)
|
328
|
-
hf =
|
330
|
+
hf = CreateFile(fn, CFflag::GENERIC_READ, CFflag::FILE_SHARE_READ | CFflag::FILE_SHARE_WRITE,
|
329
331
|
nil, CFflag::OPEN_EXISTING, CFflag::FILE_FLAG_BACKUP_SEMANTICS, 0)
|
330
|
-
raise "getfilesize: Can not open file \"#{fn}\"" if hf ==
|
332
|
+
raise "getfilesize: Can not open file \"#{fn}\"" if hf == CFflag::INVALID_HANDLE_VALUE
|
331
333
|
size = Large_Integer.new
|
332
334
|
res = GetFileSizeEx(hf, size)
|
333
335
|
raise "getfilesize: GetFileSizeEx error." if !res
|
data/specs/win32ft.spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding: GBK
|
2
2
|
|
3
|
-
|
3
|
+
require_relative "../lib/win32ft"
|
4
4
|
|
5
5
|
describe "FileTime" do
|
6
6
|
it "new FileTime instance should ==" do
|
@@ -121,8 +121,8 @@ describe "File Create Read Write Flush Close GetFileSizeEx" do
|
|
121
121
|
@msg = Time.now.to_s + " asfas f;asjf;lasdfj;s af;alsj f"
|
122
122
|
end
|
123
123
|
|
124
|
-
it "
|
125
|
-
hf = Win32ft.
|
124
|
+
it "CreateFile WriteFile CloseHandle GetFileSizeEx" do
|
125
|
+
hf = Win32ft.CreateFile(@fn1, CFflag::GENERIC_WRITE,
|
126
126
|
CFflag::FILE_SHARE_READ | CFflag::FILE_SHARE_WRITE,
|
127
127
|
nil, CFflag::OPEN_ALWAYS, 0, 0)
|
128
128
|
hf.should satisfy { |obj| obj.is_a? Fixnum }
|
@@ -141,7 +141,7 @@ describe "File Create Read Write Flush Close GetFileSizeEx" do
|
|
141
141
|
it "ReadFile" do
|
142
142
|
buffer = FFI::MemoryPointer.new :char, @msg.bytesize*2
|
143
143
|
rded = FFI::MemoryPointer.new :uint32, 1
|
144
|
-
hf = Win32ft.
|
144
|
+
hf = Win32ft.CreateFile(@fn1, CFflag::GENERIC_READ,
|
145
145
|
CFflag::FILE_SHARE_READ | CFflag::FILE_SHARE_WRITE,
|
146
146
|
nil, CFflag::OPEN_EXISTING, 0, 0)
|
147
147
|
hf.should satisfy { |obj| obj.is_a? Fixnum }
|
@@ -155,10 +155,10 @@ describe "File Create Read Write Flush Close GetFileSizeEx" do
|
|
155
155
|
it "ReadFile no exist file" do
|
156
156
|
Dir.mkdir "c:\\tmp" rescue nil
|
157
157
|
fn = "c:\\tmp\\noexist.txt"
|
158
|
-
hf = Win32ft.
|
158
|
+
hf = Win32ft.CreateFile(fn, CFflag::GENERIC_READ,
|
159
159
|
CFflag::FILE_SHARE_READ | CFflag::FILE_SHARE_WRITE,
|
160
160
|
nil, CFflag::OPEN_EXISTING, 0, 0)
|
161
|
-
hf.should ==
|
161
|
+
hf.should == CFflag::INVALID_HANDLE_VALUE
|
162
162
|
end
|
163
163
|
|
164
164
|
it "getfilesize" do
|
data/win32_filetime.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["windwiny"]
|
10
10
|
spec.email = ["windwiny.ubt@gmail.com"]
|
11
11
|
spec.description = %q{win32 filetime api}
|
12
|
-
spec.summary = %q{win32 filetime api}
|
12
|
+
spec.summary = %q{win32 filetime api.}
|
13
13
|
spec.homepage = "https://github.com/windwiny/win32_filetime.git"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: win32_filetime
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- windwiny
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-01-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -97,5 +97,5 @@ rubyforge_project:
|
|
97
97
|
rubygems_version: 2.0.14
|
98
98
|
signing_key:
|
99
99
|
specification_version: 4
|
100
|
-
summary: win32 filetime api
|
100
|
+
summary: win32 filetime api.
|
101
101
|
test_files: []
|