2018-10-28 06:37:33 +00:00
|
|
|
require 'win32ole'
|
2018-10-27 22:50:08 +00:00
|
|
|
|
2017-05-07 12:04:49 +00:00
|
|
|
module WIN32OLESpecs
|
2018-12-07 14:37:28 +00:00
|
|
|
MSXML_AVAILABLE = WIN32OLE_TYPELIB.typelibs.any? { |t| t.name.start_with?('Microsoft XML') }
|
|
|
|
SYSTEM_MONITOR_CONTROL_AVAILABLE = WIN32OLE_TYPELIB.typelibs.any? { |t| t.name.start_with?('System Monitor Control') }
|
2018-10-27 22:50:08 +00:00
|
|
|
|
2017-05-07 12:04:49 +00:00
|
|
|
def self.new_ole(name)
|
2018-10-27 13:57:23 +00:00
|
|
|
tries = 0
|
2017-05-07 12:04:49 +00:00
|
|
|
begin
|
|
|
|
WIN32OLE.new(name)
|
|
|
|
rescue WIN32OLERuntimeError => e
|
2018-10-27 13:57:23 +00:00
|
|
|
if tries < 3
|
|
|
|
tries += 1
|
|
|
|
$stderr.puts "WIN32OLESpecs#new_ole retry (#{tries}): #{e.class}: #{e.message}"
|
|
|
|
sleep(2 ** tries)
|
2017-05-07 12:04:49 +00:00
|
|
|
retry
|
2018-10-27 13:57:23 +00:00
|
|
|
else
|
|
|
|
raise
|
2017-05-07 12:04:49 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|