| 239 | } |
| 240 | |
| 241 | String 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) { |
nothing calls this directly
no test coverage detected