Compare commits

...

3 Commits

Author SHA1 Message Date
655fc14557 Handle user not having an avatar image 2024-03-04 17:34:55 -06:00
6772d4757f Bump version 2024-03-04 16:36:50 -06:00
3383cbd019 Make import button gooder, explicitly require excon http client 2024-03-04 16:35:52 -06:00
9 changed files with 105 additions and 36 deletions

View File

@@ -1,6 +1,7 @@
source "https://rubygems.org" source "https://rubygems.org"
gem "base64" gem "base64"
gem "excon"
gem "cyberarm_engine" gem "cyberarm_engine"
gem "sdl2-bindings" gem "sdl2-bindings"
gem "digest-crc" gem "digest-crc"

View File

@@ -44,7 +44,7 @@ class W3DHub
# if auto-import fails ask user for path to game exe # if auto-import fails ask user for path to game exe
# mark app as imported/installed # mark app as imported/installed
@tasks.push(Importer.new(app_id, channel)) push_state(W3DHub::States::ImportGameDialog, app_id: app_id, channel: channel)
end end
def settings(app_id, channel) def settings(app_id, channel)
@@ -389,17 +389,19 @@ class W3DHub
false false
end end
def imported!(task, exe_path) def imported!(application, channel, exe_path)
exe_path.gsub!("\\", "/")
application_data = { application_data = {
name: task.application.name, name: application.name,
install_directory: File.dirname(exe_path), install_directory: File.dirname(exe_path),
installed_version: task.channel.current_version, installed_version: channel.current_version,
install_path: exe_path, install_path: exe_path,
wine_prefix: task.wine_prefix wine_prefix: nil
} }
Store.settings[:games] ||= {} Store.settings[:games] ||= {}
Store.settings[:games][:"#{task.app_id}_#{task.release_channel}"] = application_data Store.settings[:games][:"#{application.id}_#{channel.id}"] = application_data
Store.settings.save_settings Store.settings.save_settings
end end

View File

@@ -238,7 +238,8 @@ class W3DHub
@files.delete_if { |f| f.name.casecmp?(file.name) } unless file.patch? @files.delete_if { |f| f.name.casecmp?(file.name) } unless file.patch?
# If file has been recreated in a newer patch, don't delete it; A full file package will exist for it so it will get completely replaced. # If file has been recreated in a newer patch, don't delete it;
# A full file package will exist for it so it will get completely replaced.
@deleted_files.delete_if { |f| f.name.casecmp?(file.name) } @deleted_files.delete_if { |f| f.name.casecmp?(file.name) }
@files.push(file) @files.push(file)

View File

@@ -1,26 +0,0 @@
class W3DHub
class ApplicationManager
class Importer < Task
LOG_TAG = "W3DHub::ApplicationManager::Importer".freeze
def type
:importer
end
def execute_task
path = W3DHub.ask_file
unless File.exist?(path) && !File.directory?(path)
fail!("File #{path.inspect} does not exist or is a directory")
fail_silently! if path.nil? || path&.length&.zero? # User likely canceled the file selection
end
return false if failed?
Store.application_manager.imported!(self, path)
true
end
end
end
end

View File

@@ -104,7 +104,11 @@ class W3DHub
def populate_account_info def populate_account_info
@host.instance_variable_get(:"@account_container").clear do @host.instance_variable_get(:"@account_container").clear do
flow(fill: true, height: 1.0) do flow(fill: true, height: 1.0) do
avatar_image = get_image(Cache.path(Store.account.avatar_uri)) avatar_image = begin
get_image(Cache.path(Store.account.avatar_uri))
rescue
get_image("#{GAME_ROOT_PATH}/media/icons/default_icon.png")
end
mask_image = get_image("#{GAME_ROOT_PATH}/media/textures/circle_mask.png") mask_image = get_image("#{GAME_ROOT_PATH}/media/textures/circle_mask.png")
composite_image = Gosu.render(256, 256) do composite_image = Gosu.render(256, 256) do

View File

