-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] u3d/installation: add feature to create shortcuts #336
base: master
Are you sure you want to change the base?
Changes from all commits
8aa01cb
681622d
e5a1e3e
b21064f
ed3dce4
b360ae8
ea304c2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -110,6 +110,18 @@ def run | |
end | ||
end | ||
|
||
command :shortcuts do |c| | ||
c.syntax = 'u3d shortcuts [-u | --unity_version <version>] [-t | --target <folder>]' | ||
c.option '-u', '--unity_version STRING', String, 'Creates a shortcut for this version of Unity only.' | ||
c.option '-d', '--directory STRING', String, 'Specifies which directory to create the shortcuts in' | ||
c.example 'Create a shortcut for all installed versions on the Desktop', 'u3d shortcuts -d ~/Desktop' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it risky to create shortcuts for all versions without specifying --all? |
||
c.example 'Create a shortcut for Unity 5.6.0f3', 'u3d shortcuts -u 5.6.0f3' | ||
c.summary = 'Create shortcuts for installed versions of Unity' | ||
c.action do |_args, options| | ||
Commands.create_shortcuts(options: convert_options(options)) | ||
end | ||
end | ||
|
||
command :available do |c| | ||
oses = U3dCore::Helper.operating_systems | ||
c.syntax = 'u3d available [-r | --release_level <level>] [-o | --operating_system <OS>] [-u | --unity_version <version>] [-p | --packages] [-f | --force]' | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -305,6 +305,30 @@ def build_number(exe_path) | |
nil | ||
end | ||
|
||
def create_shortcut(path_to_unity_exe, unity_version, target_directory) | ||
require 'win32-shortcut' | ||
full_exe_path = File.expand_path(path_to_unity_exe) | ||
lnk_parent = if target_directory.nil? | ||
File.expand_path('..', full_exe_path) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. weird implementation of a default no? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't it be the desktop? In which case, should it be passed to the function (and let the caller define it). |
||
else | ||
File.expand_path(target_directory) | ||
end | ||
|
||
lnk_name = "Unity_#{unity_version}.lnk" | ||
lnk_path = File.join(lnk_parent, lnk_name) | ||
|
||
if File.exist? lnk_path | ||
UI.message "Shortcut already exists at #{lnk_path}" | ||
return Win32::Shortcut.open(lnk_path) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do we open it here? |
||
end | ||
|
||
shortcut = Win32::Shortcut.new(lnk_path) do |s| | ||
s.description = "Shortcut to Unity.exe for Unity #{unity_version}. Automatically created by u3d." | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we need to remove shortcuts when uninstalling? |
||
s.path = full_exe_path | ||
end | ||
shortcut.tap { |s| UI.success "Created shortcut for #{s.path} at #{s.file}" } | ||
end | ||
|
||
private | ||
|
||
def string_file_info(info, path) | ||
|
@@ -408,5 +432,9 @@ def module_name_pattern(module_name) | |
def clean_install? | ||
do_not_move? || !(root_path =~ UNITY_DIR_CHECK).nil? | ||
end | ||
|
||
def create_shortcut(target_directory) | ||
WindowsInstallationHelper.new.create_shortcut(exe_path, version, target_directory) | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ Gem::Specification.new do |spec| | |
spec.add_dependency 'inifile', '>= 3.0.0', '< 4.0.0' # Parses INI files | ||
spec.add_dependency 'plist', '>= 3.1.0', '< 4.0.0' # Generate the Xcode config plist file | ||
spec.add_dependency 'security', '= 0.1.3' # macOS Keychain manager, a dead project, no updates expected | ||
spec.add_dependency 'win32-shortcut', '>= 0.3.0' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see overall comment related to platform specific dependency. |
||
# Development only | ||
spec.add_development_dependency "bundler", "~> 1.13" | ||
spec.add_development_dependency "coveralls" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems optional. It should document where it creates the screenshot when it isn't passed.