Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

u3d/install: add support for installing .msi packages on Windows #230

Merged
merged 4 commits into from
Jan 15, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/u3d/downloader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module Downloader
# Path to the directory for the package downloading
DOWNLOAD_PATH = "#{ENV['HOME']}/Downloads".freeze
# Regex to get the name of a package out of its file name
UNITY_MODULE_FILE_REGEX = %r{\/([\w\-_\.\+]+\.(?:pkg|exe|zip|sh|deb))}
UNITY_MODULE_FILE_REGEX = %r{\/([\w\-_\.\+]+\.(?:pkg|exe|zip|sh|deb|msi))[^\/]*$}

class << self
def download_directory
Expand Down
10 changes: 7 additions & 3 deletions lib/u3d/installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ def installed

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'
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,
Expand All @@ -311,7 +311,11 @@ def install_exe(file_path, installation_path: nil, info: {})
command = nil
if info['cmd']
command = info['cmd']
command.sub!(/{FILENAME}/, file_path)
if /msiexec/ =~ command
command.sub!(/{FILENAME}/, '"' + file_path.gsub(%r{\/(\d)}, '/\\\\\1').tr('/', '\\') + '"')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

turn this into a private method?

windows_path(file_path) or something?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe put in utils?
This could be reusable

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as you wish. At least extract it from here to that we can understand what happens without decrypting the code :)

else
command.sub!(/{FILENAME}/, file_path)
end
command.sub!(/{INSTDIR}/, final_path)
command.sub!(/{DOCDIR}/, final_path)
command.sub!(/{MODULEDIR}/, final_path)
Expand All @@ -320,7 +324,7 @@ def install_exe(file_path, installation_path: nil, info: {})
command ||= file_path.to_s
U3dCore::CommandExecutor.execute(command: command, admin: true)
rescue StandardError => e
UI.error "Failed to install exe at #{file_path}: #{e}"
UI.error "Failed to install package at #{file_path}: #{e}"
else
UI.success "Successfully installed #{info['title']}"
end
Expand Down