win32_filetime 0.0.2 → 0.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6a332a4717ba9a99e9e8dc2be746ac9a8203d442
4
- data.tar.gz: 2c9d0e6b3b09ae3cc4409edac0b069187fc70a27
3
+ metadata.gz: 830f1f3edc8a98b28d8e31f67292287de8cf6889
4
+ data.tar.gz: b0b5e8a8c21fcfac1cbe2f96d38a7592bbd49da8
5
5
  SHA512:
6
- metadata.gz: 0daf73590535b81b980301789abeb8403c8b2e912fffc1646b03e8fbd336c2d726f28156aafc85458247abb16e0ea0ee693ff76238d4afd956e6fbee32bf61fd
7
- data.tar.gz: 874c3810671a49e11cbe8dfe2ef3968881f2857ef14b03e08a4305f5818ec848b7901cbbb3efa667c45bc7fd7a4fe04d03ebded31070b085ce2e77fd88960489
6
+ metadata.gz: 3a7adf57edf0860b6995e8677f67c72a4d4d3df7bc53baef2b929c8967292935b89c463ec9d4d2b9546f37c8b9233992b43b6b52c3237ab74c6c7a51f11d7d47
7
+ data.tar.gz: 13cfd910e9d73a6456387a4de6973117ac8086d7d84f8fdd5f723ccca8c4dc80730aba287611058bade1481e3f48973d7be8970d152e3aa6de4a7cb65e76b77f
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env ruby -w
2
+ # encoding: GBK
3
+
4
+ require 'openssl'
5
+ require 'win32ft'
6
+ W = Win32ft
7
+
8
+ trap "SIGINT" do
9
+ STDERR.puts "exit on Ctrl-C."
10
+ exit 1
11
+ end
12
+
13
+ def rolloldtime(d1, fn)
14
+ fn = File.absolute_path(fn)
15
+ Dir.chdir(d1) do
16
+ File.foreach(fn) do |line|
17
+ line.strip!
18
+ next if line.empty? || line[0] == '#'
19
+
20
+ p1 = line.index(/ 0x\w+ 0x\w+ 0x\w+ \d+/)
21
+ fn = line[0...p1]
22
+ next if !File.file?(fn) && !File.directory?(fn)
23
+
24
+ tc1,ta1,tm1,_sz1 = line[p1..-1].split
25
+ W.setfiletime(fn, tc1, ta1, tm1)
26
+ end
27
+ end
28
+ end
29
+
30
+ def main
31
+ if ARGV.size != 2
32
+ STDERR.puts "Syntax: restoreoldtimes.rb Dir1 file.log"
33
+ exit 1
34
+ end
35
+ if !File.directory?(ARGV[0]) || !File.file?(ARGV[1])
36
+ STDERR.puts "Syntax: Dir1 file.log.\n using file.log restore directory files times"
37
+ end
38
+ rolloldtime(ARGV[0], ARGV[1])
39
+ end
40
+
41
+ main
@@ -1,3 +1,3 @@
1
1
  module Win32Filetime
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/win32ft.rb CHANGED
@@ -187,6 +187,16 @@ module Win32ft
187
187
  ft = lft2ft(ft) if convlft2ft
188
188
  ft
189
189
  end
190
+ def self.str2ft(str, convlft2ft: false)
191
+ str = str[2..-1] if str[0...2] =~ /0[xX]/
192
+ h1 = str[0...8].to_i(16)
193
+ l1 = str[8..-1].to_i(16)
194
+ ft = FileTime.new
195
+ ft[:dwHighDateTime] = h1
196
+ ft[:dwLowDateTime] = l1
197
+ ft = lft2ft(ft) if convlft2ft
198
+ ft
199
+ end
190
200
 
191
201
  attach_function :GetSystemTime, [SystemTime.by_ref], :void
192
202
  def self.getsystemtime
@@ -265,6 +275,9 @@ CloseHandle(HANDLE)
265
275
  hf = CreateFileA(fn, CFflag::GENERIC_WRITE, CFflag::FILE_SHARE_READ | CFflag::FILE_SHARE_WRITE,
266
276
  nil, CFflag::OPEN_EXISTING, CFflag::FILE_FLAG_BACKUP_SEMANTICS, 0)
267
277
  raise "setfiletime: Can not open file \"#{fn}\"" if hf == -1
278
+ tc = str2ft(tc) if String === tc
279
+ ta = str2ft(ta) if String === ta
280
+ tm = str2ft(tm) if String === tm
268
281
  res = SetFileTime(hf, tc, ta, tm)
269
282
  raise "setfiletime: SetFileTime error." if !res
270
283
  CloseHandle(hf)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: win32_filetime
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - windwiny
@@ -57,6 +57,7 @@ email:
57
57
  - windwiny.ubt@gmail.com
58
58
  executables:
59
59
  - getdirtimes
60
+ - restoreoldtimes
60
61
  - rolloldtimes
61
62
  extensions: []
62
63
  extra_rdoc_files: []
@@ -67,8 +68,8 @@ files:
67
68
  - README.md
68
69
  - Rakefile
69
70
  - bin/getdirtimes
71
+ - bin/restoreoldtimes
70
72
  - bin/rolloldtimes
71
- - lib/win32_filetime.rb
72
73
  - lib/win32_filetime/version.rb
73
74
  - lib/win32ft.rb
74
75
  - specs/win32ft.spec.rb
@@ -1,5 +0,0 @@
1
- require "win32_filetime/version"
2
-
3
- module Win32Filetime
4
- # Your code goes here...
5
- end