Module: U3d::INIparser

Defined in:
lib/u3d/iniparser.rb

Overview

Load and parse INI files

INI parameters to load and save ini files collapse

INI_NAME =
'unity-%{version}-%{os}.ini'.freeze
INI_LINUX_PATH =
File.join(ENV['HOME'], '.u3d', 'ini_files').freeze
INI_MAC_PATH =
File.join(ENV['HOME'], 'Library', 'Application Support', 'u3d', 'ini_files').freeze
INI_WIN_PATH =
File.join(ENV['HOME'], 'AppData', 'Local', 'u3d', 'ini_files').freeze

INI parameters to load and save ini files collapse

Class Method Details

.load_ini(version, cached_versions, os: U3dCore::Helper.operating_system, offline: false) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/u3d/iniparser.rb', line 39

def load_ini(version, cached_versions, os: U3dCore::Helper.operating_system, offline: false)
  unless os == :win || os == :mac
    raise ArgumentError, "OS #{os.id2name} does not use ini files"
  end
  os = if os == :mac
         'osx'
       else
         os.id2name
       end
  ini_name = INI_NAME % { version: version, os: os }
  Utils.ensure_dir(default_ini_path)
  ini_path = File.expand_path(ini_name, default_ini_path)
  unless File.file?(ini_path)
    raise "INI file does not exist at #{ini_path}" if offline
    uri = URI(cached_versions[version] + ini_name)
    File.open(ini_path, 'wb') do |f|
      data = Net::HTTP.get(uri)
      data.tr!("\"", '')
      data.gsub!(/Note:.+\n/, '')
      f.write(data)
    end
  end
  begin
    result = IniFile.load(ini_path).to_h
  rescue => e
    raise "Could not parse INI data (#{e})"
  end
  result
end