Added ApplicationManager::Status, DownloadManager now displays data from Status, added improved progress information to DownloadManager via Task updating its Status object

This commit is contained in:
2021-11-26 12:17:26 -06:00
parent 935aed1a7a
commit 6c18e16357
10 changed files with 220 additions and 81 deletions

View File

@@ -2,7 +2,7 @@ class W3DHub
class Api class Api
class Package class Package
attr_reader :category, :subcategory, :name, :version, :size, :checksum, :checksum_chunk_size, :checksum_chunks, attr_reader :category, :subcategory, :name, :version, :size, :checksum, :checksum_chunk_size, :checksum_chunks,
:custom_partially_valid_at_bytes :custom_partially_valid_at_bytes, :custom_is_patch
def initialize(hash) def initialize(hash)
@data = hash @data = hash
@@ -18,6 +18,7 @@ class W3DHub
@checksum_chunks = @data[:"checksum-chunks"] @checksum_chunks = @data[:"checksum-chunks"]
@custom_partially_valid_at_bytes = 0 @custom_partially_valid_at_bytes = 0
@custom_is_patch = false
end end
def chunk(key) def chunk(key)
@@ -28,6 +29,10 @@ class W3DHub
@custom_partially_valid_at_bytes = i @custom_partially_valid_at_bytes = i
end end
def is_patch=(file)
@custom_is_patch = file
end
class Chunk class Chunk
attr_reader :chunk, :checksum attr_reader :chunk, :checksum

View File

@@ -0,0 +1,40 @@
class W3DHub
class ApplicationManager
class Status
attr_reader :application, :channel, :step, :operations, :data
attr_accessor :label, :value, :progress
def initialize(application:, channel:, label: "", value: "", progress: 0.0, step: :pending, operations: {}, &callback)
@application = application
@channel = channel
@label = label
@value = value
@progress = progress
@step = step
@operations = operations
@callback = callback
@data = {}
end
def step=(sym)
@step = sym
@callback&.call(self)
@step
end
class Operation
attr_accessor :label, :value, :progress
def initialize(label:, value:, progress:)
@label = label
@value = value
@progress = progress
end
end
end
end
end

View File

