lib/u3d/installer.rb in u3d-0.9.1 vs lib/u3d/installer.rb in u3d-0.9.2

- old
+ new

@@ -157,81 +157,10 @@ raise "Unity installation does not seem correct. Couldn't locate PlaybackEngines." unless Dir.exist? fpath Dir.entries(fpath).select { |e| File.directory?(File.join(fpath, e)) && !(e == '.' || e == '..') } end end - class Runner - def run(installation, args, raw_logs: false) - require 'fileutils' - - log_file = find_logFile_in_args(args) - - if log_file # we wouldn't want to do that for the default log file. - File.delete(log_file) if File.exist?(log_file) - else - log_file = installation.default_log_file - end - - FileUtils.touch(log_file) - - tail_thread = Thread.new do - begin - if raw_logs - pipe(log_file) { |l| UI.message l.rstrip } - else - analyzer = LogAnalyzer.new - pipe(log_file) { |l| analyzer.parse_line l } - end - rescue => e - UI.error "Failure while trying to pipe #{log_file}: #{e.message}" - e.backtrace.each { |l| UI.error " #{l}" } - end - end - - begin - args.unshift(installation.exe_path) - if Helper.windows? - args.map! { |a| a =~ / / ? "\"#{a}\"" : a } - else - args.map!(&:shellescape) - end - U3dCore::CommandExecutor.execute(command: args) - ensure - sleep 0.5 - Thread.kill(tail_thread) - end - end - - def find_logFile_in_args(args) - find_arg_in_args('-logFile', args) - end - - def find_projectpath_in_args(args) - find_arg_in_args('-projectpath', args) - end - - def find_arg_in_args(arg_to_find, args) - raise 'Only arguments of type array supported right now' unless args.is_a?(Array) - args.each_with_index do |arg, index| - return args[index + 1] if arg == arg_to_find && index < args.count - 1 - end - nil - end - - private - - def pipe(file) - File.open(file, 'r') do |f| - f.extend File::Tail - f.interval = 0.1 - f.max_interval = 0.4 - f.backward 100 - f.tail { |l| yield l } - end - end - end - class Installer def self.create installer = if Helper.mac? MacInstaller.new elsif Helper.linux? @@ -247,34 +176,15 @@ end end installer end - def self.install_module(file_path, version, installation_path: nil, info: {}) - extension = File.extname(file_path) - if extension == '.pkg' - path = installation_path || DEFAULT_MAC_INSTALL - MacInstaller.install_pkg( - file_path, - version: version, - target_path: path - ) - elsif extension == '.exe' - path = installation_path || File.join(DEFAULT_WINDOWS_INSTALL, UNITY_DIR % version) - WindowsInstaller.install_exe( - file_path, - installation_path: path, - info: info - ) - elsif extension == '.sh' - path = installation_path || File.join(DEFAULT_LINUX_INSTALL, UNITY_DIR % version) - LinuxInstaller.install_sh( - file_path, - installation_path: path - ) - else - raise "File type #{extension} not yet supported" + def self.install_modules(files, version, installation_path: nil) + installer = Installer.create + files.each do |name, file, info| + UI.verbose "Installing #{name}#{info['mandatory'] ? ' (mandatory package)' : ''}, with file #{file}" + installer.install(file, version, installation_path: installation_path, info: info) end end end class MacInstaller @@ -308,14 +218,25 @@ # sorting should take into account stable/patch etc versions.sort! { |x, y| x.version <=> y.version } end - def self.install_pkg(file_path, version: nil, target_path: nil) + def install(file_path, version, installation_path: nil, info: {}) + extension = File.extname(file_path) + raise "Installation of #{extension} files is not supported on Mac" if extension != '.pkg' + path = installation_path || DEFAULT_MAC_INSTALL + install_pkg( + file_path, + version: version, + target_path: path + ) + end + + def install_pkg(file_path, version: nil, target_path: nil) target_path ||= DEFAULT_MAC_INSTALL command = "installer -pkg #{file_path.shellescape} -target #{target_path.shellescape}" - unity = Installer.create.installed.find { |u| u.version == version } + unity = installed.find { |u| u.version == version } if unity.nil? UI.verbose "No Unity install for version #{version} was found" U3dCore::CommandExecutor.execute(command: command, admin: true) else begin @@ -359,11 +280,21 @@ # sorting should take into account stable/patch etc versions.sort! { |x, y| x.version <=> y.version } end - def self.install_sh(file, installation_path: nil) + def install(file_path, version, installation_path: nil, info: {}) + extension = File.extname(file_path) + raise "Installation of #{extension} files is not supported on Linux" if extension != '.sh' + path = installation_path || File.join(DEFAULT_LINUX_INSTALL, UNITY_DIR % version) + install_sh( + file_path, + installation_path: path + ) + end + + def install_sh(file, installation_path: nil) cmd = file.shellescape if installation_path Utils.ensure_dir(installation_path) U3dCore::CommandExecutor.execute(command: "cd #{installation_path}; #{cmd}", admin: true) else @@ -399,10 +330,21 @@ # sorting should take into account stable/patch etc versions.sort! { |x, y| x.version <=> y.version } end - def self.install_exe(file_path, installation_path: nil, info: {}) + def install(file_path, version, installation_path: nil, info: {}) + extension = File.extname(file_path) + raise "Installation of #{extension} files is not supported on Windows" if extension != '.exe' + path = installation_path || File.join(DEFAULT_WINDOWS_INSTALL, UNITY_DIR % version) + install_exe( + file_path, + installation_path: path, + info: info + ) + end + + def install_exe(file_path, installation_path: nil, info: {}) installation_path ||= DEFAULT_WINDOWS_INSTALL final_path = installation_path.tr('/', '\\') Utils.ensure_dir(final_path) begin command = nil