Stubbed out tasks system for installers

This commit is contained in:
2021-11-15 10:15:04 -06:00
parent 7fd38cd92d
commit dae620ccbd
14 changed files with 287 additions and 60 deletions

View File

@@ -1,26 +1,67 @@
class W3DHub
class ApplicationManager
def install(app_id)
puts "Installation Request: #{app_id}"
def initialize
@tasks = [] # :installer, :importer, :repairer, :uninstaller
end
def import(app_id, path)
puts "Import Request: #{app_id} -> #{path}"
def install(app_id, channel)
puts "Installation Request: #{app_id}-#{channel}"
return false if installed?(app_id, channel) || installing?(app_id, channel)
# if on unix: ask/make a wine prefix
# add install task to a list and mark as installing
# fetch manifests
# cycle through manifests and check package cache
# generate list of required packages to download
# download packages
# verify packages
# unpack packages
# install dependencies (e.g. visual C runtime)
@tasks.push(Installer.new(app_id, channel))
end
def settings(app_id)
puts "Settings Request: #{app_id}"
def import(app_id, channel, path)
puts "Import Request: #{app_id}-#{channel} -> #{path}"
# Check registry for auto-import if windows
# if auto-import fails ask user for path to game exe
# mark app as imported/installed
@tasks.push(Importer.new(app_id, channel, path))
end
def repair(app_id)
puts "Repair Installation Request: #{app_id}"
def settings(app_id, channel)
puts "Settings Request: #{app_id}-#{channel}"
# open wwconfig
end
def uninstall(app_id)
puts "Uninstall Request: #{app_id}"
def repair(app_id, channel)
puts "Repair Installation Request: #{app_id}-#{channel}"
return false if !installed?(app_id, channel) || installing?(app_id, channel)
# verify/download manifests
# verify game files
# verify package cache packages of any files that failed verification
# re/download needed packages
# unpack packages
# install dependencies (e.g. visual C runtime) if appropriate
@tasks.push(Repairer.new(app_id, channel))
end
def show_folder(app_id, type)
def uninstall(app_id, channel)
puts "Uninstall Request: #{app_idchannel}"
return false if !installed?(app_id, channel) || installing?(app_id, channel)
@tasks.push(Uninstaller.new(app_id, channel))
end
def show_folder(app_id, channel, type)
puts "Show Folder Request: #{app_id} -> #{type.inspect}"
case type
@@ -32,13 +73,17 @@ class W3DHub
end
end
def installed?(app_id)
def installed?(app_id, channel)
false
end
def installing?(app_id, channel)
@tasks.find { |t| t.is_a?(Installer) && t.app_id == app_id }
end
# No application tasks are being done
def idle?
true
@tasks.empty?
end
# Whether some operation is in progress

View File

@@ -0,0 +1,145 @@
class W3DHub
class ApplicationManager
class Task
include CyberarmEngine::Common
attr_reader :app_id, :release_channel
def initialize(app_id, release_channel)
@app_id = app_id
@release_channel = release_channel
@task_state = :not_started # :not_started, :running, :paused, :halted, :complete, :failed
@task_steps = []
@task_step_index = 0
@application = window.applications.games.find { |g| g.id == app_id }
@channel = @application.channels.find { |c| c.name == release_channel }
setup
end
def setup
end
def state
@task_state
end
# Start task, inside its own thread
def start
@task_state = :running
Thread.new do
@task_steps.each_with_index do |step, i|
break if @task_state == :halted
@task_step_index = i
success = step.start
failure!(step) unless success
break unless success
end
@task_state = :complete unless @task_state == :failed
end
end
# Suspend operation, if possible
def pause
@task_state = :paused if pauseable?
end
# Halt operation, if possible
def stop
@task_state = :halted if stoppable?
end
def pauseable?
false
end
def stoppable?
false
end
def complete?
@task_state == :complete
end
def failed?
@task_state == :failed
end
def failure_reason
@task_failure_reason || ""
end
def failure!(step)
@task_state = :failed
@task_failure_reason = "Failed to complete: \"#{step.name}\" due to an error: #{step.error}"
end
def run_on_main_thread(block)
window.main_thread_queue << block
end
def add_step(name, method, *args)
@task_steps << Step.new(name, method, args)
end
def fetch_manifests
# Do stuff
package_fetch("games", app_id, "manifest.xml", @channel.version)
end
def package_fetch(category, subcategory, package, version)
end
class Step
attr_reader :name
def initialize(name, method, args)
@name = name
@method = method
@args = args
@step_state = :not_started # :not_started, :running, :paused, :halted, :complete, :failed
@success = false
end
def start
# do work
# ensure that a boolean value is returned
ensure
@success
end
def pause
end
def stop
end
def status
nil
end
def progress
0.0
end
def total_work
1.0
end
# data to pass on to next step(s)
def result
nil
end
end
end
end
end

