Class: U3d::WindowsInstaller

Inherits:
Object
  • Object
show all
Defined in:
lib/u3d/installer.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.install_exe(file_path, installation_path: nil, info: {}) ⇒ Object



404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
# File 'lib/u3d/installer.rb', line 404

def self.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
    if info['cmd']
      command = info['cmd']
      command.sub!(/{FILENAME}/, file_path)
      command.sub!(/{INSTDIR}/, final_path)
      command.sub!(/{DOCDIR}/, final_path)
      command.sub!(/{MODULEDIR}/, final_path)
      command.sub!(/\/D=/, '/S /D=') unless /\/S/ =~ command
    end
    command ||= file_path.to_s
    U3dCore::CommandExecutor.execute(command: command, admin: true)
  rescue => e
    UI.error "Failed to install exe at #{file_path}: #{e}"
  else
    UI.success "Successfully installed #{info['title']}"
  end
end

Instance Method Details

#installedObject



396
397
398
399
400
401
402
# File 'lib/u3d/installer.rb', line 396

def installed
  find = File.join(DEFAULT_WINDOWS_INSTALL, 'Unity*', 'Editor', 'Uninstall.exe')
  versions = Dir[find].map { |path| WindowsInstallation.new(path: File.expand_path('../..', path)) }

  # sorting should take into account stable/patch etc
  versions.sort! { |x, y| x.version <=> y.version }
end

#sanitize_install(unity) ⇒ Object



380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
# File 'lib/u3d/installer.rb', line 380

def sanitize_install(unity)
  source_path = File.expand_path(unity.path)
  parent = File.expand_path('..', source_path)
  new_path = File.join(parent, UNITY_DIR % unity.version)
  UI.important "Moving #{source_path} to #{new_path}..."
  source_path.tr!('/', '\\')
  new_path.tr!('/', '\\')
  source_path = "\"" + source_path + "\"" if source_path =~ / /
  new_path = "\"" + new_path + "\"" if new_path =~ / /
  U3dCore::CommandExecutor.execute(command: "move #{source_path} #{new_path}", admin: true)
rescue => e
  UI.error "Unable to move #{source_path} to #{new_path}: #{e}"
else
  UI.success "Successfully moved #{source_path} to #{new_path}"
end