lib/u3d/installation.rb in u3d-1.2.3 vs lib/u3d/installation.rb in u3d-1.3.0
- old
+ new
@@ -1,5 +1,7 @@
+# frozen_string_literal: true
+
## --- BEGIN LICENSE BLOCK ---
# Copyright (c) 2016-present WeWantToKnow AS
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
@@ -23,13 +25,16 @@
require 'u3d/utils'
require 'u3d_core/admin_tools'
require 'fileutils'
module U3d
- UNITY_DIR_CHECK = /Unity_\d+\.\d+\.\d+[a-z]\d+/
- UNITY_DIR_CHECK_LINUX = /unity-editor-\d+\.\d+\.\d+[a-z]\d+\z/
- U3D_DO_NOT_MOVE = ".u3d_do_not_move".freeze
+ UNITY_DIR_CHECK = /Unity_\d+\.\d+\.\d+[a-z]\d+/.freeze
+ UNITY_DIR_CHECK_LINUX = /unity-editor-\d+\.\d+\.\d+[a-z]\d+\z/.freeze
+ # Linux unity_builtin_extra seek position for version
+ UNITY_VERSION_LINUX_POS_LE_2019 = 20
+ UNITY_VERSION_LINUX_POS_GT_2019 = 48
+ U3D_DO_NOT_MOVE = ".u3d_do_not_move"
class Installation
attr_accessor :root_path
NOT_PLAYBACKENGINE_PACKAGES = %w[Documentation StandardAssets MonoDevelop].freeze
@@ -112,10 +117,11 @@
def self.node_value(config_path, node_name)
require 'rexml/document'
UI.verbose("reading #{config_path}")
raise "File not found at #{config_path}" unless File.exist? config_path
+
doc = REXML::Document.new(File.read(config_path))
REXML::XPath.first(doc, node_name).value
end
def self.module_name(config_path)
@@ -140,14 +146,23 @@
end
class InstallationUtils
def self.read_version_from_unity_builtin_extra(file)
File.open(file, "rb") do |f|
- f.seek(20)
+ # Check if it is version lower or equal to 2019
+ seek_pos = UNITY_VERSION_LINUX_POS_LE_2019
+ f.seek(seek_pos)
+ z = f.read(1)
+ if z == "\x00"
+ # Version is greater than 2019
+ seek_pos = UNITY_VERSION_LINUX_POS_GT_2019
+ end
+ f.seek(seek_pos)
s = ""
while (c = f.read(1))
break if c == "\x00"
+
s += c
end
s
end
end
@@ -173,10 +188,11 @@
end
def path
UI.deprecated("path is deprecated. Use root_path instead")
return @path if @path
+
"#{@root_path}/Unity.app"
end
def packages
pack = []
@@ -215,17 +231,18 @@
def plist
@plist ||=
begin
fpath = "#{root_path}/Unity.app/Contents/Info.plist"
raise "#{fpath} doesn't exist" unless File.exist? fpath
+
Plist.parse_xml(fpath)
end
end
end
class LinuxInstallationHelper
- STRINGS_FULL_VERSION_MATCHER = /^[0-9\.abfp]+_[0-9a-f]{12}/
+ STRINGS_FULL_VERSION_MATCHER = /^[0-9.abfp]+_[0-9a-f]{12}/.freeze
def find_build_number(root)
known_rev_locations.each do |p|
rev = find_build_number_in("#{root}#{p}")
return rev if rev
@@ -234,14 +251,14 @@
end
private
def strings(path)
- if `which strings` != ''
- binutils_strings(path)
- else
+ if `which strings` == ''
Utils.strings(path).to_a
+ else
+ binutils_strings(path)
end
end
def binutils_strings(path)
command = "strings #{path.shellescape}"
@@ -256,12 +273,13 @@
'/Editor/Unity']
end
def find_build_number_in(path = nil)
return nil unless File.exist? path
+
str = strings(path)
- lines = str.select { |l| l =~ STRINGS_FULL_VERSION_MATCHER }
+ lines = str.grep(STRINGS_FULL_VERSION_MATCHER)
lines.empty? ? nil : lines[0].split('_')[1]
end
end
class LinuxInstallation < Installation
@@ -345,59 +363,23 @@
end
private
def unity_version_info
- @uvf ||= string_file_info('Unity Version', @exe_path)
+ @unity_version_info ||= U3d::Utils.windows_fileversion('Unity Version', @exe_path)
end
-
- def string_file_info(info, path)
- require "Win32API"
- get_file_version_info_size = Win32API.new('version.dll', 'GetFileVersionInfoSize', 'PP', 'L')
- get_file_version_info = Win32API.new('version.dll', 'GetFileVersionInfo', 'PIIP', 'I')
- ver_query_value = Win32API.new('version.dll', 'VerQueryValue', 'PPPP', 'I')
- rtl_move_memory = Win32API.new('kernel32.dll', 'RtlMoveMemory', 'PLL', 'I')
-
- file = path.tr("/", "\\")
-
- buf = [0].pack('L')
- version_size = get_file_version_info_size.call(file + "\0", buf)
- raise Exception if version_size.zero? # TODO: use GetLastError
-
- version_info = 0.chr * version_size
- version_ok = get_file_version_info.call(file, 0, version_size, version_info)
- raise Exception if version_ok.zero? # TODO: use GetLastError
-
- # hardcoding lang codepage
- struct_path = "\\StringFileInfo\\040904b0\\#{info}"
-
- addr = [0].pack('L')
- size = [0].pack('L')
- query_ok = ver_query_value.call(version_info, struct_path + "\0", addr, size)
- raise Exception if query_ok.zero?
-
- raddr = addr.unpack('L')[0]
- rsize = size.unpack('L')[0]
-
- info = Array.new(rsize, 0).pack('L*')
- rtl_move_memory.call(info, raddr, info.length)
- info.strip
- rescue StandardError => e
- UI.verbose("Failure to find '#{info}' under '#{path}': #{e}")
- UI.verbose(e.backtrace)
- nil
- end
end
class WindowsInstallation < Installation
def version
version = helper.version
return version unless version.nil?
path = "#{root_path}/Editor/Data/"
package = IvyPlaybackEngineUtils.list_module_configs(path).first
raise "Couldn't find a module under #{path}" unless package
+
IvyPlaybackEngineUtils.unity_version(package)
end
def build_number
helper.build_number
@@ -408,11 +390,11 @@
begin
loc_appdata = Utils.windows_local_appdata
log_dir = File.expand_path('Unity/Editor/', loc_appdata)
UI.important "Log directory (#{log_dir}) does not exist" unless Dir.exist? log_dir
@logfile = File.expand_path('Editor.log', log_dir)
- rescue RuntimeError => ex
- UI.error "Unable to retrieve the editor logfile: #{ex}"
+ rescue RuntimeError => e
+ UI.error "Unable to retrieve the editor logfile: #{e}"
end
end
@logfile
end