Class: FactorioMods::Install
- Inherits:
-
Object
- Object
- FactorioMods::Install
- Defined in:
- lib/factorio_mods/install.rb
Instance Attribute Summary collapse
-
#architecture ⇒ Object
readonly
Returns the value of attribute architecture.
-
#base_path ⇒ Object
readonly
Returns the value of attribute base_path.
-
#is_steam ⇒ Object
readonly
Returns the value of attribute is_steam.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
Instance Method Summary collapse
- #bin_path ⇒ Object
- #binary ⇒ Object
- #data_path ⇒ Object
-
#initialize(path) ⇒ Install
constructor
A new instance of Install.
- #mod_path(mod) ⇒ Object
- #mods_path ⇒ Object
- #read_path ⇒ Object
- #valid? ⇒ Boolean
- #write_path ⇒ Object
Constructor Details
#initialize(path) ⇒ Install
Returns a new instance of Install.
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/factorio_mods/install.rb', line 28 def initialize(path) @base_path = File. path return unless valid? info = JSON.parse(File.read(File.join(mod_path('base'), 'info.json')), symbolize_names: true) @version = info[:version] @is_steam = !(path.tr('\\', '/') =~ %r{/steamapps/common/}i).nil? @architecture = Dir.entries(File.join(base_path, 'bin')) .reject { |e| e.start_with? '.' } .first end |
Instance Attribute Details
#architecture ⇒ Object (readonly)
Returns the value of attribute architecture.
5 6 7 |
# File 'lib/factorio_mods/install.rb', line 5 def architecture @architecture end |
#base_path ⇒ Object (readonly)
Returns the value of attribute base_path.
5 6 7 |
# File 'lib/factorio_mods/install.rb', line 5 def base_path @base_path end |
#is_steam ⇒ Object (readonly)
Returns the value of attribute is_steam.
5 6 7 |
# File 'lib/factorio_mods/install.rb', line 5 def is_steam @is_steam end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
5 6 7 |
# File 'lib/factorio_mods/install.rb', line 5 def version @version end |
Class Method Details
.discover ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/factorio_mods/install.rb', line 7 def self.discover to_scan = if FactorioMods::OS.windows? [ 'C:\Program Files (x86)\Steam\steamapps\ccommon\Factorio', 'C:\Program Files\Factorio' ] elsif FactorioMods::OS.mac? [ '~/Library/Application Support/Steam/steamapps/common/Factorio/factorio.app/Contents', '/Applications/factorio.app/Contents' ] elsif FactorioMods::OS.linux? [ '~/.steam/steam/steamapps/common/Factorio', '~/.factorio' ] end to_scan.map { |path| Install.new path }.select(&:valid?) end |
Instance Method Details
#bin_path ⇒ Object
76 77 78 |
# File 'lib/factorio_mods/install.rb', line 76 def bin_path File.join base_path, 'bin', architecture end |
#binary ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/factorio_mods/install.rb', line 42 def binary if OS.windows? File.join bin_path, 'factorio.exe' else File.join bin_path, 'factorio' end end |
#data_path ⇒ Object
80 81 82 |
# File 'lib/factorio_mods/install.rb', line 80 def data_path File.join base_path, 'data' end |
#mod_path(mod) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/factorio_mods/install.rb', line 88 def mod_path(mod) if %w[base core].include? mod.to_s File.join data_path, mod else matching = Dir.entries(mods_path).select { |entry| entry.start_with?(mod) } return nil unless matching.any? raise 'More than one mod matches' if matching.count > 1 File.join(mods_path, matching.first) end end |
#mods_path ⇒ Object
84 85 86 |
# File 'lib/factorio_mods/install.rb', line 84 def mods_path File.join read_path, 'mods' end |
#read_path ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/factorio_mods/install.rb', line 50 def read_path @read_path ||= begin if uses_system_paths config = IniFile.load(File.join(system_path, 'config', 'config.ini')) config['path']['read-data'] .gsub '__PATH__system-read-data__', system_path else base_path end end end |
#valid? ⇒ Boolean
100 101 102 103 |
# File 'lib/factorio_mods/install.rb', line 100 def valid? Dir.exist?(base_path) && File.exist?(File.join(mod_path('base'), 'info.json')) end |
#write_path ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/factorio_mods/install.rb', line 63 def write_path @write_path ||= begin if uses_system_paths config = IniFile.load(File.join(system_path, 'config', 'config.ini')) config['path']['write-data'] .gsub '__PATH__system-write-data__', system_path else base_path end end end |