diff --git a/Gemfile b/Gemfile index a44c375..c3cb479 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,7 @@ source "https://rubygems.org" gem "cyberarm_engine" +gem "sdl2-bindings" gem "digest-crc" gem "i18n" gem "ircparser" diff --git a/Gemfile.lock b/Gemfile.lock index 84ca054..eaa2669 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -21,6 +21,8 @@ GEM rake (13.1.0) rexml (3.2.6) rubyzip (2.3.2) + sdl2-bindings (0.2.2) + ffi (~> 1.15) websocket (1.2.10) websocket-client-simple (0.8.0) event_emitter @@ -43,6 +45,7 @@ DEPENDENCIES ircparser rexml rubyzip + sdl2-bindings websocket-client-simple win32-process win32-security diff --git a/lib/hardware_survey.rb b/lib/hardware_survey.rb index 4ed83bf..e4f990a 100644 --- a/lib/hardware_survey.rb +++ b/lib/hardware_survey.rb @@ -6,8 +6,19 @@ class W3DHub @data = { displays: [], system: { - motherboard: {}, - operating_system: {}, + motherboard: { + manufacturer: "Unknown", + model: "Unknown", + bios_vendor: "Unknown", + bios_release_date: "Unknown", + bios_version: "Unknown" + }, + operating_system: { + name: "Unknown", + build: "Unknown", + version: "Unknown", + edition: "Unknown" + }, cpus: [], cpu_instruction_sets: {}, ram: 0, @@ -16,12 +27,13 @@ class W3DHub } # Hardware survey only works on Windows atm - return unless RbConfig::CONFIG["host_os"] =~ /mswin|msys|mingw|cygwin/ - lib_dir = File.dirname($LOADED_FEATURES.find { |file| file.include?("gosu.so") }) - SDL.load_lib("#{lib_dir}64/SDL2.dll") - # Gosu already handles this - # SDL.VideoInit(nil) + if Gem::win_platform? + lib_dir = File.dirname($LOADED_FEATURES.find { |file| file.include?("gosu.so") }) + SDL.load_lib("#{lib_dir}64/SDL2.dll") + else + SDL.load_lib("libSDL2") + end query_displays query_motherboard @@ -56,6 +68,8 @@ class W3DHub end def query_motherboard + return unless Gem::win_platform? + Win32::Registry::HKEY_LOCAL_MACHINE.open("HARDWARE\\DESCRIPTION\\System\\BIOS", Win32::Registry::KEY_READ) do |reg| @data[:system][:motherboard][:manufacturer] = safe_reg(reg, "SystemManufacturer") @data[:system][:motherboard][:model] = safe_reg(reg, "SystemProductName") @@ -72,6 +86,8 @@ class W3DHub end def query_operating_system + return unless Gem::win_platform? + Win32::Registry::HKEY_LOCAL_MACHINE.open("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", Win32::Registry::KEY_READ) do |reg| @data[:system][:operating_system][:name] = safe_reg(reg, "ProductName") @data[:system][:operating_system][:build] = safe_reg(reg, "CurrentBuild") @@ -86,24 +102,26 @@ class W3DHub end def query_cpus - begin - Win32::Registry::HKEY_LOCAL_MACHINE.open("HARDWARE\\DESCRIPTION\\System\\CentralProcessor", Win32::Registry::KEY_READ) do |reg| - i = 0 + if Gem::win_platform? + begin + Win32::Registry::HKEY_LOCAL_MACHINE.open("HARDWARE\\DESCRIPTION\\System\\CentralProcessor", Win32::Registry::KEY_READ) do |reg| + i = 0 - reg.each_key do |key| - reg.open(key) do |cpu| - @data[:system][:cpus] << { - manufacturer: safe_reg(cpu, "VendorIdentifier", "Unknown"), - model: safe_reg(cpu, "ProcessorNameString").strip, - mhz: safe_reg(cpu, "~MHz"), - family: safe_reg(cpu, "Identifier") - } + reg.each_key do |key| + reg.open(key) do |cpu| + @data[:system][:cpus] << { + manufacturer: safe_reg(cpu, "VendorIdentifier", "Unknown"), + model: safe_reg(cpu, "ProcessorNameString").strip, + mhz: safe_reg(cpu, "~MHz"), + family: safe_reg(cpu, "Identifier") + } - i += 1 + i += 1 + end end end + rescue Win32::Registry::Error end - rescue Win32::Registry::Error end instruction_sets = %w[ HasRDTSC HasAltiVec HasMMX Has3DNow HasSSE HasSSE2 HasSSE3 HasSSE41 HasSSE42 HasAVX HasAVX2 HasAVX512F HasARMSIMD HasNEON ] # HasLSX HasLASX # These cause a crash atm @@ -122,6 +140,8 @@ class W3DHub end def query_gpus + return unless Gem::win_platform? + Win32::Registry::HKEY_LOCAL_MACHINE.open("SYSTEM\\ControlSet001\\Control\\Class\\{4d36e968-e325-11ce-bfc1-08002be10318}", Win32::Registry::KEY_READ) do |reg| i = 0 diff --git a/lib/win32_stub.rb b/lib/win32_stub.rb new file mode 100644 index 0000000..2edd790 --- /dev/null +++ b/lib/win32_stub.rb @@ -0,0 +1,110 @@ +module Win32 + class Registry + module Constants + HKEY_CLASSES_ROOT = 0x80000000 + HKEY_CURRENT_USER = 0x80000001 + HKEY_LOCAL_MACHINE = 0x80000002 + HKEY_USERS = 0x80000003 + HKEY_PERFORMANCE_DATA = 0x80000004 + HKEY_PERFORMANCE_TEXT = 0x80000050 + HKEY_PERFORMANCE_NLSTEXT = 0x80000060 + HKEY_CURRENT_CONFIG = 0x80000005 + HKEY_DYN_DATA = 0x80000006 + + REG_NONE = 0 + REG_SZ = 1 + REG_EXPAND_SZ = 2 + REG_BINARY = 3 + REG_DWORD = 4 + REG_DWORD_LITTLE_ENDIAN = 4 + REG_DWORD_BIG_ENDIAN = 5 + REG_LINK = 6 + REG_MULTI_SZ = 7 + REG_RESOURCE_LIST = 8 + REG_FULL_RESOURCE_DESCRIPTOR = 9 + REG_RESOURCE_REQUIREMENTS_LIST = 10 + REG_QWORD = 11 + REG_QWORD_LITTLE_ENDIAN = 11 + + STANDARD_RIGHTS_READ = 0x00020000 + STANDARD_RIGHTS_WRITE = 0x00020000 + KEY_QUERY_VALUE = 0x0001 + KEY_SET_VALUE = 0x0002 + KEY_CREATE_SUB_KEY = 0x0004 + KEY_ENUMERATE_SUB_KEYS = 0x0008 + KEY_NOTIFY = 0x0010 + KEY_CREATE_LINK = 0x0020 + KEY_READ = STANDARD_RIGHTS_READ | + KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS | KEY_NOTIFY + KEY_WRITE = STANDARD_RIGHTS_WRITE | + KEY_SET_VALUE | KEY_CREATE_SUB_KEY + KEY_EXECUTE = KEY_READ + KEY_ALL_ACCESS = KEY_READ | KEY_WRITE | KEY_CREATE_LINK + + REG_OPTION_RESERVED = 0x0000 + REG_OPTION_NON_VOLATILE = 0x0000 + REG_OPTION_VOLATILE = 0x0001 + REG_OPTION_CREATE_LINK = 0x0002 + REG_OPTION_BACKUP_RESTORE = 0x0004 + REG_OPTION_OPEN_LINK = 0x0008 + REG_LEGAL_OPTION = REG_OPTION_RESERVED | + REG_OPTION_NON_VOLATILE | REG_OPTION_CREATE_LINK | + REG_OPTION_BACKUP_RESTORE | REG_OPTION_OPEN_LINK + + REG_CREATED_NEW_KEY = 1 + REG_OPENED_EXISTING_KEY = 2 + + REG_WHOLE_HIVE_VOLATILE = 0x0001 + REG_REFRESH_HIVE = 0x0002 + REG_NO_LAZY_FLUSH = 0x0004 + REG_FORCE_RESTORE = 0x0008 + + MAX_KEY_LENGTH = 514 + MAX_VALUE_LENGTH = 32768 + end + include Constants + include Enumerable + + class Error < ::StandardError + attr_reader :code + end + + class PredefinedKey < Registry + def initialize(hkey, keyname) + @hkey = hkey + @parent = nil + @keyname = keyname + @disposition = REG_OPENED_EXISTING_KEY + end + + # Predefined keys cannot be closed + def close + raise Error.new(5) ## ERROR_ACCESS_DENIED + end + + # Fake #class method for Registry#open, Registry#create + def class + Registry + end + + # Make all + Constants.constants.grep(/^HKEY_/) do |c| + Registry.const_set c, new(Constants.const_get(c), c.to_s) + end + end + + def open(*args) + raise Win32::Registry::Error + end + + def create(*args) + Stub.new + end + + class Stub + def write_i(*arg) + # No OP + end + end + end +end diff --git a/w3d_hub_linux_launcher.rb b/w3d_hub_linux_launcher.rb index c27f066..ba44f74 100644 --- a/w3d_hub_linux_launcher.rb +++ b/w3d_hub_linux_launcher.rb @@ -78,6 +78,8 @@ I18n.default_locale = :en # GUI_DEBUG = true require_relative "lib/gui_state_ext" +require_relative "lib/win32_stub" unless Gem.win_platform? + require_relative "lib/version" require_relative "lib/theme" require_relative "lib/common"