Class: U3d::Downloader::LinuxDownloader

Inherits:
Object
  • Object
show all
Defined in:
lib/u3d/downloader.rb

Class Method Summary collapse

Class Method Details

.download(version, cached_versions) ⇒ Object



212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# File 'lib/u3d/downloader.rb', line 212

def download(version, cached_versions)
  if cached_versions[version].nil?
    UI.error "No version #{version} was found in cache. It might need updating."
    return nil
  end
  url = cached_versions[version]
  dir = File.join(DOWNLOAD_PATH, DOWNLOAD_DIRECTORY, version)
  Utils.ensure_dir(dir)
  file_name = UNITY_MODULE_FILE_REGEX.match(url)[1]
  file_path = File.expand_path(file_name, dir)

  # Check if file already exists
  # Note: without size or hash validation, the file is assumed to be correct
  if File.file?(file_path)
    UI.important "File already downloaded at #{file_path}"
    return file_path
  end

  # Download file
  UI.header "Downloading Unity #{version}"
  UI.verbose 'Downloading from ' + url.to_s.cyan.underline
  Downloader.download_package(file_path, url)
  U3dCore::CommandExecutor.execute(command: "chmod a+x #{file_path}")
  file_path
end

.local_file(version) ⇒ Object



238
239
240
241
242
243
244
245
# File 'lib/u3d/downloader.rb', line 238

def local_file(version)
  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)
  find_cmd = "find #{dir}/ -maxdepth 2 -name '*.sh'"
  files = U3dCore::CommandExecutor.execute(command: find_cmd).split("\n")
  return files[0] unless files.empty?
  raise 'No file has been downloaded'
end