lib/u3d/installer.rb in u3d-1.0.12 vs lib/u3d/installer.rb in u3d-1.0.13

- old
+ new

@@ -29,12 +29,12 @@ module U3d DEFAULT_LINUX_INSTALL = '/opt/'.freeze DEFAULT_MAC_INSTALL = '/'.freeze DEFAULT_WINDOWS_INSTALL = 'C:/Program Files/'.freeze - UNITY_DIR = "Unity_%s".freeze - UNITY_DIR_LINUX = "unity-editor-%s".freeze + UNITY_DIR = "Unity_%<version>s".freeze + UNITY_DIR_LINUX = "unity-editor-%<version>s".freeze class Installer def self.create installer = if Helper.mac? MacInstaller.new @@ -86,20 +86,20 @@ else UI.important "Moving '#{source_path}' to '#{new_path}'..." U3dCore::CommandExecutor.execute(command: command, admin: true) UI.success "Successfully moved '#{source_path}' to '#{new_path}'" end - rescue => e + rescue StandardError => e UI.error "Unable to move '#{source_path}' to '#{new_path}': #{e}" end end class MacInstaller def sanitize_install(unity, dry_run: false) source_path = unity.root_path parent = File.expand_path('..', source_path) - new_path = File.join(parent, UNITY_DIR % unity.version) + new_path = File.join(parent, format(UNITY_DIR, version: unity.version)) command = "mv #{source_path.shellescape} #{new_path.shellescape}" CommonInstaller.sanitize_install(source_path, new_path, command, dry_run: dry_run) end @@ -128,11 +128,11 @@ 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', UNITY_DIR % version) + 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 @@ -144,21 +144,21 @@ U3dCore::CommandExecutor.execute(command: command, admin: true) ensure FileUtils.mv temp_path, path if move_to_temp end end - rescue => e + rescue StandardError => e UI.error "Failed to install pkg at #{file_path}: #{e}" else UI.success "Successfully installed package from #{file_path}" end 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 => e + rescue StandardError => e UI.error "Failed to uninstall unity at #{unity.path}: #{e}" else UI.success "Successfully uninstalled '#{unity.root_path}'" end @@ -193,11 +193,11 @@ class LinuxInstaller def sanitize_install(unity, dry_run: false) source_path = File.expand_path(unity.root_path) parent = File.expand_path('..', source_path) - new_path = File.join(parent, UNITY_DIR_LINUX % unity.version) + new_path = File.join(parent, format(UNITY_DIR_LINUX, version: unity.version)) command = "mv #{source_path.shellescape} #{new_path.shellescape}" CommonInstaller.sanitize_install(source_path, new_path, command, dry_run: dry_run) end @@ -231,28 +231,26 @@ U3dCore::CommandExecutor.execute(command: "chmod a+x #{cmd}") if installation_path command = "cd #{installation_path.shellescape}; #{cmd}" - unless File.directory? installation_path - command = "mkdir -p #{installation_path.shellescape}; #{command}" - end + command = "mkdir -p #{installation_path.shellescape}; #{command}" unless File.directory? installation_path U3dCore::CommandExecutor.execute(command: command, admin: true) else U3dCore::CommandExecutor.execute(command: cmd, admin: true) end - rescue => e + rescue StandardError => e UI.error "Failed to install bash file at #{file}: #{e}" else UI.success 'Installation successful' end def uninstall(unity: nil) UI.verbose("Uninstalling Unity at '#{unity.root_path}'...") command = "rm -r #{unity.root_path}" U3dCore::CommandExecutor.execute(command: command, admin: true) - rescue => e + rescue StandardError => e UI.error "Failed to uninstall unity at #{unity.path}: #{e}" else UI.success "Successfully uninstalled '#{unity.root_path}'" end @@ -277,11 +275,11 @@ class WindowsInstaller def sanitize_install(unity, dry_run: false) source_path = File.expand_path(unity.root_path) parent = File.expand_path('..', source_path) - new_path = File.join(parent, UNITY_DIR % unity.version) + new_path = File.join(parent, format(UNITY_DIR, version: unity.version)) source_path.tr!('/', '\\') new_path.tr!('/', '\\') command = "move #{source_path.argescape} #{new_path.argescape}" @@ -295,11 +293,11 @@ end def install(file_path, version, installation_path: nil, info: {}) extension = File.extname(file_path) raise "Installation of #{extension} files is not supported on Windows" if extension != '.exe' - path = installation_path || File.join(DEFAULT_WINDOWS_INSTALL, UNITY_DIR % version) + path = installation_path || File.join(DEFAULT_WINDOWS_INSTALL, format(UNITY_DIR, version: version)) install_exe( file_path, installation_path: path, info: info ) @@ -319,11 +317,11 @@ command.sub!(/{MODULEDIR}/, final_path) command.sub!(%r{\/D=}, '/S /D=') unless %r{\/S} =~ command end command ||= file_path.to_s U3dCore::CommandExecutor.execute(command: command, admin: true) - rescue => e + rescue StandardError => e UI.error "Failed to install exe at #{file_path}: #{e}" else UI.success "Successfully installed #{info['title']}" end end @@ -332,10 +330,10 @@ 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 => e + rescue StandardError => e UI.error "Failed to uninstall unity at #{unity.path}: #{e}" else UI.success "Successfully uninstalled '#{unity.root_path}'" end end