Task now ask Interface to update task status instead of just doing it themselves whenever they want, stubbed apply_patch method, moved unpacking into its own method

This commit is contained in:
2021-11-26 15:21:22 -06:00
parent 6c18e16357
commit 2a65761b8d
3 changed files with 41 additions and 14 deletions

View File

@@ -123,7 +123,7 @@ class W3DHub
def update_interface_task_status
run_on_main_thread(
proc do
window.current_state.update_interface_task_status(self)
window.current_state.interface_task_update_pending = self
end
)
end
@@ -237,7 +237,7 @@ class W3DHub
@status.step = :prefetch_verifying_packages
package_details.each do |pkg|
package_details.each_with_index.each do |pkg, i|
operation = @status.operations[:"#{pkg.checksum}"]
if verify_package(pkg)
@@ -250,6 +250,8 @@ class W3DHub
operation.progress = pkg.custom_partially_valid_at_bytes.to_f / pkg.size
end
@status.progress = i.to_f / package_details.count
update_interface_task_status
end
@@ -300,24 +302,29 @@ class W3DHub
packages.each do |pkg|
@status.operations[:"#{pkg.checksum}"] = Status::Operation.new(
label: pkg.name,
value: "Pending",
value: "Pending...",
progress: 0.0
)
end
@status.step = :unpacking
# TODO: Add support for patches
packages.each do |package|
puts " #{package.name}:#{package.version}"
package_path = Cache.package_path(package.category, package.subcategory, "#{package.name}.zip", package.version)
status = if package.custom_is_patch
@status.operations[:"#{package.checksum}"].value = "Patching..."
update_interface_task_status
puts " Running #{W3DHub.tar_command} command: #{"#{W3DHub.tar_command} -xf #{package_path} -C #{path}"}"
status = system("#{W3DHub.tar_command} -xf #{package_path} -C #{path}")
apply_patch(package)
else
@status.operations[:"#{package.checksum}"].value = "Unpacking..."
update_interface_task_status
unpack_package(package)
end
if status
@status.operations[:"#{pkg.checksum}"].value = "Unpacked"
@status.operations[:"#{pkg.checksum}"].progress = 1.0
@status.operations[:"#{package.checksum}"].value = "Unpacked"
@status.operations[:"#{package.checksum}"].progress = 1.0
update_interface_task_status
else
@@ -440,6 +447,7 @@ class W3DHub
package.checksum_chunks.each do |chunk_start, checksum|
i += 1
operation&.progress = i.to_f / chunks
update_interface_task_status
chunk_start = Integer(chunk_start.to_s)
@@ -471,6 +479,24 @@ class W3DHub
def load_manifest(category, subcategory, name, version)
Manifest.new(category, subcategory, name, version)
end
def unpack_package(package)
puts " #{package.name}:#{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}"}"
return system("#{W3DHub.tar_command} -xf #{package_path} -C #{path}")
end
def apply_patch(package)
# Unpack patch to a known directory
# Load MIX1 file
# Read and Parse .w3dhub.patch json file
# Load target MIX1 (.mix and .dat)
# Update and remove files
# Overwrite updated file
false
end
end
end
end

View File

@@ -53,14 +53,10 @@ class W3DHub
@operations_container = stack(width: 1.0, height: 0.9, padding: 8, scroll: true) do
# TODO: Show actual list of downloads
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
background 0xff_333333 if i.odd?

View File

@@ -2,6 +2,7 @@ class W3DHub
class States
class Interface < CyberarmEngine::GuiState
attr_reader :main_thread_queue
attr_accessor :interface_task_update_pending
def setup
window.show_cursor = true
@@ -10,6 +11,8 @@ class W3DHub
@service_status = @options[:service_status]
@applications = @options[:applications]
@interface_task_update_pending = nil
@page = nil
@pages = {}
@@ -141,6 +144,8 @@ class W3DHub
while(block = @main_thread_queue.shift)
block&.call
end
update_interface_task_status(@interface_task_update_pending) if @interface_task_update_pending
end
def button_down(id)