Compare commits

..

6 Commits

11 changed files with 106 additions and 29 deletions

View File

@@ -4,15 +4,15 @@ gem "base64"
gem "excon" gem "excon"
gem "cyberarm_engine" gem "cyberarm_engine"
gem "sdl2-bindings" gem "sdl2-bindings"
gem "libui" gem "libui", platforms: [:windows]
gem "digest-crc" gem "digest-crc"
gem "i18n" gem "i18n"
gem "ircparser" gem "ircparser"
gem "rexml" gem "rexml"
gem "rubyzip" gem "rubyzip"
gem "websocket-client-simple" gem "websocket-client-simple"
gem "win32-process", platforms: [:x64_mingw, :mingw] gem "win32-process", platforms: [:windows]
gem "win32-security", platforms: [:x64_mingw, :mingw] gem "win32-security", platforms: [:windows]
# PACKAGING NOTES # PACKAGING NOTES
# bundler 2.5.x doesn't seem to play nice with ocra[n] # bundler 2.5.x doesn't seem to play nice with ocra[n]

View File

@@ -10,10 +10,11 @@ GEM
event_emitter (0.2.6) event_emitter (0.2.6)
excon (0.109.0) excon (0.109.0)
ffi (1.16.3) ffi (1.16.3)
ffi (1.16.3-x64-mingw-ucrt)
ffi-win32-extensions (1.0.4) ffi-win32-extensions (1.0.4)
ffi ffi
gosu (1.4.6) gosu (1.4.6)
i18n (1.14.1) i18n (1.14.4)
concurrent-ruby (~> 1.0) concurrent-ruby (~> 1.0)
ircparser (1.0.0) ircparser (1.0.0)
libui (0.0.15) libui (0.0.15)
@@ -34,6 +35,7 @@ GEM
PLATFORMS PLATFORMS
x64-mingw-ucrt x64-mingw-ucrt
x86_64-linux
DEPENDENCIES DEPENDENCIES
base64 base64

View File

@@ -1,6 +1,8 @@
class W3DHub class W3DHub
class Api class Api
class Applications class Applications
attr_reader :data
def initialize(response) def initialize(response)
@data = JSON.parse(response, symbolize_names: true) @data = JSON.parse(response, symbolize_names: true)
@@ -35,10 +37,11 @@ class W3DHub
color = @data[:"extended-data"].find { |h| h[:name] == "colour" }[:value].sub("#", "") color = @data[:"extended-data"].find { |h| h[:name] == "colour" }[:value].sub("#", "")
color = color.sub("ff", "") if color.length == 8
@color = "ff#{color}".to_i(16) @color = "ff#{color}".to_i(16)
cfg = @data[:"extended-data"].find { |h| h[:name] == "usesEngineCfg" } cfg = @data[:"extended-data"].find { |h| h[:name] == "usesEngineCfg" }
@uses_engine_cfg = (cfg && cfg[:value].downcase.strip == "true") == true # explicit truthy compare to prevent return `nil` @uses_engine_cfg = (cfg && cfg[:value].to_s.downcase.strip == "true") == true # explicit truthy compare to prevent return `nil`
end end
def uses_engine_cfg? def uses_engine_cfg?

View File

@@ -147,16 +147,56 @@ class W3DHub
end end
def self.ask_file(title: "Open File", filter: "*game*.exe") def self.ask_file(title: "Open File", filter: "*game*.exe")
if W3DHub.unix?
# search for command
cmds = %w{ zenity matedialog qarma kdialog }
command = cmds.find do |cmd|
cmd if system("which #{cmd}")
end
path = case File.basename(command)
when "zenity", "matedialog", "qarma"
`#{command} --file-selection --title "#{title}" --file-filter "#{filter}"`
when "kdialog"
`#{command} --title "#{title}" --getopenfilename . "#{filter}"`
else
raise "No known command found for system file selection dialog!"
end
path.strip
else
result_ptr = LibUI.open_file(LIBUI_WINDOW) result_ptr = LibUI.open_file(LIBUI_WINDOW)
result = result_ptr.null? ? "" : result_ptr.to_s.gsub("\\", "/") result = result_ptr.null? ? "" : result_ptr.to_s.gsub("\\", "/")
result result.strip
end
end end
def self.ask_folder(title: "Open Folder") def self.ask_folder(title: "Open Folder")
result_ptr = LibUI.open_folder(window) if W3DHub.unix?
result = result_ptr.null? ? "" : result_ptr.to_s.gsub("\\", "/") # search for command
cmds = %w{ zenity matedialog qarma kdialog }
result command = cmds.find do |cmd|
cmd if system("which #{cmd}")
end
path = case File.basename(command)
when "zenity", "matedialog", "qarma"
`#{command} --file-selection --directory --title "#{title}"`
when "kdialog"
`#{command} --title "#{title}" --getexistingdirectory #{Dir.home}"`
else
raise "No known command found for system file selection dialog!"
end
path.strip
else
result_ptr = LibUI.open_folder(window)
result = result_ptr.null? ? "" : result_ptr.to_s.gsub("\\", "/")
result.strip
end
end end
end end

