lib/u3d/downloader.rb in u3d-1.2.3 vs lib/u3d/downloader.rb in u3d-1.3.0
- old
+ new
@@ -1,5 +1,7 @@
+# frozen_string_literal: true
+
## --- BEGIN LICENSE BLOCK ---
# Copyright (c) 2016-present WeWantToKnow AS
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
@@ -25,17 +27,17 @@
module U3d
# Take care of downloading files and packages
module Downloader
# Name of the directory for the package downloading
- DOWNLOAD_DIRECTORY = 'Unity_Packages'.freeze
+ DOWNLOAD_DIRECTORY = 'Unity_Packages'
# Path to the directory for the package downloading
- DOWNLOAD_PATH = "#{ENV['HOME']}/Downloads".freeze
+ DOWNLOAD_PATH = "#{ENV['HOME']}/Downloads"
# Regex to get the name of a localization asset
- UNITY_LANGUAGE_FILE_REGEX = %r{\/\d+/[0-9\.]+\/([\w-]+)$}
+ UNITY_LANGUAGE_FILE_REGEX = %r{/\d+/[0-9.]+/([\w-]+)$}.freeze
# Regex to get the name of a package out of its file name
- UNITY_MODULE_FILE_REGEX = %r{\/([\w\-_\.\+]+\.(?:pkg|dmg|exe|zip|sh|deb|msi|xz))[^\/]*$}
+ UNITY_MODULE_FILE_REGEX = %r{/([\w\-_.+]+\.(?:pkg|dmg|exe|zip|sh|deb|msi|xz))[^/]*$}.freeze
class << self
def download_directory
File.expand_path(ENV['U3D_DOWNLOAD_PATH'] || File.join(DOWNLOAD_PATH, DOWNLOAD_DIRECTORY))
end
@@ -110,19 +112,19 @@
UI.message "#{package_info.name} is already downloaded"
files << [package, path, package_info]
return
else
extension = File.extname(path)
- new_path = File.join(File.dirname(path), File.basename(path, extension) + '_CORRUPTED' + extension)
+ new_path = File.join(File.dirname(path), "#{File.basename(path, extension)}_CORRUPTED#{extension}")
UI.important "File present at #{path} is not correct, it has been renamed to #{new_path}"
File.rename(path, new_path)
end
end
UI.header "Downloading #{package_info.name} version #{definition.version}"
- UI.message 'Downloading from ' + url.to_s.cyan.underline
- UI.message 'Download will be found at ' + path
+ UI.message "Downloading from #{url.to_s.cyan.underline}"
+ UI.message "Download will be found at #{path}"
download_package(path, url, size: package_info.download_size)
if validator.validate(package, path, definition)
UI.success "Successfully downloaded #{package}."
files << [package, path, package_info]
@@ -151,11 +153,11 @@
dir = File.join(Downloader.download_directory, definition.version)
Utils.ensure_dir(dir)
file_name = if (language_match = UNITY_LANGUAGE_FILE_REGEX.match(final_url))
- language_match[1] + '.po' # Unity uses PO (Portable object files) for localization
+ "#{language_match[1]}.po" # Unity uses PO (Portable object files) for localization
elsif (module_match = UNITY_MODULE_FILE_REGEX.match(final_url))
module_match[1]
else
raise "Unable to download file at #{final_url}. Please report it to the u3d issues on Github: https://github.com/DragonBox/u3d/issues/new"
end
@@ -180,11 +182,13 @@
end
# for backward compatibility
class MacDownloader < StandardPackageDownloader
end
+
class LinuxDownloader < StandardPackageDownloader
end
+
class WindowsDownloader < StandardPackageDownloader
end
end
end