Check entered and trimmed path when create, import, install project
This commit is contained in:
parent
bbc71083c1
commit
2d9e89ea2a
1 changed files with 22 additions and 30 deletions
|
@ -75,15 +75,22 @@ private:
|
||||||
String zip_title;
|
String zip_title;
|
||||||
AcceptDialog *dialog_error;
|
AcceptDialog *dialog_error;
|
||||||
|
|
||||||
bool _test_path() {
|
String _test_path() {
|
||||||
|
|
||||||
error->set_text("");
|
error->set_text("");
|
||||||
get_ok()->set_disabled(true);
|
get_ok()->set_disabled(true);
|
||||||
DirAccess *d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
|
DirAccess *d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
|
||||||
if (project_path->get_text() != "" && d->change_dir(project_path->get_text())!=OK) {
|
String valid_path;
|
||||||
|
if (d->change_dir(project_path->get_text())==OK){
|
||||||
|
valid_path=project_path->get_text();
|
||||||
|
} else if (d->change_dir(project_path->get_text().strip_edges())==OK) {
|
||||||
|
valid_path=project_path->get_text().strip_edges();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (valid_path == "") {
|
||||||
error->set_text(TTR("Invalid project path, the path must exist!"));
|
error->set_text(TTR("Invalid project path, the path must exist!"));
|
||||||
memdelete(d);
|
memdelete(d);
|
||||||
return false;
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mode!=MODE_IMPORT) {
|
if (mode!=MODE_IMPORT) {
|
||||||
|
@ -92,30 +99,29 @@ private:
|
||||||
|
|
||||||
error->set_text(TTR("Invalid project path, engine.cfg must not exist."));
|
error->set_text(TTR("Invalid project path, engine.cfg must not exist."));
|
||||||
memdelete(d);
|
memdelete(d);
|
||||||
return false;
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if (project_path->get_text() != "" && !d->file_exists("engine.cfg")) {
|
if (valid_path != "" && !d->file_exists("engine.cfg")) {
|
||||||
|
|
||||||
error->set_text(TTR("Invalid project path, engine.cfg must exist."));
|
error->set_text(TTR("Invalid project path, engine.cfg must exist."));
|
||||||
memdelete(d);
|
memdelete(d);
|
||||||
return false;
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
memdelete(d);
|
memdelete(d);
|
||||||
get_ok()->set_disabled(false);
|
get_ok()->set_disabled(false);
|
||||||
return true;
|
return valid_path;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void _path_text_changed(const String& p_path) {
|
void _path_text_changed(const String& p_path) {
|
||||||
|
|
||||||
if ( _test_path() ) {
|
String sp=_test_path();
|
||||||
|
if ( sp!="" ) {
|
||||||
String sp=p_path;
|
|
||||||
|
|
||||||
sp=sp.replace("\\","/");
|
sp=sp.replace("\\","/");
|
||||||
int lidx=sp.find_last("/");
|
int lidx=sp.find_last("/");
|
||||||
|
@ -173,27 +179,15 @@ private:
|
||||||
|
|
||||||
void ok_pressed() {
|
void ok_pressed() {
|
||||||
|
|
||||||
if (!_test_path())
|
String dir=_test_path();
|
||||||
|
if (dir=="") {
|
||||||
|
error->set_text(TTR("Invalid project path (changed anything?)."));
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
String dir;
|
|
||||||
|
|
||||||
if (mode==MODE_IMPORT) {
|
if (mode==MODE_IMPORT) {
|
||||||
dir=project_path->get_text();
|
// nothing to do
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
DirAccess *d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
|
|
||||||
|
|
||||||
if (d->change_dir(project_path->get_text())!=OK) {
|
|
||||||
error->set_text(TTR("Invalid project path (changed anything?)."));
|
|
||||||
memdelete(d);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
dir=d->get_current_dir();
|
|
||||||
memdelete(d);
|
|
||||||
|
|
||||||
if (mode==MODE_NEW) {
|
if (mode==MODE_NEW) {
|
||||||
|
|
||||||
|
|
||||||
|
@ -321,8 +315,6 @@ private:
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dir=dir.replace("\\","/");
|
dir=dir.replace("\\","/");
|
||||||
|
@ -402,7 +394,7 @@ public:
|
||||||
popup_centered(Size2(500,125)*EDSCALE);
|
popup_centered(Size2(500,125)*EDSCALE);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
project_path->grab_focus();
|
||||||
|
|
||||||
_test_path();
|
_test_path();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue