Renamed W3DHub.captured_command to simply W3DHub.command, replace usages of system with W3DHub.command, resolves command prompt's popping up on Windows under rubyw.

This commit is contained in:
2022-10-30 22:02:20 -05:00
parent 388c3a2606
commit ab73b62c4b
3 changed files with 18 additions and 15 deletions

View File

@@ -49,7 +49,7 @@ class W3DHub
lambda do lambda do
@ping = -1 @ping = -1
W3DHub.captured_commmand("ping #{@address} #{W3DHub.windows? ? '-n 3' : '-c 3'}") do |line| W3DHub.command("ping #{@address} #{W3DHub.windows? ? '-n 3' : '-c 3'}") do |line|
if W3DHub.windows? && line =~ /Minimum|Maximum|Maximum/i if W3DHub.windows? && line =~ /Minimum|Maximum|Maximum/i
@ping = line.strip.split(",").last.split("=").last.sub("ms", "").to_i @ping = line.strip.split(",").last.split("=").last.sub("ms", "").to_i
elsif W3DHub.unix? && line.start_with?("rtt min/avg/max/mdev") elsif W3DHub.unix? && line.start_with?("rtt min/avg/max/mdev")

View File

@@ -147,12 +147,12 @@ class W3DHub
# FIXME: Check that there is enough disk space # FIXME: Check that there is enough disk space
# tar present? # tar present?
bsdtar_present = system("#{W3DHub.tar_command} --help") bsdtar_present = W3DHub.command("#{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? # Wine present?
if W3DHub.unix? if W3DHub.unix?
wine_present = system("which #{Store.settings[:wine_command]}") wine_present = W3DHub.command("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
end end
end end
@@ -636,7 +636,7 @@ class W3DHub
package_path = Cache.package_path(package.category, package.subcategory, package.name, package.version) package_path = Cache.package_path(package.category, package.subcategory, package.name, package.version)
logger.info(LOG_TAG) { " Running #{W3DHub.tar_command} command: #{W3DHub.tar_command} -xf \"#{package_path}\" -C \"#{path}\"" } logger.info(LOG_TAG) { " Running #{W3DHub.tar_command} command: #{W3DHub.tar_command} -xf \"#{package_path}\" -C \"#{path}\"" }
return system("#{W3DHub.tar_command} -xf \"#{package_path}\" -C \"#{path}\"") return W3DHub.command("#{W3DHub.tar_command} -xf \"#{package_path}\" -C \"#{path}\"")
end end
def apply_patch(package, path) def apply_patch(package, path)
@@ -648,7 +648,7 @@ class W3DHub
Cache.create_directories(temp_path, true) Cache.create_directories(temp_path, true)
logger.info(LOG_TAG) { " Running #{W3DHub.tar_command} command: #{W3DHub.tar_command} -xf \"#{package_path}\" -C \"#{temp_path}\"" } logger.info(LOG_TAG) { " Running #{W3DHub.tar_command} command: #{W3DHub.tar_command} -xf \"#{package_path}\" -C \"#{temp_path}\"" }
system("#{W3DHub.tar_command} -xf \"#{package_path}\" -C \"#{temp_path}\"") W3DHub.command("#{W3DHub.tar_command} -xf \"#{package_path}\" -C \"#{temp_path}\"")
logger.info(LOG_TAG) { " Loading #{temp_path}/#{manifest_file.name}.patch..." } logger.info(LOG_TAG) { " Loading #{temp_path}/#{manifest_file.name}.patch..." }
patch_mix = W3DHub::Mixer::Reader.new(file_path: "#{temp_path}/#{manifest_file.name}.patch", ignore_crc_mismatches: false) patch_mix = W3DHub::Mixer::Reader.new(file_path: "#{temp_path}/#{manifest_file.name}.patch", ignore_crc_mismatches: false)

View File

@@ -40,7 +40,7 @@ class W3DHub
end end
end end
def self.captured_commmand(command, &block) def self.command(command, &block)
if windows? if windows?
stdout_read, stdout_write = IO.pipe stdout_read, stdout_write = IO.pipe
@@ -60,23 +60,26 @@ class W3DHub
status = -1 status = -1
until (status = Process.get_exitcode(pid)) until (status = Process.get_exitcode(pid))
readable, _writable, _errorable = IO.select([stdout_read], [], [], 1) if block
readable, _writable, _errorable = IO.select([stdout_read], [], [], 1)
readable&.each do |io| readable&.each do |io|
line = io.readpartial(1024) line = io.readpartial(1024)
block&.call(line) block&.call(line)
end
else
sleep 0.1
end end
end end
stdout_read.close
stdout_write.close
status.zero? status.zero?
else else
IO.popen(command) do |io| IO.popen(command) do |io|
io.each_line do |line| if block
block&.call(line) io.each_line do |line|
block&.call(line)
end
end end
end end