lib/u3d/downloader.rb in u3d-1.0.13 vs lib/u3d/downloader.rb in u3d-1.0.14
- old
+ new
@@ -29,11 +29,11 @@
# Name of the directory for the package downloading
DOWNLOAD_DIRECTORY = 'Unity_Packages'.freeze
# 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
File.expand_path(ENV['U3D_DOWNLOAD_PATH'] || File.join(DOWNLOAD_PATH, DOWNLOAD_DIRECTORY))
end
@@ -80,10 +80,11 @@
end
private #-----------------------------------------------------------------
def setup_os(os)
+ # downloader = Downloader::StandardPackageDownloader.new
case os
when :linux
validator = LinuxValidator.new
downloader = Downloader::LinuxDownloader.new
when :mac
@@ -97,12 +98,11 @@
end
return validator, downloader
end
def get_package(downloader, validator, package, definition, files)
- path = downloader.destination_for(package, definition)
- url = downloader.url_for(package, definition)
+ path, url = downloader.destination_and_url_for(package, definition)
if File.file?(path)
UI.verbose "Installer file for #{package} seems to be present at #{path}"
if validator.validate(package, path, definition)
UI.message "#{package.capitalize} is already downloaded"
files << [package, path, definition[package]]
@@ -135,48 +135,46 @@
File.delete path
raise e
end
end
- class MacDownloader
+ class StandardPackageDownloader
+ # for backward compatibility
def destination_for(package, definition)
- dir = File.join(Downloader.download_directory, definition.version)
- Utils.ensure_dir(dir)
- file_name = UNITY_MODULE_FILE_REGEX.match(definition[package]['url'])[1]
-
- File.expand_path(file_name, dir)
+ destination_and_url_for(package, definition)[0]
end
- def url_for(package, definition)
- definition.url + definition[package]['url']
- end
- end
+ def destination_and_url_for(package, definition)
+ final_url = url_for(package, definition)
- class LinuxDownloader
- def destination_for(package, definition)
dir = File.join(Downloader.download_directory, definition.version)
Utils.ensure_dir(dir)
- file_name = UNITY_MODULE_FILE_REGEX.match(definition[package]['url'])[1]
+ file_name = UNITY_MODULE_FILE_REGEX.match(final_url)[1]
- File.expand_path(file_name, dir)
- end
+ destination = File.expand_path(file_name, dir)
- def url_for(_package, definition)
- definition.url
+ [destination, final_url]
end
- end
- class WindowsDownloader
- def destination_for(package, definition)
- dir = File.join(Downloader.download_directory, definition.version)
- Utils.ensure_dir(dir)
- file_name = UNITY_MODULE_FILE_REGEX.match(definition[package]['url'])[1]
-
- File.expand_path(file_name, dir)
- end
-
def url_for(package, definition)
- definition.url + definition[package]['url']
+ url = definition[package]['url']
+ if url
+ if url =~ /^http/
+ Utils.final_url(url)
+ else
+ definition.url + url
+ end
+ else
+ definition.url
+ end
end
+ end
+
+ # for backward compatibility
+ class MacDownloader < StandardPackageDownloader
+ end
+ class LinuxDownloader < StandardPackageDownloader
+ end
+ class WindowsDownloader < StandardPackageDownloader
end
end
end