mirror of
https://github.com/cyberarm/w3d_hub_linux_launcher.git
synced 2025-12-16 01:02:34 +00:00
Removed idea to have Tasks have a seperate step class; needless abstraction at this point, added manifest parser
This commit is contained in:
39
lib/cache.rb
39
lib/cache.rb
@@ -6,6 +6,7 @@ class W3DHub
|
||||
"#{CACHE_PATH}/#{Digest::SHA2.hexdigest(uri)}.#{ext}"
|
||||
end
|
||||
|
||||
# Fetch a generic uri
|
||||
def self.fetch(uri)
|
||||
path = path(uri)
|
||||
|
||||
@@ -26,7 +27,43 @@ class W3DHub
|
||||
end
|
||||
end
|
||||
|
||||
def self.fetch_package(*args)
|
||||
def self.create_directories(path)
|
||||
target_directory = File.dirname(path)
|
||||
|
||||
FileUtils.mkdir_p(target_directory) unless Dir.exist?(target_directory)
|
||||
end
|
||||
|
||||
def self.package_path(category, subcategory, name, version)
|
||||
package_cache_dir = $window.settings[:package_cache_dir]
|
||||
|
||||
"#{package_cache_dir}/#{category}/#{subcategory}/#{version}/#{name}.package"
|
||||
end
|
||||
|
||||
# Download a W3D Hub package
|
||||
def self.fetch_package(socket, category, subcategory, name, version, block)
|
||||
path = package_path(category, subcategory, name, version)
|
||||
|
||||
create_directories(path)
|
||||
|
||||
file = File.open(path, "wb")
|
||||
|
||||
streamer = lambda do |chunk, remaining_bytes, total_bytes|
|
||||
file.write(chunk)
|
||||
|
||||
block.call(chunk, remaining_bytes, total_bytes)
|
||||
# puts "Remaining: #{remaining_bytes.to_f / total_bytes}%"
|
||||
end
|
||||
|
||||
response = socket.post(
|
||||
path: "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
|
||||
)
|
||||
|
||||
file.close
|
||||
|
||||
response.status == 200
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user