Class: U3d::MacInstaller
- Inherits:
-
BaseInstaller
- Object
- BaseInstaller
- U3d::MacInstaller
- Defined in:
- lib/u3d/installer.rb
Instance Method Summary collapse
-
#install(file_path, version, installation_path: nil, info: {}) ⇒ Object
rubocop:disable UnusedMethodArgument.
- #install_pkg(file_path, version: nil, target_path: nil) ⇒ Object
- #installed ⇒ Object
- #sanitize_install(unity, long: false, dry_run: false) ⇒ Object
- #uninstall(unity: nil) ⇒ Object
Methods inherited from BaseInstaller
#installed_sorted_by_versions, #sanitize_installs
Instance Method Details
#install(file_path, version, installation_path: nil, info: {}) ⇒ Object
rubocop:disable UnusedMethodArgument
123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/u3d/installer.rb', line 123 def install(file_path, version, installation_path: nil, info: {}) # rubocop:enable UnusedMethodArgument 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 |
#install_pkg(file_path, version: nil, target_path: nil) ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/u3d/installer.rb', line 135 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 = installed.find { |u| u.version == version } temp_path = File.join(target_path, 'Applications', 'Unity') if unity.nil? UI.verbose "No Unity install for version #{version} was found" U3dCore::CommandExecutor.execute(command: command, admin: true) destination_path = File.join(target_path, 'Applications', format(UNITY_DIR, version: version)) FileUtils.mv temp_path, destination_path else UI.verbose "Unity install for version #{version} found under #{unity.root_path}" begin path = unity.root_path move_to_temp = (temp_path != path) if move_to_temp UI.verbose "Temporary switching location of #{path} to #{temp_path} for installation purpose" FileUtils.mv path, temp_path end U3dCore::CommandExecutor.execute(command: command, admin: true) ensure FileUtils.mv temp_path, path if move_to_temp end end rescue StandardError => e UI.error "Failed to install pkg at #{file_path}: #{e}" else UI.success "Successfully installed package from #{file_path}" end |
#installed ⇒ Object
117 118 119 120 |
# File 'lib/u3d/installer.rb', line 117 def installed paths = (list_installed_paths + spotlight_installed_paths).uniq paths.map { |path| MacInstallation.new(root_path: path) } end |
#sanitize_install(unity, long: false, dry_run: false) ⇒ Object
106 107 108 109 110 111 112 113 114 115 |
# File 'lib/u3d/installer.rb', line 106 def sanitize_install(unity, long: false, dry_run: false) source_path = unity.root_path parent = File.('..', 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(:mac, source_path, new_path, dry_run: dry_run) unity.root_path = new_path if moved && !dry_run end |
#uninstall(unity: nil) ⇒ Object
165 166 167 168 169 170 171 172 173 |
# File 'lib/u3d/installer.rb', line 165 def uninstall(unity: nil) UI.verbose("Uninstalling Unity at '#{unity.root_path}'...") command = "rm -r #{unity.root_path.argescape}" 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 |