View File

@@ -0,0 +1,11 @@
class W3DHub
class ApplicationManager
class Importer < Task
def initialize(app_id, channel, path)
super(app_id, channel)
@path = path
end
end
end
end

View File

@@ -0,0 +1,20 @@
class W3DHub
class ApplicationManager
class Installer < Task
def setup
add_step("Fetching manifests...", :fetch_manifests)
add_step("Building package list...", :build_package_list)
add_step("Downloading packages...", :fetch_packages)
add_step("Verifying packages...", :verify_packages)
add_step("Unpacking packages...", :unpack_packages)
add_step("Crushing grapes...", :create_wine_prefix)
add_step("Installing dependencies...", :install_dependencies)
add_step("Completed.", :mark_application_installed)
end
end
end
end

View File

@@ -0,0 +1,6 @@
class W3DHub
class ApplicationManager
class Repairer < Task
end
end
end

View File

@@ -0,0 +1,6 @@
class W3DHub
class ApplicationManager
class Uninstaller < Task
end
end
end

View File

@@ -35,7 +35,7 @@ class W3DHub
# Available to download
stack(width: 1.0, height: 0.8, padding: 8, scroll: true) do
@host.applications.games.reject { |g| g.id == "ren" }.each_with_index do |game, i|
window.applications.games.reject { |g| g.id == "ren" }.each_with_index do |game, i|
flow(width: 1.0, height: 64, padding: 8) do
background 0xff_333333 if i.odd?

View File

