Skip to content

Commit

Permalink
Merge pull request #289 from lacostej/hotfixes
Browse files Browse the repository at this point in the history
u3d/move command, renaming install dirs. Support long version names. Fixes #274
  • Loading branch information
lacostej authored Apr 22, 2018
2 parents ec91a5e + a2dbde6 commit e8792dc
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 6 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ Right now u3d has light support for build numbers. The build number can be found

If you wish a particular Unity installation to be ignored by the sanitization feature, create a `.u3d_do_not_move` file inside it.

If you wish to have your pre-installed unities directory name to automatically contain the full version (unity version + build number), you can call `u3d move --long <version>`.

## Security

When you install Unity with this tool, you will have to grant it higher privileges so it can perform the installation. It means that under MacOS and Linux, you will be asked for your `sudo` password.
Expand Down
5 changes: 5 additions & 0 deletions WIP
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
* merge other PRs

* note: matcher in sanitization is partial on full path and doesn't ask you to move things like Unity_Version_XXX as Version matches it
* optim: only move with super admin rights if necessary

21 changes: 21 additions & 0 deletions lib/u3d/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
require 'u3d_core/command_executor'
require 'u3d_core/credentials'
require 'fileutils'
require 'pry'

module U3d
# API for U3d, redirecting calls to class they concern
Expand Down Expand Up @@ -82,6 +83,26 @@ def console
end
# rubocop:enable Style/FormatStringToken

def move(args: {}, options: {})
long_name = options[:long]
UI.user_error! "move only supports long version name for now" unless long_name

version = args[0]
UI.user_error! "Please specify a Unity version" unless version
unity = check_unity_presence(version: version)
if unity.nil?
UI.message "Specified version '#{version}' not found."
return
end
if unity.do_not_move?
UI.error "Specified version is specicically marked as _do not move_."
return
end
Installer.create.sanitize_install(unity, long: true, dry_run: options[:dry_run])

unity.do_not_move!(dry_run: options[:dry_run]) # this may fail because of admin rights
end

def list_available(options: {})
ver = options[:unity_version]
os = valid_os_or_current(options[:operating_system])
Expand Down
18 changes: 18 additions & 0 deletions lib/u3d/commands_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,24 @@ def run
end
end

command :move do |c|
c.syntax = 'u3d move [--dry_run] --long <version>'
# c.option '-f', '--force', Array, 'Specifies which packages to download/install. Overriden by --all'
c.option '-l', '--long', "Rename the installation dir into its long name pattern, namely #{U3d::UNITY_DIR_LONG} on Windows/Mac and #{U3d::UNITY_DIR_LINUX_LONG} on Linux"
c.option '--dry_run', "show what would have happened"
c.summary = "Move an existing Unity install to an optionally specified new folder, marking it as non moveable later on"
c.description = %(
#{c.summary}
Sometimes you want to move Unity to a different folder/path and let u3d stop modifying trying to move it around.
The current command only supports 'long' installation dir names, containing not only the version but also the build number.
See https://github.com/DragonBox/u3d#unity-build-numbers for more information.
)
c.action do |args, options|
Commands.move(args: args, options: convert_options(options))
end
end

default_command :run

run!
Expand Down
17 changes: 11 additions & 6 deletions lib/u3d/installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ module U3d
DEFAULT_MAC_INSTALL = '/'.freeze
DEFAULT_WINDOWS_INSTALL = 'C:/Program Files/'.freeze
UNITY_DIR = "Unity_%<version>s".freeze
UNITY_DIR_LONG = "Unity_%<version>s_%<build_number>s".freeze
UNITY_DIR_LINUX = "unity-editor-%<version>s".freeze
UNITY_DIR_LINUX_LONG = "unity-editor-%<version>s_%<build_number>s".freeze

class Installer
def self.create
Expand Down Expand Up @@ -101,10 +103,11 @@ def self.sanitize_install(source_path, new_path, command, dry_run: false)
end

class MacInstaller < BaseInstaller
def sanitize_install(unity, dry_run: false)
def sanitize_install(unity, long: false, dry_run: false)
source_path = unity.root_path
parent = File.expand_path('..', source_path)
dir_name = format(UNITY_DIR, version: unity.version)
dir_name = format(long ? UNITY_DIR_LONG : UNITY_DIR,
version: unity.version, build_number: unity.build_number)
new_path = File.join(parent, dir_name)

moved = U3dCore::AdminTools.move_os_file(:mac, source_path, new_path, dry_run: dry_run)
Expand Down Expand Up @@ -199,10 +202,11 @@ def spotlight_installed_paths
end

class LinuxInstaller < BaseInstaller
def sanitize_install(unity, dry_run: false)
def sanitize_install(unity, long: false, dry_run: false)
source_path = File.expand_path(unity.root_path)
parent = File.expand_path('..', source_path)
dir_name = format(UNITY_DIR_LINUX, version: unity.version)
dir_name = format(long ? UNITY_DIR_LINUX_LONG : UNITY_DIR_LINUX,
version: unity.version, build_number: unity.build_number)
new_path = File.join(parent, dir_name)

moved = U3dCore::AdminTools.move_os_file(:linux, source_path, new_path, dry_run: dry_run)
Expand Down Expand Up @@ -298,10 +302,11 @@ def debian_installed_paths
end

class WindowsInstaller < BaseInstaller
def sanitize_install(unity, dry_run: false)
def sanitize_install(unity, long: false, dry_run: false)
source_path = File.expand_path(unity.root_path)
parent = File.expand_path('..', source_path)
dir_name = format(UNITY_DIR, version: unity.version)
dir_name = format(long ? UNITY_DIR_LONG : UNITY_DIR,
version: unity.version, build_number: unity.build_number)
new_path = File.join(parent, dir_name)

moved = U3dCore::AdminTools.move_os_file(:windows, source_path, new_path, dry_run: dry_run)
Expand Down

0 comments on commit e8792dc

Please sign in to comment.