mirror of
https://github.com/cyberarm/w3d_hub_linux_launcher.git
synced 2025-12-16 09:12:35 +00:00
Drafted async-http downloader, fixed not correctly fetching icons at startup
This commit is contained in:
@@ -542,8 +542,6 @@ class W3DHub
|
|||||||
def package_fetch(package, &block)
|
def package_fetch(package, &block)
|
||||||
puts "Downloading: #{package.category}:#{package.subcategory}:#{package.name}-#{package.version}"
|
puts "Downloading: #{package.category}:#{package.subcategory}:#{package.name}-#{package.version}"
|
||||||
|
|
||||||
internet = Async::HTTP::Internet.instance
|
|
||||||
|
|
||||||
Api.package(package) do |chunk, remaining_bytes, total_bytes|
|
Api.package(package) do |chunk, remaining_bytes, total_bytes|
|
||||||
block&.call(chunk, remaining_bytes, total_bytes)
|
block&.call(chunk, remaining_bytes, total_bytes)
|
||||||
end
|
end
|
||||||
|
|||||||
39
lib/cache.rb
39
lib/cache.rb
@@ -51,6 +51,44 @@ class W3DHub
|
|||||||
"#{Store.settings[:app_install_dir]}/#{application.category}/#{application.id}/#{channel.id}"
|
"#{Store.settings[:app_install_dir]}/#{application.category}/#{application.id}/#{channel.id}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Download a W3D Hub package
|
||||||
|
# TODO: More work needed to make this work reliably
|
||||||
|
def self._async_fetch_package(package, block)
|
||||||
|
path = package_path(package.category, package.subcategory, package.name, package.version)
|
||||||
|
headers = Api::FORM_ENCODED_HEADERS
|
||||||
|
start_from_bytes = package.custom_partially_valid_at_bytes
|
||||||
|
|
||||||
|
puts " Start from bytes: #{start_from_bytes} of #{package.size}"
|
||||||
|
|
||||||
|
create_directories(path)
|
||||||
|
|
||||||
|
file = File.open(path, start_from_bytes.positive? ? "r+b" : "wb")
|
||||||
|
|
||||||
|
if start_from_bytes.positive?
|
||||||
|
headers = Api::FORM_ENCODED_HEADERS + [["Range", "bytes=#{start_from_bytes}-"]]
|
||||||
|
file.pos = start_from_bytes
|
||||||
|
end
|
||||||
|
|
||||||
|
body = "data=#{JSON.dump({ category: package.category, subcategory: package.subcategory, name: package.name, version: package.version })}"
|
||||||
|
|
||||||
|
response = Api.post("#{Api::ENDPOINT}/apis/launcher/1/get-package", headers, body)
|
||||||
|
|
||||||
|
total_bytes = package.size
|
||||||
|
remaining_bytes = total_bytes - start_from_bytes
|
||||||
|
|
||||||
|
response.each do |chunk|
|
||||||
|
file.write(chunk)
|
||||||
|
|
||||||
|
remaining_bytes -= chunk.size
|
||||||
|
|
||||||
|
block.call(chunk, remaining_bytes, total_bytes)
|
||||||
|
end
|
||||||
|
|
||||||
|
response.success?
|
||||||
|
ensure
|
||||||
|
file&.close
|
||||||
|
end
|
||||||
|
|
||||||
# Download a W3D Hub package
|
# Download a W3D Hub package
|
||||||
def self.fetch_package(package, block)
|
def self.fetch_package(package, block)
|
||||||
path = package_path(package.category, package.subcategory, package.name, package.version)
|
path = package_path(package.category, package.subcategory, package.name, package.version)
|
||||||
@@ -73,7 +111,6 @@ class W3DHub
|
|||||||
file.write(chunk)
|
file.write(chunk)
|
||||||
|
|
||||||
block.call(chunk, remaining_bytes, total_bytes)
|
block.call(chunk, remaining_bytes, total_bytes)
|
||||||
# puts " Remaining: #{((remaining_bytes.to_f / total_bytes) * 100.0).round}% (#{W3DHub::format_size(total_bytes - remaining_bytes)} / #{W3DHub::format_size(total_bytes)})"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Create a new connection due to some weirdness somewhere in Excon
|
# Create a new connection due to some weirdness somewhere in Excon
|
||||||
|
|||||||
@@ -134,9 +134,10 @@ class W3DHub
|
|||||||
|
|
||||||
regenerate = false
|
regenerate = false
|
||||||
|
|
||||||
if File.exist?(path)
|
broken_or_out_dated_icon = Digest::SHA256.new.hexdigest(File.binread(path)).upcase != package.checksum.upcase if File.exist?(path)
|
||||||
regenerate = Digest::SHA256.new.hexdigest(File.binread(path)).upcase != package.checksum.upcase
|
|
||||||
regenerate ||= !File.exist?(generated_icon_path)
|
if File.exist?(path) && !broken_or_out_dated_icon
|
||||||
|
regenerate = !File.exist?(generated_icon_path)
|
||||||
else
|
else
|
||||||
Cache.fetch_package(package, proc {})
|
Cache.fetch_package(package, proc {})
|
||||||
regenerate = true
|
regenerate = true
|
||||||
|
|||||||
Reference in New Issue
Block a user