mirror of
https://github.com/cyberarm/w3d_hub_linux_launcher.git
synced 2025-12-15 16:52:34 +00:00
'Fixed' downloads failing at point due to Excon shared connection and threads, added byte size formatter
This commit is contained in:
@@ -51,11 +51,12 @@ class W3DHub
|
||||
file.write(chunk)
|
||||
|
||||
block.call(chunk, remaining_bytes, total_bytes)
|
||||
# puts "Remaining: #{remaining_bytes.to_f / 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
|
||||
|
||||
response = socket.post(
|
||||
path: "apis/launcher/1/get-package",
|
||||
# Create a new connection due to some weirdness somewhere in Excon
|
||||
response = Excon.post(
|
||||
"#{Api::ENDPOINT}/apis/launcher/1/get-package",
|
||||
headers: Api::DEFAULT_HEADERS.merge({"Content-Type": "application/x-www-form-urlencoded"}),
|
||||
body: "data=#{JSON.dump({ category: category, subcategory: subcategory, name: name, version: version })}",
|
||||
response_block: streamer
|
||||
|
||||
18
lib/common.rb
Normal file
18
lib/common.rb
Normal file
@@ -0,0 +1,18 @@
|
||||
class W3DHub
|
||||
def self.format_size(bytes)
|
||||
case bytes
|
||||
when 0..1023 # Bytes
|
||||
"#{bytes} B"
|
||||
when 1024..1_048_575 # KiloBytes
|
||||
"#{format_size_number(bytes / 1024.0)} KB"
|
||||
when 1_048_576..1_073_741_999 # MegaBytes
|
||||
"#{format_size_number(bytes / 1_048_576.0)} MB"
|
||||
else # GigaBytes
|
||||
"#{format_size_number(bytes / 1_073_742_000.0)} GB"
|
||||
end
|
||||
end
|
||||
|
||||
def self.format_size_number(i)
|
||||
format("%0.1f", i)
|
||||
end
|
||||
end
|
||||
@@ -10,6 +10,7 @@ require "fileutils"
|
||||
require "digest"
|
||||
require "rexml"
|
||||
require "zlib"
|
||||
|
||||
require "launchy"
|
||||
|
||||
class W3DHub
|
||||
@@ -22,6 +23,7 @@ class W3DHub
|
||||
end
|
||||
|
||||
require_relative "lib/version"
|
||||
require_relative "lib/common"
|
||||
require_relative "lib/window"
|
||||
require_relative "lib/cache"
|
||||
require_relative "lib/settings"
|
||||
|
||||
Reference in New Issue
Block a user