void DependencyRemoveDialog::ok_pressed() { DirAccess *da = DirAccess::create(DirAccess::ACCESS_RESOURCES); for (Map<String, TreeItem *>::Element *E = files.front(); E; E = E->next()) { if (da->dir_exists(E->key())) { String path = OS::get_singleton()->get_resource_dir() + E->key().replace_first("res://", "/"); OS::get_singleton()->move_path_to_trash(path); EditorFileSystem::get_singleton()->scan(); } else { if (ResourceCache::has(E->key())) { Resource *res = ResourceCache::get(E->key()); res->set_path(""); //clear reference to path } da->remove(E->key()); EditorFileSystem::get_singleton()->update_file(E->key()); } } memdelete(da); }
void ProjectManager::_files_dropped(StringArray p_files, int p_screen) { Set<String> folders_set; DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); for (int i = 0; i < p_files.size(); i++) { String file = p_files[i]; folders_set.insert(da->dir_exists(file) ? file : file.get_base_dir()); } memdelete(da); if (folders_set.size()>0) { StringArray folders; for (Set<String>::Element *E=folders_set.front();E;E=E->next()) { folders.append(E->get()); } bool confirm = true; if (folders.size()==1) { DirAccess *dir = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); if (dir->change_dir(folders[0])==OK) { dir->list_dir_begin(); String file = dir->get_next(); while(confirm && file!=String()) { if (!da->current_is_dir() && file.ends_with("engine.cfg")) { confirm = false; } file = dir->get_next(); } dir->list_dir_end(); } memdelete(dir); } if (confirm) { multi_scan_ask->get_ok()->disconnect("pressed", this, "_scan_multiple_folders"); multi_scan_ask->get_ok()->connect("pressed", this, "_scan_multiple_folders", varray(folders)); multi_scan_ask->set_text(vformat(TTR("You are about the scan %s folders for existing Godot projects. Do you confirm?"), folders.size())); multi_scan_ask->popup_centered_minsize(); } else { _scan_multiple_folders(folders); } } }
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(); }