LP-Exporter 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1737f9eeb02ced60385e6d7781e889fce85ecb99
4
+ data.tar.gz: 40df1c1894314932719c942f30017abc489c2eed
5
+ SHA512:
6
+ metadata.gz: af0eefe20a8d3983743ece744a6c030ea8c1208a8f7a2e55703c510813e6831cee9150a4ddb6c2862db97453df03153726a35b4b719ab299204efabe85278400
7
+ data.tar.gz: cd2c458af7b394d39336f274a4c52e33dc5088524364530ffa3dead7d9f680c55e2a36cf056723af0473b8266703897eae6d91154475f70761e39b1b4d3cd998
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/.yardopts ADDED
@@ -0,0 +1 @@
1
+ --markup markdown
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # encoding: UTF-8
2
+ source 'https://rubygems.org'
3
+
4
+ # Specify your gem's dependencies in LP-Exporter.gemspec
5
+ gemspec
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'lp/exporter/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'LP-Exporter'
8
+ spec.version = LP::Exporter::VERSION
9
+ spec.authors = ['Dāvis']
10
+ spec.email = ['davispuh@gmail.com']
11
+ spec.summary = 'Export langauge data from Microsoft language pack lp.cab files'
12
+ spec.description = 'Application to export langauge data from Microsoft language pack lp.cab files'
13
+ spec.homepage = 'https://github.com/davispuh/LP-Exporter'
14
+ spec.license = 'UNLICENSE'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_runtime_dependency 'libmspack'
22
+ spec.add_runtime_dependency 'pedump'
23
+ spec.add_development_dependency 'bundler'
24
+ spec.add_development_dependency 'rake'
25
+ spec.add_development_dependency 'rspec'
26
+ spec.add_development_dependency 'yard'
27
+ spec.add_development_dependency 'simplecov'
28
+ end
data/README.md ADDED
@@ -0,0 +1,63 @@
1
+ # LP-Exporter
2
+
3
+ Application to export language data from Microsoft language pack lp.cab files
4
+
5
+ ## Installation
6
+
7
+ `gem install lp-exporter`
8
+
9
+ ### Dependencies
10
+
11
+ gems:
12
+
13
+ * `libmspack` (required)
14
+
15
+ ## Usage
16
+
17
+ for command information use `-h` or `--help` flag
18
+
19
+ `lp_exporter -h`
20
+
21
+ ```
22
+ Usage: lp_exporter.rb [options] lp.cab|langpacks
23
+ -p, --path dir Path to output directory
24
+ -f, --files names Names for files to match
25
+ -l, --[no-]lang Use language name not LangID from PE
26
+ -h, --help Show this message
27
+ ```
28
+
29
+ * `-p, --path` Path to output directory, example `-p "./tmp"`
30
+ * `-f, --files` comma separated list with file names in cab, example `-f ntprint,pnpui`
31
+ * `-l, --[no-]lang` will use `en-us` for langauge name rather than `1033`
32
+
33
+ ## Code status
34
+
35
+ [![Dependency Status](https://gemnasium.com/davispuh/ruby-libmspack.png)](https://gemnasium.com/davispuh/ruby-libmspack)
36
+ [![Code Climate](https://codeclimate.com/github/davispuh/ruby-libmspack.png)](https://codeclimate.com/github/davispuh/ruby-libmspack)
37
+
38
+ ## Unlicense
39
+
40
+ ![Copyright-Free](http://unlicense.org/pd-icon.png)
41
+
42
+ All text, documentation, code and files in this repository are in public domain (including this text, README).
43
+ It means you can copy, modify, distribute and include in your own work/code, even for commercial purposes, all without asking permission.
44
+
45
+ [About Unlicense](http://unlicense.org/)
46
+
47
+ ## Contributing
48
+
49
+ Feel free to improve anything.
50
+
51
+ 1. Fork it
52
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
53
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
54
+ 4. Push to the branch (`git push origin my-new-feature`)
55
+ 5. Create new Pull Request
56
+
57
+
58
+ **Warning**: By sending pull request to this repository you dedicate any and all copyright interest in pull request (code files and all other) to the public domain. (files will be in public domain even if pull request doesn't get merged)
59
+
60
+ Also before sending pull request you acknowledge that you own all copyrights or have authorization to dedicate them to public domain.
61
+
62
+ If you don't want to dedicate code to public domain or if you're not allowed to (eg. you don't own required copyrights) then DON'T send pull request.
63
+
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ # encoding: UTF-8
2
+ require 'bundler/gem_tasks'
3
+ require 'rspec/core/rake_task'
4
+ require 'yard'
5
+
6
+
7
+ desc 'Default: run specs.'
8
+ task :default => :spec
9
+
10
+ desc 'Run specs'
11
+ RSpec::Core::RakeTask.new(:spec) do |t|
12
+ end
13
+
14
+ YARD::Rake::YardocTask.new(:doc) do |t|
15
+ end
data/UNLICENSE ADDED
@@ -0,0 +1,24 @@
1
+ This is free and unencumbered software released into the public domain.
2
+
3
+ Anyone is free to copy, modify, publish, use, compile, sell, or
4
+ distribute this software, either in source code form or as a compiled
5
+ binary, for any purpose, commercial or non-commercial, and by any
6
+ means.
7
+
8
+ In jurisdictions that recognize copyright laws, the author or authors
9
+ of this software dedicate any and all copyright interest in the
10
+ software to the public domain. We make this dedication for the benefit
11
+ of the public at large and to the detriment of our heirs and
12
+ successors. We intend this dedication to be an overt act of
13
+ relinquishment in perpetuity of all present and future rights to this
14
+ software under copyright law.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ For more information, please refer to <http://unlicense.org/>
data/bin/lp_exporter ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+ require 'lp/exporter/app'
4
+ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + '/../lib'))
5
+ LP::Exporter::App.start
@@ -0,0 +1,71 @@
1
+ # encoding: UTF-8
2
+ require 'optparse'
3
+ require 'tmpdir'
4
+ require 'lp/exporter'
5
+
6
+ module LP
7
+ module Exporter
8
+ # Application module
9
+ module App
10
+ # Parse passed options
11
+ # @return [Hash] options
12
+ def self.getOptions
13
+ options = {
14
+ :Parser => nil,
15
+ :LP => nil,
16
+ :Path => './tmp/',
17
+ :Files => [],
18
+ :Lang => false
19
+ }
20
+ options[:Parser] = OptionParser.new do |opts|
21
+ opts.banner = 'Usage: lp_exporter.rb [options] lp.cab|langpacks'
22
+ opts.on('-p', '--path dir', 'Path to output directory') do |path|
23
+ options[:Path] = path
24
+ end
25
+ opts.on('-f','--files names', Array, 'Names for files to match') do |files|
26
+ files.each do |file|
27
+ options[:Files] << file
28
+ end
29
+ end
30
+ opts.on('-l','--[no-]lang', 'Use language name not LangID from PE') do |lang|
31
+ options[:Lang] = lang
32
+ end
33
+
34
+ opts.on_tail('-h', '--help', 'Show this message') do
35
+ puts opts
36
+ return false
37
+ end
38
+ end
39
+ begin
40
+ options[:LP] = options[:Parser].parse!.first
41
+ rescue OptionParser::ParseError => e
42
+ $stderr.puts e.message
43
+ return false
44
+ end
45
+ options
46
+ end
47
+
48
+ # Start Application
49
+ def self.start
50
+ options = getOptions
51
+ if not options or options[:LP].nil?
52
+ puts options[:Parser].help
53
+ return false
54
+ end
55
+ Dir.mktmpdir do |tmpdir|
56
+ cabs = []
57
+ if File.directory?(options[:LP])
58
+ cabs += Dir[File.join(options[:LP],'**','*.cab')]
59
+ else
60
+ cabs << options[:LP]
61
+ end
62
+ cabs.each do |cab|
63
+ LP::Exporter.process(cab, options[:Files], tmpdir, options[:Path], options[:Lang])
64
+ puts 'Done for ' + cab
65
+ end
66
+ end
67
+ true
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,6 @@
1
+ module LP
2
+ module Exporter
3
+ # Version
4
+ VERSION = '0.0.1'
5
+ end
6
+ end
@@ -0,0 +1,90 @@
1
+ # encoding: UTF-8
2
+ require 'libmspack'
3
+ require 'pedump'
4
+ require 'fileutils'
5
+ require 'yaml'
6
+ require 'lp/exporter/version'
7
+
8
+ # Language Pack module
9
+ module LP
10
+ # Exporter module
11
+ module Exporter
12
+ # Start extracting cab
13
+ # @param [String] cab filename of cab
14
+ # @param [Array] files list of names for files to match from cab
15
+ # @param [String] tmpdir path to directory where keep extracted cab files
16
+ # @param [String] path path to output location
17
+ # @param [Boolean] lang if should use language name rather than LangID
18
+ def self.process(cab, files, tmpdir, path, lang)
19
+ files = extract(cab, files, tmpdir)
20
+ files.each do |base, entries|
21
+ entries.each do |entry|
22
+ export(path, entry, lang)
23
+ end
24
+ puts 'Exported ' + base
25
+ end
26
+ end
27
+
28
+ # Extract cab
29
+ # @param [String] cab filename of cab
30
+ # @param [Array] files list of names for files to match from cab
31
+ # @param [String] dir path to directory where keep extracted cab files
32
+ # @return [Hash] Info about extracted files
33
+ def self.extract(cab, files, dir)
34
+ decompressor = LibMsPack::CabDecompressor.new
35
+ cab = decompressor.open(cab)
36
+ file = cab.files
37
+ fileList = {}
38
+ begin
39
+ path = Pathname.new(file.getFilename)
40
+ next unless path.extname == '.mui'
41
+ realname = path.basename('.*').to_s
42
+ found = (files.count == 0)
43
+ files.each do |str|
44
+ if realname.match(str)
45
+ found = true
46
+ break
47
+ end
48
+ end
49
+ next unless found
50
+ nameparts = realname.split('.')
51
+ base = nameparts.first
52
+ namelen = nameparts.length
53
+ namelen -= 1 if nameparts[-1] == 'dll'
54
+ name = nameparts[0, namelen].join('.')
55
+ data = path.dirname.to_s.split('_')
56
+ arch = data[0]
57
+ lang = data[-2]
58
+ newName = [lang, arch, realname].join('_')
59
+
60
+ location = File.join(dir, base, newName)
61
+ fileList[base] ||= []
62
+ fileList[base] << [name, lang, arch, location]
63
+ FileUtils.mkdir_p(File.join(dir, base))
64
+ decompressor.extract(file, location)
65
+ end until (file = file.next).nil?
66
+ decompressor.close(cab)
67
+ decompressor.destroy
68
+ fileList
69
+ end
70
+
71
+ # Export strings from file to YAML
72
+ # @param [String] path path to output location
73
+ # @param [Array] entry info about file
74
+ # @param [Boolean] lang if should use language name rather than LangID
75
+ def self.export(path, entry, lang = false)
76
+ filepath = File.join(path, entry.first)+'.yml'
77
+ data = {}
78
+ data = YAML.load_file(filepath) if File.exists?(filepath)
79
+ langName = entry[1]
80
+ File.open(entry.last, 'rb') do |file|
81
+ PEdump.new(file).strings.each do |str|
82
+ langName = str.lang unless lang
83
+ data[langName] ||= {}
84
+ data[langName][str.id] = str.value
85
+ end
86
+ end
87
+ File.write(filepath, Hash[data.to_a.sort_by { |d| d.first } ].to_yaml)
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe LP::Exporter do
4
+
5
+ end
@@ -0,0 +1,5 @@
1
+ require 'simplecov'
2
+
3
+ SimpleCov.start
4
+
5
+ require_relative '../lib/lp/exporter.rb'
metadata ADDED
@@ -0,0 +1,161 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: LP-Exporter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Dāvis
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: libmspack
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pedump
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: yard
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Application to export langauge data from Microsoft language pack lp.cab
112
+ files
113
+ email:
114
+ - davispuh@gmail.com
115
+ executables:
116
+ - lp_exporter
117
+ extensions: []
118
+ extra_rdoc_files: []
119
+ files:
120
+ - ".gitignore"
121
+ - ".rspec"
122
+ - ".yardopts"
123
+ - Gemfile
124
+ - LP-Exporter.gemspec
125
+ - README.md
126
+ - Rakefile
127
+ - UNLICENSE
128
+ - bin/lp_exporter
129
+ - lib/lp/exporter.rb
130
+ - lib/lp/exporter/app.rb
131
+ - lib/lp/exporter/version.rb
132
+ - spec/lp-exporter_spec.rb
133
+ - spec/spec_helper.rb
134
+ homepage: https://github.com/davispuh/LP-Exporter
135
+ licenses:
136
+ - UNLICENSE
137
+ metadata: {}
138
+ post_install_message:
139
+ rdoc_options: []
140
+ require_paths:
141
+ - lib
142
+ required_ruby_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ required_rubygems_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ requirements: []
153
+ rubyforge_project:
154
+ rubygems_version: 2.2.1
155
+ signing_key:
156
+ specification_version: 4
157
+ summary: Export langauge data from Microsoft language pack lp.cab files
158
+ test_files:
159
+ - spec/lp-exporter_spec.rb
160
+ - spec/spec_helper.rb
161
+ has_rdoc: