Module: LP::Exporter
- Defined in:
- lib/lp/exporter.rb,
lib/lp/exporter/app.rb,
lib/lp/exporter/version.rb
Overview
Exporter module
Defined Under Namespace
Modules: App
Constant Summary collapse
- VERSION =
Version
'0.0.2'
Class Method Summary collapse
-
.export(path, entry, lang = false) ⇒ Object
Export strings from file to YAML.
-
.extract(cab, files, dir) ⇒ Hash
Extract cab.
-
.process(cab, files, tmpdir, path, lang) ⇒ Object
Start extracting cab.
Class Method Details
.export(path, entry, lang = false) ⇒ Object
Export strings from file to YAML
75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/lp/exporter.rb', line 75 def self.export(path, entry, lang = false) filepath = File.join(path, entry.first)+'.yml' data = {} data = YAML.load_file(filepath) if File.exists?(filepath) langName = entry[1] File.open(entry.last, 'rb') do |file| PEdump.new(file).strings.each do |str| langName = str.lang unless lang data[langName] ||= {} data[langName][str.id] = str.value end end File.write(filepath, Hash[data.to_a.sort_by { |d| d.first } ].to_yaml) end |
.extract(cab, files, dir) ⇒ Hash
Extract cab
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 |
# File 'lib/lp/exporter.rb', line 33 def self.extract(cab, files, dir) decompressor = LibMsPack::CabDecompressor.new cab = decompressor.open(cab) file = cab.files fileList = {} begin path = Pathname.new(file.getFilename) next unless path.extname == '.mui' realname = path.basename('.*').to_s found = (files.count == 0) files.each do |str| if realname.match(str) found = true break end end next unless found nameparts = realname.split('.') base = nameparts.first namelen = nameparts.length namelen -= 1 if nameparts[-1] == 'dll' name = nameparts[0, namelen].join('.') data = path.dirname.to_s.split('_') arch = data[0] lang = data[-2] newName = [lang, arch, realname].join('_') location = File.join(dir, base, newName) fileList[base] ||= [] fileList[base] << [name, lang, arch, location] FileUtils.mkdir_p(File.join(dir, base)) decompressor.extract(file, location) end until (file = file.next).nil? decompressor.close(cab) decompressor.destroy fileList end |
.process(cab, files, tmpdir, path, lang) ⇒ Object
Start extracting cab
18 19 20 21 22 23 24 25 26 |
# File 'lib/lp/exporter.rb', line 18 def self.process(cab, files, tmpdir, path, lang) files = extract(cab, files, tmpdir) files.each do |base, entries| entries.each do |entry| export(path, entry, lang) end puts 'Exported ' + base end end |