Module: U3d::INIModulesParser

Defined in:
lib/u3d/ini_modules_parser.rb

Overview

Load and parse INI files

INI parameters to load and save ini files collapse

INI_NAME =
'unity-%<version>s-%<os>s.ini'.freeze

INI parameters to load and save ini files collapse

Class Method Details

.create_linux_ini(version, size, url) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/u3d/ini_modules_parser.rb', line 57

def create_linux_ini(version, size, url)
  ini_name = format(INI_NAME, version: version, os: 'linux')
  Utils.ensure_dir(default_ini_path)
  ini_path = File.expand_path(ini_name, default_ini_path)
  return if File.file?(ini_path) && File.size(ini_path) > 0
  data = %([Unity]
; -- NOTE --
; This is not an official Unity file
; This has been created by u3d
; ----------
title=Unity
size=#{size}
url=#{url}
)
  write_ini_file(ini_path, data)
end

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



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/u3d/ini_modules_parser.rb', line 36

def load_ini(version, cached_versions, os: U3dCore::Helper.operating_system, offline: false)
  os = if os == :mac
         'osx'
       else
         os.id2name
       end
  ini_name = format(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) && File.size(ini_path) > 0
    raise "INI file does not exist at #{ini_path}" if offline
    download_ini(version, cached_versions, os, ini_name, ini_path)
  end
  begin
    result = IniFile.load(ini_path).to_h
  rescue StandardError => e
    raise "Could not parse INI data (#{e})"
  end
  result
end