Class: Mmi::Modloader::Fabric

Inherits:
Object
  • Object
show all
Includes:
PropertyAttributes
Defined in:
lib/mmi/modloader/fabric.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from PropertyAttributes

#[], #initialize, #parse!, #parsed_property_store, prepended, #to_h, #update_properties!, #validate_constraints!

Class Method Details

.allowed_install_typesObject



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_dirObject



68
69
70
# File 'lib/mmi/modloader/fabric.rb', line 68

def absolute_install_dir
	File.expand_path(self.install_dir)
end

#available_versionsObject



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(, , Mmi::ContentHash::Sha512.new(URI.parse().read))
	rescue OpenURI::HTTPError => e
		Mmi.fail! "Error when requesting available fabric installer versions.\n#{e.inspect}"
	end
	
	xml = File.open() do |f|
		Nokogiri::XML(f)
	end
	
	xml.xpath('/metadata/versioning/versions/version').map(&:inner_html)
end

#base_uriObject



40
41
42
# File 'lib/mmi/modloader/fabric.rb', line 40

def base_uri
	'https://maven.fabricmc.net/net/fabricmc/fabric-installer'
end

#download_installerObject



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

#installObject



98
99
100
101
# File 'lib/mmi/modloader/fabric.rb', line 98

def install
	download_installer
	run_installer
end

#installer_pathObject



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_uriObject



60
61
62
# File 'lib/mmi/modloader/fabric.rb', line 60

def installer_sha512sum_uri
	"#{installer_uri}.sha512"
end

#installer_uriObject



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

#metadata_pathObject



52
53
54
# File 'lib/mmi/modloader/fabric.rb', line 52

def 
	File.join(Mmi::Constants.cache_dir, 'fabric_maven_metadata.xml')
end

#metadata_sha512sum_uriObject



48
49
50
# File 'lib/mmi/modloader/fabric.rb', line 48

def 
	"#{}.sha512"
end

#metadata_uriObject



44
45
46
# File 'lib/mmi/modloader/fabric.rb', line 44

def 
	File.join(base_uri, 'maven-metadata.xml')
end

#run_installerObject



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' : '')
		# Pass.
	else
		Mmi.fail! 'Failed to install Fabric modloader.'
	end
end