diff --git a/lib/pages/games.rb b/lib/pages/games.rb index d9b5274..c2b73be 100644 --- a/lib/pages/games.rb +++ b/lib/pages/games.rb @@ -65,7 +65,7 @@ module W3DHubLauncher @game_content_container.clear do flow(fill: true, height: 1.0, scroll: true, tag: :hi_mom) do |e| @games.each do |app| - image safe_get_image("#{ROOT_PATH}/media/co1oqw.png"), aspect_ratio: 3 / 4.0, width: 1.0 / game_cover_width_ratio(e), margin_left: HALF_PADDING, margin_right: HALF_PADDING, margin_bottom: PADDING, tip: app.name + image safe_get_image("#{ROOT_PATH}/media/default_game_cover.png"), aspect_ratio: 3 / 4.0, width: 1.0 / game_cover_width_ratio(e), margin_left: HALF_PADDING, margin_right: HALF_PADDING, margin_bottom: PADDING, tip: app.name end e.subscribe(:size_changed) do |e| @@ -184,7 +184,9 @@ module W3DHubLauncher elsif @current_app.servicable? # pp @current_app button "Import", enabled: false, tip: "Import existing application installation", fill: true, height: 1.0, background_nine_slice: NINE_SLICE_ROUNDED_LEFT, **CTA_BUTTON_THEME - button "Download", tip: "Download and install application", fill: true, height: 1.0, background_nine_slice: NINE_SLICE_ROUNDED_RIGHT, **CTA_BUTTON_THEME + button "Download", tip: "Download and install application", fill: true, height: 1.0, background_nine_slice: NINE_SLICE_ROUNDED_RIGHT, **CTA_BUTTON_THEME do + Worker::Api.install_application(@current_app.id, @current_channel.id) + end else button "Import", enabled: false, tip: "Import existing application installation", fill: true, height: 1.0, **CTA_BUTTON_THEME end diff --git a/lib/worker.rb b/lib/worker.rb index ff6fef0..a378228 100644 --- a/lib/worker.rb +++ b/lib/worker.rb @@ -8,6 +8,8 @@ module W3DHubLauncher Response = Data.define(:status, :request_id, :result) + attr_reader :w3dhub_api + def initialize end @@ -29,6 +31,7 @@ module W3DHubLauncher def init_server @threads = [] @requests = [] + @tasks = [] @client = nil @@ -369,19 +372,32 @@ module W3DHubLauncher deliver_response(response.result, query) end - def install_application(query) + def task_install_application(query) + application = @w3dhub_api.applications.find { |app| app.id == query.data["app_id"] } + channel = application.channels.find { |chan| chan.id == query.data["channel_id"] } + + @tasks << Task::InstallApplication.new( + request_id: query.request_id, + application: application, + channel: channel, + installed_version: nil, + target_version: channel.version + ) + @tasks.last.start(self) + + Response.new(Request::STATUS_PENDING, query.request_id, CyberarmEngine::Result.new(data: true)) end - def update_application(query) + def task_update_application(query) end - def repair_application(query) + def task_repair_application(query) end - def move_application(query) + def task_move_application(query) end - def uninstall_application(query) + def task_uninstall_application(query) end end end diff --git a/lib/worker/api.rb b/lib/worker/api.rb index 8c120fc..f6607a0 100644 --- a/lib/worker/api.rb +++ b/lib/worker/api.rb @@ -65,31 +65,36 @@ module W3DHubLauncher # request installation of application # # periodically reports progress until completion - def self.install_application(app_id, channel_id) + def self.install_application(app_id, channel_id, &block) + Worker::Request.new(:task_install_application, { app_id: app_id, channel_id: channel_id }, &block) end # request update of application # # periodically reports progress until completion - def self.update_application(app_id, channel_id) + def self.update_application(app_id, channel_id, &block) + Worker::Request.new(:task_update_application, { app_id: app_id, channel_id: channel_id }, &block) end # request repair of application # # periodically reports progress until completion - def self.repair_application(app_id, channel_id) + def self.repair_application(app_id, channel_id, &block) + Worker::Request.new(:task_repair_application, { app_id: app_id, channel_id: channel_id }, &block) end # request relocation of application # # periodically reports progress until completion - def self.move_application(app_id, channel_id) + def self.move_application(app_id, channel_id, target_directory, &block) + Worker::Request.new(:task_move_application, { app_id: app_id, channel_id: channel_id, target_directory: target_directory }, &block) end # request removal of application # # periodically reports progress until completion - def self.uninstall_application(app_id, channel_id) + def self.uninstall_application(app_id, channel_id, &block) + Worker::Request.new(:task_uninstall_application, { app_id: app_id, channel_id: channel_id }, &block) end end end diff --git a/lib/worker/task.rb b/lib/worker/task.rb index 9f16fa5..2977b4f 100644 --- a/lib/worker/task.rb +++ b/lib/worker/task.rb @@ -1,4 +1,84 @@ module W3DHubLauncher class Task + attr_reader :request_id, :application, :channel, :installed_version, :target_version + + def initialize(request_id:, application:, channel:, installed_version:, target_version:) + @request_id = request_id + @application = application + @channel = channel + @installed_version = installed_version + @target_version = target_version + + pp self + + setup + end + + def setup + end + + def start(worker) + @worker = worker + + execute + end + + def fetch_manifests(version = @target_version) + result = fetch_manifest(version) + if result.okay? + pp result + else + pp [:error, result] + end + end + + def fetch_manifest(version) + @worker.w3dhub_api.fetch_package_details([{category: "games", subcategory: @application.id, name: "manifest.xml", version: version }]) + end end end + +def execute_task + show_application_taskbar + + fail_fast + return false if failed? + + fetch_manifests + return false if failed? + + build_package_list + return false if failed? + + remove_deleted_files + return false if failed? + + verify_files + return false if failed? + + fetch_packages + return false if failed? + + verify_packages + return false if failed? + + unpack_packages + return false if failed? + + create_wine_prefix + return false if failed? + + install_dependencies + return false if failed? + + write_paths_ini + return false if failed? + + mark_application_installed + return false if failed? + + sleep 1 + hide_application_taskbar + + true +end diff --git a/lib/worker/tasks/install_application.rb b/lib/worker/tasks/install_application.rb index e69de29..9f359e1 100644 --- a/lib/worker/tasks/install_application.rb +++ b/lib/worker/tasks/install_application.rb @@ -0,0 +1,26 @@ +module W3DHubLauncher + class Task + class InstallApplication < Task + def setup + end + + def execute + # TODO: + # fail_fast + + # fetch manifests for currently installed version + # AND the target version so we can detect files that need to be removed + # between versions + manifests_result = fetch_manifests + abort_task!(manifests_result) unless manifests_result.okay? + + package_list_result = build_package_list(manifests_result) + abort_task!(package_list_result) unless package_list_result.okay? + + # remove_deleted_files + + verify_files + end + end + end +end diff --git a/lib/worker/w3dhub_api.rb b/lib/worker/w3dhub_api.rb index 52d3e7f..0b15d94 100644 --- a/lib/worker/w3dhub_api.rb +++ b/lib/worker/w3dhub_api.rb @@ -6,9 +6,13 @@ module W3DHubLauncher PRIMARY_W3DHUB_API_ENDPOINT = "https://secure.w3dhub.com".freeze ALTERNATIVE_W3DHUB_API_ENDPOINT = "https://backend.w3d.cyberarm.dev".freeze + attr_reader :applications + def initialize @access_token = nil + @applications = [] + @http_clients = {} end @@ -33,7 +37,7 @@ module W3DHubLauncher Sync do |task| task.with_timeout(API_TIMEOUT) do Async::HTTP::Internet.send(method, url, headers, body) do |response| - # pp [method, url, headers, body] + pp [method, url, headers, body, response] if response.success? result.data = response.read else @@ -104,23 +108,31 @@ module W3DHubLauncher primary_result = @access_token ? fetch("#{PRIMARY_W3DHUB_API_ENDPOINT}/apis/launcher/1/get-applications") : CyberarmEngine::Result.new(error: true) alternate_result = fetch("#{ALTERNATIVE_W3DHUB_API_ENDPOINT}/apis/launcher/1/get-applications") + single_source = false + # We've failed to retrieve data if primary_result.error? && alternate_result.error? return result # We've only gotten data back from the primary backend elsif primary_result.okay? && alternate_result.error? result.data = primary_result.data - return result + single_source = true # We've only gotten data back from the alternate backend elsif primary_result.error? && alternate_result.okay? result.data = alternate_result.data - return result + single_source = true end - # We've gotten data back from both backends, merge them. - # pp [primary_result, alternate_result] + unless single_source + puts "FIXME: merge applications source" + # We've gotten data back from both backends, merge them. + # pp [primary_result, alternate_result] + + # FIXME: Merge primary and alternate results + end + + @applications = JSON.parse(result.data)["applications"]&.map { |app| W3DHubLauncher::Worker::Api::Application.new(app) } || [] - # FIXME: Merge primary and alternate results result end @@ -140,15 +152,12 @@ module W3DHubLauncher result = CyberarmEngine::Result.new end - def fetch_manifests() - result = CyberarmEngine::Result.new + def fetch_package_details(packages) + body = URI.encode_www_form("data": JSON.dump({ packages: packages })) + fetch("#{@access_token ? PRIMARY_W3DHUB_API_ENDPOINT : ALTERNATIVE_W3DHUB_API_ENDPOINT}/apis/launcher/1/get-package-details", method: :post, body: body, headers: headers(form_encoded: true)) end - def fetch_package_details() - result = CyberarmEngine::Result.new - end - - def fetch_package() + def download_package() download() end end diff --git a/media/game_cover.png b/media/default_game_cover.png similarity index 100% rename from media/game_cover.png rename to media/default_game_cover.png diff --git a/media/default_map_preview.png b/media/default_map_preview.png new file mode 100644 index 0000000..a15a2d8 Binary files /dev/null and b/media/default_map_preview.png differ