Error OS_Unix::open_dynamic_library(const String p_path, void *&p_library_handle, bool p_also_set_library_path) { String path = p_path; if (FileAccess::exists(path) && path.is_rel_path()) { // dlopen expects a slash, in this case a leading ./ for it to be interpreted as a relative path, // otherwise it will end up searching various system directories for the lib instead and finally failing. path = "./" + path; } if (!FileAccess::exists(path)) { //this code exists so gdnative can load .so files from within the executable path path = get_executable_path().get_base_dir().plus_file(p_path.get_file()); } if (!FileAccess::exists(path)) { //this code exists so gdnative can load .so files from a standard unix location path = get_executable_path().get_base_dir().plus_file("../lib").plus_file(p_path.get_file()); } p_library_handle = dlopen(path.utf8().get_data(), RTLD_NOW); if (!p_library_handle) { ERR_EXPLAIN("Can't open dynamic library: " + p_path + ". Error: " + dlerror()); ERR_FAIL_V(ERR_CANT_OPEN); } return OK; }
void DependencyEditor::edit(const String& p_path) { editing=p_path; set_title(TTR("Dependencies For: ")+p_path.get_file()); _update_list(); popup_centered_ratio(); if (EditorNode::get_singleton()->is_scene_open(p_path)) { EditorNode::get_singleton()->show_warning(TTR("Scene '")+p_path.get_file()+"' is currently being edited.\nChanges will not take effect unless reloaded."); } else if (ResourceCache::has(p_path)) { EditorNode::get_singleton()->show_warning(TTR("Resource '")+p_path.get_file()+"' is in use.\nChanges will take effect when reloaded."); } }
void DependencyErrorDialog::show(Mode p_mode, const String &p_for_file, const Vector<String> &report) { mode = p_mode; for_file = p_for_file; set_title(TTR("Error loading:") + " " + p_for_file.get_file()); files->clear(); TreeItem *root = files->create_item(NULL); for (int i = 0; i < report.size(); i++) { String dep; String type = "Object"; dep = report[i].get_slice("::", 0); if (report[i].get_slice_count("::") > 0) type = report[i].get_slice("::", 1); Ref<Texture> icon = EditorNode::get_singleton()->get_class_icon(type); TreeItem *ti = files->create_item(root); ti->set_text(0, dep); ti->set_icon(0, icon); } popup_centered_minsize(Size2(500, 220)); }
void ResourcePreloaderEditor::_files_load_request(const Vector<String> &p_paths) { for (int i = 0; i < p_paths.size(); i++) { String path = p_paths[i]; RES resource; resource = ResourceLoader::load(path); if (resource.is_null()) { dialog->set_text(TTR("ERROR: Couldn't load resource!")); dialog->set_title(TTR("Error!")); //dialog->get_cancel()->set_text("Close"); dialog->get_ok()->set_text(TTR("Close")); dialog->popup_centered_minsize(); return; ///beh should show an error i guess } String basename = path.get_file().get_basename(); String name = basename; int counter = 1; while (preloader->has_resource(name)) { counter++; name = basename + " " + itos(counter); } undo_redo->create_action(TTR("Add Resource")); undo_redo->add_do_method(preloader, "add_resource", name, resource); undo_redo->add_undo_method(preloader, "remove_resource", name); undo_redo->add_do_method(this, "_update_library"); undo_redo->add_undo_method(this, "_update_library"); undo_redo->commit_action(); } }
void EditorFileDialog::_update_favorites() { bool res = access == ACCESS_RESOURCES; String current = get_current_dir(); Ref<Texture> star = get_icon("Favorites", "EditorIcons"); favorites->clear(); favorite->set_pressed(false); Vector<String> favorited = EditorSettings::get_singleton()->get_favorite_dirs(); for (int i = 0; i < favorited.size(); i++) { bool cres = favorited[i].begins_with("res://"); if (cres != res) continue; String name = favorited[i]; bool setthis = name == current; if (res && name == "res://") { name = "/"; } else { name = name.get_file() + "/"; } //print_line("file: "+name); favorites->add_item(name, star); favorites->set_item_metadata(favorites->get_item_count() - 1, favorited[i]); if (setthis) { favorite->set_pressed(true); favorites->set_current(favorites->get_item_count() - 1); } } }
void ResourcePreloaderEditor::_file_load_request(const String& p_path) { RES resource; resource = ResourceLoader::load(p_path); if (resource.is_null()) { dialog->set_text("ERROR: Couldn't load resource!"); dialog->set_title("Error!"); //dialog->get_cancel()->set_text("Close"); dialog->get_ok()->set_text("Close"); dialog->popup_centered(Size2(300,60)); return; ///beh should show an error i guess } String basename = p_path.get_file().basename(); String name=basename; int counter=1; while(preloader->has_resource(name)) { counter++; name=basename+" "+itos(counter); } undo_redo->create_action("Add Resource"); undo_redo->add_do_method(preloader,"add_resource",name,resource); undo_redo->add_undo_method(preloader,"remove_resource",name); undo_redo->add_do_method(this,"_update_library"); undo_redo->add_undo_method(this,"_update_library"); undo_redo->commit_action(); }
void SampleLibraryEditor::_file_load_request(const DVector<String>& p_path) { for(int i=0; i<p_path.size(); i++) { String path = p_path[i]; Ref<Sample> sample = ResourceLoader::load(path,"Sample"); if (sample.is_null()) { dialog->set_text("ERROR: Couldn't load sample!"); dialog->set_title("Error!"); //dialog->get_cancel()->set_text("Close"); dialog->get_ok()->set_text("Close"); dialog->popup_centered_minsize(); return; ///beh should show an error i guess } String basename = path.get_file().basename(); String name=basename; int counter=0; while(sample_library->has_sample(name)) { counter++; name=basename+"_"+itos(counter); } undo_redo->create_action("Add Sample"); undo_redo->add_do_method(sample_library.operator->(),"add_sample",name,sample); undo_redo->add_undo_method(sample_library.operator->(),"remove_sample",name); undo_redo->add_do_method(this,"_update_library"); undo_redo->add_undo_method(this,"_update_library"); undo_redo->commit_action(); } }
void DependencyErrorDialog::show(const String& p_for_file,const Vector<String> &report) { for_file=p_for_file; set_title(TTR("Error loading: ")+p_for_file.get_file()); files->clear(); TreeItem *root = files->create_item(NULL); for(int i=0;i<report.size();i++) { String dep; String type="Object"; dep=report[i].get_slice("::",0); if (report[i].get_slice_count("::")>0) type=report[i].get_slice("::",1); Ref<Texture> icon; if (!has_icon(type,TTR("EditorIcons"))) { icon=get_icon("Object","EditorIcons"); } else { icon=get_icon(type,"EditorIcons"); } TreeItem *ti=files->create_item(root); ti->set_text(0,dep); ti->set_icon(0,icon); } popup_centered_minsize(Size2(500,220)); }
void EditorSceneImportDialog::_choose_script(const String& p_path) { String p = Globals::get_singleton()->localize_path(p_path); if (!p.is_resource_file()) p=Globals::get_singleton()->get_resource_path().path_to(p_path.get_base_dir())+p_path.get_file(); script_path->set_text(p); }
void DependencyEditorOwners::show(const String &p_path) { editing = p_path; owners->clear(); _fill_owners(EditorFileSystem::get_singleton()->get_filesystem()); popup_centered_ratio(); set_title(TTR("Owners Of:") + " " + p_path.get_file()); }
void EditorFileSystem::update_file(const String& p_file) { EditorFileSystemDirectory *fs=NULL; int cpos=-1; if (!_find_file(p_file,&fs,cpos)) { if (!fs) return; } if (!FileAccess::exists(p_file)) { //was removed memdelete( fs->files[cpos] ); fs->files.remove(cpos); call_deferred("emit_signal","filesystem_changed"); //update later return; } String type = ResourceLoader::get_resource_type(p_file); if (cpos==-1) { int idx=0; for(int i=0;i<fs->files.size();i++) { if (p_file<fs->files[i]->file) break; idx++; } EditorFileSystemDirectory::FileInfo *fi = memnew( EditorFileSystemDirectory::FileInfo ); fi->file=p_file.get_file(); if (idx==fs->files.size()) { fs->files.push_back(fi); } else { fs->files.insert(idx,fi); } cpos=idx; } //print_line("UPDATING: "+p_file); fs->files[cpos]->type=type; fs->files[cpos]->modified_time=FileAccess::get_modified_time(p_file); fs->files[cpos]->meta=_get_meta(p_file); EditorResourcePreview::get_singleton()->call_deferred("check_for_invalidation",p_file); call_deferred("emit_signal","filesystem_changed"); //update later }
void DependencyEditor::_update_list() { List<String> deps; ResourceLoader::get_dependencies(editing,&deps,true); tree->clear(); missing.clear(); TreeItem *root = tree->create_item(); Ref<Texture> folder = get_icon("folder","FileDialog"); bool broken=false; for(List<String>::Element *E=deps.front();E;E=E->next()) { TreeItem *item = tree->create_item(root); String n = E->get(); String path; String type; if (n.find("::")!=-1) { path = n.get_slice("::",0); type = n.get_slice("::",1); } else { path=n; type="Resource"; } String name = path.get_file(); Ref<Texture> icon; if (has_icon(type,TTR("EditorIcons"))) { icon=get_icon(type,"EditorIcons"); } else { icon=get_icon("Object","EditorIcons"); } item->set_text(0,name); item->set_icon(0,icon); item->set_metadata(0,type); item->set_text(1,path); if (!FileAccess::exists(path)) { item->set_custom_color(1,Color(1,0.4,0.3)); missing.push_back(path); broken=true; } item->add_button(1,folder,0); } fixdeps->set_disabled(!broken); }
void EditorAudioBuses::_file_dialog_callback(const String &p_string) { if (file_dialog->get_mode() == EditorFileDialog::MODE_OPEN_FILE) { Ref<AudioBusLayout> state = ResourceLoader::load(p_string); if (state.is_null()) { EditorNode::get_singleton()->show_warning(TTR("Invalid file, not an audio bus layout.")); return; } edited_path = p_string; file->set_text(p_string.get_file()); AudioServer::get_singleton()->set_bus_layout(state); _update_buses(); EditorNode::get_singleton()->get_undo_redo()->clear_history(); call_deferred("_select_layout"); } else if (file_dialog->get_mode() == EditorFileDialog::MODE_SAVE_FILE) { if (new_layout) { Ref<AudioBusLayout> empty_state; empty_state.instance(); AudioServer::get_singleton()->set_bus_layout(empty_state); } Error err = ResourceSaver::save(p_string, AudioServer::get_singleton()->generate_bus_layout()); if (err != OK) { EditorNode::get_singleton()->show_warning("Error saving file: " + p_string); return; } edited_path = p_string; file->set_text(p_string.get_file()); _update_buses(); EditorNode::get_singleton()->get_undo_redo()->clear_history(); call_deferred("_select_layout"); } }
void DependencyRemoveDialog::_fill_owners(EditorFileSystemDirectory *efsd) { if (!efsd) return; for(int i=0;i<efsd->get_subdir_count();i++) { _fill_owners(efsd->get_subdir(i)); } for(int i=0;i<efsd->get_file_count();i++) { Vector<String> deps = efsd->get_file_deps(i); //print_line(":::"+efsd->get_file_path(i)); Set<String> met; for(int j=0;j<deps.size();j++) { if (files.has(deps[j])) { met.insert(deps[j]); } } if (!met.size()) continue; exist=true; Ref<Texture> icon; String type=efsd->get_file_type(i); if (!has_icon(type,TTR("EditorIcons"))) { icon=get_icon("Object","EditorIcons"); } else { icon=get_icon(type,"EditorIcons"); } for(Set<String>::Element *E=met.front();E;E=E->next()) { String which = E->get(); if (!files[which]) { TreeItem *ti=owners->create_item(owners->get_root()); ti->set_text(0,which.get_file()); files[which]=ti; } TreeItem *ti=owners->create_item(files[which]); ti->set_text(0,efsd->get_file_path(i)); ti->set_icon(0,icon); } } }
void EditorFileDialog::_post_popup() { ConfirmationDialog::_post_popup(); if (invalidated) { update_file_list(); invalidated=false; } if (mode==MODE_SAVE_FILE) file->grab_focus(); else item_list->grab_focus(); if (is_visible() && get_current_file()!="") _request_single_thumbnail(get_current_dir().plus_file(get_current_file())); if (is_visible()) { Ref<Texture> folder = get_icon("folder","FileDialog"); recent->clear(); bool res = access==ACCESS_RESOURCES; Vector<String> recentd = EditorSettings::get_singleton()->get_recent_dirs(); for(int i=0;i<recentd.size();i++) { bool cres = recentd[i].begins_with("res://"); if (cres!=res) continue; String name = recentd[i]; if (res && name=="res://") { name="/"; } else { name=name.get_file()+"/"; } //print_line("file: "+name); recent->add_item(name,folder); recent->set_item_metadata( recent->get_item_count()-1,recentd[i]); } local_history.clear(); local_history_pos=-1; _push_history(); _update_favorites(); } set_process_unhandled_input(true); }
void ScenesDock::open(const String& p_path) { String npath; String nfile; if (p_path.ends_with("/")) { if (p_path!="res://") npath=p_path.substr(0,p_path.length()-1); else npath="res://"; } else { nfile=p_path.get_file(); npath=p_path.get_base_dir(); } path=npath; if (tree_mode && nfile=="") { _update_tree(); tree->grab_focus(); tree->call_deferred("ensure_cursor_is_visible"); _push_to_history(); return; } else if (tree_mode){ _update_tree(); tree->grab_focus(); tree->ensure_cursor_is_visible(); _open_pressed(); current_path->set_text(path); } else { _update_files(false); _push_to_history(); } for(int i=0;i<files->get_item_count();i++) { String md = files->get_item_metadata(i); if (md==p_path) { files->select(i,true); files->ensure_current_is_visible(); break; } } }
void EditorFileSystem::update_file(const String& p_file) { EditorFileSystemDirectory *fs=NULL; int cpos=-1; if (!_find_file(p_file,&fs,cpos)) { if (!fs) return; } String type = ResourceLoader::get_resource_type(p_file); if (cpos==-1) { int idx=0; for(int i=0;i<fs->files.size();i++) { if (p_file<fs->files[i].file) break; idx++; } EditorFileSystemDirectory::FileInfo fi; fi.file=p_file.get_file(); if (idx==fs->files.size()) { fs->files.push_back(fi); } else { fs->files.insert(idx,fi); } cpos=idx; } print_line("UPDATING: "+p_file); fs->files[cpos].type=type; fs->files[cpos].modified_time=FileAccess::get_modified_time(p_file); fs->files[cpos].meta=_get_meta(p_file); call_deferred("emit_signal","filesystem_changed"); //update later }
void ScriptCreateDialog::_file_selected(const String &p_file) { String p = ProjectSettings::get_singleton()->localize_path(p_file); if (is_browsing_parent) { parent_name->set_text("\"" + p + "\""); _class_name_changed("\"" + p + "\""); } else { file_path->set_text(p); _path_changed(p); String filename = p.get_file().get_basename(); int select_start = p.find_last(filename); file_path->select(select_start, select_start + filename.length()); file_path->set_cursor_position(select_start + filename.length()); file_path->grab_focus(); } }
void EditorAudioBuses::open_layout(const String &p_path) { EditorNode::get_singleton()->make_bottom_panel_item_visible(this); Ref<AudioBusLayout> state = ResourceLoader::load(p_path); if (state.is_null()) { EditorNode::get_singleton()->show_warning(TTR("Invalid file, not an audio bus layout.")); return; } edited_path = p_path; file->set_text(p_path.get_file()); AudioServer::get_singleton()->set_bus_layout(state); _update_buses(); EditorNode::get_singleton()->get_undo_redo()->clear_history(); call_deferred("_select_layout"); }
void ProjectExportDialog::_validate_export_path(const String &p_path) { // Disable export via OK button or Enter key if LineEdit has an empty filename bool invalid_path = (p_path.get_file().get_basename() == ""); // Check if state change before needlessly messing with signals if (invalid_path && export_project->get_ok()->is_disabled()) return; if (!invalid_path && !export_project->get_ok()->is_disabled()) return; if (invalid_path) { export_project->get_ok()->set_disabled(true); export_project->get_line_edit()->disconnect("text_entered", export_project, "_file_entered"); } else { export_project->get_ok()->set_disabled(false); export_project->get_line_edit()->connect("text_entered", export_project, "_file_entered"); } }
void ProjectExportDialog::_export_project_to_path(const String &p_path) { // Save this name for use in future exports (but drop the file extension) default_filename = p_path.get_file().get_basename(); EditorSettings::get_singleton()->set_project_metadata("export_options", "default_filename", default_filename); Ref<EditorExportPreset> current = EditorExport::get_singleton()->get_export_preset(presets->get_current()); ERR_FAIL_COND(current.is_null()); Ref<EditorExportPlatform> platform = current->get_platform(); ERR_FAIL_COND(platform.is_null()); current->set_export_path(p_path); Error err = platform->export_project(current, export_debug->is_pressed(), p_path, 0); if (err != OK) { error_dialog->set_text(TTR("Export templates for this platform are missing/corrupted:") + " " + platform->get_name()); error_dialog->show(); error_dialog->popup_centered_minsize(Size2(300, 80)); ERR_PRINT("Failed to export project"); } }
void PackedData::add_path(const String& pkg_path, const String& path, uint64_t ofs, uint64_t size,const uint8_t* p_md5, PackSource* p_src) { bool exists = files.has(path); PackedFile pf; pf.pack=pkg_path; pf.offset=ofs; pf.size=size; for(int i=0;i<16;i++) pf.md5[i]=p_md5[i]; pf.src = p_src; files[path]=pf; if (!exists) { //search for dir String p = path.replace_first("res://",""); PackedDir *cd=root; if (p.find("/")!=-1) { //in a subdir Vector<String> ds=p.get_base_dir().split("/"); for(int j=0;j<ds.size();j++) { if (!cd->subdirs.has(ds[j])) { PackedDir *pd = memnew( PackedDir ); pd->name=ds[j]; pd->parent=cd; cd->subdirs[pd->name]=pd; cd=pd; } else { cd=cd->subdirs[ds[j]]; } } } cd->files.insert(path.get_file()); } }
void ProjectExportDialog::_export_project_to_path(const String &p_path) { // Save this name for use in future exports (but drop the file extension) default_filename = p_path.get_file().get_basename(); EditorSettings::get_singleton()->set_project_metadata("export_options", "default_filename", default_filename); Ref<EditorExportPreset> current = get_current_preset(); ERR_FAIL_COND(current.is_null()); Ref<EditorExportPlatform> platform = current->get_platform(); ERR_FAIL_COND(platform.is_null()); current->set_export_path(p_path); Error err = platform->export_project(current, export_debug->is_pressed(), p_path, 0); if (err != OK) { if (err == ERR_FILE_NOT_FOUND) { error_dialog->set_text(vformat(TTR("Failed to export the project for platform '%s'.\nExport templates seem to be missing or invalid."), platform->get_name())); } else { // Assume misconfiguration. FIXME: Improve error handling and preset config validation. error_dialog->set_text(vformat(TTR("Failed to export the project for platform '%s'.\nThis might be due to a configuration issue in the export preset or your export settings."), platform->get_name())); } ERR_PRINTS(vformat("Failed to export the project for platform '%s'.", platform->get_name())); error_dialog->show(); error_dialog->popup_centered_minsize(Size2(300, 80)); } }
void ExportTemplateManager::_install_from_file(const String &p_file, bool p_use_progress) { FileAccess *fa = NULL; zlib_filefunc_def io = zipio_create_io_from_file(&fa); unzFile pkg = unzOpen2(p_file.utf8().get_data(), &io); if (!pkg) { EditorNode::get_singleton()->show_warning(TTR("Can't open export templates zip.")); return; } int ret = unzGoToFirstFile(pkg); int fc = 0; //count them and find version String version; while (ret == UNZ_OK) { unz_file_info info; char fname[16384]; ret = unzGetCurrentFileInfo(pkg, &info, fname, 16384, NULL, 0, NULL, 0); String file = fname; if (file.ends_with("version.txt")) { Vector<uint8_t> data; data.resize(info.uncompressed_size); //read unzOpenCurrentFile(pkg); ret = unzReadCurrentFile(pkg, data.ptrw(), data.size()); unzCloseCurrentFile(pkg); String data_str; data_str.parse_utf8((const char *)data.ptr(), data.size()); data_str = data_str.strip_edges(); // Version number should be of the form major.minor[.patch].status[.module_config] // so it can in theory have 3 or more slices. if (data_str.get_slice_count(".") < 3) { EditorNode::get_singleton()->show_warning(vformat(TTR("Invalid version.txt format inside templates: %s."), data_str)); unzClose(pkg); return; } version = data_str; } if (file.get_file().size() != 0) { fc++; } ret = unzGoToNextFile(pkg); } if (version == String()) { EditorNode::get_singleton()->show_warning(TTR("No version.txt found inside templates.")); unzClose(pkg); return; } String template_path = EditorSettings::get_singleton()->get_templates_dir().plus_file(version); DirAccess *d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); Error err = d->make_dir_recursive(template_path); if (err != OK) { EditorNode::get_singleton()->show_warning(TTR("Error creating path for templates:") + "\n" + template_path); unzClose(pkg); return; } memdelete(d); ret = unzGoToFirstFile(pkg); EditorProgress *p = NULL; if (p_use_progress) { p = memnew(EditorProgress("ltask", TTR("Extracting Export Templates"), fc)); } fc = 0; while (ret == UNZ_OK) { //get filename unz_file_info info; char fname[16384]; unzGetCurrentFileInfo(pkg, &info, fname, 16384, NULL, 0, NULL, 0); String file = String(fname).get_file(); if (file.size() == 0) { ret = unzGoToNextFile(pkg); continue; } Vector<uint8_t> data; data.resize(info.uncompressed_size); //read unzOpenCurrentFile(pkg); unzReadCurrentFile(pkg, data.ptrw(), data.size()); unzCloseCurrentFile(pkg); if (p) { p->step(TTR("Importing:") + " " + file, fc); } FileAccess *f = FileAccess::open(template_path.plus_file(file), FileAccess::WRITE); if (!f) { ret = unzGoToNextFile(pkg); fc++; ERR_CONTINUE(!f); } f->store_buffer(data.ptr(), data.size()); memdelete(f); ret = unzGoToNextFile(pkg); fc++; } if (p) { memdelete(p); } unzClose(pkg); _update_template_list(); }
void ScenesDock::_move_operation(const String& p_to_path) { if (p_to_path==path) { EditorNode::get_singleton()->show_warning(TTR("Same source and destination paths, doing nothing.")); return; } //find files inside dirs to be moved Vector<String> inside_files; for(int i=0;i<move_dirs.size();i++) { if (p_to_path.begins_with(move_dirs[i])) { EditorNode::get_singleton()->show_warning(TTR("Can't move directories to within themselves.")); return; } EditorFileSystemDirectory *efsd=EditorFileSystem::get_singleton()->get_path(move_dirs[i]); if (!efsd) continue; _find_inside_move_files(efsd,inside_files); } //make list of remaps Map<String,String> renames; String repfrom=path=="res://"?path:String(path+"/"); String repto=p_to_path=="res://"?p_to_path:String(p_to_path+"/"); for(int i=0;i<move_files.size();i++) { renames[move_files[i]]=move_files[i].replace_first(repfrom,repto); print_line("move file "+move_files[i]+" -> "+renames[move_files[i]]); } for(int i=0;i<inside_files.size();i++) { renames[inside_files[i]]=inside_files[i].replace_first(repfrom,repto); print_line("inside file "+inside_files[i]+" -> "+renames[inside_files[i]]); } //make list of files that will be run the remapping List<String> remap; _find_remaps(EditorFileSystem::get_singleton()->get_filesystem(),renames,remap); print_line("found files to remap: "+itos(remap.size())); //perform remaps for(List<String>::Element *E=remap.front();E;E=E->next()) { Error err = ResourceLoader::rename_dependencies(E->get(),renames); print_line("remapping: "+E->get()); if (err!=OK) { EditorNode::get_singleton()->add_io_error("Can't rename deps for:\n"+E->get()+"\n"); } } //finally, perform moves DirAccess *da=DirAccess::create(DirAccess::ACCESS_RESOURCES); for(int i=0;i<move_files.size();i++) { String to = move_files[i].replace_first(repfrom,repto); Error err = da->rename(move_files[i],to); print_line("moving file "+move_files[i]+" to "+to); if (err!=OK) { EditorNode::get_singleton()->add_io_error("Error moving file:\n"+move_files[i]+"\n"); } } for(int i=0;i<move_dirs.size();i++) { String mdir = move_dirs[i]; if (mdir=="res://") continue; if (mdir.ends_with("/")) { mdir=mdir.substr(0,mdir.length()-1); } String to = p_to_path.plus_file(mdir.get_file()); Error err = da->rename(mdir,to); print_line("moving dir "+mdir+" to "+to); if (err!=OK) { EditorNode::get_singleton()->add_io_error("Error moving dir:\n"+move_dirs[i]+"\n"); } } memdelete(da); //rescan everything print_line("call rescan!"); _rescan(); }
String ResourceFormatImporter::get_import_base_path(const String &p_for_file) const { return "res://.import/" + p_for_file.get_file() + "-" + p_for_file.md5_text(); }
Error EditorSceneImportPlugin::import2(Node *scene, const String& p_dest_path, const Ref<ResourceImportMetadata>& p_from) { Error err=OK; Ref<ResourceImportMetadata> from=p_from; String src_path=EditorImportPlugin::expand_source_path(from->get_source_path(0)); int animation_flags=p_from->get_option("animation_flags"); int scene_flags = from->get_option("flags"); EditorProgress progress("import","Import Scene",104); progress.step("Importing Scene..",2); bool merge = !bool(from->get_option("reimport")); from->set_source_md5(0,FileAccess::get_md5(src_path)); from->set_editor(get_name()); from->set_option("reimport",false); String target_res_path=p_dest_path.get_base_dir(); Map<Ref<Mesh>,Ref<Shape> > collision_map; Ref<ResourceImportMetadata> imd = memnew(ResourceImportMetadata); Set< Ref<ImageTexture> > imagemap; scene=_fix_node(scene,scene,collision_map,scene_flags,imagemap); /// BEFORE ANYTHING, RUN SCRIPT progress.step("Running Custom Script..",2); String post_import_script_path = from->get_option("post_import_script"); Ref<EditorScenePostImport> post_import_script; if (post_import_script_path!="") { post_import_script_path = EditorImportPlugin::expand_source_path(post_import_script_path); Ref<Script> scr = ResourceLoader::load(post_import_script_path); if (!scr.is_valid()) { EditorNode::add_io_error("Couldn't load post-import script: '"+post_import_script_path); } else { post_import_script = Ref<EditorScenePostImport>( memnew( EditorScenePostImport ) ); post_import_script->set_script(scr.get_ref_ptr()); if (!post_import_script->get_script_instance()) { EditorNode::add_io_error("Invalid/Broken Script for Post-Import: '"+post_import_script_path); post_import_script.unref(); } } } if (post_import_script.is_valid()) { err = post_import_script->post_import(scene); if (err) { EditorNode::add_io_error("Error running Post-Import script: '"+post_import_script_path); return err; } } /// IMPORT IMAGES int idx=0; int image_format = from->get_option("texture_format"); int image_flags = from->get_option("texture_flags"); float image_quality = from->get_option("texture_quality"); for (Set< Ref<ImageTexture> >::Element *E=imagemap.front();E;E=E->next()) { //texture could be converted to something more useful for 3D, that could load individual mipmaps and stuff //but not yet.. Ref<ImageTexture> texture = E->get(); ERR_CONTINUE(!texture.is_valid()); String path = texture->get_path(); String fname= path.get_file(); String target_path = Globals::get_singleton()->localize_path(target_res_path.plus_file(fname)); progress.step("Import Img: "+fname,3+(idx)*100/imagemap.size()); idx++; if (path==target_path) { EditorNode::add_io_error("Can't import a file over itself: '"+target_path); continue; } if (!target_path.begins_with("res://")) { EditorNode::add_io_error("Couldn't localize path: '"+target_path+"' (already local)"); continue; } { target_path=target_path.basename()+".tex"; Ref<ResourceImportMetadata> imd = memnew( ResourceImportMetadata ); print_line("flags: "+itos(image_flags)); imd->set_option("flags",image_flags); imd->set_option("format",image_format); imd->set_option("quality",image_quality); imd->set_option("atlas",false); imd->add_source(EditorImportPlugin::validate_source_path(path)); if (FileAccess::exists(target_path)) { Ref<ResourceImportMetadata> rimdex = ResourceLoader::load_import_metadata(target_path); if (rimdex.is_valid()) { //make sure the options are the same, otherwise re-import List<String> opts; imd->get_options(&opts); bool differ=false; for (List<String>::Element *E=opts.front();E;E=E->next()) { if (!(rimdex->get_option(E->get())==imd->get_option(E->get()))) { differ=true; break; } } if (!differ) { texture->set_path(target_path); continue; //already imported } } } Error err = EditorTextureImportPlugin::get_singleton(EditorTextureImportPlugin::MODE_TEXTURE_3D)->import(target_path,imd); } } /// BEFORE SAVING - MERGE if (merge) { progress.step("Merging..",103); FileAccess *fa = FileAccess::create(FileAccess::ACCESS_FILESYSTEM); if (fa->file_exists(p_dest_path)) { //try to merge Ref<PackedScene> s = ResourceLoader::load(p_dest_path); if (s.is_valid()) { Node *existing = s->instance(true); if (existing) { _merge_scenes(scene,existing); memdelete(scene); scene=existing; } } } memdelete(fa); } progress.step("Saving..",104); Ref<PackedScene> packer = memnew( PackedScene ); packer->pack(scene); packer->set_path(p_dest_path); packer->set_import_metadata(from); print_line("SAVING TO: "+p_dest_path); err = ResourceSaver::save(p_dest_path,packer); //EditorFileSystem::get_singleton()->update_resource(packer); memdelete(scene); /* scene->set_filename(p_dest_path); if (r_scene) { *r_scene=scene; } else { memdelete(scene); } String sp; if (p_post_import.is_valid() && !p_post_import->get_script().is_null()) { Ref<Script> scr = p_post_import->get_script(); if (scr.is_valid()) sp=scr->get_path(); } String op=_getrelpath(p_path,p_dest_path); */ return err; }
Error EditorExportPlatformJavaScript::export_project(const String& p_path,bool p_debug,const String& p_password) { String src_template; EditorProgress ep("export","Exporting for javascript",104); String template_path = EditorSettings::get_singleton()->get_settings_path()+"/templates/"; if (p_debug) { src_template=custom_debug_package!=""?custom_debug_package:template_path+"javascript_debug.zip"; } else { src_template=custom_release_package!=""?custom_release_package:template_path+"javascript_release.zip"; } FileAccess *src_f=NULL; zlib_filefunc_def io = zipio_create_io_from_file(&src_f); ep.step("Exporting to HTML5",0); ep.step("Finding Files..",1); FileAccess *f=FileAccess::open(p_path.get_base_dir()+"/data.pck",FileAccess::WRITE); if (!f) { EditorNode::add_io_error("Could not create file for writing:\n"+p_path.basename()+"_files.js"); return ERR_FILE_CANT_WRITE; } Error err = save_pack(f); size_t len = f->get_len(); memdelete(f); if (err) return err; unzFile pkg = unzOpen2(src_template.utf8().get_data(), &io); if (!pkg) { EditorNode::add_io_error("Could not find template HTML5 to export:\n"+src_template); return ERR_FILE_NOT_FOUND; } ERR_FAIL_COND_V(!pkg, ERR_CANT_OPEN); int ret = unzGoToFirstFile(pkg); while(ret==UNZ_OK) { //get filename unz_file_info info; char fname[16384]; ret = unzGetCurrentFileInfo(pkg,&info,fname,16384,NULL,0,NULL,0); String file=fname; Vector<uint8_t> data; data.resize(info.uncompressed_size); //read unzOpenCurrentFile(pkg); unzReadCurrentFile(pkg,data.ptr(),data.size()); unzCloseCurrentFile(pkg); //write if (file=="godot.html") { _fix_html(data,p_path.get_file().basename(),1<<(max_memory+5)); file=p_path.get_file(); } if (file=="filesystem.js") { _fix_files(data,len); file=p_path.get_file().basename()+"_filesystem.js"; } if (file=="godot.js") { //_fix_godot(data); file=p_path.get_file().basename()+".js"; } String dst = p_path.get_base_dir().plus_file(file); FileAccess *f=FileAccess::open(dst,FileAccess::WRITE); if (!f) { EditorNode::add_io_error("Could not create file for writing:\n"+dst); unzClose(pkg); return ERR_FILE_CANT_WRITE; } f->store_buffer(data.ptr(),data.size()); memdelete(f); ret = unzGoToNextFile(pkg); } return OK; }
RES ResourceFormatLoaderImage::load(const String &p_path,const String& p_original_path) { if (p_path.extension()=="cube") { // open as cubemap txture CubeMap* ptr = memnew(CubeMap); Ref<CubeMap> cubemap( ptr ); Error err; FileAccess *f = FileAccess::open(p_path,FileAccess::READ,&err); if (err) { ERR_FAIL_COND_V( err, RES() ); } String base_path=p_path.substr( 0, p_path.find_last("/")+1 ); for(int i=0;i<6;i++) { String file = f->get_line().strip_edges(); Image image; Error err = ImageLoader::load_image(base_path+file,&image); if (err) { memdelete(f); ERR_FAIL_COND_V( err, RES() ); } if (i==0) { //cubemap->create(image.get_width(),image.get_height(),image.get_format(),Texture::FLAGS_DEFAULT|Texture::FLAG_CUBEMAP); } static const CubeMap::Side cube_side[6]= { CubeMap::SIDE_LEFT, CubeMap::SIDE_RIGHT, CubeMap::SIDE_BOTTOM, CubeMap::SIDE_TOP, CubeMap::SIDE_FRONT, CubeMap::SIDE_BACK }; cubemap->set_side(cube_side[i],image); } memdelete(f); cubemap->set_name(p_path.get_file()); return cubemap; } else { // simple image ImageTexture* ptr = memnew(ImageTexture); Ref<ImageTexture> texture( ptr ); uint64_t begtime; double total; Image image; if (debug_load_times) begtime=OS::get_singleton()->get_ticks_usec(); Error err = ImageLoader::load_image(p_path,&image); if (!err && debug_load_times) { double total=(double)(OS::get_singleton()->get_ticks_usec()-begtime)/1000000.0; print_line("IMAGE: "+itos(image.get_width())+"x"+itos(image.get_height())); print_line(" -load: "+rtos(total)); } ERR_EXPLAIN("Failed loading image: "+p_path); ERR_FAIL_COND_V(err, RES()); #ifdef DEBUG_ENABLED #ifdef TOOLS_ENABLED if (max_texture_size && (image.get_width() > max_texture_size || image.get_height() > max_texture_size)) { if (bool(Globals::get_singleton()->get("debug/max_texture_size_alert"))) { OS::get_singleton()->alert("Texture is too large: '"+p_path+"', at "+itos(image.get_width())+"x"+itos(image.get_height())+". Max allowed size is: "+itos(max_texture_size)+"x"+itos(max_texture_size)+".","BAD ARTIST, NO COOKIE!"); } ERR_EXPLAIN("Texture is too large: '"+p_path+"', at "+itos(image.get_width())+"x"+itos(image.get_height())+". Max allowed size is: "+itos(max_texture_size)+"x"+itos(max_texture_size)+"."); ERR_FAIL_V(RES()); } #endif #endif uint32_t flags=0; if (bool(GLOBAL_DEF("texture_import/filter",true))) flags|=Texture::FLAG_FILTER; if (bool(GLOBAL_DEF("texture_import/gen_mipmaps",true))) flags|=Texture::FLAG_MIPMAPS; if (bool(GLOBAL_DEF("texture_import/repeat",true))) flags|=Texture::FLAG_REPEAT; if (debug_load_times) begtime=OS::get_singleton()->get_ticks_usec(); //print_line("img: "+p_path+" flags: "+itos(flags)); texture->create_from_image( image,flags ); texture->set_name(p_path.get_file()); if (debug_load_times) { total=(double)(OS::get_singleton()->get_ticks_usec()-begtime)/1000000.0; print_line(" -make texture: "+rtos(total)); } return RES( texture ); } }
void EditorAutoloadSettings::_autoload_file_callback(const String& p_path) { autoload_add_name->set_text(p_path.get_file().get_basename()); }