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: nil) ⇒ Object
- #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: nil) ⇒ Object
191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/u3d/installer.rb', line 191 def install(file_path, version, installation_path: nil, info: nil) # rubocop:enable UnusedMethodArgument extension = File.extname(file_path) raise "Installation of #{extension} files is not supported on Mac" unless %w[.zip .po .pkg].include? extension path = installation_path || DEFAULT_MAC_INSTALL if extension == '.po' install_po(file_path, version, info: info) elsif extension == '.zip' install_zip(file_path, version, info: info) else install_pkg(file_path, version: version, target_path: path) end end |
#install_pkg(file_path, version: nil, target_path: nil) ⇒ Object
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 |
# File 'lib/u3d/installer.rb', line 205 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
186 187 188 189 |
# File 'lib/u3d/installer.rb', line 186 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
175 176 177 178 179 180 181 182 183 184 |
# File 'lib/u3d/installer.rb', line 175 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
235 236 237 238 239 240 241 242 243 |
# File 'lib/u3d/installer.rb', line 235 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 |