@@ -103,21 +103,25 @@ void ProjectDialog::_set_message(const String &p_msg, MessageType p_type, InputT
103103 }
104104}
105105
106+ static bool is_zip_file (Ref<DirAccess> p_d, const String &p_path) {
107+ return p_path.ends_with (" .zip" ) && p_d->file_exists (p_path);
108+ }
109+
106110String ProjectDialog::_test_path () {
107111 Ref<DirAccess> d = DirAccess::create (DirAccess::ACCESS_FILESYSTEM );
112+ const String base_path = project_path->get_text ();
108113 String valid_path, valid_install_path;
109- if (d->change_dir (project_path->get_text ()) == OK ) {
110- valid_path = project_path->get_text ();
111- } else if (d->change_dir (project_path->get_text ().strip_edges ()) == OK ) {
112- valid_path = project_path->get_text ().strip_edges ();
113- } else if (project_path->get_text ().ends_with (" .zip" )) {
114- if (d->file_exists (project_path->get_text ())) {
115- valid_path = project_path->get_text ();
116- }
117- } else if (project_path->get_text ().strip_edges ().ends_with (" .zip" )) {
118- if (d->file_exists (project_path->get_text ().strip_edges ())) {
119- valid_path = project_path->get_text ().strip_edges ();
120- }
114+ bool is_zip = false ;
115+ if (d->change_dir (base_path) == OK ) {
116+ valid_path = base_path;
117+ } else if (is_zip_file (d, base_path)) {
118+ valid_path = base_path;
119+ is_zip = true ;
120+ } else if (d->change_dir (base_path.strip_edges ()) == OK ) {
121+ valid_path = base_path.strip_edges ();
122+ } else if (is_zip_file (d, base_path.strip_edges ())) {
123+ valid_path = base_path.strip_edges ();
124+ is_zip = true ;
121125 }
122126
123127 if (valid_path.is_empty ()) {
@@ -126,23 +130,23 @@ String ProjectDialog::_test_path() {
126130 return " " ;
127131 }
128132
129- if (mode == MODE_IMPORT && valid_path. ends_with ( " .zip " ) ) {
133+ if (mode == MODE_IMPORT && is_zip ) {
130134 if (d->change_dir (install_path->get_text ()) == OK ) {
131135 valid_install_path = install_path->get_text ();
132136 } else if (d->change_dir (install_path->get_text ().strip_edges ()) == OK ) {
133137 valid_install_path = install_path->get_text ().strip_edges ();
134138 }
135139
136140 if (valid_install_path.is_empty ()) {
137- _set_message (TTR (" The path specified doesn't exist." ), MESSAGE_ERROR , INSTALL_PATH );
141+ _set_message (TTR (" The install path specified doesn't exist." ), MESSAGE_ERROR , INSTALL_PATH );
138142 get_ok_button ()->set_disabled (true );
139143 return " " ;
140144 }
141145 }
142146
143147 if (mode == MODE_IMPORT || mode == MODE_RENAME ) {
144- if (!valid_path. is_empty () && ! d->file_exists (" project.godot" )) {
145- if (valid_path. ends_with ( " .zip " ) ) {
148+ if (!d->file_exists (" project.godot" )) {
149+ if (is_zip ) {
146150 Ref<FileAccess> io_fa;
147151 zlib_filefunc_def io = zipio_create_io (&io_fa);
148152
@@ -197,7 +201,7 @@ String ProjectDialog::_test_path() {
197201 d->list_dir_end ();
198202
199203 if (!is_folder_empty) {
200- _set_message (TTR (" Please choose an empty folder." ), MESSAGE_WARNING , INSTALL_PATH );
204+ _set_message (TTR (" Please choose an empty install folder." ), MESSAGE_WARNING , INSTALL_PATH );
201205 get_ok_button ()->set_disabled (true );
202206 return " " ;
203207 }
@@ -209,8 +213,8 @@ String ProjectDialog::_test_path() {
209213 return " " ;
210214 }
211215
212- } else if (valid_path. ends_with ( " zip " ) ) {
213- _set_message (TTR (" This directory already contains a Godot project." ), MESSAGE_ERROR , INSTALL_PATH );
216+ } else if (is_zip ) {
217+ _set_message (TTR (" The install directory already contains a Godot project." ), MESSAGE_ERROR , INSTALL_PATH );
214218 get_ok_button ()->set_disabled (true );
215219 return " " ;
216220 }
@@ -252,7 +256,7 @@ String ProjectDialog::_test_path() {
252256 return valid_path;
253257}
254258
255- void ProjectDialog::_path_text_changed (const String &p_path) {
259+ void ProjectDialog::_update_path (const String &p_path) {
256260 String sp = _test_path ();
257261 if (!sp.is_empty ()) {
258262 // If the project name is empty or default, infer the project name from the selected folder name
@@ -277,6 +281,21 @@ void ProjectDialog::_path_text_changed(const String &p_path) {
277281 }
278282}
279283
284+ void ProjectDialog::_path_text_changed (const String &p_path) {
285+ Ref<DirAccess> d = DirAccess::create (DirAccess::ACCESS_FILESYSTEM );
286+ if (mode == MODE_IMPORT && is_zip_file (d, p_path)) {
287+ install_path->set_text (p_path.get_base_dir ());
288+ install_path_container->show ();
289+ } else if (mode == MODE_IMPORT && is_zip_file (d, p_path.strip_edges ())) {
290+ install_path->set_text (p_path.strip_edges ().get_base_dir ());
291+ install_path_container->show ();
292+ } else {
293+ install_path_container->hide ();
294+ }
295+
296+ _update_path (p_path.simplify_path ());
297+ }
298+
280299void ProjectDialog::_file_selected (const String &p_path) {
281300 // If not already shown.
282301 show_dialog ();
@@ -300,7 +319,7 @@ void ProjectDialog::_file_selected(const String &p_path) {
300319
301320 String sp = p.simplify_path ();
302321 project_path->set_text (sp);
303- _path_text_changed (sp);
322+ _update_path (sp);
304323 if (p.ends_with (" .zip" )) {
305324 install_path->call_deferred (SNAME (" grab_focus" ));
306325 } else {
@@ -314,14 +333,14 @@ void ProjectDialog::_path_selected(const String &p_path) {
314333
315334 String sp = p_path.simplify_path ();
316335 project_path->set_text (sp);
317- _path_text_changed (sp);
336+ _update_path (sp);
318337 get_ok_button ()->call_deferred (SNAME (" grab_focus" ));
319338}
320339
321340void ProjectDialog::_install_path_selected (const String &p_path) {
322341 String sp = p_path.simplify_path ();
323342 install_path->set_text (sp);
324- _path_text_changed (sp);
343+ _update_path (sp);
325344 get_ok_button ()->call_deferred (SNAME (" grab_focus" ));
326345}
327346
@@ -359,7 +378,7 @@ void ProjectDialog::_create_folder() {
359378 d->change_dir (project_name_no_edges);
360379 String dir_str = d->get_current_dir ();
361380 project_path->set_text (dir_str);
362- _path_text_changed (dir_str);
381+ _update_path (dir_str);
363382 created_folder_path = d->get_current_dir ();
364383 create_dir->set_disabled (true );
365384 } else {
@@ -638,7 +657,7 @@ void ProjectDialog::cancel_pressed() {
638657 _remove_created_folder ();
639658
640659 project_path->clear ();
641- _path_text_changed (" " );
660+ _update_path (" " );
642661 project_name->clear ();
643662 _text_changed (" " );
644663
@@ -968,7 +987,7 @@ ProjectDialog::ProjectDialog() {
968987
969988 project_name->connect (" text_changed" , callable_mp (this , &ProjectDialog::_text_changed));
970989 project_path->connect (" text_changed" , callable_mp (this , &ProjectDialog::_path_text_changed));
971- install_path->connect (" text_changed" , callable_mp (this , &ProjectDialog::_path_text_changed ));
990+ install_path->connect (" text_changed" , callable_mp (this , &ProjectDialog::_update_path ));
972991 fdialog->connect (" dir_selected" , callable_mp (this , &ProjectDialog::_path_selected));
973992 fdialog->connect (" file_selected" , callable_mp (this , &ProjectDialog::_file_selected));
974993 fdialog_install->connect (" dir_selected" , callable_mp (this , &ProjectDialog::_install_path_selected));
0 commit comments