module U3d::INIModulesParser
Load and parse INI files
Constants
- INI_NAME
@!group INI parameters to load and save ini files
Public Class Methods
create_linux_ini(version, size, url)
click to toggle source
# 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)
click to toggle source
# 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
Private Class Methods
default_ini_path()
click to toggle source
# File lib/u3d/ini_modules_parser.rb, line 105 def default_ini_path File.join(U3dCore::Helper.data_path, 'ini_files') end
download_ini(version, cached_versions, os, ini_name, ini_path)
click to toggle source
# File lib/u3d/ini_modules_parser.rb, line 76 def download_ini(version, cached_versions, os, ini_name, ini_path) # former urls for Linux pointed to unity-editor-installer.sh directlry if os == 'linux' && cached_versions[version] =~ /.*.sh$/ UI.verbose "No INI on server. Faking one by finding out package size for version #{version}" url = cached_versions[version] size = Utils.get_url_content_length(url) if size create_linux_ini(version, size, url) else UI.important "u3d tried to get the size of the installer for version #{version}, but wasn't able to" end return end uri = URI(cached_versions[version] + ini_name) UI.verbose("Searching for ini file at #{uri}") data = Net::HTTP.get(uri) data.tr!("\"", '') data.gsub!(/Note:.+\n/, '') write_ini_file(ini_path, data) end
write_ini_file(ini_path, data)
click to toggle source
# File lib/u3d/ini_modules_parser.rb, line 99 def write_ini_file(ini_path, data) File.open(ini_path, 'wb') do |f| f.write(data) end end