Exemple #1
0
	bool _test_path() {

		error->set_text("");
		get_ok()->set_disabled(true);
		DirAccess *d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
		if (d->change_dir(project_path->get_text())!=OK) {
			error->set_text("Invalid Path for Project, Path Must Exist!");
			memdelete(d);
			return false;
		}

		if (!import_mode) {

			if (d->file_exists("engine.cfg")) {

				error->set_text("Invalid Project Path (engine.cfg must not exist).");
				memdelete(d);
				return false;
			}

		} else {

			if (!d->file_exists("engine.cfg")) {

				error->set_text("Invalid Project Path (engine.cfg must exist).");
				memdelete(d);
				return false;
			}
		}

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

	}
Exemple #2
0
	bool _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) {
			error->set_text(TTR("Invalid project path, the path must exist!"));
			memdelete(d);
			return false;
		}

		if (mode!=MODE_IMPORT) {

			if (d->file_exists("engine.cfg")) {

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

		} else {

			if (project_path->get_text() != "" && !d->file_exists("engine.cfg")) {

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

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

	}
Exemple #3
0
	String _test_path() {

		error->set_text("");
		get_ok()->set_disabled(true);
		DirAccess *d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
		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 "";
		}

		if (mode!=MODE_IMPORT) {

			if (d->file_exists("godot.cfg")) {

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

		} else {

			if (valid_path != "" && !d->file_exists("godot.cfg")) {

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

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

	}
void ScriptCreateDialog::_path_changed(const String &p_path) {

	is_path_valid = false;
	is_new_script_created = true;
	String p = p_path;

	if (p == "") {
		_msg_path_valid(false, TTR("Path is empty"));
		_update_dialog();
		return;
	}

	p = ProjectSettings::get_singleton()->localize_path(p);
	if (!p.begins_with("res://")) {
		_msg_path_valid(false, TTR("Path is not local"));
		_update_dialog();
		return;
	}

	if (p.find("/") || p.find("\\")) {
		DirAccess *d = DirAccess::create(DirAccess::ACCESS_RESOURCES);
		if (d->change_dir(p.get_base_dir()) != OK) {
			_msg_path_valid(false, TTR("Invalid base path"));
			memdelete(d);
			_update_dialog();
			return;
		}
		memdelete(d);
	}

	/* Does file already exist */

	DirAccess *f = DirAccess::create(DirAccess::ACCESS_RESOURCES);
	if (f->dir_exists(p)) {
		is_new_script_created = false;
		is_path_valid = false;
		_msg_path_valid(false, TTR("Directory of the same name exists"));
	} else if (f->file_exists(p)) {
		is_new_script_created = false;
		is_path_valid = true;
		_msg_path_valid(true, TTR("File exists, will be reused"));
	} else {
		path_error_label->set_text("");
	}
	memdelete(f);
	_update_dialog();

	/* Check file extension */

	String extension = p.get_extension();
	List<String> extensions;

	// get all possible extensions for script
	for (int l = 0; l < language_menu->get_item_count(); l++) {
		ScriptServer::get_language(l)->get_recognized_extensions(&extensions);
	}

	bool found = false;
	bool match = false;
	int index = 0;
	for (List<String>::Element *E = extensions.front(); E; E = E->next()) {
		if (E->get().nocasecmp_to(extension) == 0) {
			//FIXME (?) - changing language this way doesn't update controls, needs rework
			//language_menu->select(index); // change Language option by extension
			found = true;
			if (E->get() == ScriptServer::get_language(language_menu->get_selected())->get_extension()) {
				match = true;
			}
			break;
		}
		index++;
	}

	if (!found) {
		_msg_path_valid(false, TTR("Invalid extension"));
		_update_dialog();
		return;
	}

	if (!match) {
		_msg_path_valid(false, TTR("Wrong extension chosen"));
		_update_dialog();
		return;
	}

	/* All checks passed */

	is_path_valid = true;
	_update_dialog();
}