30
30
31
31
module U3d
32
32
DEFAULT_LINUX_INSTALL = '/opt/' . freeze
33
- DEFAULT_MAC_INSTALL = '/' . freeze
33
+ DEFAULT_MAC_INSTALL = '/Applications/ ' . freeze
34
34
DEFAULT_WINDOWS_INSTALL = 'C:/Program Files/' . freeze
35
35
UNITY_DIR = "Unity_%<version>s" . freeze
36
36
UNITY_DIR_LONG = "Unity_%<version>s_%<build_number>s" . freeze
@@ -103,6 +103,10 @@ def self.sanitize_install(source_path, new_path, command, dry_run: false)
103
103
end
104
104
105
105
class MacInstaller < BaseInstaller
106
+ def install_directory
107
+ File . expand_path ( ENV [ 'U3D_INSTALL_PATH' ] || DEFAULT_MAC_INSTALL )
108
+ end
109
+
106
110
def sanitize_install ( unity , long : false , dry_run : false )
107
111
source_path = unity . root_path
108
112
parent = File . expand_path ( '..' , source_path )
@@ -124,23 +128,24 @@ def install(file_path, version, installation_path: nil, info: {})
124
128
# rubocop:enable UnusedMethodArgument
125
129
extension = File . extname ( file_path )
126
130
raise "Installation of #{ extension } files is not supported on Mac" if extension != '.pkg'
127
- path = installation_path || DEFAULT_MAC_INSTALL
131
+ path = installation_path || install_directory
128
132
install_pkg (
129
133
file_path ,
130
134
version : version ,
131
- target_path : path
135
+ installation_path : path
132
136
)
133
137
end
134
138
135
- def install_pkg ( file_path , version : nil , target_path : nil )
136
- target_path ||= DEFAULT_MAC_INSTALL
139
+ # FIXME: we don't support target_path anymore
140
+ def install_pkg ( file_path , version : nil , installation_path : nil )
141
+ target_path = '/'
137
142
command = "installer -pkg #{ file_path . shellescape } -target #{ target_path . shellescape } "
138
143
unity = installed . find { |u | u . version == version }
139
- temp_path = File . join ( target_path , 'Applications' , 'Unity' )
144
+ temp_path = File . join ( installation_path , 'Unity' )
140
145
if unity . nil?
141
146
UI . verbose "No Unity install for version #{ version } was found"
142
147
U3dCore ::CommandExecutor . execute ( command : command , admin : true )
143
- destination_path = File . join ( target_path , 'Applications' , format ( UNITY_DIR , version : version ) )
148
+ destination_path = File . join ( install_directory , format ( UNITY_DIR , version : version ) )
144
149
FileUtils . mv temp_path , destination_path
145
150
else
146
151
UI . verbose "Unity install for version #{ version } found under #{ unity . root_path } "
@@ -175,7 +180,7 @@ def uninstall(unity: nil)
175
180
private
176
181
177
182
def list_installed_paths
178
- find = File . join ( DEFAULT_MAC_INSTALL , 'Applications' , 'Unity*' , 'Unity.app' )
183
+ find = File . join ( install_directory , 'Unity*' , 'Unity.app' )
179
184
paths = Dir [ find ]
180
185
paths = paths . map { |u | Pathname . new ( u ) . parent . to_s }
181
186
UI . verbose "Found list_installed_paths: #{ paths } "
@@ -202,6 +207,10 @@ def spotlight_installed_paths
202
207
end
203
208
204
209
class LinuxInstaller < BaseInstaller
210
+ def install_directory
211
+ File . expand_path ( ENV [ 'U3D_INSTALL_PATH' ] || DEFAULT_LINUX_INSTALL )
212
+ end
213
+
205
214
def sanitize_install ( unity , long : false , dry_run : false )
206
215
source_path = File . expand_path ( unity . root_path )
207
216
parent = File . expand_path ( '..' , source_path )
@@ -225,10 +234,10 @@ def install(file_path, version, installation_path: nil, info: {})
225
234
226
235
raise "Installation of #{ extension } files is not supported on Linux" unless [ '.sh' , '.xz' ] . include? extension
227
236
if extension == '.sh'
228
- path = installation_path || DEFAULT_LINUX_INSTALL
237
+ path = installation_path || install_directory
229
238
install_sh ( file_path , installation_path : path )
230
239
elsif extension == '.xz'
231
- new_path = File . join ( DEFAULT_LINUX_INSTALL , format ( UNITY_DIR_LINUX , version : version ) )
240
+ new_path = File . join ( install_directory , format ( UNITY_DIR_LINUX , version : version ) )
232
241
path = installation_path || new_path
233
242
install_xz ( file_path , installation_path : path )
234
243
end
@@ -285,7 +294,7 @@ def uninstall(unity: nil)
285
294
private
286
295
287
296
def list_installed_paths
288
- find = File . join ( DEFAULT_LINUX_INSTALL , 'unity-editor-*' , 'Editor' )
297
+ find = File . join ( install_directory , 'unity-editor-*' , 'Editor' )
289
298
paths = Dir [ find ]
290
299
paths = paths . map { |u | Pathname . new ( u ) . parent . to_s }
291
300
UI . verbose "Found list_installed_paths: #{ paths } "
@@ -302,6 +311,10 @@ def debian_installed_paths
302
311
end
303
312
304
313
class WindowsInstaller < BaseInstaller
314
+ def install_directory
315
+ File . expand_path ( ENV [ 'U3D_INSTALL_PATH' ] || DEFAULT_WINDOWS_INSTALL )
316
+ end
317
+
305
318
def sanitize_install ( unity , long : false , dry_run : false )
306
319
source_path = File . expand_path ( unity . root_path )
307
320
parent = File . expand_path ( '..' , source_path )
@@ -314,14 +327,14 @@ def sanitize_install(unity, long: false, dry_run: false)
314
327
end
315
328
316
329
def installed
317
- find = File . join ( DEFAULT_WINDOWS_INSTALL , 'Unity*' , 'Editor' , 'Uninstall.exe' )
330
+ find = File . join ( install_directory , 'Unity*' , 'Editor' , 'Uninstall.exe' )
318
331
Dir [ find ] . map { |path | WindowsInstallation . new ( root_path : File . expand_path ( '../..' , path ) ) }
319
332
end
320
333
321
334
def install ( file_path , version , installation_path : nil , info : { } )
322
335
extension = File . extname ( file_path )
323
336
raise "Installation of #{ extension } files is not supported on Windows" unless %w[ .exe .msi ] . include? extension
324
- path = installation_path || File . join ( DEFAULT_WINDOWS_INSTALL , format ( UNITY_DIR , version : version ) )
337
+ path = installation_path || File . join ( install_directory , format ( UNITY_DIR , version : version ) )
325
338
install_exe (
326
339
file_path ,
327
340
installation_path : path ,
@@ -330,7 +343,7 @@ def install(file_path, version, installation_path: nil, info: {})
330
343
end
331
344
332
345
def install_exe ( file_path , installation_path : nil , info : { } )
333
- installation_path ||= DEFAULT_WINDOWS_INSTALL
346
+ installation_path ||= install_directory
334
347
final_path = U3dCore ::Helper . windows_path ( installation_path )
335
348
Utils . ensure_dir ( final_path )
336
349
begin
0 commit comments