Class: Mmi::Modloader::Fabric
- Inherits:
-
Object
- Object
- Mmi::Modloader::Fabric
- Defined in:
- lib/mmi/modloader/fabric.rb
Instance Attribute Summary collapse
-
#install_dir ⇒ Object
readonly
Returns the value of attribute install_dir.
-
#install_type ⇒ Object
readonly
Returns the value of attribute install_type.
-
#mcversion ⇒ Object
readonly
Returns the value of attribute mcversion.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #absolute_install_dir ⇒ Object
- #download_installer ⇒ Object
-
#initialize(options) ⇒ Fabric
constructor
A new instance of Fabric.
- #install ⇒ Object
- #installer_path ⇒ Object
- #installer_sha512sum_uri ⇒ Object
- #installer_uri ⇒ Object
- #run_installer ⇒ Object
Constructor Details
#initialize(options) ⇒ Fabric
Returns a new instance of Fabric.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/mmi/modloader/fabric.rb', line 11 def initialize() @options = @version = ['version' ] @install_type = ['install_type' ] @mcversion = ['minecraft_version'] @install_dir = ['install_dir' ] || Mmi.minecraft_dir if self.version if self.install_type if ['client', 'server'].include?(self.install_type) if self.mcversion # Pass. else raise Mmi::MissingAttributeError, 'Missing "modloader.minecraft_version".' end else raise Mmi::InvalidAttributeError, %Q{Invalid "modloader.install_type". Expecting "client" or "server", got #{self.install_type.inspect}.} end else raise Mmi::MissingAttributeError, 'Missing "modloader.install_type".' end else raise Mmi::MissingAttributeError, 'Missing "modloader.version".' end end |
Instance Attribute Details
#install_dir ⇒ Object (readonly)
Returns the value of attribute install_dir.
9 10 11 |
# File 'lib/mmi/modloader/fabric.rb', line 9 def install_dir @install_dir end |
#install_type ⇒ Object (readonly)
Returns the value of attribute install_type.
7 8 9 |
# File 'lib/mmi/modloader/fabric.rb', line 7 def install_type @install_type end |
#mcversion ⇒ Object (readonly)
Returns the value of attribute mcversion.
8 9 10 |
# File 'lib/mmi/modloader/fabric.rb', line 8 def mcversion @mcversion end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/mmi/modloader/fabric.rb', line 4 def @options end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
6 7 8 |
# File 'lib/mmi/modloader/fabric.rb', line 6 def version @version end |
Instance Method Details
#absolute_install_dir ⇒ Object
50 51 52 |
# File 'lib/mmi/modloader/fabric.rb', line 50 def absolute_install_dir File.(self.install_dir) end |
#download_installer ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/mmi/modloader/fabric.rb', line 54 def download_installer Mmi.info "Downloading fabric-installer version #{self.version.inspect}." begin FileUtils.mkdir_p(Mmi.cache_dir) expected_hexdigest = URI.open(installer_sha512sum_uri).read if !File.exists?(installer_path) || expected_hexdigest != Digest::SHA512.hexdigest(File.read(installer_path)) stream = URI.open(installer_uri) IO.copy_stream(stream, installer_path) actual_hexdigest = Digest::SHA512.hexdigest(File.read(installer_path)) if expected_hexdigest == actual_hexdigest # Pass. else Mmi.fail! "Expected fabric installer to have SHA512 sum #{expected_hexdigest.inspect} but received #{actual_hexdigest.inspect}." end else Mmi.info 'Using cached fabric-installer.' end rescue OpenURI::HTTPError => e Mmi.fail! %Q{Error when requesting fabric installer. Maybe "modloader.version" == #{version.inspect} is invalid.\n#{e.inspect}} end end |
#install ⇒ Object
92 93 94 95 |
# File 'lib/mmi/modloader/fabric.rb', line 92 def install download_installer run_installer end |
#installer_path ⇒ Object
46 47 48 |
# File 'lib/mmi/modloader/fabric.rb', line 46 def installer_path File.join(Mmi.cache_dir, "fabric-installer-#{self.version}.jar") end |
#installer_sha512sum_uri ⇒ Object
42 43 44 |
# File 'lib/mmi/modloader/fabric.rb', line 42 def installer_sha512sum_uri "#{installer_uri}.sha512" end |
#installer_uri ⇒ Object
38 39 40 |
# File 'lib/mmi/modloader/fabric.rb', line 38 def installer_uri "https://maven.fabricmc.net/net/fabricmc/fabric-installer/#{self.version}/fabric-installer-#{self.version}.jar" end |
#run_installer ⇒ Object
82 83 84 85 86 87 88 89 90 |
# File 'lib/mmi/modloader/fabric.rb', line 82 def run_installer FileUtils.mkdir_p(absolute_install_dir) if system('java', '-jar', installer_path, 'client', '-dir', absolute_install_dir, '-noprofile', '-mcversion', self.mcversion) # Pass. else Mmi.fail! 'Failed to install Fabric modloader.' end end |