Class: StarCitizen::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/starcitizen/config.rb

Overview

Configuration for starcitizen-tools.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**kwargs) ⇒ Config

Returns a new instance of Config.

Parameters:

  • kwargs (Hash)

    a customizable set of options

Options Hash (**kwargs):

  • :path (String)

    Config file path.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/starcitizen/config.rb', line 18

def initialize **kwargs
  @path = File.expand_path kwargs.fetch(:path, '~/starcitizen-tools.cfg.yaml')
  
  # Create config file.
  unless File.exists? @path
    begin
      require 'win32/registry'
      game_path = File.dirname Win32::Registry::HKEY_CURRENT_USER
        .open('Software\Cloud Imperium Games\StarCitizen')['UninstallString']
    rescue LoadError # Not Windows
      game_path = File.expand_path '~/.wine/drive_c/Program Files/StarCitizen'
    end
    
    File.open(@path, 'w') do |f|
      f.write({ 'game_path' => game_path }.to_yaml)
    end
  end
  
  @config = YAML.load_file @path
end

Instance Attribute Details

#pathObject (readonly)

Config file path.



15
16
17
# File 'lib/starcitizen/config.rb', line 15

def path
  @path
end

Class Method Details

.game_pathObject

Location of Star Citizen.



9
10
11
# File 'lib/starcitizen/config.rb', line 9

def self.game_path
  new.game_path
end

Instance Method Details

#game_pathObject

Location of Star Citizen.



40
41
42
# File 'lib/starcitizen/config.rb', line 40

def game_path
  @config['game_path'].gsub('\\', '/')
end