View File

@@ -232,8 +232,10 @@ class W3DHub
end end
unless Store.offline_mode unless Store.offline_mode
menu_item(I18n.t(:"games.game_modifications")) do if W3DHUB_DEVELOPER
populate_game_modifications(game, channel) menu_item(I18n.t(:"games.game_modifications")) do
populate_game_modifications(game, channel)
end
end end
if game.id != "ren" if game.id != "ren"

View File

@@ -102,6 +102,8 @@ class W3DHub
end end
def populate_account_info def populate_account_info
return if Store.offline_mode
@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 = begin avatar_image = begin

View File

@@ -438,8 +438,8 @@ class W3DHub
end end
if W3DHUB_DEVELOPER if W3DHUB_DEVELOPER
list_box(items: (1..12).to_a.map(&:to_s), margin_left: 16, width: 72, tip: "Number of game clients", **TESTING_BUTTON) list_box(items: (1..12).to_a.map(&:to_s), margin_left: 16, width: 72, tip: "Number of game clients", enabled: (game_installed && !game_updatable), **TESTING_BUTTON)
button "Multijoin", tip: "Launch multiple clients with configured username_\#{number}", **TESTING_BUTTON, enabled: true button "Multijoin", tip: "Launch multiple clients with configured username_\#{number}", enabled: (game_installed && !game_updatable), **TESTING_BUTTON
end end
flow(fill: true) flow(fill: true)

View File

@@ -71,5 +71,15 @@ class W3DHub
def save_settings def save_settings
File.write(SETTINGS_FILE_PATH, @settings.to_json) File.write(SETTINGS_FILE_PATH, @settings.to_json)
end end
def save_application_cache(json)
File.write(APPLICATIONS_CACHE_FILE_PATH, json)
end
def load_application_cache
JSON.parse(File.read(APPLICATIONS_CACHE_FILE_PATH), symbolize_names: true)
rescue
nil
end
end end
end end

View File

@@ -29,8 +29,8 @@ class W3DHub
stack(width: 1.0, height: 60) do stack(width: 1.0, height: 60) do
flow(width: 1.0, height: 26, margin_left: 16, margin_right: 16, margin_bottom: 8, margin_top: 8) do flow(width: 1.0, height: 26, margin_left: 16, margin_right: 16, margin_bottom: 8, margin_top: 8) do
@status_label = caption "Starting #{I18n.t(:app_name_simple)}...", width: 0.5 @status_label = caption "Starting #{I18n.t(:app_name_simple)}...", fill: true
para "#{I18n.t(:app_name)} #{W3DHub::VERSION}", width: 0.5, text_align: :right para "#{I18n.t(:app_name)} #{W3DHub::VERSION}", text_align: :right
end end
@progressbar = progress height: 4, width: 1.0, margin_left: 16, margin_right: 16, margin_bottom: 8 @progressbar = progress height: 4, width: 1.0, margin_left: 16, margin_right: 16, margin_bottom: 8
@@ -52,7 +52,16 @@ class W3DHub
@progressbar.value = @fraction @progressbar.value = @fraction
load_offline_applications_list if @offline_mode if @offline_mode
load_offline_applications_list
unless Store.applications
@progressbar.value = 0.0
@status_label.value = "<c=f80>Unable to connect to W3D Hub API. No application data cached, unable to continue.</c>"
return
end
end
if @offline_mode || (@progressbar.value >= 1.0 && @task_index == @tasks.size) if @offline_mode || (@progressbar.value >= 1.0 && @task_index == @tasks.size)
pop_state pop_state
@@ -65,7 +74,7 @@ class W3DHub
application = Store.applications.games.find { |g| g.id == key.to_s.split("_", 2).first } application = Store.applications.games.find { |g| g.id == key.to_s.split("_", 2).first }
next unless application next unless application
game[:colour] = application.color game[:colour] = "##{application.color.to_s(16)}"
game[:uses_engine_cfg] = application.uses_engine_cfg? game[:uses_engine_cfg] = application.uses_engine_cfg?
end end
end end
@@ -156,7 +165,7 @@ class W3DHub
Api.on_thread(:applications) do |applications| Api.on_thread(:applications) do |applications|
if applications if applications
Store.applications = applications Store.applications = applications
Store.settings.save_application_cache(applications.data.to_json)
@tasks[:applications][:complete] = true @tasks[:applications][:complete] = true
else else
# FIXME: Failed to retreive! # FIXME: Failed to retreive!
@@ -227,6 +236,12 @@ class W3DHub
end end
def load_offline_applications_list def load_offline_applications_list
if (application_cache = Store.settings.load_application_cache)
Store.applications = Api::Applications.new(application_cache.to_json)
return
end
hash = { hash = {
applications: [] applications: []
} }

