-
Notifications
You must be signed in to change notification settings - Fork 180
/
Copy pathconvert.rb
52 lines (46 loc) · 1.42 KB
/
convert.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
# encoding: utf-8
$:.unshift << File.dirname(__FILE__)
require "zlib"
require "fileutils"
def load_data(filename)
File.open(filename, "rb") { |f|
obj = Marshal.load(f)
}
end
def create_require_script(load_filename, save_filename)
new_script = []
original_script = load_data(load_filename)
for i in 0...original_script.size
script = original_script[i].dup
content = Zlib::Inflate.inflate(script[2]).force_encoding("UTF-8")
if content =~ /# filename (.*)\r\n/
content = "require \"#{$1}\""
end
script[2] = Zlib::Deflate.deflate(content)
new_script.push(script)
end
obj = Marshal.dump(new_script)
output = File.new(save_filename, "wb+")
output.write(obj)
output.close
end
def create_require_to_content(load_filename, save_filename, load_path)
new_script = []
original_script = load_data(load_filename)
for i in 0...original_script.size
script = original_script[i].dup
content = Zlib::Inflate.inflate(script[2]).force_encoding("UTF-8")
if content =~ /require \"(.*)\"/
s = File.read("#{load_path}/#{$1}")
content = s
end
script[2] = Zlib::Deflate.deflate(content)
new_script.push(script)
end
obj = Marshal.dump(new_script)
output = File.new(save_filename, "wb+")
output.write(obj)
output.close
end
# require version to compress version
create_require_to_content("Client/Data/Scripts.rxdata", "Client/Data/Scripts-extract.rxdata", "Client/Data/script")