@@ -128,24 +128,46 @@ func _on_Download_pressed():
128
128
var file_regex = RegEx .new ()
129
129
file_regex .compile ("[^/]+?\\ .zip" )
130
130
var filename = file_regex .search (url ).get_string ()
131
+ var zip_path = "res://sketchfab/%s " % filename
131
132
132
133
downloader .connect ("download_progressed" , self , "_on_download_progressed" )
133
- downloader .request (path , null , { "download_to" : "res://sketchfab/ %s " % filename })
134
+ downloader .request (path , null , { "download_to" : zip_path })
134
135
result = yield (downloader , "completed" )
136
+ if ! result :
137
+ return
135
138
downloader .term ()
136
139
downloader = null
137
140
138
- download .visible = true
139
- progress .visible = false
140
- size_label .visible = false
141
- if result :
142
- if result .ok && result .code == 200 :
143
- download .text = "Model downloaded!"
144
- download .disabled = true
145
- else :
146
- OS .alert (
147
- "Please check your network connectivity, free disk space and try again." ,
148
- "Download error" )
141
+ if ! result .ok || result .code != 200 :
142
+ download .visible = true
143
+ progress .visible = false
144
+ size_label .visible = false
145
+ OS .alert (
146
+ "Please check your network connectivity, free disk space and try again." ,
147
+ "Download error" )
148
+ return
149
+
150
+ # Unpack
151
+
152
+ progress .percent_visible = false
153
+ size_label .text = " Model downloaded! Unpacking..."
154
+ yield (get_tree (), "idle_frame" )
155
+ if ! get_tree ():
156
+ return
157
+
158
+ var out = []
159
+ OS .execute (OS .get_executable_path (), [
160
+ "-s" , ProjectSettings .globalize_path ("res://addons/sketchfab/unzip.gd" ),
161
+ "--zip-to-unpack %s " % ProjectSettings .globalize_path (zip_path ),
162
+ "--no-window" ,
163
+ "--quit" ,
164
+ ], true , out )
165
+ print (out )
166
+
167
+ size_label .text = " Model unpacked into project!"
168
+
169
+ # Trigger import
170
+ get_tree ().get_meta ("__editor_interface" ).get_resource_filesystem ().scan ()
149
171
150
172
func _on_download_progressed (bytes , total_bytes ):
151
173
if ! get_tree ():
0 commit comments