@@ -0,0 +1,85 @@
class W3DHub
class States
class ImportGameDialog < CyberarmEngine::GuiState
def setup
@application = Store.applications.games.find { |g| g.id == @options[:app_id] }
@channel = @application.channels.find { |c| c.id == @options[:channel] }
theme W3DHub::THEME
background 0x88_525252
stack(width: 1.0, max_width: 760, height: 1.0, max_height: 268, v_align: :center, h_align: :center, background: 0xee_222222) do
# Title bar
flow(width: 1.0, height: 36, padding: 8) do
background 0x88_000000
# image "#{GAME_ROOT_PATH}/media/ui_icons/export.png", width: 32, align: :center, color: 0xaa_ffffff
# tagline "<b>#{I18n.t(:"server_browser.direct_connect")}</b>", fill: true, text_align: :center
title "Import #{@application.name} (#{@channel.name})", width: 1.0, text_align: :center, font: BOLD_FONT
end
stack(width: 1.0, fill: true, padding_left: 8, padding_right: 8) do
stack(width: 1.0, height: 72) do
para "Path to Executable:"
flow(width: 1.0, fill: true) do
@game_path = edit_line "", fill: true, height: 1.0
button "Browse...", width: 128, height: 1.0, enabled: W3DHub.unix?, tip: W3DHub.unix? ? "Browse for game executable" : "Not available on Windows" do
path = W3DHub.ask_file
@game_path.value = path if !path.empty? && File.exist?(path)
end
end
end
flow(fill: true)
flow(width: 1.0, margin_top: 8, height: 46, padding_bottom: 8) do
button "Cancel", fill: true, margin_right: 4 do
pop_state
end
flow(fill: true)
@save_button = button "Save", fill: true, margin_left: 4, enabled: false do
pop_state
Store.application_manager.imported!(@application, @channel, @game_path.value)
end
end
end
end
end
def draw
previous_state&.draw
Gosu.flush
super
end
def update
super
@save_button.enabled = valid?
end
def button_down(id)
super
case id
when Gosu::KB_ESCAPE
pop_state
end
end
def valid?
path = @game_path.value
File.exist?(path) && !File.directory?(path) && File.extname(path) == ".exe"
end
end
end
end

View File

@@ -1,4 +1,4 @@
class W3DHub class W3DHub
DIR_NAME = "W3DHubAlt" DIR_NAME = "W3DHubAlt"
VERSION = "0.4.0" VERSION = "0.4.1"
end end

View File

@@ -1,6 +1,7 @@
class W3DHub class W3DHub
class Window < CyberarmEngine::Window class Window < CyberarmEngine::Window
def setup def setup
self.show_stats_plotter = false
self.caption = I18n.t(:app_name) self.caption = I18n.t(:app_name)
Store[:server_list] = [] Store[:server_list] = []

View File

@@ -14,6 +14,7 @@ require "logger"
require "time" require "time"
require "base64" require "base64"
require "zip" require "zip"
require "excon"
class W3DHub class W3DHub
W3DHUB_DEBUG = ARGV.join.include?("--debug") W3DHUB_DEBUG = ARGV.join.include?("--debug")
@@ -110,7 +111,6 @@ require_relative "lib/application_manager/tasks/installer"
require_relative "lib/application_manager/tasks/updater" require_relative "lib/application_manager/tasks/updater"
require_relative "lib/application_manager/tasks/uninstaller" require_relative "lib/application_manager/tasks/uninstaller"
require_relative "lib/application_manager/tasks/repairer" require_relative "lib/application_manager/tasks/repairer"
require_relative "lib/application_manager/tasks/importer"
require_relative "lib/states/demo_input_delay" require_relative "lib/states/demo_input_delay"
require_relative "lib/states/boot" require_relative "lib/states/boot"
require_relative "lib/states/interface" require_relative "lib/states/interface"
@@ -121,6 +121,7 @@ require_relative "lib/states/dialogs/prompt_dialog"
require_relative "lib/states/dialogs/confirm_dialog" require_relative "lib/states/dialogs/confirm_dialog"
require_relative "lib/states/dialogs/direct_connect_dialog" require_relative "lib/states/dialogs/direct_connect_dialog"
require_relative "lib/states/dialogs/game_settings_dialog" require_relative "lib/states/dialogs/game_settings_dialog"
require_relative "lib/states/dialogs/import_game_dialog"
require_relative "lib/api" require_relative "lib/api"
require_relative "lib/api/service_status" require_relative "lib/api/service_status"