Skip to content

Instantly share code, notes, and snippets.

@dogtopus
Last active December 16, 2015 10:28
Show Gist options
  • Save dogtopus/5420114 to your computer and use it in GitHub Desktop.
Save dogtopus/5420114 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'zlib'
require 'yaml'
def decode(fname,dir)
begin
Dir.mkdir(dir) if !File.exist?(dir) and !File.directory?(dir)
marshal=File.open(fname,'rb')
yaml=File.open(File.join(dir,'Scripts.yaml'),'wb')
obj=Marshal.load(marshal)
meta=Hash.new()
obj.each{|content|
begin
h2=File.open(File.join(dir,content[0].to_s+'.rb'),'wb')
h2.write(Zlib::Inflate.inflate(content[2]))
meta[content[0]]=content[1]
ensure
h2.close
end
}
yaml.write(YAML::dump(meta))
ensure
marshal.close
yaml.close
end
end
def encode(dir,fname)
begin
yaml=File.open(File.join(dir,'Scripts.yaml'),'rb')
marshal=File.open(fname,'wb')
meta=YAML::load(yaml)
obj=[]
meta.each{|id,sname|
begin
element=[id,sname]
h2=File.open(File.join(dir,id.to_s+'.rb'),'rb')
element.push(Zlib::Deflate.deflate(h2.read()))
obj.push(element)
ensure
h2.close
end
}
marshal.write(Marshal.dump(obj))
ensure
yaml.close
marshal.close
end
end
print "Usage: scrextract [-e] [-d] <in> <out>\n" if ARGV.length!=3
decode(ARGV[1],ARGV[2]) if ARGV[0]=='-d'
encode(ARGV[1],ARGV[2]) if ARGV[0]=='-e'
exit
#!/usr/bin/env ruby
require 'zlib'
handler=File.open('./Scripts.rxdata','rb')
obj=Marshal.load(handler)
obj.each_with_index{|content,i|
h2=File.open('./Scripts/'+content[1]+'.rb','wb')
h2.write(Zlib::Inflate.inflate(content[2]))
h2.close
}
handler.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment