mirror of
https://github.com/cyberarm/w3d_hub_linux_launcher.git
synced 2025-12-16 17:22:35 +00:00
Compare commits
2 Commits
7da254fd61
...
610bee05eb
| Author | SHA1 | Date | |
|---|---|---|---|
| 610bee05eb | |||
| e3cb9805fe |
@@ -9,7 +9,7 @@ class W3DHub
|
|||||||
@games = []
|
@games = []
|
||||||
|
|
||||||
games.each { |hash| @games << Game.new(hash) }
|
games.each { |hash| @games << Game.new(hash) }
|
||||||
@games.sort_by! { |a| a.slot }.reverse
|
@games.sort_by! { |a| a.name }.reverse
|
||||||
end
|
end
|
||||||
|
|
||||||
def games
|
def games
|
||||||
@@ -17,13 +17,11 @@ class W3DHub
|
|||||||
end
|
end
|
||||||
|
|
||||||
class Game
|
class Game
|
||||||
attr_reader :slot, :id, :name, :type, :category, :studio_id, :channels, :web_links, :color
|
attr_reader :id, :name, :type, :category, :studio_id, :channels, :web_links, :color
|
||||||
|
|
||||||
def initialize(hash)
|
def initialize(hash)
|
||||||
@data = hash
|
@data = hash
|
||||||
|
|
||||||
@slot = slot_index(@data[:id])
|
|
||||||
|
|
||||||
@id = @data[:id]
|
@id = @data[:id]
|
||||||
@name = @data[:name]
|
@name = @data[:name]
|
||||||
@type = @data[:type]
|
@type = @data[:type]
|
||||||
@@ -40,23 +38,6 @@ class W3DHub
|
|||||||
@color = "ff#{color}".to_i(16)
|
@color = "ff#{color}".to_i(16)
|
||||||
end
|
end
|
||||||
|
|
||||||
private def slot_index(app_id)
|
|
||||||
case app_id
|
|
||||||
when "ren"
|
|
||||||
1
|
|
||||||
when "ecw"
|
|
||||||
2
|
|
||||||
when "ia"
|
|
||||||
3
|
|
||||||
when "apb"
|
|
||||||
4
|
|
||||||
when "tsr"
|
|
||||||
5
|
|
||||||
else
|
|
||||||
-10
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
class Channel
|
class Channel
|
||||||
attr_reader :id, :name, :user_level, :current_version
|
attr_reader :id, :name, :user_level, :current_version
|
||||||
|
|
||||||
|
|||||||
@@ -52,8 +52,15 @@ class W3DHub
|
|||||||
# open wwconfig.exe or config.exe for ecw
|
# open wwconfig.exe or config.exe for ecw
|
||||||
|
|
||||||
if (app_data = installed?(app_id, channel))
|
if (app_data = installed?(app_id, channel))
|
||||||
config_exe = app_id == "ecw" ? "config.exe" : "wwconfig.exe"
|
exe = if File.exist?("#{app_data[:install_directory]}/wwconfig.exe")
|
||||||
exe = "#{app_data[:install_directory]}/#{config_exe}"
|
"#{app_data[:install_directory]}/wwconfig.exe"
|
||||||
|
|
||||||
|
elsif File.exist?("#{app_data[:install_directory]}/WWConfig.exe")
|
||||||
|
"#{app_data[:install_directory]}/WWConfig.exe"
|
||||||
|
|
||||||
|
elsif File.exist?("#{app_data[:install_directory]}/config.exe")
|
||||||
|
"#{app_data[:install_directory]}/config.exe"
|
||||||
|
end
|
||||||
|
|
||||||
if File.exist?(exe)
|
if File.exist?(exe)
|
||||||
pid = Process.spawn("#{wine_command(app_id, channel)}\"#{exe}\"")
|
pid = Process.spawn("#{wine_command(app_id, channel)}\"#{exe}\"")
|
||||||
|
|||||||
@@ -115,10 +115,13 @@ class W3DHub
|
|||||||
|
|
||||||
# Quick checks before network and computational work starts
|
# Quick checks before network and computational work starts
|
||||||
def fail_fast
|
def fail_fast
|
||||||
|
# Have enough disk space
|
||||||
|
|
||||||
# tar present?
|
# tar present?
|
||||||
bsdtar_present = system("#{W3DHub.tar_command} --help")
|
bsdtar_present = system("#{W3DHub.tar_command} --help")
|
||||||
fail!("FAIL FAST: `#{W3DHub.tar_command} --help` command failed, #{W3DHub.tar_command} is not installed. Will be unable to unpack packages.") unless bsdtar_present
|
fail!("FAIL FAST: `#{W3DHub.tar_command} --help` command failed, #{W3DHub.tar_command} is not installed. Will be unable to unpack packages.") unless bsdtar_present
|
||||||
|
|
||||||
|
# Wine present?
|
||||||
if W3DHub.unix?
|
if W3DHub.unix?
|
||||||
wine_present = system("which #{Store.settings[:wine_command]}")
|
wine_present = system("which #{Store.settings[:wine_command]}")
|
||||||
fail!("FAIL FAST: `which #{Store.settings[:wine_command]}` command failed, wine is not installed. Will be unable to create prefixes or launch games.") unless wine_present
|
fail!("FAIL FAST: `which #{Store.settings[:wine_command]}` command failed, wine is not installed. Will be unable to create prefixes or launch games.") unless wine_present
|
||||||
|
|||||||
90
lib/ico.rb
Normal file
90
lib/ico.rb
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
require "stringio"
|
||||||
|
|
||||||
|
class W3DHub
|
||||||
|
class ICO
|
||||||
|
IconDirectory = Struct.new(:reserved, :type, :image_count)
|
||||||
|
|
||||||
|
IconDirectoryEntity = Struct.new(
|
||||||
|
:width,
|
||||||
|
:height,
|
||||||
|
:palette_size,
|
||||||
|
:reserved,
|
||||||
|
:color_planes,
|
||||||
|
:bit_depth,
|
||||||
|
:image_size,
|
||||||
|
:image_offset
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def initialize(file:)
|
||||||
|
@file = StringIO.new(File.binread(file))
|
||||||
|
|
||||||
|
@images = []
|
||||||
|
|
||||||
|
parse
|
||||||
|
end
|
||||||
|
|
||||||
|
def directory
|
||||||
|
@icon_directory
|
||||||
|
end
|
||||||
|
|
||||||
|
def images
|
||||||
|
@images
|
||||||
|
end
|
||||||
|
|
||||||
|
# SEE: https://en.wikipedia.org/wiki/ICO_(file_format)
|
||||||
|
def parse
|
||||||
|
# Parse IconDirectory
|
||||||
|
@icon_directory = IconDirectory.new(
|
||||||
|
read_u16, read_u16, read_u16
|
||||||
|
)
|
||||||
|
|
||||||
|
@icon_directory.image_count.times do
|
||||||
|
@images << IconDirectoryEntity.new(
|
||||||
|
read_u8,
|
||||||
|
read_u8,
|
||||||
|
read_u8,
|
||||||
|
read_u8,
|
||||||
|
read_u16,
|
||||||
|
read_u16,
|
||||||
|
read_u32,
|
||||||
|
read_u32
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def read_u8
|
||||||
|
@file.read(1).unpack1("C")
|
||||||
|
end
|
||||||
|
|
||||||
|
def read_u16
|
||||||
|
@file.read(2).unpack1("v")
|
||||||
|
end
|
||||||
|
|
||||||
|
def read_u32
|
||||||
|
@file.read(4).unpack1("V")
|
||||||
|
end
|
||||||
|
|
||||||
|
def to_rgba32_blob(image)
|
||||||
|
@file.pos = image.image_offset
|
||||||
|
buf = @file.read(image.image_size)
|
||||||
|
|
||||||
|
File.write("TEMP.bmp", buf)
|
||||||
|
end
|
||||||
|
|
||||||
|
def select_pngs
|
||||||
|
@images.select do |image|
|
||||||
|
@file.pos = image.image_offset
|
||||||
|
buf = @file.read(8).unpack1("a*")
|
||||||
|
buf == "\211PNG\r\n\032\n".force_encoding("ASCII-8BIT")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def select_bmps
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
data = W3DHub::ICO.new(file: "/home/cyberarm/Downloads/icos/ar.ico")
|
||||||
|
pp data.select_pngs.size, data.images.size
|
||||||
|
# data.to_rgba32_blob(data.images.first)
|
||||||
@@ -28,7 +28,7 @@ class W3DHub
|
|||||||
background task.application.color
|
background task.application.color
|
||||||
|
|
||||||
flow(width: 0.70, height: 1.0) do
|
flow(width: 0.70, height: 1.0) do
|
||||||
image_path = File.exist?("#{GAME_ROOT_PATH}/media/icons/#{task.app_id}.png") ? "#{GAME_ROOT_PATH}/media/icons/#{task.app_id}.png" : "#{GAME_ROOT_PATH}/media/icons/app.png"
|
image_path = File.exist?("#{GAME_ROOT_PATH}/media/icons/#{task.app_id}.png") ? "#{GAME_ROOT_PATH}/media/icons/#{task.app_id}.png" : "#{GAME_ROOT_PATH}/media/ui_icons/question.png"
|
||||||
@application_image = image image_path, height: 1.0
|
@application_image = image image_path, height: 1.0
|
||||||
|
|
||||||
stack(margin_left: 8, width: 0.75) do
|
stack(margin_left: 8, width: 0.75) do
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ class W3DHub
|
|||||||
image "#{GAME_ROOT_PATH}/media/ui_icons/return.png", width: 1.0, color: Gosu::Color::GRAY if Store.application_manager.updateable?(game.id, game.channels.first.id)
|
image "#{GAME_ROOT_PATH}/media/ui_icons/return.png", width: 1.0, color: Gosu::Color::GRAY if Store.application_manager.updateable?(game.id, game.channels.first.id)
|
||||||
image "#{GAME_ROOT_PATH}/media/ui_icons/import.png", width: 0.5, color: 0x88_ffffff unless Store.application_manager.installed?(game.id, game.channels.first.id)
|
image "#{GAME_ROOT_PATH}/media/ui_icons/import.png", width: 0.5, color: 0x88_ffffff unless Store.application_manager.installed?(game.id, game.channels.first.id)
|
||||||
end
|
end
|
||||||
image_path = File.exist?("#{GAME_ROOT_PATH}/media/icons/#{game.id}.png") ? "#{GAME_ROOT_PATH}/media/icons/#{game.id}.png" : "#{GAME_ROOT_PATH}/media/icons/app.png"
|
image_path = File.exist?("#{GAME_ROOT_PATH}/media/icons/#{game.id}.png") ? "#{GAME_ROOT_PATH}/media/icons/#{game.id}.png" : "#{GAME_ROOT_PATH}/media/ui_icons/question.png"
|
||||||
|
|
||||||
image image_path, height: 48, color: Store.application_manager.installed?(game.id, game.channels.first.id) ? 0xff_ffffff : 0x88_ffffff
|
image image_path, height: 48, color: Store.application_manager.installed?(game.id, game.channels.first.id) ? 0xff_ffffff : 0x88_ffffff
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ class W3DHub
|
|||||||
@filters.each do |app_id, enabled|
|
@filters.each do |app_id, enabled|
|
||||||
app = Store.applications.games.find { |a| a.id == app_id.to_s }
|
app = Store.applications.games.find { |a| a.id == app_id.to_s }
|
||||||
|
|
||||||
image_path = File.exist?("#{GAME_ROOT_PATH}/media/icons/#{app_id}.png") ? "#{GAME_ROOT_PATH}/media/icons/#{app_id}.png" : "#{GAME_ROOT_PATH}/media/icons/app.png"
|
image_path = File.exist?("#{GAME_ROOT_PATH}/media/icons/#{app_id}.png") ? "#{GAME_ROOT_PATH}/media/icons/#{app_id}.png" : "#{GAME_ROOT_PATH}/media/ui_icons/question.png"
|
||||||
|
|
||||||
image image_path, tip: "#{app.name}", height: 1.0,
|
image image_path, tip: "#{app.name}", height: 1.0,
|
||||||
border_thickness_bottom: 1, border_color_bottom: 0x00_000000,
|
border_thickness_bottom: 1, border_color_bottom: 0x00_000000,
|
||||||
@@ -361,7 +361,7 @@ class W3DHub
|
|||||||
end
|
end
|
||||||
|
|
||||||
def game_icon(server)
|
def game_icon(server)
|
||||||
image_path = File.exist?("#{GAME_ROOT_PATH}/media/icons/#{server.game.nil? ? 'ren' : server.game}.png") ? "#{GAME_ROOT_PATH}/media/icons/#{server.game.nil? ? 'ren' : server.game}.png" : "#{GAME_ROOT_PATH}/media/icons/app.png"
|
image_path = File.exist?("#{GAME_ROOT_PATH}/media/icons/#{server.game.nil? ? 'ren' : server.game}.png") ? "#{GAME_ROOT_PATH}/media/icons/#{server.game.nil? ? 'ren' : server.game}.png" : "#{GAME_ROOT_PATH}/media/ui_icons/question.png"
|
||||||
|
|
||||||
if server.status.password
|
if server.status.password
|
||||||
@server_locked_icons[server.game] ||= Gosu.render(96, 96) do
|
@server_locked_icons[server.game] ||= Gosu.render(96, 96) do
|
||||||
|
|||||||
@@ -63,7 +63,8 @@ class W3DHub
|
|||||||
if Store.settings[:account, :data]
|
if Store.settings[:account, :data]
|
||||||
account = Api::Account.new(Store.settings[:account, :data], {})
|
account = Api::Account.new(Store.settings[:account, :data], {})
|
||||||
|
|
||||||
if (Time.now.to_i - account.access_token_expiry.to_i) >= 60 * 3 # Older than 3 hours then refresh
|
if (account.access_token_expiry - Time.now) / 60 <= 60 * 3 # Refresh if token expires within 3 hours
|
||||||
|
puts "Refreshing user login..."
|
||||||
@account = Api.refresh_user_login(account.refresh_token)
|
@account = Api.refresh_user_login(account.refresh_token)
|
||||||
else
|
else
|
||||||
@account = account
|
@account = account
|
||||||
|
|||||||
Reference in New Issue
Block a user