Skip to content

Commit

Permalink
Merge pull request #262 from lacostej/list_licenses
Browse files Browse the repository at this point in the history
u3d/licenses: add feature to display licenses
  • Loading branch information
lacostej authored Mar 9, 2018
2 parents 013a5e8 + dc6757c commit f9b1965
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Binary file added docs/assets/u3d_licenses.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions lib/u3d.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
6 changes: 6 additions & 0 deletions lib/u3d/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
8 changes: 8 additions & 0 deletions lib/u3d/commands_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 <logfile>'
c.summary = 'Prettify a saved Unity logfile'
Expand Down
76 changes: 76 additions & 0 deletions lib/u3d/unity_license.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit f9b1965

Please sign in to comment.