Class: U3d::WindowsInstaller
Overview
rubocop:enable ClassLength
Instance Method Summary
collapse
#installed_sorted_by_versions, #sanitize_installs
Instance Method Details
#install(file_path, version, installation_path: nil, info: nil) ⇒ Object
465
466
467
468
469
470
471
472
473
474
475
476
|
# File 'lib/u3d/installer.rb', line 465
def install(file_path, version, installation_path: nil, info: nil)
extension = File.extname(file_path)
raise "Installation of #{extension} files is not supported on Windows" unless %w[.po .zip .exe .msi].include? extension
path = installation_path || File.join(DEFAULT_WINDOWS_INSTALL, format(UNITY_DIR, version: version))
if extension == '.po'
install_po(file_path, version, info: info)
elsif extension == '.zip'
install_zip(file_path, version, info: info)
else
install_exe(file_path, installation_path: path, info: info)
end
end
|
#install_exe(file_path, installation_path: nil, info: nil) ⇒ Object
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
|
# File 'lib/u3d/installer.rb', line 478
def install_exe(file_path, installation_path: nil, info: nil)
installation_path ||= DEFAULT_WINDOWS_INSTALL
final_path = U3dCore::Helper.windows_path(installation_path)
Utils.ensure_dir(final_path)
begin
command = nil
if info.command
command = info.command
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.name}"
end
end
|
#installed ⇒ Object
454
455
456
457
458
459
460
461
462
463
|
# File 'lib/u3d/installer.rb', line 454
def installed
find_installations_with_path(
default_root_path: DEFAULT_WINDOWS_INSTALL,
postfix: %w[
Unity*
Editor
Uninstall.exe
]
) { |path| WindowsInstallation.new(root_path: File.expand_path('../..', path)) }
end
|
#sanitize_install(unity, long: false, dry_run: false) ⇒ Object
443
444
445
446
447
448
449
450
451
452
|
# File 'lib/u3d/installer.rb', line 443
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
505
506
507
508
509
510
511
512
513
514
515
|
# File 'lib/u3d/installer.rb', line 505
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
|