diff options
| author | Rémi Verschelde <rverschelde@gmail.com> | 2016-11-15 08:17:21 +0100 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-11-15 08:17:21 +0100 | 
| commit | 394d48a5fc287e5422a937ecfd5b9197ec2ad3ff (patch) | |
| tree | 8fc36672da1f7f1c4a1b98bf3b632903cf665626 /tools/editor/project_manager.cpp | |
| parent | 77f5b683c4af56e9004bd0359fa47ca4d209b6e8 (diff) | |
| parent | 2d9e89ea2a34df173611bd3c7192296f9cedd8da (diff) | |
Merge pull request #7113 from volzhs/check-project-path
Check entered and trimmed path when create, import, install project
Diffstat (limited to 'tools/editor/project_manager.cpp')
| -rw-r--r-- | tools/editor/project_manager.cpp | 52 | 
1 files changed, 22 insertions, 30 deletions
diff --git a/tools/editor/project_manager.cpp b/tools/editor/project_manager.cpp index 069d7cef81..c678e4a6b0 100644 --- a/tools/editor/project_manager.cpp +++ b/tools/editor/project_manager.cpp @@ -75,15 +75,22 @@ private:  	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) { @@ -92,30 +99,29 @@ private:  				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("/"); @@ -173,27 +179,15 @@ private:  	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) { @@ -321,8 +315,6 @@ private:  			} - -  		}  		dir=dir.replace("\\","/"); @@ -402,7 +394,7 @@ public:  			popup_centered(Size2(500,125)*EDSCALE);  		} - +		project_path->grab_focus();  		_test_path();  	}  |