MCPcopy Create free account
hub / github.com/Redot-Engine/redot-engine / _validate_path

Method _validate_path

editor/script/script_create_dialog.cpp:241–317  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

239}
240
241String ScriptCreateDialog::_validate_path(const String &p_path, bool p_file_must_exist, bool *r_path_valid) {
242 String p = p_path.strip_edges();
243 if (r_path_valid) {
244 *r_path_valid = false;
245 }
246
247 if (p.is_empty()) {
248 return TTR("Path is empty.");
249 }
250 if (p.get_file().get_basename().is_empty()) {
251 return TTR("Filename is empty.");
252 }
253
254 if (!p.get_file().get_basename().is_valid_filename()) {
255 return TTR("Filename is invalid.");
256 }
257 if (p.get_file().begins_with(".")) {
258 return TTR("Name begins with a dot.");
259 }
260
261 p = ProjectSettings::get_singleton()->localize_path(p);
262 if (!p.begins_with("res://")) {
263 return TTR("Path is not local.");
264 }
265
266 {
267 Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
268 if (da->change_dir(p.get_base_dir()) != OK) {
269 return TTR("Base path is invalid.");
270 }
271 }
272
273 {
274 // Check if file exists.
275 Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
276 if (da->dir_exists(p)) {
277 return TTR("A directory with the same name exists.");
278 } else if (p_file_must_exist && !da->file_exists(p)) {
279 return TTR("File does not exist.");
280 }
281 }
282
283 if (r_path_valid) {
284 *r_path_valid = true;
285 }
286
287 // Check file extension.
288 String extension = p.get_extension();
289 List<String> extensions;
290
291 // Get all possible extensions for script.
292 for (int l = 0; l < language_menu->get_item_count(); l++) {
293 ScriptServer::get_language(l)->get_recognized_extensions(&extensions);
294 }
295
296 bool found = false;
297 bool match = false;
298 for (const String &E : extensions) {

Callers

nothing calls this directly

Calls 15

TTRFunction · 0.85
get_languageFunction · 0.85
strip_edgesMethod · 0.80
get_basenameMethod · 0.80
is_valid_filenameMethod · 0.80
begins_withMethod · 0.80
localize_pathMethod · 0.80
get_base_dirMethod · 0.80
nocasecmp_toMethod · 0.80
createFunction · 0.50
is_emptyMethod · 0.45
get_fileMethod · 0.45

Tested by

no test coverage detected