Skip to content

Commit 78d6d99

Browse files
Merge pull request #26 from Lyaaaaaaaaaaaaaaa/Develop
Release 1.0.2
2 parents 5508fbd + c730262 commit 78d6d99

File tree

4 files changed

+34
-12
lines changed

4 files changed

+34
-12
lines changed

Godot/addons/file_downloader/file_downloader.gd

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,17 @@
8686
#--
8787
#-- - 15/11/2023 Lyaaaaa
8888
#-- - Updated _downloads_done to call _reset before emitting "downloads_finished"
89+
#--
90+
#-- - 18/12/2023 Lyaaaaa
91+
#-- - Replaced the prints by push_error when needed.
92+
#-- - Replaced the _downloading var by _is_busy.
93+
#-- - Added is_busy method.
94+
#-- - is_downloading is now depreciated and calls is_busy.
95+
#-- - Updated _download_next_file to set busy to true.
96+
#--
97+
#-- - 05/02/2024 Lyaaaaa
98+
#-- - Added use_threads = true in _init to always have it on. It is important
99+
#-- for download speed
89100
#------------------------------------------------------------------------------
90101
class_name FileDownloader
91102
extends HTTPRequest
@@ -112,11 +123,13 @@ var _downloaded_size : float = 0
112123

113124
var _last_method : int
114125

115-
var _downloading : bool = false:
116-
get = is_downloading
126+
var _busy : bool = false:
127+
get = is_busy,
128+
set = set_busy
117129

118130

119131
func _init() -> void:
132+
use_threads = true
120133
set_process(false)
121134
connect("request_completed", Callable(self, "_on_request_completed"))
122135

@@ -134,7 +147,8 @@ func start_download(p_urls : PackedStringArray = file_urls,
134147
file_urls = p_urls
135148
save_path = p_save_path
136149
_create_directory()
137-
_download_next_file()
150+
if not is_busy():
151+
_download_next_file()
138152

139153

140154
func get_stats() -> Dictionary:
@@ -147,15 +161,23 @@ func get_stats() -> Dictionary:
147161

148162

149163
func is_downloading() -> bool:
150-
return _downloading
164+
# Depreciated. Will be removed in next release
165+
return is_busy()
166+
167+
168+
func is_busy() -> bool:
169+
return _busy
170+
171+
func set_busy(p_busy : bool) -> void:
172+
_busy = p_busy
151173

152174

153175
func _reset() -> void:
154176
_current_url = ""
155177
_current_url_index = 0
156178
_downloaded_percent = 0
157179
_downloaded_size = 0
158-
_downloading = false
180+
set_busy(false)
159181

160182

161183
func _downloads_done() -> void:
@@ -178,14 +200,13 @@ func _send_get_request() -> void:
178200
var error = request(_current_url, _headers, HTTPClient.METHOD_GET)
179201
if error == OK:
180202
emit_signal("downloads_started")
181-
_downloading = true
182203
_last_method = HTTPClient.METHOD_GET
183204
set_process(true)
184205

185206
elif error == ERR_INVALID_PARAMETER:
186-
print("Given string isn't a valid url ")
207+
push_error("Given string isn't a valid url: ", _current_url)
187208
elif error == ERR_CANT_CONNECT:
188-
print("Can't connect to host")
209+
push_error("Can't connect to host")
189210

190211

191212
func _update_stats() -> void:
@@ -214,6 +235,7 @@ func _create_directory() -> void:
214235

215236
func _download_next_file() -> void:
216237
if _current_url_index < file_urls.size():
238+
set_busy(true)
217239
_current_url = file_urls[_current_url_index]
218240
_file_name = _current_url.get_file()
219241
download_file = save_path.path_join(_file_name)
@@ -253,7 +275,7 @@ func _on_request_completed(p_result,
253275
emit_signal("file_downloaded", _file_name)
254276
_download_next_file()
255277
else:
256-
print("HTTP Request error: ", p_result)
278+
push_error("HTTP Request error: ", p_result)
257279

258280

259281
func _on_file_downloaded() -> void:
@@ -266,3 +288,4 @@ func _on_file_downloaded() -> void:
266288

267289
else:
268290
_downloads_done()
291+

Godot/addons/file_downloader/plugin.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
name="FileDownloader"
44
description="An easy to use file downloader class"
55
author="Lyaaaaaaaaaaaaaaa"
6-
version="1.0.2"
6+
version="1.0.3"
77
script="plugin.gd"

Godot/node_example/demo.tscn

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ script = ExtResource("2")
1313
[node name="FileDownloader" type="HTTPRequest" parent="."]
1414
use_threads = true
1515
script = ExtResource("1")
16-
save_path = "user://cache/"
1716
file_urls = PackedStringArray("https://godotengine.org/assets/home/features/cross-platform.svg", "https://godotengine.org/assets/home/features/oss.svg", "https://godotengine.org/assets/showcase/dome-keeper.jpg", "https://godotengine.org/assets/showcase/brotato-2.jpg")
1817

1918
[node name="Button" type="Button" parent="."]

Godot/project.godot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ config_version=5
1212

1313
config/name="File Downloader"
1414
run/main_scene="res://node_example/demo.tscn"
15-
config/features=PackedStringArray("4.1")
15+
config/features=PackedStringArray("4.2")
1616
config/icon="res://icon.png"
1717

1818
[debug]

0 commit comments

Comments
 (0)