@@ -4,8 +4,7 @@ class W3DHub
include CyberarmEngine::Common include CyberarmEngine::Common
attr_reader :app_id, :release_channel, :application, :channel, attr_reader :app_id, :release_channel, :application, :channel,
:total_bytes_to_download, :bytes_downloaded, :packages_to_download, :manifests, :packages, :files, :wine_prefix, :status
:manifests, :packages, :files, :wine_prefix
def initialize(app_id, release_channel) def initialize(app_id, release_channel)
@app_id = app_id @app_id = app_id
@@ -26,6 +25,8 @@ class W3DHub
@wine_prefix = nil @wine_prefix = nil
@status = Status.new(application: @application, channel: channel) { update_interface_task_status }
setup setup
end end
@@ -119,19 +120,10 @@ class W3DHub
) )
end end
def update_application_taskbar(message, status, progress) def update_interface_task_status
run_on_main_thread( run_on_main_thread(
proc do proc do
window.current_state.show_application_taskbar window.current_state.update_interface_task_status(self)
window.current_state.update_application_taskbar(message, status, progress)
end
)
end
def update_download_manager_task(checksum, message, status, progress)
run_on_main_thread(
proc do
window.current_state.update_download_manager_task(checksum, message, status, progress)
end end
) )
end end
@@ -149,6 +141,13 @@ class W3DHub
############### ###############
def fetch_manifests def fetch_manifests
@status.operations.clear
@status.label = "Downloading #{@application.name}..."
@status.value = "Fetching manifests..."
@status.progress = 0.0
@status.step = :fetching_manifests
if fetch_manifest("games", app_id, "manifest.xml", @channel.current_version) if fetch_manifest("games", app_id, "manifest.xml", @channel.current_version)
manifest = load_manifest("games", app_id, "manifest.xml", @channel.current_version) manifest = load_manifest("games", app_id, "manifest.xml", @channel.current_version)
@manifests << manifest @manifests << manifest
@@ -164,6 +163,13 @@ class W3DHub
end end
def build_package_list(manifests) def build_package_list(manifests)
@status.operations.clear
@status.label = "Downloading #{@application.name}..."
@status.value = "Building package list..."
@status.progress = 0.0
@status.step = :build_package_list
packages = [] packages = []
manifests.reverse.each do |manifest| manifests.reverse.each do |manifest|
@@ -191,6 +197,8 @@ class W3DHub
{ category: "games", subcategory: @app_id, name: file.package, version: manifest.version } { category: "games", subcategory: @app_id, name: file.package, version: manifest.version }
) )
) )
packages.last.is_patch = file if file.patch?
end end
# TODO: Dependencies # TODO: Dependencies
@@ -215,34 +223,58 @@ class W3DHub
@packages = [package_details].flatten @packages = [package_details].flatten
@packages_to_download = [] @packages_to_download = []
update_application_taskbar("Downloading #{@application.name}...", "Verifying local packages...", 0.0) @status.label = "Downloading #{@application.name}..."
@status.value = "Verifying local packages..."
@status.progress = 0.0
package_details.each do |pkg| package_details.each do |pkg|
@packages_to_download << pkg unless verify_package(pkg) @status.operations[:"#{pkg.checksum}"] = Status::Operation.new(
label: pkg.name,
value: "Verifying...",
progress: 0.0
)
end end
@status.step = :prefetch_verifying_packages
package_details.each do |pkg|
operation = @status.operations[:"#{pkg.checksum}"]
if verify_package(pkg)
operation.value = "Verified."
operation.progress = 1.0
else
@packages_to_download << pkg
operation.value = "#{W3DHub.format_size(pkg.custom_partially_valid_at_bytes)} / #{W3DHub.format_size(pkg.size)}"
operation.progress = pkg.custom_partially_valid_at_bytes.to_f / pkg.size
end
update_interface_task_status
end
@status.operations.delete_if { |key, o| o.progress >= 1.0 }
@status.step = :fetch_packages
@total_bytes_to_download = @packages_to_download.sum { |pkg| pkg.size - pkg.custom_partially_valid_at_bytes } @total_bytes_to_download = @packages_to_download.sum { |pkg| pkg.size - pkg.custom_partially_valid_at_bytes }
@bytes_downloaded = 0 @bytes_downloaded = 0
@packages_to_download.each do |pkg| @packages_to_download.each do |pkg|
package_bytes_downloaded = 0 package_bytes_downloaded = pkg.custom_partially_valid_at_bytes
package_fetch(pkg) do |chunk, remaining_bytes, total_bytes| package_fetch(pkg) do |chunk, remaining_bytes, total_bytes|
@bytes_downloaded += chunk.to_s.length @bytes_downloaded += chunk.to_s.length
package_bytes_downloaded += chunk.to_s.length package_bytes_downloaded += chunk.to_s.length
update_application_taskbar( @status.value = "#{W3DHub.format_size(@bytes_downloaded)} / #{W3DHub.format_size(@total_bytes_to_download)}"
"Downloading #{@application.name}...", @status.progress = @bytes_downloaded.to_f / @total_bytes_to_download
"#{W3DHub.format_size(@bytes_downloaded)} / #{W3DHub.format_size(@total_bytes_to_download)}",
@bytes_downloaded.to_f / @total_bytes_to_download
)
update_download_manager_task( operation = @status.operations[:"#{pkg.checksum}"]
pkg.checksum, operation.value = "#{W3DHub.format_size(package_bytes_downloaded)} / #{W3DHub.format_size(pkg.size)}"
pkg.name, operation.progress = package_bytes_downloaded.to_f / total_bytes
"#{W3DHub.format_size(package_bytes_downloaded)} / #{W3DHub.format_size(total_bytes)}",
package_bytes_downloaded.to_f / total_bytes update_interface_task_status
)
end end
end end
else else
@@ -260,33 +292,75 @@ class W3DHub
puts "Unpacking packages in '#{path}'..." puts "Unpacking packages in '#{path}'..."
Cache.create_directories(path, true) Cache.create_directories(path, true)
@status.operations.clear
@status.label = "Installing #{@application.name}..."
@status.value = "Unpacking..."
@status.progress = 0.0
packages.each do |pkg|
@status.operations[:"#{pkg.checksum}"] = Status::Operation.new(
label: pkg.name,
value: "Pending",
progress: 0.0
)
end
@status.step = :unpacking
# TODO: Add support for patches
packages.each do |package| packages.each do |package|
puts " #{package.name}:#{package.version}" puts " #{package.name}:#{package.version}"
package_path = Cache.package_path(package.category, package.subcategory, "#{package.name}.zip", package.version) package_path = Cache.package_path(package.category, package.subcategory, "#{package.name}.zip", package.version)
puts " Running #{W3DHub.tar_command} command: #{"#{W3DHub.tar_command} -xf #{package_path} -C #{path}"}" puts " Running #{W3DHub.tar_command} command: #{"#{W3DHub.tar_command} -xf #{package_path} -C #{path}"}"
status = system("#{W3DHub.tar_command} -xf #{package_path} -C #{path}") status = system("#{W3DHub.tar_command} -xf #{package_path} -C #{path}")
if status if status
@status.operations[:"#{pkg.checksum}"].value = "Unpacked"
@status.operations[:"#{pkg.checksum}"].progress = 1.0
update_interface_task_status
else else
puts "COMMAND FAILED!" puts "COMMAND FAILED!"
fail!("Failed to unpack #{package.name}") fail!("Failed to unpack #{package.name}")
break break
end end
end end
end end
def create_wine_prefix def create_wine_prefix
if W3DHub.unix? if W3DHub.unix? && @wine_prefix
# TODO: create a wine prefix if configured # TODO: create a wine prefix if configured
@status.operations.clear
@status.label = "Installing #{@application.name}..."
@status.value = "Creating wine prefix..."
@status.progress = 0.0
@status.step = :create_wine_prefix
end end
end end
def install_dependencies(packages) def install_dependencies(packages)
# TODO: install dependencies
@status.operations.clear
@status.label = "Installing #{@application.name}..."
@status.value = "Installing dependencies..."
@status.progress = 0.0
@status.step = :install_dependencies
end end
def mark_application_installed def mark_application_installed
Store.application_manager.installed!(self) Store.application_manager.installed!(self)
@status.operations.clear
@status.label = "Installed #{@application.name}"
@status.value = ""
@status.progress = 1.0
@status.step = :mark_application_installed
puts "#{@app_id} has been installed." puts "#{@app_id} has been installed."
end end
@@ -353,12 +427,20 @@ class W3DHub
return false unless File.exist?(path) return false unless File.exist?(path)
operation = @status.operations[:"#{package.checksum}"]
operation&.value = "Verifying..."
file_size = File.size(path) file_size = File.size(path)
puts " File size: #{file_size}" puts " File size: #{file_size}"
chunk_size = package.checksum_chunk_size chunk_size = package.checksum_chunk_size
chunks = package.checksum_chunks.size
File.open(path) do |f| File.open(path) do |f|
i = -1
package.checksum_chunks.each do |chunk_start, checksum| package.checksum_chunks.each do |chunk_start, checksum|
i += 1
operation&.progress = i.to_f / chunks
chunk_start = Integer(chunk_start.to_s) chunk_start = Integer(chunk_start.to_s)
read_length = chunk_size read_length = chunk_size

View File

@@ -9,11 +9,11 @@ class W3DHub
fail_fast fail_fast
return false if failed? return false if failed?
update_application_taskbar("Downloading #{@application.name}...", "Fetching manifests...", 0.0) # update_application_taskbar("Downloading #{@application.name}...", "Fetching manifests...", 0.0)
manifests = fetch_manifests manifests = fetch_manifests
return false if failed? return false if failed?
update_application_taskbar("Downloading #{@application.name}...", "Building package list...", 0.0) # update_application_taskbar("Downloading #{@application.name}...", "Building package list...", 0.0)
packages = build_package_list(manifests) packages = build_package_list(manifests)
return false if failed? return false if failed?
@@ -21,21 +21,21 @@ class W3DHub
fetch_packages(packages) fetch_packages(packages)
return false if failed? return false if failed?
update_application_taskbar("Downloading #{@application.name}...", "Verifying packages...", 0.0) # update_application_taskbar("Downloading #{@application.name}...", "Verifying packages...", 0.0)
verify_packages(packages) verify_packages(packages)
return false if failed? return false if failed?
update_application_taskbar("Installing #{@application.name}...", "Unpacking...", 0.0) # update_application_taskbar("Installing #{@application.name}...", "Unpacking...", 0.0)
unpack_packages(packages) unpack_packages(packages)
return false if failed? return false if failed?
sleep 1 sleep 1
update_application_taskbar("Installing #{@application.name}...", "Creating wine prefix...", 0.0) # update_application_taskbar("Installing #{@application.name}...", "Creating wine prefix...", 0.0)
create_wine_prefix create_wine_prefix
return false if failed? return false if failed?
sleep 1 sleep 1
update_application_taskbar("Installing #{@application.name}...", "Installing dependencies...", 0.0) # update_application_taskbar("Installing #{@application.name}...", "Installing dependencies...", 0.0)
install_dependencies(packages) install_dependencies(packages)
return false if failed? return false if failed?
sleep 1 sleep 1
@@ -43,7 +43,7 @@ class W3DHub
mark_application_installed mark_application_installed
return false if failed? return false if failed?
update_application_taskbar("Installed #{@application.name}", "", 1.0) # update_application_taskbar("Installed #{@application.name}", "", 1.0)
sleep 5 sleep 5
hide_application_taskbar hide_application_taskbar

