Class: U3d::Downloader::WindowsDownloader
- Inherits:
-
Object
- Object
- U3d::Downloader::WindowsDownloader
- Defined in:
- lib/u3d/downloader.rb
Class Method Summary collapse
- .all_local_files(version) ⇒ Object
- .download_all(version, cached_versions) ⇒ Object
-
.download_specific(package, version, cached_versions) ⇒ Object
Downloads a specific package for given version.
- .local_file(package, version) ⇒ Object
Class Method Details
.all_local_files(version) ⇒ Object
284 285 286 287 288 289 290 291 292 |
# File 'lib/u3d/downloader.rb', line 284 def all_local_files(version) files = [] ini_file = INIparser.load_ini(version, {}, offline: true) ini_file.keys.each do |k| result = local_file(k, version) files << [k, result[0], result[1]] unless result.nil? end files end |
.download_all(version, cached_versions) ⇒ Object
251 252 253 254 255 256 257 258 259 260 261 262 263 |
# File 'lib/u3d/downloader.rb', line 251 def download_all(version, cached_versions) if cached_versions[version].nil? UI.error "No version #{version} was found in cache. It might need updating." return nil end files = [] ini_file = INIparser.load_ini(version, cached_versions) ini_file.keys.each do |k| result = download_specific(k, version, cached_versions) files << [k, result[0], result[1]] unless result.nil? end files end |
.download_specific(package, version, cached_versions) ⇒ Object
Downloads a specific package for given version
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
# File 'lib/u3d/downloader.rb', line 266 def download_specific(package, version, cached_versions) if cached_versions[version].nil? UI.error "No version #{version} was found in cache. It might need updating." return nil end ini_file = INIparser.load_ini(version, cached_versions) if ini_file[package].empty? UI.error "No package \"#{package}\" was found for version #{version}." return nil end url = cached_versions[version] dir = File.join(DOWNLOAD_PATH, DOWNLOAD_DIRECTORY, version) Utils.ensure_dir(dir) return [get_package(package, ini_file, dir, url), ini_file[package]] end |
.local_file(package, version) ⇒ Object
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 |
# File 'lib/u3d/downloader.rb', line 294 def local_file(package, version) ini_file = INIparser.load_ini(version, {}, offline: true) if ini_file[package].empty? UI.error "No package \"#{package}\" was found for version #{version}." return nil end dir = File.join(DOWNLOAD_PATH, DOWNLOAD_DIRECTORY, version) raise "Main directory #{dir} does not exist. Nothing has been downloaded for version #{version}" unless Dir.exist?(dir) file_name = UNITY_MODULE_FILE_REGEX.match(ini_file[package]['url'])[1] file_path = File.(file_name, dir) unless File.file?(file_path) UI.error "Package #{package} has not been downloaded" return nil end rounded_size = (File.size(file_path).to_f / 1024).floor unless Downloader.size_validation(expected: ini_file[package]['size'], actual: rounded_size) && Downloader.hash_validation(expected: ini_file[package]['md5'], actual: Utils.hashfile(file_path)) UI.error "File at #{file_path} is corrupted, deleting it" File.delete(file_path) return nil end return [file_path, ini_file[package]] end |