Class: U3d::WindowsInstaller

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

Overview

rubocop:enable ClassLength

Instance Method Summary collapse

Methods inherited from BaseInstaller

#installed_sorted_by_versions, #sanitize_installs

Instance Method Details

#install(file_path, version, installation_path: nil, info: {}) ⇒ Object



369
370
371
372
373
374
375
376
377
378
# File 'lib/u3d/installer.rb', line 369

def install(file_path, version, installation_path: nil, info: {})
  extension = File.extname(file_path)
  raise "Installation of #{extension} files is not supported on Windows" unless %w[.exe .msi].include? extension
  path = installation_path || File.join(DEFAULT_WINDOWS_INSTALL, format(UNITY_DIR, version: version))
  install_exe(
    file_path,
    installation_path: path,
    info: info
  )
end

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



380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
# File 'lib/u3d/installer.rb', line 380

def install_exe(file_path, installation_path: nil, info: {})
  installation_path ||= DEFAULT_WINDOWS_INSTALL
  final_path = U3dCore::Helper.windows_path(installation_path)
  Utils.ensure_dir(final_path)
  begin
    command = nil
    if info['cmd']
      command = info['cmd']
      if /msiexec/ =~ command
        command.sub!(/{FILENAME}/, '"' + U3dCore::Helper.windows_path(file_path) + '"')
      else
        command.sub!(/{FILENAME}/, file_path.argescape)
      end
      command.sub!(/{INSTDIR}/, final_path)
      command.sub!(/{DOCDIR}/, final_path)
      command.sub!(/{MODULEDIR}/, final_path)
      command.sub!(%r{\/D=}, '/S /D=') unless %r{\/S} =~ command
    end
    command ||= file_path.argescape
    U3dCore::CommandExecutor.execute(command: command, admin: true)
  rescue StandardError => e
    UI.error "Failed to install package at #{file_path}: #{e}"
  else
    UI.success "Successfully installed #{info['title']}"
  end
end

#installedObject



364
365
366
367
# File 'lib/u3d/installer.rb', line 364

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

#sanitize_install(unity, long: false, dry_run: false) ⇒ Object



353
354
355
356
357
358
359
360
361
362
# File 'lib/u3d/installer.rb', line 353

def sanitize_install(unity, long: false, dry_run: false)
  source_path = File.expand_path(unity.root_path)
  parent = File.expand_path('..', source_path)
  dir_name = format(long ? UNITY_DIR_LONG : UNITY_DIR,
                    version: unity.version, build_number: unity.build_number)
  new_path = File.join(parent, dir_name)

  moved = U3dCore::AdminTools.move_os_file(:win, source_path, new_path, dry_run: dry_run)
  unity.root_path = new_path if moved && !dry_run
end

#uninstall(unity: nil) ⇒ Object



407
408
409
410
411
412
413
414
415
416
417
# File 'lib/u3d/installer.rb', line 407

def uninstall(unity: nil)
  UI.verbose("Uninstalling Unity at '#{unity.root_path}'...")
  uninstall_exe = File.join(unity.root_path, 'Editor', 'Uninstall.exe')
  command = "#{uninstall_exe.argescape} /S"
  UI.message("Although the uninstall process completed, it takes a few seconds before the files are actually removed")
  U3dCore::CommandExecutor.execute(command: command, admin: true)
rescue StandardError => e
  UI.error "Failed to uninstall unity at #{unity.path}: #{e}"
else
  UI.success "Successfully uninstalled '#{unity.root_path}'"
end