u3d 1.0.15 → 1.0.16

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a16167249f7c241c3d56a26a4f4f57799637f2bf
4
- data.tar.gz: ec668456ad48bb9ea4ab5ffd259551fedce73c80
3
+ metadata.gz: f7fc56b235f6627c0f4e44e12dddb35e1f22b9ef
4
+ data.tar.gz: e6dbe1daf2d3ca3e1dcf6956e39541fb0d15fff6
5
5
  SHA512:
6
- metadata.gz: 79e190c037b298fa2bd96d5f9736f641348bdbf70c243566400c9f52f5d01804337f9583afc0f8861fef2c486a8503c9fd9a98bb85be6512a2a16583cdee78c6
7
- data.tar.gz: ff0c122ca7266eaebe87c416a742e7e95ab58f82bca7880249bc1bddee14d5ee1863ece34ab88afec3d697cde25d6d2b85c35fd0dd7cb5e75a6b981158d4c972
6
+ metadata.gz: d4ca5e97456b6d6a2769ca8d8cfe57fb3122b88a0a769a965eb5eb2b72bdcf1d7d379fd996b93480e0580e847c7c15af1a2326f80aaddb12258cc0b50d34e453
7
+ data.tar.gz: d58536ae973dfbd0261f97671472c8ae425277c9d5e61c5a7e022e8ef8c444573bd1f53eb0e485d011458b3d2ed81d23900a72d94f3e4ee6d22ef8a160236f96
@@ -0,0 +1,18 @@
1
+ <!--
2
+ Thank you for helping u3d to get better!
3
+ Before you post your issue, please make sure that you checked the boxes! (put an x in the [ ] without spaces)
4
+ If possible, try to indicate what type of issue you are facing with the tags!
5
+ -->
6
+
7
+ ### Issue Checklist
8
+
9
+ - [ ] I'm using the latest u3d version
10
+ - [ ] I ran `u3d --help`
11
+ - [ ] I read the [README](https://github.com/DragonBox/u3d/blob/master/README.md)
12
+ - [ ] I made sure that a similar [issue](https://github.com/DragonBox/u3d/issues) doesn't exit
13
+
14
+ ### Issue Description
15
+
16
+ <!-- Please describe your issue with as much precision as possible. Write there the command you ran, its output, the behaviour you expect... -->
17
+
18
+ [DESCRIBE YOUR ISSUE HERE]
@@ -0,0 +1,20 @@
1
+ <!--
2
+ Thank you for contributing to u3d!
3
+ Before you post your pull request, please make sure that you checked the boxes! (put an x in the [ ] without spaces)
4
+ If possible, try to name your pull request by prefixing it with <SUBJECT>. For instance, if you're modifying the downloading, you could prefix it with u3d/download:
5
+ -->
6
+
7
+ ### Pull Request Checklist
8
+
9
+ - [ ] My pull request has been rebased on master
10
+ - [ ] I ran `bundle exec rspec` to make sure that my PR didn't break any test
11
+ - [ ] I ran `bundle exec rubocop` to make sure that my PR is inline with our code style
12
+ - [ ] I have read the [code of conduct](https://github.com/DragonBox/u3d/blob/master/CODE_OF_CONDUCT.md)
13
+
14
+ ### Pull Request Description
15
+
16
+ <!-- If this pull request is related to a specific issue, please specify here "Fixes #ISSUE_NO" -->
17
+ <!-- Please describe your pull request with as much precision as possible. Write here why you think this change is required, what problem it solves, how it solves it... -->
18
+ <!-- Please describe to what extent you tested your modifications -->
19
+
20
+ [DESCRIBE YOUR PULL REQUEST HERE]
@@ -1,4 +1,4 @@
1
- future-release=v1.0.15
1
+ future-release=v1.0.16
2
2
  since-tag=v0.9
3
3
  exclude_tags_regex=v0\.[0-8]\..*
4
4
  exclude-labels=nochangelog,question
data/CHANGELOG.md CHANGED
@@ -1,9 +1,35 @@
1
1
  # Change Log
2
2
 
3
+ ## [v1.0.16](https://github.com/DragonBox/u3d/tree/v1.0.16) (2018-02-04)
4
+ [Full Changelog](https://github.com/DragonBox/u3d/compare/v1.0.15...v1.0.16)
5
+
6
+ **Implemented enhancements:**
7
+
8
+ - support install of .xz files [\#251](https://github.com/DragonBox/u3d/issues/251)
9
+ - Linux ini partial support exists now [\#244](https://github.com/DragonBox/u3d/issues/244)
10
+
11
+ **Fixed bugs:**
12
+
13
+ - u3d/install & u3d/available no INI file error on Linux [\#242](https://github.com/DragonBox/u3d/issues/242)
14
+ - u3d/prettify: Fix rule termination when there are special characters in the file name [\#246](https://github.com/DragonBox/u3d/pull/246) ([niezbop](https://github.com/niezbop))
15
+
16
+ **Closed issues:**
17
+
18
+ - u3d/available missing latest versions on Linux [\#241](https://github.com/DragonBox/u3d/issues/241)
19
+ - u3d/install fails to install Linux dependencies inside docker [\#240](https://github.com/DragonBox/u3d/issues/240)
20
+
21
+ **Merged pull requests:**
22
+
23
+ - u3d/install linux xz format \(fixes \#251\) [\#252](https://github.com/DragonBox/u3d/pull/252) ([lacostej](https://github.com/lacostej))
24
+ - u3d/available: support broken parts of Linux INI \(\#244\) [\#248](https://github.com/DragonBox/u3d/pull/248) ([lacostej](https://github.com/lacostej))
25
+ - u3d/available: fix forums parsing and move ini faking/downloading at available time, to support package based Linux versions [\#247](https://github.com/DragonBox/u3d/pull/247) ([lacostej](https://github.com/lacostej))
26
+ - u3d/prettify: Parse Android command invocation failure [\#245](https://github.com/DragonBox/u3d/pull/245) ([niezbop](https://github.com/niezbop))
27
+ - Support linux forums pagination [\#243](https://github.com/DragonBox/u3d/pull/243) ([lacostej](https://github.com/lacostej))
28
+
3
29
  ## [v1.0.15](https://github.com/DragonBox/u3d/tree/v1.0.15) (2018-01-16)
4
30
  [Full Changelog](https://github.com/DragonBox/u3d/compare/v1.0.14...v1.0.15)
5
31
 
6
- **Merged pull requests:**
32
+ **Fixed bugs:**
7
33
 
8
34
  - u3d/install: download beta for mac also needs to discard checking md5s on Windows packages [\#234](https://github.com/DragonBox/u3d/pull/234) ([lacostej](https://github.com/lacostej))
9
35
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- u3d (1.0.15)
4
+ u3d (1.0.16)
5
5
  colored (>= 1.2, < 2.0.0)
6
6
  commander (>= 4.4.0, < 5.0.0)
7
7
  file-tail (>= 1.2.0)
@@ -24,7 +24,7 @@ GEM
24
24
  builder (3.2.3)
25
25
  coderay (1.1.1)
26
26
  colored (1.2)
27
- commander (4.4.3)
27
+ commander (4.4.4)
28
28
  highline (~> 1.7.2)
29
29
  concurrent-ruby (1.0.5)
30
30
  coveralls (0.8.21)
@@ -11,7 +11,7 @@
11
11
  "fail": {
12
12
  "active": true,
13
13
  "start_pattern": "^(?<fail>Failed to .+)\\n",
14
- "end_pattern": "Filename: (?:[\\w/:]+/(?<file>\\w+\\.\\w+))? Line: (?<line>-?\\d+)",
14
+ "end_pattern": "Filename: (?:.+/(?<file>\\w+\\.\\w+))? Line: (?<line>-?\\d+)",
15
15
  "start_message": false,
16
16
  "end_message": "%{file}(line %{line}): %{fail}",
17
17
  "store_lines": false,
@@ -39,7 +39,7 @@
39
39
  "exception_report": {
40
40
  "active": true,
41
41
  "start_pattern": "^(?<message>.*threw exception\\.)\\n",
42
- "end_pattern": "Filename: (?:[\\w/:]+/(?<file>\\w+\\.\\w+))? Line: (?<line>-?\\d+)",
42
+ "end_pattern": "Filename: (?:.+/(?<file>\\w+\\.\\w+))? Line: (?<line>-?\\d+)",
43
43
  "start_message": false,
44
44
  "end_message": "%{file}(line %{line}): %{message}",
45
45
  "store_lines": false,
@@ -74,7 +74,7 @@
74
74
  "fetched_line_pattern": "(?<message>.*)\\n",
75
75
  "fetched_line_message": false,
76
76
  "start_message": false,
77
- "end_pattern": "Filename: (?:[\\w/:]+/(?<file>\\w+\\.\\w+))? Line: (?<line>-?\\d+)",
77
+ "end_pattern": "Filename: (?:.+/(?<file>\\w+\\.\\w+))? Line: (?<line>-?\\d+)",
78
78
  "end_message": "[LOG] %{file}(line %{line}): %{message}",
79
79
  "type": "warning"
80
80
  },
@@ -83,12 +83,13 @@
83
83
  "start_pattern": "UnityEngine\\.Debug:LogWarning\\(Object\\)",
84
84
  "fetch_first_line_not_matching": [
85
85
  "UnityEngine\\.",
86
- "^\\n"
86
+ "^\\n",
87
+ "^\\s+"
87
88
  ],
88
89
  "fetched_line_pattern": "(?<message>.*)\\n",
89
90
  "fetched_line_message": false,
90
91
  "start_message": false,
91
- "end_pattern": "Filename: (?:[\\w/:]+/(?<file>\\w+\\.\\w+))? Line: (?<line>-?\\d+)",
92
+ "end_pattern": "Filename: (?:.+/(?<file>\\w+\\.\\w+))? Line: (?<line>-?\\d+)",
92
93
  "end_message": "[LOG] %{file}(line %{line}): %{message}",
93
94
  "type": "warning"
94
95
  },
@@ -104,7 +105,7 @@
104
105
  "fetched_line_pattern": "(?<message>.*)\\n",
105
106
  "fetched_line_message": false,
106
107
  "start_message": false,
107
- "end_pattern": "Filename: (?:[\\w/:]+/(?<file>\\w+\\.\\w+))? Line: (?<line>-?\\d+)",
108
+ "end_pattern": "Filename: (?:.+/(?<file>\\w+\\.\\w+))? Line: (?<line>-?\\d+)",
108
109
  "end_message": "[LOG] %{file}(line %{line}): %{message}",
109
110
  "type": "error"
110
111
  },
@@ -120,7 +121,7 @@
120
121
  "fetched_line_pattern": "(?<message>.*)\\n",
121
122
  "fetched_line_message": false,
122
123
  "start_message": false,
123
- "end_pattern": "Filename: (?:[\\w/:]+/(?<file>\\w+\\.\\w+))? Line: (?<line>-?\\d+)",
124
+ "end_pattern": "Filename: (?:.+/(?<file>\\w+\\.\\w+))? Line: (?<line>-?\\d+)",
124
125
  "end_message": "[LOG] %{file}(line %{line}): %{message}",
125
126
  "type": "error"
126
127
  },
@@ -307,6 +308,42 @@
307
308
  "start_pattern": "Textures\\s+\\d+\\.?\\d* .b\\s+\\d{1,3}\\.?\\d*%",
308
309
  "end_pattern": "Complete size\\s+\\d+\\.?\\d* .b\\s+\\d{1,3}\\.?\\d*%",
309
310
  "store_lines": true
311
+ },
312
+ "command_invocation_failure": {
313
+ "active": true,
314
+ "start_pattern": "CommandInvokationFailure: (?<message>.+\\.)",
315
+ "store_lines": true,
316
+ "end_pattern": "^\\n",
317
+ "start_message": "[ANDROID] Command invocation failure: %{message}",
318
+ "end_message": false,
319
+ "type": "error"
320
+ },
321
+ "command_invocation_failure_stderr": {
322
+ "active": true,
323
+ "start_pattern": "stderr\\[",
324
+ "store_lines": true,
325
+ "ignore_lines": ["^\\n"],
326
+ "end_pattern": "\\]\\n",
327
+ "start_message": "[ANDROID] Errors:",
328
+ "end_message": false,
329
+ "type": "error"
330
+ },
331
+ "command_invocation_failure_stdout": {
332
+ "active": true,
333
+ "start_pattern": "stdout\\[",
334
+ "store_lines": true,
335
+ "ignore_lines": ["^\\n"],
336
+ "end_pattern": "\\]\\n",
337
+ "start_message": "[ANDROID] Warnings:",
338
+ "end_message": false,
339
+ "type": "warning"
340
+ },
341
+ "command_invocation_failure_stack": {
342
+ "active": true,
343
+ "start_pattern": "[Ee]xit code: (?<code>\\d+)",
344
+ "end_pattern": "Filename: (?:.+/(?<file>\\w+\\.\\w+))? Line: (?<line>-?\\d+)",
345
+ "start_message": false,
346
+ "end_message": "[ANDROID] %{file}(line %{line}) Exit code %{code}"
310
347
  }
311
348
  }
312
349
  }
data/lib/u3d/cache.rb CHANGED
@@ -133,6 +133,7 @@ module U3d
133
133
  @cache = data unless need_update
134
134
  !need_update
135
135
  rescue StandardError => e
136
+ UI.verbose(e.backtrace.join("\n"))
136
137
  UI.error("Failed fetching central versions.json. Manual fetch for platform #{os} #{e}")
137
138
  false
138
139
  end
data/lib/u3d/commands.rb CHANGED
@@ -106,7 +106,7 @@ module U3d
106
106
  UI.user_error!("You cannot use the --operating_system and the --install options together") if options[:install] && options[:operating_system]
107
107
  os = valid_os_or_current(options[:operating_system])
108
108
 
109
- packages = packages_with_unity_first(os, options)
109
+ packages = packages_with_unity_first(options)
110
110
 
111
111
  cache_versions = cache_versions(os, offline: !options[:download])
112
112
  version = interpret_latest(version, cache_versions)
@@ -286,11 +286,7 @@ module U3d
286
286
  iversion
287
287
  end
288
288
 
289
- def packages_with_unity_first(os, options)
290
- if os == :linux
291
- UI.important 'Option -a | --all currently meaningless for Linux (only one package available)' if options[:all]
292
- UI.important 'Option -p | --packages currently meaningless for Linux (only one package available)' if options[:packages]
293
- end
289
+ def packages_with_unity_first(options)
294
290
  temp = options[:packages] || ['Unity']
295
291
  temp.insert(0, 'Unity') if temp.delete('Unity')
296
292
  temp
@@ -31,7 +31,7 @@ module U3d
31
31
  # Path to the directory for the package downloading
32
32
  DOWNLOAD_PATH = "#{ENV['HOME']}/Downloads".freeze
33
33
  # Regex to get the name of a package out of its file name
34
- UNITY_MODULE_FILE_REGEX = %r{\/([\w\-_\.\+]+\.(?:pkg|exe|zip|sh|deb|msi))[^\/]*$}
34
+ UNITY_MODULE_FILE_REGEX = %r{\/([\w\-_\.\+]+\.(?:pkg|exe|zip|sh|deb|msi|xz))[^\/]*$}
35
35
 
36
36
  class << self
37
37
  def download_directory
data/lib/u3d/iniparser.rb CHANGED
@@ -46,21 +46,12 @@ module U3d
46
46
  Utils.ensure_dir(default_ini_path)
47
47
  ini_path = File.expand_path(ini_name, default_ini_path)
48
48
  unless File.file?(ini_path)
49
- if os == 'linux'
50
- UI.error "No INI file for version #{version}. Try discovering the available versions with 'u3d available -f'" unless offline
51
- return nil
52
- end
53
49
  raise "INI file does not exist at #{ini_path}" if offline
54
- uri = URI(cached_versions[version] + ini_name)
55
- File.open(ini_path, 'wb') do |f|
56
- data = Net::HTTP.get(uri)
57
- data.tr!("\"", '')
58
- data.gsub!(/Note:.+\n/, '')
59
- f.write(data)
60
- end
50
+ download_ini(version, cached_versions, os, ini_name, ini_path)
61
51
  end
62
52
  begin
63
53
  result = IniFile.load(ini_path).to_h
54
+ result = filter_broken_linux(result) if os == 'linux'
64
55
  rescue StandardError => e
65
56
  raise "Could not parse INI data (#{e})"
66
57
  end
@@ -87,6 +78,33 @@ url=#{url}
87
78
 
88
79
  private
89
80
 
81
+ def download_ini(version, cached_versions, os, ini_name, ini_path)
82
+ # former urls for Linux pointed to unity-editor-installer.sh directlry
83
+ if os == 'linux' && cached_versions[version] =~ /.*.sh$/
84
+ UI.verbose "No INI on server. Faking one by finding out package size for version #{version}"
85
+ url = cached_versions[version]
86
+ size = Utils.get_url_content_length(url)
87
+ if size
88
+ create_linux_ini(version, size, url)
89
+ else
90
+ UI.important "u3d tried to get the size of the installer for version #{version}, but wasn't able to"
91
+ end
92
+ return
93
+ end
94
+ uri = URI(cached_versions[version] + ini_name)
95
+ UI.verbose("Searching for ini file at #{uri}")
96
+ File.open(ini_path, 'wb') do |f|
97
+ data = Net::HTTP.get(uri)
98
+ data.tr!("\"", '')
99
+ data.gsub!(/Note:.+\n/, '')
100
+ f.write(data)
101
+ end
102
+ end
103
+
104
+ def filter_broken_linux(ini_hash)
105
+ ini_hash.select { |_k, v| v['url'] && !v['url'].end_with?('.pkg') }
106
+ end
107
+
90
108
  def default_ini_path
91
109
  case U3dCore::Helper.operating_system
92
110
  when :linux
@@ -189,6 +189,32 @@ module U3d
189
189
  @root_path || @path
190
190
  end
191
191
 
192
+ def packages
193
+ path = "#{root_path}/Editor/Data/"
194
+ pack = []
195
+ PlaybackEngineUtils.list_module_configs(path).each do |mpath|
196
+ pack << PlaybackEngineUtils.module_name(mpath)
197
+ end
198
+ NOT_PLAYBACKENGINE_PACKAGES.each do |module_name|
199
+ pack << module_name unless Dir[module_name_pattern(module_name)].empty?
200
+ end
201
+ pack
202
+ end
203
+
204
+ def module_name_pattern(module_name)
205
+ # FIXME: we are not yet sure where these modules will end up yet
206
+ case module_name
207
+ when 'Documentation'
208
+ return "#{root_path}/Editor/Data/Documentation/"
209
+ when 'StandardAssets'
210
+ return "#{root_path}/Editor/Standard Assets/"
211
+ when 'MonoDevelop'
212
+ return "#{root_path}/MonoDevelop/"
213
+ else
214
+ UI.crash! "No pattern is known for #{module_name} on Linux"
215
+ end
216
+ end
217
+
192
218
  def clean_install?
193
219
  !(root_path =~ UNITY_DIR_CHECK_LINUX).nil?
194
220
  end
data/lib/u3d/installer.rb CHANGED
@@ -212,12 +212,17 @@ module U3d
212
212
  def install(file_path, version, installation_path: nil, info: {})
213
213
  # rubocop:enable UnusedMethodArgument
214
214
  extension = File.extname(file_path)
215
- raise "Installation of #{extension} files is not supported on Linux" if extension != '.sh'
216
- path = installation_path || DEFAULT_LINUX_INSTALL
217
- install_sh(
218
- file_path,
219
- installation_path: path
220
- )
215
+
216
+ raise "Installation of #{extension} files is not supported on Linux" unless ['.sh', '.xz'].include? extension
217
+ if extension == '.sh'
218
+ path = installation_path || DEFAULT_LINUX_INSTALL
219
+ install_sh(file_path, installation_path: path)
220
+ elsif extension == '.xz'
221
+ new_path = File.join(DEFAULT_LINUX_INSTALL, format(UNITY_DIR_LINUX, version: version))
222
+ path = installation_path || new_path
223
+ install_xz(file_path, installation_path: path)
224
+ end
225
+
221
226
  # Forces sanitation for installation of 'weird' versions eg 5.6.1xf1Linux
222
227
  unity = installed.select { |u| u.version == version }.first
223
228
  if unity
@@ -240,7 +245,19 @@ module U3d
240
245
  U3dCore::CommandExecutor.execute(command: cmd, admin: true)
241
246
  end
242
247
  rescue StandardError => e
243
- UI.error "Failed to install bash file at #{file}: #{e}"
248
+ UI.error "Failed to install sh file #{file} at #{installation_path}: #{e}"
249
+ else
250
+ UI.success 'Installation successful'
251
+ end
252
+
253
+ def install_xz(file, installation_path: nil)
254
+ raise 'Missing installation_path' unless installation_path
255
+
256
+ command = "cd #{installation_path.shellescape}; tar xf #{file.shellescape}"
257
+ command = "mkdir -p #{installation_path.shellescape}; #{command}" unless File.directory? installation_path
258
+ U3dCore::CommandExecutor.execute(command: command, admin: true)
259
+ rescue StandardError => e
260
+ UI.error "Failed to install xz file #{file} at #{installation_path}: #{e}"
244
261
  else
245
262
  UI.success 'Installation successful'
246
263
  end
@@ -58,9 +58,5 @@ module U3d
58
58
  return -1 unless @ini[package] && @ini[package]['size']
59
59
  @os == :win ? @ini[package]['size'] * 1024 : @ini[package]['size']
60
60
  end
61
-
62
- def self.create_fake(version, size, url)
63
- INIparser.create_linux_ini(version, size, url)
64
- end
65
61
  end
66
62
  end
@@ -25,6 +25,78 @@ require 'u3d_core/helper'
25
25
  require 'net/http'
26
26
 
27
27
  module U3d
28
+ class UnityForums
29
+ def pagination_urls(url)
30
+ # hardcoded for now
31
+ # otherwise maybe
32
+ # # <div class="PageNav" data-page="7" data-range="2" data-start="5" data-end="9" data-last="10" data-sentinel="{{sentinel}}" data-baseurl="threads/twitter.12003/page-{{sentinel}}"
33
+ # <span class="pageNavHeader">Page 7 of 10</span>
34
+ [url,
35
+ "#{url}page-2"]
36
+ end
37
+
38
+ def page_content(url)
39
+ fetch_cookie
40
+ request_headers = { 'Connection' => 'keep-alive', 'Cookie' => @cookie }
41
+ UI.verbose "Fetching from #{url}"
42
+ Utils.page_content(url, request_headers: request_headers)
43
+ end
44
+
45
+ private
46
+
47
+ def fetch_cookie
48
+ UI.verbose "FetchCookie? #{@cookie}"
49
+ return @cookie if @cookie
50
+ cookie_str = ''
51
+ url = 'https://forum.unity.com/forums/linux-editor.93/' # a page that triggers cookies
52
+ uri = URI(url)
53
+ Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
54
+ request = Net::HTTP::Get.new uri
55
+ request['Connection'] = 'keep-alive'
56
+ response = http.request request
57
+
58
+ case response
59
+ when Net::HTTPSuccess then
60
+ UI.verbose "unexpected result"
61
+ when Net::HTTPRedirection then
62
+ # A session must be opened with the server before accessing forum
63
+ res = nil
64
+ cookie_str = ''
65
+ # Store the name and value of the cookies returned by the server
66
+ response['set-cookie'].gsub(/\s+/, '').split(',').each do |c|
67
+ cookie_str << c.split(';', 2)[0] + '; '
68
+ end
69
+ cookie_str.chomp!('; ')
70
+
71
+ # It should be the Unity register API
72
+ uri = URI(response['location'])
73
+ UI.verbose "Redirecting to #{uri}"
74
+ Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http_api|
75
+ request = Net::HTTP::Get.new uri
76
+ request['Connection'] = 'keep-alive'
77
+ res = http_api.request request
78
+ end
79
+
80
+ raise 'Unexpected result' unless res.is_a? Net::HTTPRedirection
81
+ # It should be a redirection to the forum to perform authentication
82
+ uri = URI(res['location'])
83
+ UI.verbose "Redirecting to #{uri}"
84
+ request = Net::HTTP::Get.new uri
85
+ request['Connection'] = 'keep-alive'
86
+ request['Cookie'] = cookie_str
87
+
88
+ res = http.request request
89
+
90
+ raise 'Unable to establish a session with Unity forum' unless res.is_a? Net::HTTPRedirection
91
+
92
+ UI.verbose "Found cookie_str #{cookie_str}"
93
+ cookie_str << '; ' + res['set-cookie'].gsub(/\s+/, '').split(';', 2)[0]
94
+ end
95
+ end
96
+ UI.verbose "Found @cookie #{cookie_str}"
97
+ @cookie = cookie_str
98
+ end
99
+ end
28
100
  # Takes care of fectching versions and version list
29
101
  module UnityVersions
30
102
  #####################################################
@@ -45,6 +117,7 @@ module U3d
45
117
  # @!group REGEX: expressions to interpret data
46
118
  #####################################################
47
119
  # Captures a version and its base url
120
+ LINUX_DOWNLOAD = %r{'(https?://[\w/\.-]+/[0-9a-f]{12}/)(./)?UnitySetup-(\d+\.\d+\.\d+\w\d+)'}
48
121
  MAC_DOWNLOAD = %r{"(https?://[\w/\.-]+/[0-9a-f]{12}/)MacEditorInstaller/[a-zA-Z0-9/\.]+-(\d+\.\d+\.\d+\w\d+)\.?\w+"}
49
122
  WIN_DOWNLOAD = %r{"(https?://[\w/\.-]+/[0-9a-f]{12}/)Windows..EditorInstaller/[a-zA-Z0-9/\.]+-(\d+\.\d+\.\d+\w\d+)\.?\w+"}
50
123
  LINUX_DOWNLOAD_DATED = %r{"(https?://[\w/\._-]+/unity\-editor\-installer\-(\d+\.\d+\.\d+\w\d+).*\.sh)"}
@@ -94,127 +167,56 @@ module U3d
94
167
  end
95
168
 
96
169
  class LinuxVersions
170
+ @unity_forums = U3d::UnityForums.new
97
171
  class << self
172
+ attr_accessor :unity_forums
173
+
98
174
  def list_available
99
175
  UI.message 'Loading Unity releases'
176
+ versions = @unity_forums.pagination_urls(UNITY_LINUX_DOWNLOADS).map do |page_url|
177
+ list_available_from_page(@unity_forums, unity_forums.page_content(page_url))
178
+ end.reduce({}, :merge)
179
+ if versions.count.zero?
180
+ UI.important 'Found no releases'
181
+ else
182
+ UI.success "Found #{versions.count} releases."
183
+ end
184
+ versions
185
+ end
100
186
 
101
- data = linux_forum_page_content
187
+ private
102
188
 
189
+ def list_available_from_page(unity_forums, data)
103
190
  versions = {}
104
191
  results = data.scan(LINUX_DOWNLOAD_DATED)
105
192
  results.each do |capt|
106
- save_package_size(capt[1], capt[0])
107
193
  versions[capt[1]] = capt[0]
108
194
  end
109
195
 
110
- response = nil
111
196
  results = data.scan(LINUX_DOWNLOAD_RECENT_PAGE)
112
197
  results.each do |page|
113
- response = linux_forum_version_page_content(page[0])
114
- if response.is_a? Net::HTTPSuccess
115
- capt = response.body.match(LINUX_DOWNLOAD_RECENT_FILE)
116
- if capt && capt[1] && capt[2]
117
- ver = capt[2].delete('x')
118
- UI.important "Version #{ver} does not match standard Unity versions" unless ver =~ Utils::UNITY_VERSION_REGEX
119
- save_package_size(ver, capt[1])
198
+ url = page[0]
199
+ page_body = unity_forums.page_content(url)
200
+ capt = page_body.match(LINUX_DOWNLOAD_RECENT_FILE)
201
+ if capt && capt[1] && capt[2]
202
+ ver = capt[2].delete('x')
203
+ UI.important "Version #{ver} does not match standard Unity versions" unless ver =~ Utils::UNITY_VERSION_REGEX
204
+ versions[ver] = capt[1]
205
+ else
206
+ capt = page_body.match(LINUX_DOWNLOAD)
207
+ # newer version of unity on linux support ini files
208
+ # http://beta.unity3d.com/download/3c89f8d277f5/unity-2017.3.0f1-linux.ini
209
+ if capt && capt[1] && capt[3]
210
+ ver = capt[3]
211
+ UI.verbose("Linux version #{ver}. Could not retrieve a fitting file from #{url}. Assuming ini file present")
120
212
  versions[ver] = capt[1]
121
213
  else
122
- UI.error("Could not retrieve a fitting file from #{url}")
214
+ UI.important("Could not retrieve a fitting file from #{url}.")
123
215
  end
124
- else
125
- UI.error("Could not access #{url}")
126
216
  end
127
217
  end
128
- if versions.count.zero?
129
- UI.important 'Found no releases'
130
- else
131
- UI.success "Found #{versions.count} releases."
132
- end
133
218
  versions
134
219
  end
135
-
136
- def save_package_size(version, url)
137
- uvd = UnityVersionDefinition.new(version, :linux, nil, offline: true)
138
- if (size = uvd.size_in_bytes('Unity'))
139
- UI.verbose "Package size for version #{version} already cached: #{size}"
140
- return
141
- end
142
- UI.verbose "Finding out package size for version #{version}"
143
- size = Utils.get_url_content_length(url)
144
- if size
145
- UnityVersionDefinition.create_fake(version, size, url)
146
- else
147
- UI.important "u3d tried to get the size of the installer for version #{version}, but wasn't able to"
148
- end
149
- end
150
-
151
- def linux_forum_page_content
152
- response = nil
153
- data = ''
154
- uri = URI(UNITY_LINUX_DOWNLOADS)
155
- Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
156
- request = Net::HTTP::Get.new uri
157
- request['Connection'] = 'keep-alive'
158
- response = http.request request
159
-
160
- case response
161
- when Net::HTTPSuccess then
162
- # Successfully retrieved forum content
163
- data = response.body
164
- when Net::HTTPRedirection then
165
- # A session must be opened with the server before accessing forum
166
- res = nil
167
- cookie_str = ''
168
- # Store the name and value of the cookies returned by the server
169
- response['set-cookie'].gsub(/\s+/, '').split(',').each do |c|
170
- cookie_str << c.split(';', 2)[0] + '; '
171
- end
172
- cookie_str.chomp!('; ')
173
-
174
- # It should be the Unity register API
175
- uri = URI(response['location'])
176
- Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http_api|
177
- request = Net::HTTP::Get.new uri
178
- request['Connection'] = 'keep-alive'
179
- res = http_api.request request
180
- end
181
-
182
- raise 'Unexpected result' unless res.is_a? Net::HTTPRedirection
183
- # It should be a redirection to the forum to perform authentication
184
- uri = URI(res['location'])
185
-
186
- request = Net::HTTP::Get.new uri
187
- request['Connection'] = 'keep-alive'
188
- request['Cookie'] = cookie_str
189
-
190
- res = http.request request
191
-
192
- raise 'Unable to establish a session with Unity forum' unless res.is_a? Net::HTTPRedirection
193
-
194
- cookie_str << '; ' + res['set-cookie'].gsub(/\s+/, '').split(';', 2)[0]
195
-
196
- uri = URI(res['location'])
197
-
198
- request = Net::HTTP::Get.new uri
199
- request['Connection'] = 'keep-alive'
200
- request['Cookie'] = cookie_str
201
-
202
- res = http.request request
203
-
204
- data = res.body if res.is_a? Net::HTTPSuccess
205
- else raise "Request failed with status #{response.code}"
206
- end
207
- end
208
- data
209
- end
210
-
211
- def linux_forum_version_page_content(url)
212
- uri = URI(url)
213
- Net::HTTP.start(uri.host, uri.port) do |http|
214
- request = Net::HTTP::Get.new uri
215
- return http.request request
216
- end
217
- end
218
220
  end
219
221
  end
220
222
 
data/lib/u3d/utils.rb CHANGED
@@ -40,13 +40,18 @@ module U3d
40
40
  end
41
41
  end
42
42
 
43
- def get_ssl(url, redirect_limit: 10)
44
- follow_redirects(url, redirect_limit: redirect_limit) do |_request, response|
43
+ # FIXME: alias deprecated
44
+ def get_ssl(url, redirect_limit: 10, request_headers: {})
45
+ page_content(url, redirect_limit: redirect_limit, request_headers: request_headers)
46
+ end
47
+
48
+ def page_content(url, redirect_limit: 10, request_headers: {})
49
+ follow_redirects(url, redirect_limit: redirect_limit, request_headers: request_headers) do |_request, response|
45
50
  response.body
46
51
  end
47
52
  end
48
53
 
49
- def follow_redirects(url, redirect_limit: 10, http_method: :get, &block)
54
+ def follow_redirects(url, redirect_limit: 10, http_method: :get, request_headers: {}, &block)
50
55
  raise 'Too many redirections' if redirect_limit.zero?
51
56
  response = nil
52
57
  request = nil
@@ -55,6 +60,9 @@ module U3d
55
60
  use_ssl = /^https/.match(url)
56
61
  Net::HTTP.start(uri.host, uri.port, use_ssl: use_ssl) do |http|
57
62
  request = http_request_class http_method, uri
63
+ request_headers.each do |k, v|
64
+ request[k] = v
65
+ end
58
66
  response = http.request request
59
67
  end
60
68
  rescue OpenSSL::OpenSSLError => ssl_error
@@ -67,7 +75,7 @@ module U3d
67
75
  yield(request, response)
68
76
  when Net::HTTPRedirection then
69
77
  UI.verbose "Redirected to #{response['location']}"
70
- follow_redirects(response['location'], redirect_limit: redirect_limit - 1, http_method: http_method, &block)
78
+ follow_redirects(response['location'], redirect_limit: redirect_limit - 1, http_method: http_method, request_headers: request_headers, &block)
71
79
  else raise "Request failed with status #{response.code}"
72
80
  end
73
81
  end
data/lib/u3d/version.rb CHANGED
@@ -21,7 +21,7 @@
21
21
  ## --- END LICENSE BLOCK ---
22
22
 
23
23
  module U3d
24
- VERSION = '1.0.15'.freeze
24
+ VERSION = '1.0.16'.freeze
25
25
  DESCRIPTION = 'Provides numerous tools for installing, managing and running the Unity3D game engine from command line.'.freeze
26
26
  UNITY_VERSIONS_NOTE = "Unity3d uses the following version formatting: 0.0.0x0. The \'x\' can takes different values:\n"\
27
27
  "\t. 'f' are the main release candidates for Unity3d\n"\
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: u3d
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.15
4
+ version: 1.0.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jerome Lacoste
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2018-01-16 00:00:00.000000000 Z
12
+ date: 2018-02-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: colored
@@ -254,6 +254,8 @@ extensions: []
254
254
  extra_rdoc_files: []
255
255
  files:
256
256
  - ".circleci/config.yml"
257
+ - ".github/ISSUE_TEMPLATE.md"
258
+ - ".github/PULL_REQUEST_TEMPLATE.md"
257
259
  - ".github_changelog_generator"
258
260
  - ".gitignore"
259
261
  - ".licenses.json"