Removed idea to have Tasks have a seperate step class; needless abstraction at this point, added manifest parser

This commit is contained in:
2021-11-15 19:22:09 -06:00
parent dae620ccbd
commit 1ab835ba98
14 changed files with 280 additions and 149 deletions

View File

@@ -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