From 2dfa1279eaed14c4d42d431fc62f3e8c881c2d38 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Sun, 12 Apr 2015 16:45:59 -0300 Subject: [PATCH] improved save path error messages for scene, textures and audio, fixes #1514 --- core/os/dir_access.cpp | 9 ++++++++ core/os/dir_access.h | 2 +- platform/x11/os_x11.cpp | 1 + .../editor_sample_import_plugin.cpp | 18 ++++++++++++++++ .../io_plugins/editor_scene_import_plugin.cpp | 21 +++++++++++++++---- .../editor_texture_import_plugin.cpp | 17 ++++++++++++--- 6 files changed, 60 insertions(+), 8 deletions(-) diff --git a/core/os/dir_access.cpp b/core/os/dir_access.cpp index 53fe792c4605..26a8090fe806 100644 --- a/core/os/dir_access.cpp +++ b/core/os/dir_access.cpp @@ -399,6 +399,15 @@ Error DirAccess::copy(String p_from,String p_to) { return err; } +bool DirAccess::exists(String p_dir) { + + DirAccess* da = DirAccess::create_for_path(p_dir); + bool valid = da->change_dir(p_dir)==OK; + memdelete(da); + return valid; + +} + DirAccess::DirAccess(){ _access_type=ACCESS_FILESYSTEM; diff --git a/core/os/dir_access.h b/core/os/dir_access.h index dc56f2308e14..304e2399edc4 100644 --- a/core/os/dir_access.h +++ b/core/os/dir_access.h @@ -93,7 +93,7 @@ class DirAccess { virtual bool file_exists(String p_file)=0; virtual bool dir_exists(String p_dir)=0; - + static bool exists(String p_dir); virtual size_t get_space_left()=0; virtual Error copy(String p_from,String p_to); diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index 4dc10c5b366c..e65503e71031 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -266,6 +266,7 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi continue; if (AudioDriverManagerSW::get_driver(i)->init()==OK) { success=true; + print_line("Audio Driver Failed: "+String(AudioDriverManagerSW::get_driver(p_audio_driver)->get_name())); print_line("Using alternate audio driver: "+String(AudioDriverManagerSW::get_driver(i)->get_name())); break; } diff --git a/tools/editor/io_plugins/editor_sample_import_plugin.cpp b/tools/editor/io_plugins/editor_sample_import_plugin.cpp index 377af8f1797a..196b1ecd9400 100644 --- a/tools/editor/io_plugins/editor_sample_import_plugin.cpp +++ b/tools/editor/io_plugins/editor_sample_import_plugin.cpp @@ -254,6 +254,24 @@ class EditorSampleImportDialog : public ConfirmationDialog { error_dialog->popup_centered(Size2(200,100)); } + if (save_path->get_text().strip_edges()=="") { + error_dialog->set_text("Target path is empty."); + error_dialog->popup_centered_minsize(); + return; + } + + if (!save_path->get_text().begins_with("res://")) { + error_dialog->set_text("Target path must be full resource path."); + error_dialog->popup_centered_minsize(); + return; + } + + if (!DirAccess::exists(save_path->get_text())) { + error_dialog->set_text("Target path must exist."); + error_dialog->popup_centered_minsize(); + return; + } + for(int i=0;i imd = memnew( ResourceImportMetadata ); diff --git a/tools/editor/io_plugins/editor_scene_import_plugin.cpp b/tools/editor/io_plugins/editor_scene_import_plugin.cpp index d01c2af90756..20be43cd5f04 100644 --- a/tools/editor/io_plugins/editor_scene_import_plugin.cpp +++ b/tools/editor/io_plugins/editor_scene_import_plugin.cpp @@ -671,15 +671,28 @@ void EditorSceneImportDialog::_import(bool p_and_open) { wip_open=p_and_open; //' ImportMonitorBlock imb; - if (import_path->get_text()=="") { + + if (import_path->get_text().strip_edges()=="") { error_dialog->set_text("Source path is empty."); - error_dialog->popup_centered(Size2(200,100)); + error_dialog->popup_centered_minsize(); return; } - if (save_path->get_text()=="") { + if (save_path->get_text().strip_edges()=="") { error_dialog->set_text("Target path is empty."); - error_dialog->popup_centered(Size2(200,100)); + error_dialog->popup_centered_minsize(); + return; + } + + if (!save_path->get_text().begins_with("res://")) { + error_dialog->set_text("Target path must be full resource path."); + error_dialog->popup_centered_minsize(); + return; + } + + if (!DirAccess::exists(save_path->get_text())) { + error_dialog->set_text("Target path must exist."); + error_dialog->popup_centered_minsize(); return; } diff --git a/tools/editor/io_plugins/editor_texture_import_plugin.cpp b/tools/editor/io_plugins/editor_texture_import_plugin.cpp index ce376f2e7b09..247989600de0 100644 --- a/tools/editor/io_plugins/editor_texture_import_plugin.cpp +++ b/tools/editor/io_plugins/editor_texture_import_plugin.cpp @@ -321,12 +321,23 @@ void EditorTextureImportDialog::_import() { String dst_path=save_path->get_text(); - if (dst_path.empty()) { + if (save_path->get_text().strip_edges()=="") { + error_dialog->set_text("Target path is empty."); + error_dialog->popup_centered_minsize(); + return; + } - error_dialog->set_text("Please specify a valid target import path!"); - error_dialog->popup_centered(Size2(200,100)); + if (!save_path->get_text().begins_with("res://")) { + error_dialog->set_text("Target path must be full resource path."); + error_dialog->popup_centered_minsize(); return; + } + + if (!atlas && !DirAccess::exists(save_path->get_text())) { + error_dialog->set_text("Target path must exist."); + error_dialog->popup_centered_minsize(); + return; } if (atlas) { //atlas