diff --git a/README.md b/README.md index 4fa19d00..3457717f 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,10 @@ The prettifyer is on by default but can be turned off to get Unity's raw output. * `u3d dependencies`: [Linux] Install dependencies that Unity don't install by default on Linux +* `u3d licenses`: display information about your Unity licenses + +![u3d list](https://github.com/DragonBox/u3d/raw/master/docs/assets/u3d_licenses.png) + ## Installation ```shell diff --git a/docs/assets/u3d_licenses.png b/docs/assets/u3d_licenses.png new file mode 100644 index 00000000..0e3f99cf Binary files /dev/null and b/docs/assets/u3d_licenses.png differ diff --git a/lib/u3d.rb b/lib/u3d.rb index 536d7373..639fc23f 100644 --- a/lib/u3d.rb +++ b/lib/u3d.rb @@ -34,6 +34,7 @@ require 'u3d/installation' require 'u3d/installer' require 'u3d/log_analyzer' +require 'u3d/unity_license' require 'u3d/unity_project' require 'u3d/unity_runner' require 'u3d/unity_version_definition' diff --git a/lib/u3d/commands.rb b/lib/u3d/commands.rb index c3e99773..696b331a 100644 --- a/lib/u3d/commands.rb +++ b/lib/u3d/commands.rb @@ -195,6 +195,12 @@ def credentials(args: []) end end + def licenses + U3d::License.licenses.sort_by { |l| l['LicenseVersion'] }.each do |license| + UI.message "#{license.path}: #{license['LicenseVersion']} #{license.number} #{license['UpdateDate']}" + end + end + def local_analyze(args: []) raise ArgumentError, 'No files given' if args.empty? raise ArgumentError, "File #{args[0]} does not exist" unless File.exist? args[0] diff --git a/lib/u3d/commands_generator.rb b/lib/u3d/commands_generator.rb index b3ec7d8a..8a63b7f8 100644 --- a/lib/u3d/commands_generator.rb +++ b/lib/u3d/commands_generator.rb @@ -189,6 +189,14 @@ def run end end + command :licenses do |c| + c.syntax = "u3d licenses" + c.description = 'Prints Unity license information.' + c.action do |_args, _options| + Commands.licenses + end + end + command :prettify do |c| c.syntax = 'u3d prettify ' c.summary = 'Prettify a saved Unity logfile' diff --git a/lib/u3d/unity_license.rb b/lib/u3d/unity_license.rb new file mode 100644 index 00000000..6dae4d08 --- /dev/null +++ b/lib/u3d/unity_license.rb @@ -0,0 +1,76 @@ +## --- 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 +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +## --- END LICENSE BLOCK --- + +require 'rexml/document' + +module U3d + class License + attr_reader :path + + def initialize(path: nil, fields: nil) + @path = path + @fields = fields || {} + end + + def [](index) + @fields[index] + end + + # petit cachotier va! + def number + require 'base64' + Base64.decode64(self['DeveloperData'])[4..-1] + end + + class << self + LICENSES_DIR_MAC = File.join("/", "Library", "Application Support", "Unity").freeze + LICENSES_DIR_WINDOWS = File.join("C:/ProgramData", "Unity").freeze + LICENSES_DIR_LINUX = File.join(ENV['HOME'], ".local", "share", "unity3d", "Unity").freeze + + def from_path(path) + doc = REXML::Document.new(File.read(path)) + fields = {} + license = REXML::XPath.first(doc, "root/License") + unless license.nil? + fields = [] + license.each_element_with_attribute("Value") do |e| + fields << [e.name, e.attribute('Value').to_s] + end + end + License.new(path: path, fields: fields.to_h) + end + + def licenses + glob = File.join(licenses_dir, "*.ulf") + Dir.glob(glob).map do |path| + from_path(path) + end + end + + def licenses_dir + return LICENSES_DIR_MAC if U3d::Helper.mac? + return LICENSES_DIR_WINDOWS if U3d::Helper.windows? + return LICENSES_DIR_LINUX if U3d::Helper.linux? + end + end + end +end