-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfix-removed.rb
executable file
·84 lines (77 loc) · 1.69 KB
/
fix-removed.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/local/bin/ruby -w
# $Id$
# (c) 2005, Dirk Meyer, Im Grund 4, 34317 Habichtswald
#
# Updates on:
# http://anime.dinoex.net/xdcc/tools/
#
def usage(msg)
print msg, "\nUsage: #{File.basename($0)} xdccfile [xdccfile ...]\n\n"
print "add size info to iroffer xdccfile\n"
exit 64
end
def filesize_cache(key)
if ( $size_cache.has_key?( key ) )
return $size_cache[ key ]
end
bytes = File.size(key)
$size_cache[ key ] = bytes
$size_cache_dirty += 1
return bytes
end
$size_filename = "size.data"
$size_cache_dirty = 0
$size_cache = Hash.new(0)
File.stat($size_filename).file? or usage('Size-file does not exist!', options)
begin
File.open($size_filename, 'r').each_line { |line|
line.delete!( "\n" )
line.delete!( "\r" )
words = line.split( ':' )
$size_cache[ words[ 0 ] ] = words[ 1 ].to_i
}
rescue
$stderr.print "Failure at #{$size_filename}: #{$!} => Skipping!\n"
end
if ARGV.size > 0 then
ARGV.each { |filename|
File.stat(filename).file? or next
File.open(filename, 'r').each_line { |line|
line.delete!( "\n" )
line.delete!( "\r" )
if ( /^Do Not Edit This File[:] /.match( line ) )
puts line
next
end
words = line.split( ' ', 2 )
case words[ 0 ]
when 'xx_file'
$xf = words[ 1 ]
$bytes = 0
when 'xx_size'
$bytes = words[ 1 ].to_i
when 'xx_gets'
if $bytes == 0
$bytes = filesize_cache( $xf )
puts "xx_size #{$bytes}"
end
end
puts line
}
}
else
usage('XDCC-file not given!')
end
if ( $size_cache_dirty > 0 )
f = File.new($size_filename, 'w')
if ( f.nil? )
$stderr.print "Failure to save cache #{$size_filename}\n"
exit 1
end
$size_cache.each {|key, value|
f.write( "#{key}:#{value}\n" )
}
f.close
end
exit 0
#