class U3d::BaseInstaller

Public Instance Methods

installed_sorted_by_versions() click to toggle source
# File lib/u3d/installer.rb, line 85
def installed_sorted_by_versions
  list = installed
  return [] if list.empty?
  list.sort { |a, b| UnityVersionComparator.new(a.version) <=> UnityVersionComparator.new(b.version) }
end
sanitize_installs() click to toggle source
# File lib/u3d/installer.rb, line 72
def sanitize_installs
  return unless UI.interactive? || Helper.test?
  unclean = []
  installed.each { |unity| unclean << unity unless unity.clean_install? }
  return if unclean.empty?
  UI.important("u3d can optionally standardize the existing Unity installation names and locations.")
  UI.important("Check the documentation for more information:")
  UI.important("** https://github.com/DragonBox/u3d/blob/master/README.md#default-installation-paths **")
  unclean.each { |unity| sanitize_install(unity, dry_run: true) }
  return unless UI.confirm("#{unclean.count} Unity installation(s) will be moved. Proceed??")
  unclean.each { |unity| sanitize_install(unity) }
end

Protected Instance Methods

extra_installation_paths() click to toggle source

extra installation paths are stored in U3D_EXTRA_PATHS environment variable, following a standard PATH variable format. Returns an array of ruby style paths

# File lib/u3d/installer.rb, line 152
def extra_installation_paths
  return [] if ENV['U3D_EXTRA_PATHS'].nil?
  ENV['U3D_EXTRA_PATHS'].strip.split(File::PATH_SEPARATOR).map { |p| File.expand_path p }
end
find_installations_with_path(default_root_path: '', postfix: []) { |found_path| ... } click to toggle source
# File lib/u3d/installer.rb, line 157
def find_installations_with_path(default_root_path: '', postfix: [])
  ([default_root_path] | extra_installation_paths).map do |path|
    UI.verbose "Looking for installed Unity version under #{path}"
    pattern = File.join([path] + postfix)
    Dir.glob(pattern).map { |found_path| yield found_path }
  end.flatten
end
install_po(file_path, version, info: nil) click to toggle source
# File lib/u3d/installer.rb, line 93
def install_po(file_path, version, info: nil)
  unity = installed.find { |u| u.version == version }
  root_path = package_destination(info, unity.root_path)

  target_path = File.join(root_path, File.basename(file_path))
  Utils.ensure_dir(File.dirname(target_path))

  UI.verbose "Copying #{file_path} to #{target_path}"
  FileUtils.cp(file_path, target_path)

  UI.success "Successfully installed language file #{File.basename(file_path)}"
end
install_zip(file_path, version, info: nil) click to toggle source
# File lib/u3d/installer.rb, line 106
def install_zip(file_path, version, info: nil)
  unity = installed.find { |u| u.version == version }
  root_path = package_destination(info, unity.root_path)

  UI.verbose("Unzipping #{file_path} to #{root_path}")

  unless File.directory?(root_path)
    Utils.get_write_access(File.dirname(root_path)) do
      Utils.ensure_dir(root_path)
    end
  end

  Zip::File.open(file_path) do |zip_file|
    zip_file.each do |entry|
      target_path = File.join(root_path, entry.name)
      Utils.ensure_dir(File.dirname(target_path))
      zip_file.extract(entry, target_path) unless File.exist?(target_path)
    end
  end

  if info && info.rename_from && info.rename_to
    rename_from = info.rename_from.gsub(/{UNITY_PATH}/, unity.root_path)
    rename_to = info.rename_to.gsub(/{UNITY_PATH}/, unity.root_path)
    Utils.ensure_dir(rename_to)
    UI.verbose("Renaming from #{rename_from} to #{rename_to}")
    if File.file? rename_from
      FileUtils.mv(rename_from, rename_to)
    else
      Dir.glob(rename_from + '/*').each { |path| FileUtils.mv(path, rename_to) }
    end
  end

  UI.success "Successfully unizpped #{File.basename(file_path)} at #{root_path}"
end
package_destination(info, unity_root_path) click to toggle source
# File lib/u3d/installer.rb, line 141
def package_destination(info, unity_root_path)
  if info && info.destination
    info.destination.gsub(/{UNITY_PATH}/, unity_root_path)
  else
    unity_root_path
  end
end