@@ -3,7 +3,7 @@ class W3DHub
class Games < Page
def setup
@@game_news ||= {}
@focused_game ||= @host.applications.games.first
@focused_game ||= window.applications.games.first
body.clear do
# Games List
@@ -15,7 +15,7 @@ class W3DHub
end
end
populate_game_page(@host.applications.games.first)
populate_game_page(window.applications.games.first, window.applications.games.first.channels.first)
populate_games_list
end
@@ -23,7 +23,7 @@ class W3DHub
@games_list_container.clear do
background 0xff_121920
@host.applications.games.each do |game|
window.applications.games.each do |game|
selected = game == @focused_game
game_button = stack(width: 1.0, border_thickness_left: 4,
@@ -43,14 +43,14 @@ class W3DHub
end
game_button.subscribe(:clicked_left_mouse_button) do |e|
populate_game_page(game)
populate_game_page(game, game.channels.first)
populate_games_list
end
end
end
end
def populate_game_page(game)
def populate_game_page(game, channel)
@focused_game = game
@game_page_container.clear do
@@ -60,8 +60,11 @@ class W3DHub
flow(width: 1.0, height: 0.03) do
# background 0xff_444411
game.channels.each do |channel|
button "#{channel.name}", text_size: 14, padding_top: 2, padding_bottom: 2, padding_left: 4, padding_right: 4, margin: 0, margin_right: 4
puts "Generating..."
inscription "Channel"
list_box items: game.channels.map { |c| c.name }, selected: channel, enabled: game.channels.count > 1, width: 128, padding_left: 4, padding_top: 2, padding_right: 4, padding_bottom: 2, text_size: 16 do |value|
populate_game_page(game, game.channels.find{ |c| c.name == value })
end
end
@@ -81,16 +84,16 @@ class W3DHub
# end
# end
if window.application_manager.installed?(game.id)
if window.application_manager.installed?(game.id, channel.name)
Hash.new.tap { |hash|
hash["Game Settings"] = { icon: "gear", block: proc { window.application_manager.settings(game.id) } }
hash["Game Settings"] = { icon: "gear", block: proc { window.application_manager.settings(game.id, channel.name) } }
if game.id != "ren"
hash["Repair Installation"] = { icon: "wrench", block: proc { window.application_manager.repair(game.id) } }
hash["Uninstall"] = { icon: "trashCan", block: proc { window.application_manager.uninstall(game.id) } }
hash["Repair Installation"] = { icon: "wrench", block: proc { window.application_manager.repair(game.id, channel.name) } }
hash["Uninstall"] = { icon: "trashCan", block: proc { window.application_manager.uninstall(game.id, channel.name) } }
end
hash["Install Folder"] = { icon: nil, block: proc { window.application_manager.show_folder(game.id, :installation) } }
hash["User Data Folder"] = { icon: nil, block: proc { window.application_manager.show_folder(game.id, :user_data) } }
hash["View Screenshots"] = { icon: nil, block: proc { window.application_manager.show_folder(game.id, :screenshots) } }
hash["Install Folder"] = { icon: nil, block: proc { window.application_manager.show_folder(game.id, channel.name, :installation) } }
hash["User Data Folder"] = { icon: nil, block: proc { window.application_manager.show_folder(game.id, channel.name, :user_data) } }
hash["View Screenshots"] = { icon: nil, block: proc { window.application_manager.show_folder(game.id, channel.name, :screenshots) } }
}.each do |key, hash|
flow(width: 1.0, height: 22, margin_bottom: 8) do
image "#{GAME_ROOT_PATH}/media/ui_icons/#{hash[:icon]}.png", width: 0.11 if hash[:icon]
@@ -128,18 +131,18 @@ class W3DHub
# item.block&.call(game)
# end
# end
if window.application_manager.installed?(game.id)
if window.application_manager.installed?(game.id, channel.id)
button "<b>Play Now</b>", margin_left: 24
button "<b>Single Player</b>", margin_left: 24
else
unless game.id == "ren"
button "<b>Install</b>", margin_left: 24 do
window.application_manager.install(game.id)
window.application_manager.install(game.id, channel.name)
end
end
button "<b>Import</b>", margin_left: 24 do
window.application_manager.import(game.id, "?")
window.application_manager.import(game.id, channel.name, "?")
end
end
end

View File

@@ -42,16 +42,14 @@ class W3DHub
@progressbar.value = @fraction
if @progressbar.value >= 1.0 && @task_index == @tasks.size
push_state(
States::Interface,
account: @account,
service_status: @service_status,
applications: @applications
)
window.account = @account
window.service_status = @service_status
window.applications = @applications
push_state(States::Interface)
end
if @tasks.dig(@tasks.keys[@task_index], :started) == false
p @tasks.keys[@task_index]
@tasks[@tasks.keys[@task_index]][:started] = true
send(:"#{@tasks.keys[@task_index]}")

View File

@@ -2,7 +2,6 @@ class W3DHub
class States
class Interface < CyberarmEngine::GuiState
attr_reader :main_thread_queue
attr_accessor :account, :service_status, :applications
def setup
window.show_cursor = true

View File

@@ -1,6 +1,7 @@
class W3DHub
class Window < CyberarmEngine::Window
attr_reader :settings, :application_manager
attr_accessor :account, :service_status, :applications
def setup
self.caption = "#{W3DHub::NAME}"