fontist 1.8.3 → 1.8.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rspec.yml +6 -6
- data/fontist.gemspec +7 -10
- data/lib/fontist.rb +4 -0
- data/lib/fontist/cli.rb +11 -22
- data/lib/fontist/errors.rb +1 -0
- data/lib/fontist/font.rb +37 -42
- data/lib/fontist/font_installer.rb +37 -33
- data/lib/fontist/font_path.rb +29 -0
- data/lib/fontist/formula.rb +8 -4
- data/lib/fontist/import/recursive_extraction.rb +30 -110
- data/lib/fontist/index.rb +4 -65
- data/lib/fontist/indexes/base_index.rb +82 -0
- data/lib/fontist/indexes/filename_index.rb +19 -0
- data/lib/fontist/indexes/font_index.rb +21 -0
- data/lib/fontist/indexes/index_formula.rb +36 -0
- data/lib/fontist/manifest/install.rb +3 -2
- data/lib/fontist/utils.rb +0 -4
- data/lib/fontist/utils/cache.rb +1 -1
- data/lib/fontist/utils/downloader.rb +7 -4
- data/lib/fontist/version.rb +1 -1
- metadata +21 -71
- data/lib/fontist/import/extractors.rb +0 -5
- data/lib/fontist/import/extractors/cab_extractor.rb +0 -37
- data/lib/fontist/import/extractors/extractor.rb +0 -19
- data/lib/fontist/import/extractors/ole_extractor.rb +0 -41
- data/lib/fontist/import/extractors/seven_zip_extractor.rb +0 -44
- data/lib/fontist/import/extractors/zip_extractor.rb +0 -31
- data/lib/fontist/index_formula.rb +0 -30
- data/lib/fontist/utils/exe_extractor.rb +0 -75
- data/lib/fontist/utils/msi_extractor.rb +0 -31
- data/lib/fontist/utils/seven_zip_extractor.rb +0 -41
- data/lib/fontist/utils/zip_extractor.rb +0 -52
@@ -1,31 +0,0 @@
|
|
1
|
-
require "zip"
|
2
|
-
|
3
|
-
module Fontist
|
4
|
-
module Import
|
5
|
-
module Extractors
|
6
|
-
class ZipExtractor < Extractor
|
7
|
-
def extract
|
8
|
-
dir = Dir.mktmpdir
|
9
|
-
extract_zip(@archive, dir)
|
10
|
-
dir
|
11
|
-
end
|
12
|
-
|
13
|
-
def format
|
14
|
-
"zip"
|
15
|
-
end
|
16
|
-
|
17
|
-
private
|
18
|
-
|
19
|
-
def extract_zip(archive, dir)
|
20
|
-
Zip::File.open(archive) do |zip_file|
|
21
|
-
zip_file.each do |entry|
|
22
|
-
path = File.join(dir, entry.name)
|
23
|
-
FileUtils.mkdir_p(File.dirname(path))
|
24
|
-
entry.extract(path)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
module Fontist
|
2
|
-
class IndexFormula
|
3
|
-
def initialize(path)
|
4
|
-
@path = path
|
5
|
-
end
|
6
|
-
|
7
|
-
def to_s
|
8
|
-
normalized
|
9
|
-
end
|
10
|
-
|
11
|
-
def to_full
|
12
|
-
Formula.new_from_file(full_path)
|
13
|
-
end
|
14
|
-
|
15
|
-
def ==(other)
|
16
|
-
to_s == other.to_s
|
17
|
-
end
|
18
|
-
|
19
|
-
private
|
20
|
-
|
21
|
-
def normalized
|
22
|
-
escaped = Regexp.escape(Fontist.formulas_path.to_s + "/")
|
23
|
-
@path.sub(Regexp.new("^" + escaped), "")
|
24
|
-
end
|
25
|
-
|
26
|
-
def full_path
|
27
|
-
Fontist.formulas_path.join(normalized).to_s
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
@@ -1,75 +0,0 @@
|
|
1
|
-
module Fontist
|
2
|
-
module Utils
|
3
|
-
module ExeExtractor
|
4
|
-
def cab_extract(exe_file, download: true, font_ext: /.ttf|.otf|.ttc/i)
|
5
|
-
download = @downloaded === true ? false : download
|
6
|
-
|
7
|
-
exe_file = download_file(exe_file).path if download
|
8
|
-
|
9
|
-
Fontist.ui.say(%(Installing font "#{formula.key}".))
|
10
|
-
cab_file = decompressor.search(exe_file)
|
11
|
-
cabbed_fonts = grep_fonts(cab_file.files) || []
|
12
|
-
fonts_paths = extract_cabbed_fonts_to_assets(cabbed_fonts)
|
13
|
-
|
14
|
-
block_given? ? yield(fonts_paths) : fonts_paths
|
15
|
-
end
|
16
|
-
|
17
|
-
def exe_extract(source, subarchive: nil)
|
18
|
-
cab_file = decompressor.search(download_file(source).path)
|
19
|
-
subarchive_path = extract_subarchive(cab_file.files, subarchive)
|
20
|
-
block_given? ? yield(subarchive_path) : subarchive_path
|
21
|
-
end
|
22
|
-
|
23
|
-
private
|
24
|
-
|
25
|
-
def decompressor
|
26
|
-
@decompressor ||= (
|
27
|
-
require "libmspack"
|
28
|
-
LibMsPack::CabDecompressor.new
|
29
|
-
)
|
30
|
-
end
|
31
|
-
|
32
|
-
def grep_fonts(file)
|
33
|
-
Array.new.tap do |fonts|
|
34
|
-
while file
|
35
|
-
fonts.push(file) if font_file?(file.filename)
|
36
|
-
file = file.next
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def extract_cabbed_fonts_to_assets(cabbed_fonts)
|
42
|
-
Array.new.tap do |fonts|
|
43
|
-
cabbed_fonts.each do |font|
|
44
|
-
target_filename = target_filename(font.filename)
|
45
|
-
font_path = fonts_path.join(target_filename).to_s
|
46
|
-
decompressor.extract(font, font_path)
|
47
|
-
|
48
|
-
fonts.push(font_path)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def extract_subarchive(file, subarchive = nil)
|
54
|
-
while file
|
55
|
-
filename = file.filename
|
56
|
-
|
57
|
-
if subarchive_found?(filename, subarchive)
|
58
|
-
file_path = File.join(Dir.mktmpdir, filename)
|
59
|
-
decompressor.extract(file, file_path)
|
60
|
-
|
61
|
-
return file_path
|
62
|
-
end
|
63
|
-
|
64
|
-
file = file.next
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
def subarchive_found?(filename, subarchive)
|
69
|
-
return subarchive == filename if subarchive
|
70
|
-
|
71
|
-
filename.include?("cab") || filename.include?("msi")
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
module Fontist
|
2
|
-
module Utils
|
3
|
-
module MsiExtractor
|
4
|
-
def msi_extract(resource)
|
5
|
-
file = @downloaded ? resource : download_file(resource)
|
6
|
-
|
7
|
-
cab_content = read_the_largest_file(file)
|
8
|
-
|
9
|
-
cab_file = Tempfile.new(["data", ".cab"], mode: File::BINARY)
|
10
|
-
cab_file.write(cab_content)
|
11
|
-
|
12
|
-
block_given? ? yield(cab_file.path) : cab_file.path
|
13
|
-
end
|
14
|
-
|
15
|
-
private
|
16
|
-
|
17
|
-
def read_the_largest_file(file)
|
18
|
-
ole = storage.open(file)
|
19
|
-
the_largest_file = ole.dir.entries(".").max_by { |x| ole.file.size(x) }
|
20
|
-
ole.file.read(the_largest_file)
|
21
|
-
end
|
22
|
-
|
23
|
-
def storage
|
24
|
-
@storage ||= begin
|
25
|
-
require "ole/storage"
|
26
|
-
Ole::Storage
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
module Fontist
|
2
|
-
module Utils
|
3
|
-
module SevenZipExtractor
|
4
|
-
def seven_zip_extract(resource, extension: /\.cab$/)
|
5
|
-
file = download_file(resource)
|
6
|
-
|
7
|
-
extract_seven_zip_file(file, extension)
|
8
|
-
end
|
9
|
-
|
10
|
-
private
|
11
|
-
|
12
|
-
def extract_seven_zip_file(file, extension)
|
13
|
-
File.open(file, "rb") do |zip_file|
|
14
|
-
reader.open(zip_file) do |szr|
|
15
|
-
path = extract_by_extension(szr, extension)
|
16
|
-
|
17
|
-
return block_given? ? yield(path) : path
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def reader
|
23
|
-
@reader ||= begin
|
24
|
-
require "seven_zip_ruby"
|
25
|
-
SevenZipRuby::Reader
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def extract_by_extension(szr, extension)
|
30
|
-
cab_entry = szr.entries.detect do |entry|
|
31
|
-
entry.file? && entry.path.match(extension)
|
32
|
-
end
|
33
|
-
|
34
|
-
tmp_dir = Dir.mktmpdir
|
35
|
-
szr.extract(cab_entry, tmp_dir)
|
36
|
-
filename = Pathname.new(cab_entry.path).basename
|
37
|
-
File.join(tmp_dir, filename)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
require "zip"
|
2
|
-
require "pathname"
|
3
|
-
|
4
|
-
module Fontist
|
5
|
-
module Utils
|
6
|
-
module ZipExtractor
|
7
|
-
def zip_extract(resource, download: true, fonts_sub_dir: nil)
|
8
|
-
zip_file = download_file(resource) if download
|
9
|
-
zip_file ||= resource.urls.first
|
10
|
-
|
11
|
-
Fontist.ui.say(%(Installing font "#{formula.key}".))
|
12
|
-
fonts_paths = unzip_fonts(zip_file, fonts_sub_dir)
|
13
|
-
block_given? ? yield(fonts_paths) : fonts_paths
|
14
|
-
end
|
15
|
-
|
16
|
-
alias_method :unzip, :zip_extract
|
17
|
-
|
18
|
-
private
|
19
|
-
|
20
|
-
# rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
21
|
-
def unzip_fonts(file, subdir)
|
22
|
-
Zip.on_exists_proc = true
|
23
|
-
|
24
|
-
Array.new.tap do |fonts|
|
25
|
-
Zip::File.open(file) do |zip_file|
|
26
|
-
zip_file.each do |entry|
|
27
|
-
if entry.name
|
28
|
-
filename = Pathname.new(entry.name).basename.to_s
|
29
|
-
if font_directory?(entry.name, subdir) && font_file?(filename)
|
30
|
-
target_filename = target_filename(filename)
|
31
|
-
font_path = fonts_path.join(target_filename)
|
32
|
-
fonts.push(font_path.to_s)
|
33
|
-
|
34
|
-
entry.extract(font_path)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
# rubocop:enable Metrics/MethodLength, Metrics/AbcSize
|
42
|
-
|
43
|
-
def font_directory?(path, subdir)
|
44
|
-
return true unless subdir
|
45
|
-
|
46
|
-
dirname = File.dirname(path)
|
47
|
-
normalized_pattern = subdir.chomp("/")
|
48
|
-
File.fnmatch?(normalized_pattern, dirname)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|