win32_filetime 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 70b017261f7dbbe2b16694d91f7a11a5e312c228
4
- data.tar.gz: cbf648e30b528a910672494885338ca52db80100
3
+ metadata.gz: 7b3074ff5192787372d2131ab493fffd452f1c52
4
+ data.tar.gz: 9e2cf84261950416a33ed0c257865fdbc1fb783c
5
5
  SHA512:
6
- metadata.gz: 0988a7b478f4be845ed72105d99ed5a534e6de7d1d083ed174059ce96d9466918f1acb1ffac6e25418967f2a41c781f3f3586e6fa92fd2ab55644549c5d97019
7
- data.tar.gz: 4531d8cb04df6b9a80c60198b72fa942396e8e320325e5359e6b62de60c1c9091c87af971ef737c2ae384ebe25f7dddf26d0f1c251ae357bac2d92db8f3fcbfb
6
+ metadata.gz: 02b71ce76429650880ae051315979ef099c554e7092dfd9f3e25038ef81770fe3fbc0e19c4b574d9a049b2625e310a503eb2c00d128532671ea6ac615f3647e9
7
+ data.tar.gz: f74d1195f76f3c76b99f866de35949403f690f08fe41248bd86c17d4cfd5774a08fcf359f63a6a53e869110da1870a23b1a7ff8b87f0bee74d70c34b5ea36dca
data/bin/getdirtimes CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby -w
2
2
  # encoding: GBK
3
3
 
4
- require 'win32ft'
4
+ require 'win32_filetime'
5
5
  require "dirwalk"
6
6
 
7
7
  G = {
data/bin/restoreoldtimes CHANGED
@@ -2,35 +2,47 @@
2
2
  # encoding: GBK
3
3
 
4
4
  require 'openssl'
5
- require 'win32ft'
5
+ require 'win32_filetime'
6
6
  W = Win32ft
7
7
 
8
8
  trap "SIGINT" do
9
- STDERR.puts "exit on Ctrl-C."
9
+ STDERR.puts "\nexit on Ctrl-C."
10
10
  exit 1
11
11
  end
12
12
 
13
- def rolloldtime(d1, fn)
14
- fn = File.absolute_path(fn)
13
+ def rolloldtime(d1, logf)
14
+ logf = File.absolute_path(logf)
15
+ c_ds = 0
16
+ c_fs = 0
15
17
  Dir.chdir(d1) do
16
- File.foreach(fn) do |line|
18
+ File.foreach(logf) do |line|
17
19
  line.strip!
18
20
  next if line.empty?
19
21
  p1 = line.index(/ 0x\w+ 0x\w+ 0x\w+ \d+$/)
20
22
  next if !p1
21
23
 
22
24
  fn = line[0...p1]
23
- next if !File.file?(fn) && !File.directory?(fn)
25
+ next if $just_dir && !File.directory?(fn)
26
+ if File.file?(fn)
27
+ c_fs += 1
28
+ elsif File.directory?(fn)
29
+ c_ds += 1
30
+ else
31
+ next
32
+ end
24
33
 
25
34
  tc1,ta1,tm1,_sz1 = line[p1..-1].split
26
- W.setfiletime(fn, tc1, ta1, tm1)
35
+ W.setfiletime(fn, tc1, ta1, tm1) rescue STDERR.puts "\n Error! #{fn}"
27
36
  end
28
37
  end
38
+ STDERR.puts " Restoreoldtimes \"#{d1}\" dirs: #{c_ds} files: #{c_fs}"
39
+ c_fs
29
40
  end
30
41
 
31
42
  def main
43
+ $just_dir = ARGV.delete('-o') ? true : false
32
44
  if ARGV.size != 2
33
- STDERR.puts "Syntax: restoreoldtimes.rb Dir1 file.log"
45
+ STDERR.puts "Syntax: restoreoldtimes.rb Dir1 file.log [ -o ] # -o just_dir "
34
46
  exit 1
35
47
  end
36
48
  if !File.directory?(ARGV[0]) || !File.file?(ARGV[1])
data/bin/rolloldtimes CHANGED
@@ -2,7 +2,7 @@
2
2
  # encoding: GBK
3
3
 
4
4
  require 'openssl'
5
- require 'win32ft'
5
+ require 'win32_filetime'
6
6
  W = Win32ft
7
7
 
8
8
  trap "SIGINT" do
@@ -20,15 +20,19 @@ def getmd5(fn)
20
20
  md5.hexdigest
21
21
  end
22
22
 
23
- def rolloldtime(d1, d2)
24
- fs1 = Dir.chdir(d1) { Dir.glob '*' }
25
- fs2 = Dir.chdir(d2) { Dir.glob '*' }
23
+ def rolloldtime(dir_from, dir_to)
24
+ c_ds = 1
25
+ c_fs = 0
26
+ fs1 = Dir.chdir(dir_from) { Dir.glob '*' }
27
+ fs2 = Dir.chdir(dir_to) { Dir.glob '*' }
26
28
  fs = fs1 & fs2
27
29
  fs.each do |fn|
28
- f1 = File.join d1,fn
29
- f2 = File.join d2,fn
30
+ f1 = File.join dir_from,fn
31
+ f2 = File.join dir_to,fn
30
32
  if File.directory?(f1) && File.directory?(f2)
31
- rolloldtime(f1, f2)
33
+ _d1, _f1 = rolloldtime(f1, f2)
34
+ c_ds += _d1
35
+ c_fs += _f1
32
36
  elsif File.file?(f1) && File.file?(f2)
33
37
  begin
34
38
  tc1, ta1, tm1, sz1 = W.getfiletime(f1, getsize: true)
@@ -50,22 +54,25 @@ def rolloldtime(d1, d2)
50
54
  end
51
55
  end
52
56
  end
57
+ c_fs += 1
53
58
  rescue Exception => e
54
59
  STDERR.puts e
55
60
  end
56
61
  end
57
62
  end
63
+ [c_ds, c_fs]
58
64
  end
59
65
 
60
66
  def main
61
67
  if ARGV.size != 2
62
- STDERR.puts "Syntax: rolloldtimes.rb Dir1 Dir2"
68
+ STDERR.puts "Syntax: rolloldtimes.rb dir_from dir_to"
63
69
  exit 1
64
70
  end
65
71
  if !File.directory?(ARGV[0]) || !File.directory?(ARGV[1])
66
- STDERR.puts "Syntax: Dir1 Dir2 must be directory"
72
+ STDERR.puts "Syntax: Dir_from Dir_to must be directory"
67
73
  end
68
- rolloldtime(ARGV[0], ARGV[1])
74
+ c_ds, c_fs = rolloldtime(ARGV[0], ARGV[1])
75
+ STDERR.puts " Restoreoldtimes \"#{ARGV[0]}\" -> \"#{ARGV[1]}\". dirs: #{c_ds} files: #{c_fs}"
69
76
  end
70
77
 
71
78
  main
@@ -4,10 +4,10 @@
4
4
  require "win32_filetime/version"
5
5
  require "ffi"
6
6
 
7
- class FileTime < FFI::Struct
7
+ class Win32Filetime::FileTime < FFI::Struct
8
8
  layout :dwLowDateTime, :uint,
9
9
  :dwHighDateTime, :uint
10
-
10
+
11
11
  include Comparable
12
12
  def <=>(other)
13
13
  s1 = self[:dwHighDateTime] << 32 | self[:dwLowDateTime]
@@ -47,7 +47,7 @@ class FileTime < FFI::Struct
47
47
  end
48
48
  end
49
49
 
50
- class SystemTime < FFI::Struct
50
+ class Win32Filetime::SystemTime < FFI::Struct
51
51
  layout :wYear, :ushort,
52
52
  :wMonth, :ushort,
53
53
  :wDayOfWeek, :ushort,
@@ -88,7 +88,7 @@ class SystemTime < FFI::Struct
88
88
  end
89
89
  end
90
90
 
91
- class Large_Integer < FFI::Struct
91
+ class Win32Filetime::Large_Integer < FFI::Struct
92
92
  layout :LowPart, :uint,
93
93
  :HighPart, :uint
94
94
 
@@ -118,11 +118,11 @@ class Large_Integer < FFI::Struct
118
118
  end
119
119
  end
120
120
 
121
- class HANDLE < FFI::Struct
121
+ class Win32Filetime::HANDLE < FFI::Struct
122
122
  layout :handle, :uint
123
123
  end
124
124
 
125
- module CFflag
125
+ module Win32Filetime::CFflag
126
126
  GENERIC_READ = 0x80000000
127
127
  GENERIC_WRITE = 0x40000000
128
128
  GENERIC_EXECUTE = 0x20000000
@@ -153,7 +153,7 @@ module CFflag
153
153
  INVALID_HANDLE_VALUE =0xFFFFFFFF
154
154
  end
155
155
 
156
- module FA
156
+ module Win32Filetime::FA
157
157
  FILE_ATTRIBUTE_READONLY =0x00000001
158
158
  FILE_ATTRIBUTE_HIDDEN =0x00000002
159
159
  FILE_ATTRIBUTE_SYSTEM =0x00000004
@@ -171,15 +171,15 @@ module FA
171
171
  FILE_ATTRIBUTE_VIRTUAL =0x00010000
172
172
  end
173
173
 
174
- module Win32ft
174
+ module Win32Filetime
175
175
  extend FFI::Library
176
176
  ffi_lib 'msvcrt', 'kernel32'
177
177
  ffi_convention :stdcall
178
-
178
+
179
179
  attach_function :GetFileType, [:ulong], :int
180
180
  attach_function :GetLastError, [], :uint
181
181
  attach_function :FormatMessage, :FormatMessageA, [:uint, :pointer, :uint, :uint, :string, :uint, :pointer], :int
182
-
182
+
183
183
  attach_function :FileTimeToLocalFileTime, [FileTime.by_ref, FileTime.by_ref], :bool
184
184
  attach_function :LocalFileTimeToFileTime, [FileTime.by_ref, FileTime.by_ref], :bool
185
185
  def self.ft2lft(ft)
@@ -192,7 +192,7 @@ module Win32ft
192
192
  LocalFileTimeToFileTime(lft, ft)
193
193
  ft
194
194
  end
195
-
195
+
196
196
  attach_function :FileTimeToSystemTime, [FileTime.by_ref, SystemTime.by_ref], :bool
197
197
  attach_function :SystemTimeToFileTime, [SystemTime.by_ref, FileTime.by_ref], :bool
198
198
  def self.ft2st(ft, convft2lft: false)
@@ -217,7 +217,7 @@ module Win32ft
217
217
  ft = lft2ft(ft) if convlft2ft
218
218
  ft
219
219
  end
220
-
220
+
221
221
  attach_function :GetSystemTime, [SystemTime.by_ref], :void
222
222
  def self.getsystemtime
223
223
  st = SystemTime.new
@@ -232,7 +232,7 @@ module Win32ft
232
232
  end
233
233
  attach_function :GetFileAttributes, :GetFileAttributesA, [:string], :uint
234
234
  attach_function :SetFileAttributes, :SetFileAttributesA, [:string, :uint], :bool
235
-
235
+
236
236
  =begin
237
237
  CreateFile("", GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0)
238
238
  CreateFile("", GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0)
@@ -244,7 +244,7 @@ CreateFile("", GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTI
244
244
  DWORD dwCreationDisposition, # CREATE_NEW / CREATE_ALWAYS / OPEN_EXISTING / OPEN_ALWAYS / TRUNCATE_EXISTING
245
245
  DWORD dwFlagsAndAttributes, # 0 | FILE_FLAG_BACKUP_SEMANTICS if dir
246
246
  HANDLE hTemplateFile # 0
247
-
247
+
248
248
  ReadFile(
249
249
  HANDLE,
250
250
  buf, # FFI::MemoryPointer.new(:char, 100)
@@ -273,7 +273,7 @@ CloseHandle(HANDLE)
273
273
  attach_function :DeleteFile, :DeleteFileA, [:string], :bool
274
274
  attach_function :FlushFileBuffers, [:ulong], :bool
275
275
  attach_function :CloseHandle, [:ulong], :bool
276
-
276
+
277
277
  attach_function :GetFileTime, [:ulong, FileTime.by_ref, FileTime.by_ref, FileTime.by_ref], :bool
278
278
  attach_function :SetFileTime, [:ulong, FileTime.by_ref, FileTime.by_ref, FileTime.by_ref], :bool
279
279
  def self.getfiletime(fn, getsize: false)
@@ -324,7 +324,7 @@ CloseHandle(HANDLE)
324
324
  tt = (wintt - 116444736000000000) / 10**7.0
325
325
  tt
326
326
  end
327
-
327
+
328
328
  attach_function :GetFileSizeEx, [:ulong, Large_Integer.by_ref], :bool
329
329
  def self.getfilesize(fn)
330
330
  hf = CreateFile(fn, CFflag::GENERIC_READ, CFflag::FILE_SHARE_READ | CFflag::FILE_SHARE_WRITE,
@@ -337,3 +337,5 @@ CloseHandle(HANDLE)
337
337
  size.to_i
338
338
  end
339
339
  end
340
+
341
+ Win32ft = Win32Filetime
@@ -1,3 +1,3 @@
1
1
  module Win32Filetime
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -1,6 +1,7 @@
1
1
  # encoding: GBK
2
2
 
3
- require_relative "../lib/win32ft"
3
+ require_relative "../lib/win32_filetime"
4
+ include Win32Filetime
4
5
 
5
6
  describe "FileTime" do
6
7
  it "new FileTime instance should ==" do
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.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - windwiny
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-06 00:00:00.000000000 Z
11
+ date: 2014-06-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -70,8 +70,8 @@ files:
70
70
  - bin/getdirtimes
71
71
  - bin/restoreoldtimes
72
72
  - bin/rolloldtimes
73
+ - lib/win32_filetime.rb
73
74
  - lib/win32_filetime/version.rb
74
- - lib/win32ft.rb
75
75
  - specs/win32ft.spec.rb
76
76
  - win32_filetime.gemspec
77
77
  homepage: https://github.com/windwiny/win32_filetime.git
@@ -94,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
94
  version: '0'
95
95
  requirements: []
96
96
  rubyforge_project:
97
- rubygems_version: 2.0.14
97
+ rubygems_version: 2.2.2
98
98
  signing_key:
99
99
  specification_version: 4
100
100
  summary: win32 filetime api.