class FactorioMods::Install
Attributes
architecture[R]
base_path[R]
is_steam[R]
version[R]
Public Class Methods
discover()
click to toggle source
# File lib/factorio_mods/install.rb, line 7 def self.discover to_scan = if FactorioMods::OS.windows? [ 'C:\Program Files (x86)\Steam\steamapps\common\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
new(path)
click to toggle source
# File lib/factorio_mods/install.rb, line 28 def initialize(path) @base_path = File.expand_path 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
Public Instance Methods
bin_path()
click to toggle source
# File lib/factorio_mods/install.rb, line 76 def bin_path File.join base_path, 'bin', architecture end
binary()
click to toggle source
# 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()
click to toggle source
# File lib/factorio_mods/install.rb, line 80 def data_path File.join base_path, 'data' end
mod_path(mod)
click to toggle source
# 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()
click to toggle source
# File lib/factorio_mods/install.rb, line 84 def mods_path File.join read_path, 'mods' end
read_path()
click to toggle source
# 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?()
click to toggle source
# 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()
click to toggle source
# 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
Protected Instance Methods
system_path()
click to toggle source
# File lib/factorio_mods/install.rb, line 107 def system_path File.expand_path(if FactorioMods::OS.windows? File.join '%appdata%', 'Factorio' elsif FactorioMods::OS.mac? File.join '~', 'Library', 'Application Support', 'factorio' elsif FactorioMods::OS.linux? File.join '~', '.factorio' end) end
uses_system_paths()
click to toggle source
# File lib/factorio_mods/install.rb, line 117 def uses_system_paths @uses_system_paths ||= begin config = IniFile.load File.join(base_path, 'config-path.cfg') config['global']['use-system-read-write-data-directories'] end end