Class: Mmi::Modloader::Fabric
Class Method Summary
collapse
Instance Method Summary
collapse
#[], #initialize, #parse!, #parsed_property_store, prepended, #to_h, #update_properties!, #validate_constraints!
Class Method Details
.allowed_install_types ⇒ Object
21
22
23
24
25
26
|
# File 'lib/mmi/modloader/fabric.rb', line 21
def self.allowed_install_types
%w[
client
server
]
end
|
.validate_download_minecraft(value, errors) ⇒ Object
34
35
36
37
38
|
# File 'lib/mmi/modloader/fabric.rb', line 34
def self.validate_download_minecraft(value, errors)
if ![true, false].include?(value)
errors << 'modloader "download_minecraft" must be true or false'
end
end
|
.validate_install_type(value, errors) ⇒ Object
28
29
30
31
32
|
# File 'lib/mmi/modloader/fabric.rb', line 28
def self.validate_install_type(value, errors)
if !allowed_install_types.include?(value)
errors << %Q{modloader "install_type" must be one of #{allowed_install_types.map(&:inspect).join(', ')}}
end
end
|
Instance Method Details
#absolute_install_dir ⇒ Object
68
69
70
|
# File 'lib/mmi/modloader/fabric.rb', line 68
def absolute_install_dir
File.expand_path(self.install_dir)
end
|
#available_versions ⇒ Object
103
104
105
106
107
108
109
110
111
112
113
114
115
|
# File 'lib/mmi/modloader/fabric.rb', line 103
def available_versions
begin
Mmi::InstallUtils.download_to_file(metadata_uri, metadata_path, Mmi::ContentHash::Sha512.new(URI.parse(metadata_sha512sum_uri).read))
rescue OpenURI::HTTPError => e
Mmi.fail! "Error when requesting available fabric installer versions.\n#{e.inspect}"
end
xml = File.open(metadata_path) do |f|
Nokogiri::XML(f)
end
xml.xpath('/metadata/versioning/versions/version').map(&:inner_html)
end
|
#base_uri ⇒ Object
40
41
42
|
# File 'lib/mmi/modloader/fabric.rb', line 40
def base_uri
'https://maven.fabricmc.net/net/fabricmc/fabric-installer'
end
|
#download_installer ⇒ Object
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/mmi/modloader/fabric.rb', line 72
def download_installer
installer_hash = Mmi::ContentHash::Sha512.new(URI.parse(installer_sha512sum_uri).read)
if !File.exist?(installer_path) || !installer_hash.match_file?(installer_path)
Mmi.info "Downloading fabric-installer version #{self.version.inspect}."
begin
Mmi::InstallUtils.download_to_file(installer_uri, installer_path, installer_hash)
rescue OpenURI::HTTPError => e
Mmi.fail! %Q{Error when requesting fabric installer. Maybe "modloader.version" == #{version.inspect} is invalid.\n#{e.inspect}}
end
else
Mmi.info "Using cached fabric-installer version #{self.version.inspect}."
end
end
|
#install ⇒ Object
98
99
100
101
|
# File 'lib/mmi/modloader/fabric.rb', line 98
def install
download_installer
run_installer
end
|
#installer_path ⇒ Object
64
65
66
|
# File 'lib/mmi/modloader/fabric.rb', line 64
def installer_path
File.join(Mmi::Constants.cache_dir, "fabric-installer-#{self.version}.jar")
end
|
#installer_sha512sum_uri ⇒ Object
60
61
62
|
# File 'lib/mmi/modloader/fabric.rb', line 60
def installer_sha512sum_uri
"#{installer_uri}.sha512"
end
|
#installer_uri ⇒ Object
56
57
58
|
# File 'lib/mmi/modloader/fabric.rb', line 56
def installer_uri
File.join(base_uri, self.version, "fabric-installer-#{self.version}.jar")
end
|
52
53
54
|
# File 'lib/mmi/modloader/fabric.rb', line 52
def metadata_path
File.join(Mmi::Constants.cache_dir, 'fabric_maven_metadata.xml')
end
|
48
49
50
|
# File 'lib/mmi/modloader/fabric.rb', line 48
def metadata_sha512sum_uri
"#{metadata_uri}.sha512"
end
|
44
45
46
|
# File 'lib/mmi/modloader/fabric.rb', line 44
def metadata_uri
File.join(base_uri, 'maven-metadata.xml')
end
|
#run_installer ⇒ Object
88
89
90
91
92
93
94
95
96
|
# File 'lib/mmi/modloader/fabric.rb', line 88
def run_installer
FileUtils.mkdir_p(absolute_install_dir)
if system('java', '-jar', installer_path, self.install_type, '-dir', absolute_install_dir, '-noprofile', '-mcversion', self.minecraft_version, self.download_minecraft ? '-downloadMinecraft' : '')
else
Mmi.fail! 'Failed to install Fabric modloader.'
end
end
|