diff --git a/lib/application_manager.rb b/lib/application_manager.rb index 3f660e6..a712f36 100644 --- a/lib/application_manager.rb +++ b/lib/application_manager.rb @@ -298,12 +298,19 @@ class W3DHub exe_path = app_id == "ecw" ? "#{install_path}/game750.exe" : "#{install_path}/game.exe" if File.exist?(exe_path) - installed_version = reg["InstalledVersion"] unless app_id == "ren" + installed_version = app_id == "ren" ? "1.0.0.0" : reg["InstalledVersion"] + + if (installed_app = installed?(app_id, channel_id)) + current_version = Gem::Version.new(installed_app[:installed_version]) + listed_version = installed_version + + next if current_version >= listed_version + end application_data = { name: game.name, install_directory: install_path, - installed_version: app_id == "ren" ? "1.0.0.0" : installed_version, + installed_version: installed_version, install_path: exe_path, wine_prefix: nil } @@ -327,6 +334,33 @@ class W3DHub end end + def write_application_version_to_win32_registry(app_id, channel_id, version) + # TODO: Figure out how to trigger UAC, but only for this so games DO NOT spawn with admin privileges. + return + return unless W3DHub.windows? + return if app_id == "ren" + + require "win32/registry" + + registry_path ||= "SOFTWARE\\W3D Hub\\games\\#{app_id}-#{channel_id}" + reg_type = Win32::Registry::KEY_ALL_ACCESS + + Win32::Registry::HKEY_LOCAL_MACHINE.open(registry_path, reg_type) do |reg| + reg.write_s("InstalledVersion", version) + end + + rescue => e + puts e.class, e.message, e.backtrace + if Win32::Registry::Error + logger.warn(LOG_TAG) { " Failed to update #{app_id}-#{channel_id} version in the registry" } + else + logger.warn(LOG_TAG) { " An error occurred while tying to update #{app_id}-#{channel_id} version in the registry" } + logger.warn(LOG_TAG) { e } + end + + false + end + def imported!(task, exe_path) application_data = { name: task.application.name, @@ -359,6 +393,8 @@ class W3DHub Store.settings[:games] ||= {} Store.settings[:games][:"#{task.app_id}_#{task.release_channel}"] = application_data Store.settings.save_settings + + write_application_version_to_win32_registry(task.app_id, task.release_channel, task.target_version) end def installed?(app_id, channel) diff --git a/lib/common.rb b/lib/common.rb index af37546..70d63de 100644 --- a/lib/common.rb +++ b/lib/common.rb @@ -57,8 +57,9 @@ class W3DHub ) pid = process_info.process_id + status = -1 - until Process.get_exitcode(pid) + until (status = Process.get_exitcode(pid)) readable, _writable, _errorable = IO.select([stdout_read], [], [], 1) readable&.each do |io| @@ -71,7 +72,7 @@ class W3DHub stdout_read.close stdout_write.close - Process.get_exitcode(pid).zero? + status.zero? else IO.popen(command) do |io| io.each_line do |line| diff --git a/lib/pages/server_browser.rb b/lib/pages/server_browser.rb index 392b822..4b15b02 100644 --- a/lib/pages/server_browser.rb +++ b/lib/pages/server_browser.rb @@ -218,6 +218,8 @@ class W3DHub end def find_element_by_tag(container, tag, list = []) + return unless container + container.children.each do |child| list << child if child.style.tag == tag diff --git a/lib/window.rb b/lib/window.rb index d195e06..d85268c 100644 --- a/lib/window.rb +++ b/lib/window.rb @@ -37,7 +37,7 @@ class W3DHub end # Manually sleep main thread so that the BackgroundWorker thread can be scheduled - sleep(update_interval / 1000.0) if W3DHub::BackgroundWorker.busy? + sleep(update_interval / 1000.0) if W3DHub::BackgroundWorker.busy? || Store.application_manager.busy? end def gain_focus