lib/ruboto/util/setup.rb in ruboto-1.6.0 vs lib/ruboto/util/setup.rb in ruboto-1.6.1
- old
+ new
@@ -76,11 +76,18 @@
android_package_os_id == WINDOWS
end
def android_package_directory
return ENV['ANDROID_HOME'] if ENV['ANDROID_HOME']
- File.join File.expand_path('~'), windows? ? 'AppData/Local/Android/android-sdk' : "android-sdk-#{android_package_os_id}"
+ user_dir = if windows?
+ 'AppData/Local/Android/android-sdk'
+ elsif File.exist? "android-sdk-#{android_package_os_id}"
+ "android-sdk-#{android_package_os_id}"
+ else
+ "android-sdk"
+ end
+ File.join File.expand_path('~'), user_dir
end
def android_haxm_directory
Dir[File.join(android_package_directory, 'extras', 'intel', 'Hardware_Accelerated_Execution_Manager')][0]
end
@@ -137,29 +144,13 @@
require 'net/http'
require 'uri'
# Get's the Page to Scrape
page_content = Net::HTTP.get(URI.parse(SDK_DOWNLOAD_PAGE))
-
- case android_package_os_id
- when MAC_OS_X
- regex = '(\>android-sdk.*macosx.zip)'
- when LINUX
- regex = '(\>android-sdk.*.tgz)'
- when WINDOWS
- regex = '(\>installer_.*.exe)'
- else
- raise "Unknown host os: #{android_package_os_id}"
- end
-
- link = page_content.scan(/#{regex}/)
- raise "SDK link cannot be found on download page: #{SDK_DOWNLOAD_PAGE}" if link.nil?
-
- version = link.to_s.match(/r(\d+.)?(\d+.)?(\d+)/)[0]
- raise "SDK version cannot be determined from download page: #{SDK_DOWNLOAD_PAGE}" if version.nil?
-
- version.delete! 'r'
+ links = page_content.scan(/>tools_r(\d+\.\d+\.\d+)-#{android_package_os_id}.zip</)
+ raise "SDK link cannot be found on download page: #{SDK_DOWNLOAD_PAGE}" if links.empty?
+ links[0][0]
end
#########################################
#
# Check Methods
@@ -527,39 +518,16 @@
print 'Would you like to download and install it? (Y/n): '
a = STDIN.gets.chomp.upcase
end
if accept_all || a == 'Y' || a.empty?
Dir.chdir File.expand_path('~/') do
- case android_package_os_id
- when MAC_OS_X
- asdk_file_name = "android-sdk_r#{get_android_sdk_version}-#{android_package_os_id}.zip"
+ FileUtils.mkdir_p android_package_directory
+ Dir.chdir android_package_directory do
+ asdk_file_name = "tools_r#{get_android_sdk_version}-#{android_package_os_id}.zip"
download(asdk_file_name)
unzip(accept_all, asdk_file_name)
FileUtils.rm_f asdk_file_name
- when LINUX
- asdk_file_name = "android-sdk_r#{get_android_sdk_version}-#{android_package_os_id}.tgz"
- download asdk_file_name
- system "tar -xzf #{asdk_file_name}"
- FileUtils.rm_f asdk_file_name
- when WINDOWS
- # FIXME(uwe): Detect and warn if we are not "elevated" with adminstrator rights.
- #set IS_ELEVATED=0
- #whoami /groups | findstr /b /c:"Mandatory Label\High Mandatory Level" | findstr /c:"Enabled group" > nul: && set IS_ELEVATED=1
- #if %IS_ELEVATED%==0 (
- # echo You must run the command prompt as administrator to install.
- # exit /b 1
- #)
-
- asdk_file_name = "installer_r#{get_android_sdk_version}-#{android_package_os_id}.exe"
- download(asdk_file_name)
- puts "Installing #{asdk_file_name}..."
- system "#{WINDOWS_ELEVATE_CMD} #{asdk_file_name}"
- raise "Unexpected exit code while installing the Android SDK: #{$?.exitstatus}" unless $? == 0
- FileUtils.rm_f asdk_file_name
- return
- else
- raise "Unknown host os: #{RbConfig::CONFIG['host_os']}"
end
end
end
check_for_android_sdk
unless @android_loc.nil?
@@ -587,22 +555,24 @@
response.read_body do |fragment|
body << fragment
print "Downloading #{filename}: #{body.length / 1024**2}MB/#{length / 1024**2}MB #{(body.length * 100) / length}%\r"
end
end
+ puts
File.open(filename, 'wb') { |f| f << body }
end
- def download(asdk_file_name)
- print "Downloading #{asdk_file_name}: \r"
- uri = URI("http://dl.google.com/android/#{asdk_file_name}")
- process_download(asdk_file_name, uri)
+ def download(file_name)
+ print "Downloading #{file_name}: \r"
+ uri = URI("https://dl.google.com/android/repository/#{file_name}")
+ process_download(file_name, uri)
end
def unzip(accept_all, asdk_file_name, extract_to='.')
require 'zip'
+ puts "Unzipping #{asdk_file_name.inspect}"
Zip::File.open(asdk_file_name) do |zipfile|
zipfile.each do |f|
f.restore_permissions = true
f.extract("#{extract_to}/#{f.name}") { accept_all }
end