Skip to content

Commit

Permalink
Check entered and trimmed path when create, import, install project
Browse files Browse the repository at this point in the history
  • Loading branch information
volzhs committed Nov 14, 2016
1 parent bbc7108 commit 2d9e89e
Showing 1 changed file with 22 additions and 30 deletions.
52 changes: 22 additions & 30 deletions tools/editor/project_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,22 @@ class NewProjectDialog : public ConfirmationDialog {
String zip_title;
AcceptDialog *dialog_error;

bool _test_path() {
String _test_path() {

error->set_text("");
get_ok()->set_disabled(true);
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!"));
memdelete(d);
return false;
return "";
}

if (mode!=MODE_IMPORT) {
Expand All @@ -92,30 +99,29 @@ class NewProjectDialog : public ConfirmationDialog {

error->set_text(TTR("Invalid project path, engine.cfg must not exist."));
memdelete(d);
return false;
return "";
}

} 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."));
memdelete(d);
return false;
return "";
}
}

memdelete(d);
get_ok()->set_disabled(false);
return true;
return valid_path;

}

void _path_text_changed(const String& p_path) {

if ( _test_path() ) {

String sp=p_path;
String sp=_test_path();
if ( sp!="" ) {

sp=sp.replace("\\","/");
int lidx=sp.find_last("/");
Expand Down Expand Up @@ -173,27 +179,15 @@ class NewProjectDialog : public ConfirmationDialog {

void ok_pressed() {

if (!_test_path())
String dir=_test_path();
if (dir=="") {
error->set_text(TTR("Invalid project path (changed anything?)."));
return;

String dir;
}

if (mode==MODE_IMPORT) {
dir=project_path->get_text();


// nothing to do
} 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) {


Expand Down Expand Up @@ -321,8 +315,6 @@ class NewProjectDialog : public ConfirmationDialog {

}



}

dir=dir.replace("\\","/");
Expand Down Expand Up @@ -402,7 +394,7 @@ class NewProjectDialog : public ConfirmationDialog {
popup_centered(Size2(500,125)*EDSCALE);

}

project_path->grab_focus();

_test_path();
}
Expand Down

0 comments on commit 2d9e89e

Please sign in to comment.