View File

@@ -55,10 +55,10 @@ class W3DHub
create_directories(path) create_directories(path)
file = File.open(path, "wb") file = File.open(path, "ab")
if (start_from_bytes > 0) if (start_from_bytes > 0)
headers["Range"] = "bytes=#{start_from_bytes}-#{package.size}" headers["Range"] = "bytes=#{start_from_bytes}-#{package.size}"
file.seek(start_from_bytes) file.pos = start_from_bytes
end end
streamer = lambda do |chunk, remaining_bytes, total_bytes| streamer = lambda do |chunk, remaining_bytes, total_bytes|

View File

@@ -19,9 +19,6 @@ class W3DHub
@host.main_thread_queue @host.main_thread_queue
end end
def update_application_manager_status
end
def options=(options) def options=(options)
@options = options @options = options
end end

View File

@@ -1,13 +1,13 @@
class W3DHub class W3DHub
class Pages class Pages
class DownloadManager < Page class DownloadManager < Page
attr_reader :download_package_info attr_reader :operation_info
def setup def setup
@download_package_info ||= {} @operation_info ||= {}
@task = Store.application_manager.current_task task = Store.application_manager.current_task
unless @task unless task
body.clear do body.clear do
tagline "No operations pending.", width: 1.0, text_align: :center, margin: 128 tagline "No operations pending.", width: 1.0, text_align: :center, margin: 128
end end
@@ -15,50 +15,61 @@ class W3DHub
return return
end end
regenerate(task)
end
def regenerate(task)
@operation_info[:___step] = task.status.step
body.clear do body.clear do
stack(width: 1.0, height: 1.0) do stack(width: 1.0, height: 1.0) do
# TODO: Show correct application details here # TODO: Show correct application details here
flow(width: 1.0, height: 0.1, padding: 8) do flow(width: 1.0, height: 0.1, padding: 8) do
background @task.application.color background task.application.color
flow(width: 0.70, height: 1.0) do flow(width: 0.70, height: 1.0) do
@application_image = image "#{GAME_ROOT_PATH}/media/icons/#{@task.app_id}.png", height: 1.0 @application_image = image "#{GAME_ROOT_PATH}/media/icons/#{task.app_id}.png", height: 1.0
stack(margin_left: 8) do stack(margin_left: 8) do
@application_name_label = tagline "#{@task.application.name}" @application_name_label = tagline "#{task.application.name}"
@application_version_label = inscription "Version: #{@task.channel.current_version} (#{@task.channel.id})" @application_version_label = inscription "Version: #{task.channel.current_version} (#{task.channel.id})"
end end
end end
puts "OKAY"
flow(width: 0.30, height: 1.0) do flow(width: 0.30, height: 1.0) do
stack(width: 0.499, height: 1.0) do stack(width: 0.499, height: 1.0) do
para "Download Speed", width: 1.0, text_align: :center para "Download Speed", width: 1.0, text_align: :center
@download_speed_label = inscription "0 b/s", width: 1.0, text_align: :center @download_speed_label = inscription "- b/s", width: 1.0, text_align: :center
end end
stack(width: 0.5, height: 1.0) do stack(width: 0.5, height: 1.0) do
para "Downloaded", width: 1.0, text_align: :center para "Downloaded", width: 1.0, text_align: :center
inscription "325.8 MB / 1.39 GB", width: 1.0, text_align: :center inscription "---- b / ---- b", width: 1.0, text_align: :center
end end
end end
end end
# Operations # Operations
@downloads_container = stack(width: 1.0, height: 0.9, padding: 8, scroll: true) do @operations_container = stack(width: 1.0, height: 0.9, padding: 8, scroll: true) do
# TODO: Show actual list of downloads # TODO: Show actual list of downloads
@task&.packages_to_download&.each_with_index do |pkg, i| p ["DOWNLOAD MANAGER", task.status.operations.size]
i = -1
task.status.operations.each do |key, operation|
i += 1
p [key, operation.label]
stack(width: 1.0, height: 24, padding: 8) do stack(width: 1.0, height: 24, padding: 8) do
background 0xff_333333 if i.odd? background 0xff_333333 if i.odd?
flow(width: 1.0, height: 22) do flow(width: 1.0, height: 22) do
@download_package_info["#{pkg.checksum}_name"] = inscription pkg.name, width: 0.7, text_wrap: :none, tag: "#{pkg.checksum}_name" @operation_info["#{key}_name"] = inscription operation.label, width: 0.7, text_wrap: :none, tag: "#{key}_name"
@download_package_info["#{pkg.checksum}_status"] = inscription "Pending...", width: 0.3, text_align: :right, text_wrap: :none, tag: "#{pkg.checksum}_status" @operation_info["#{key}_status"] = inscription operation.value, width: 0.3, text_align: :right, text_wrap: :none, tag: "#{key}_status"
end end
@download_package_info["#{pkg.checksum}_progress"] = progress fraction: 0.0, height: 2, width: 1.0, tag: "#{pkg.checksum}_progress" @operation_info["#{key}_progress"] = progress fraction: operation.progress, height: 2, width: 1.0, tag: "#{key}_progress"
end end
end end
end end

View File

@@ -174,10 +174,6 @@ class W3DHub
@page.focus @page.focus
end end
def update_application_manager_status
@page.update_application_manager_status
end
def show_application_taskbar def show_application_taskbar
@application_taskbar_container.show @application_taskbar_container.show
end end
@@ -186,30 +182,38 @@ class W3DHub
@application_taskbar_container.hide @application_taskbar_container.hide
end end
def update_application_taskbar(message, status, progress) def update_interface_task_status(task)
@application_taskbar_label.value = message show_application_taskbar
@application_taskbar_status_label.value = status
@application_taskbar_progressbar.value = progress.clamp(0.0, 1.0)
end
# def update_download_manager_state(application, channel) @application_taskbar_label.value = task.status.label
# end @application_taskbar_status_label.value = task.status.value
@application_taskbar_progressbar.value = task.status.progress.clamp(0.0, 1.0)
def update_download_manager_list
end
def update_download_manager_task(checksum, name, status, progress)
return unless @page.is_a?(Pages::DownloadManager) return unless @page.is_a?(Pages::DownloadManager)
download_package_info = @page.download_package_info operation_info = @page.operation_info
operation_step = @page.operation_info[:___step]
name_ = download_package_info["#{checksum}_name"] if task.status.step != operation_step
status_ = download_package_info["#{checksum}_status"] @page.regenerate(task)
progress_ = download_package_info["#{checksum}_progress"]
name_.value = name if name return
status_.value = status if status end
progress_.value = progress if progress
task.status.operations.each do |key, operation|
name_ = operation_info["#{key}_name"]
status_ = operation_info["#{key}_status"]
progress_ = operation_info["#{key}_progress"]
next if name_.value == operation.label &&
status_.value == operation.value &&
progress_.value == operation.value
name_.value = operation.label if operation.label
status_.value = operation.value if operation.value
progress_.value = operation.progress.clamp(0.0, 1.0) if operation.progress
end
end end
end end
end end

View File

@@ -22,7 +22,6 @@ class W3DHub
super super
Store.application_manager.start_next_available_task if Store.application_manager.idle? Store.application_manager.start_next_available_task if Store.application_manager.idle?
current_state.update_application_manager_status if current_state.is_a?(States::Interface)
end end
def close def close

View File

@@ -35,6 +35,7 @@ require_relative "lib/settings"
require_relative "lib/mixer" require_relative "lib/mixer"
require_relative "lib/application_manager" require_relative "lib/application_manager"
require_relative "lib/application_manager/manifest" require_relative "lib/application_manager/manifest"
require_relative "lib/application_manager/status"
require_relative "lib/application_manager/task" require_relative "lib/application_manager/task"
require_relative "lib/application_manager/tasks/installer" require_relative "lib/application_manager/tasks/installer"
require_relative "lib/application_manager/tasks/uninstaller" require_relative "lib/application_manager/tasks/uninstaller"