View File

@@ -1,4 +1,4 @@
class W3DHub class W3DHub
DIR_NAME = "W3DHubAlt" DIR_NAME = "W3DHubAlt"
VERSION = "0.4.2" VERSION = "0.5.1"
end end

View File

@@ -23,6 +23,7 @@ class W3DHub
GAME_ROOT_PATH = File.expand_path(".", __dir__) GAME_ROOT_PATH = File.expand_path(".", __dir__)
CACHE_PATH = "#{GAME_ROOT_PATH}/data/cache" CACHE_PATH = "#{GAME_ROOT_PATH}/data/cache"
SETTINGS_FILE_PATH = "#{GAME_ROOT_PATH}/data/settings.json" SETTINGS_FILE_PATH = "#{GAME_ROOT_PATH}/data/settings.json"
APPLICATIONS_CACHE_FILE_PATH = "#{GAME_ROOT_PATH}/data/applications_cache.json"
LOGGER = Logger.new("#{GAME_ROOT_PATH}/data/logs/w3d_hub_linux_launcher.log", "daily") LOGGER = Logger.new("#{GAME_ROOT_PATH}/data/logs/w3d_hub_linux_launcher.log", "daily")
LOGGER.level = Logger::Severity::DEBUG # W3DHUB_DEBUG ? Logger::Severity::DEBUG : Logger::Severity::WARN LOGGER.level = Logger::Severity::DEBUG # W3DHUB_DEBUG ? Logger::Severity::DEBUG : Logger::Severity::WARN
@@ -80,15 +81,6 @@ require "i18n"
require "websocket-client-simple" require "websocket-client-simple"
require "English" require "English"
require "sdl2" require "sdl2"
require "libui"
# Using a WHOLE ui library for: native file/folder open dialogs...
LibUI.init
LIBUI_WINDOW = LibUI.new_window("", 100, 100, 0)
at_exit do
LibUI.control_destroy(LIBUI_WINDOW)
LibUI.uninit
end
I18n.load_path << Dir["#{W3DHub::GAME_ROOT_PATH}/locales/*.yml"] I18n.load_path << Dir["#{W3DHub::GAME_ROOT_PATH}/locales/*.yml"]
I18n.default_locale = :en I18n.default_locale = :en
@@ -158,7 +150,18 @@ require_relative "lib/asterisk/states/game_form"
require_relative "lib/asterisk/states/irc_profile_form" require_relative "lib/asterisk/states/irc_profile_form"
require_relative "lib/asterisk/states/server_profile_form" require_relative "lib/asterisk/states/server_profile_form"
require "win32/process" if W3DHub.windows? if W3DHub.windows?
require "libui"
require "win32/process"
# Using a WHOLE ui library for: native file/folder open dialogs...
LibUI.init
LIBUI_WINDOW = LibUI.new_window("", 100, 100, 0)
at_exit do
LibUI.control_destroy(LIBUI_WINDOW)
LibUI.uninit
end
end
logger.info(W3DHub::LOG_TAG) { "W3D Hub Linux Launcher v#{W3DHub::VERSION}" } logger.info(W3DHub::LOG_TAG) { "W3D Hub Linux Launcher v#{W3DHub::VERSION}" }