From 8d0c27d6fcec834f87d3fac3d91886d2c2292efe Mon Sep 17 00:00:00 2001 From: cyberarm Date: Sun, 19 Jun 2022 18:23:45 -0500 Subject: [PATCH] Initial support for offline mode --- lib/application_manager.rb | 3 +++ lib/pages/games_redesign.rb | 18 +++++++-------- lib/states/boot.rb | 38 ++++++++++++++++++++++++++++++++ lib/states/interface_redesign.rb | 22 +++++++++++++----- 4 files changed, 66 insertions(+), 15 deletions(-) diff --git a/lib/application_manager.rb b/lib/application_manager.rb index 7cf2251..96552b5 100644 --- a/lib/application_manager.rb +++ b/lib/application_manager.rb @@ -259,6 +259,7 @@ class W3DHub installed_version = reg["InstalledVersion"] unless app_id == "ren" application_data = { + name: task.application.name, # FIXME! install_directory: install_path, installed_version: app_id == "ren" ? "1.0.0.0" : installed_version, install_path: exe_path, @@ -286,6 +287,7 @@ class W3DHub def imported!(task, exe_path) application_data = { + name: task.application.name, install_directory: File.dirname(exe_path), installed_version: task.channel.current_version, install_path: exe_path, @@ -305,6 +307,7 @@ class W3DHub install_directory = Cache.install_path(task.application, task.channel) application_data = { + name: task.application.name, install_directory: install_directory, installed_version: task.target_version, install_path: "#{install_directory}/game.exe", diff --git a/lib/pages/games_redesign.rb b/lib/pages/games_redesign.rb index cc21445..b28cff1 100644 --- a/lib/pages/games_redesign.rb +++ b/lib/pages/games_redesign.rb @@ -5,12 +5,10 @@ class W3DHub @game_news ||= {} @game_events ||= {} - # unless Store.offline_mode - @focused_game ||= Store.applications.games.find { |g| g.id == Store.settings[:last_selected_app] } - @focused_game ||= Store.applications.games.find { |g| g.id == "ren" } - @focused_channel ||= @focused_game.channels.find { |c| c.id == Store.settings[:last_selected_channel] } - @focused_channel ||= @focused_game.channels.first - # end + @focused_game ||= Store.applications.games.find { |g| g.id == Store.settings[:last_selected_app] } + @focused_game ||= Store.applications.games.find { |g| g.id == "ren" } + @focused_channel ||= @focused_game.channels.find { |c| c.id == Store.settings[:last_selected_channel] } + @focused_channel ||= @focused_game.channels.first body.clear do stack(width: 1.0, height: 1.0) do @@ -174,10 +172,10 @@ class W3DHub items << { label: I18n.t(:"games.game_settings"), block: proc { Store.application_manager.settings(game.id, channel.id) } } items << { label: I18n.t(:"games.wine_configuration"), block: proc { Store.application_manager.wine_configuration(game.id, channel.id) } } if W3DHub.unix? - items << { label: I18n.t(:"games.game_modifications"), block: proc { populate_game_modifications(game, channel) } } + items << { label: I18n.t(:"games.game_modifications"), block: proc { populate_game_modifications(game, channel) } } unless Store.offline_mode if game.id != "ren" - items << { label: I18n.t(:"games.repair_installation"), block: proc { Store.application_manager.repair(game.id, channel.id) } } - items << { label: I18n.t(:"games.uninstall_game"), block: proc { Store.application_manager.uninstall(game.id, channel.id) } } + items << { label: I18n.t(:"games.repair_installation"), block: proc { Store.application_manager.repair(game.id, channel.id) } } unless Store.offline_mode + items << { label: I18n.t(:"games.uninstall_game"), block: proc { Store.application_manager.uninstall(game.id, channel.id) } } unless Store.offline_mode end # From gui_state_ext.rb @@ -225,6 +223,8 @@ class W3DHub end end + return if Store.offline_mode + unless Cache.net_lock?("game_news_#{game.id}") if @game_events[game.id] populate_game_events(game) diff --git a/lib/states/boot.rb b/lib/states/boot.rb index d5f419a..7ab9ba5 100644 --- a/lib/states/boot.rb +++ b/lib/states/boot.rb @@ -54,6 +54,8 @@ class W3DHub @progressbar.value = @fraction + load_offline_applications_list if @offline_mode + push_state(States::Interface) if @offline_mode || (@progressbar.value >= 1.0 && @task_index == @tasks.size) return if @offline_mode @@ -188,6 +190,42 @@ class W3DHub @tasks[:server_list][:complete] = true end end + + def load_offline_applications_list + hash = { + applications: [] + } + + Store.settings[:games].each do |key, game| + app_id, channel_id = key.to_s.split("_") + + app = hash[:applications].find { |a| a[:id] == app_id } + app_in_array = !app.nil? + app ||= { + id: app_id, + name: game[:name], + type: "", + category: "games", + "studio-id": "", + channels: [], + "web-links": [], + "extended-data": [{ name: "colour", value: "#353535" }] + } + + channel = { + id: channel_id, + name: channel_id, + "user-level": "", + "current-version": game[:installed_version] + } + + app[:channels] << channel + + hash[:applications] << app unless app_in_array + end + + Store.applications = Api::Applications.new(hash.to_json) + end end end end diff --git a/lib/states/interface_redesign.rb b/lib/states/interface_redesign.rb index 1e08cf4..15997cd 100644 --- a/lib/states/interface_redesign.rb +++ b/lib/states/interface_redesign.rb @@ -76,13 +76,23 @@ class W3DHub end @account_container = flow(width: 256, height: 1.0) do - stack(width: 1.0, height: 1.0) do - tagline "#{I18n.t(:"interface.not_logged_in")}", text_wrap: :none + if Store.offline_mode + stack(width: 1.0, height: 1.0) do + flow(fill: true) - flow(width: 1.0) do - link(I18n.t(:"interface.log_in"), text_size: 16, width: 0.5) { page(W3DHub::Pages::Login) } - link I18n.t(:"interface.register"), text_size: 16, width: 0.49 do - Launchy.open("https://secure.w3dhub.com/forum/index.php?app=core&module=global§ion=register") + title "OFFLINE", text_wrap: :none, width: 1.0, text_align: :center + + flow(fill: true) + end + else + stack(width: 1.0, height: 1.0) do + tagline "#{I18n.t(:"interface.not_logged_in")}", text_wrap: :none + + flow(width: 1.0) do + link(I18n.t(:"interface.log_in"), text_size: 16, width: 0.5) { page(W3DHub::Pages::Login) } + link I18n.t(:"interface.register"), text_size: 16, width: 0.49 do + Launchy.open("https://secure.w3dhub.com/forum/index.php?app=core&module=global§ion=register") + end end end end