void PluginConfigDialog::_on_confirmed() { String path = "res://addons/" + subfolder_edit->get_text(); if (!_edit_mode) { DirAccess *d = DirAccess::create(DirAccess::ACCESS_RESOURCES); if (!d || d->make_dir_recursive(path) != OK) return; } Ref<ConfigFile> cf = memnew(ConfigFile); cf->set_value("plugin", "name", name_edit->get_text()); cf->set_value("plugin", "description", desc_edit->get_text()); cf->set_value("plugin", "author", author_edit->get_text()); cf->set_value("plugin", "version", version_edit->get_text()); cf->set_value("plugin", "script", script_edit->get_text()); cf->save(path.plus_file("plugin.cfg")); if (!_edit_mode) { int lang_idx = script_option_edit->get_selected(); String lang_name = ScriptServer::get_language(lang_idx)->get_name(); Ref<Script> script; // TODO Use script templates. Right now, this code won't add the 'tool' annotation to other languages. // TODO Better support script languages with named classes (has_named_classes). if (lang_name == GDScriptLanguage::get_singleton()->get_name()) { // Hard-coded GDScript template to keep usability until we use script templates. Ref<GDScript> gdscript = memnew(GDScript); gdscript->set_source_code( "tool\n" "extends EditorPlugin\n" "\n" "func _enter_tree():\n" "\tpass\n" "\n" "func _exit_tree():\n" "\tpass\n"); String script_path = path.plus_file(script_edit->get_text()); gdscript->set_path(script_path); ResourceSaver::save(script_path, gdscript); script = gdscript; } else { String script_path = path.plus_file(script_edit->get_text()); String class_name = script_path.get_file().get_basename(); script = ScriptServer::get_language(lang_idx)->get_template(class_name, "EditorPlugin"); script->set_path(script_path); ResourceSaver::save(script_path, script); } emit_signal("plugin_ready", script.operator->(), active_edit->is_pressed() ? subfolder_edit->get_text() : ""); } else { EditorNode::get_singleton()->get_project_settings()->update_plugins(); } _clear_fields(); }
void FindInFiles::_scan_dir(String path, PoolStringArray &out_folders) { DirAccess *dir = DirAccess::open(path); if (dir == NULL) { print_line("Cannot open directory! " + path); return; } dir->list_dir_begin(); for (int i = 0; i < 1000; ++i) { String file = dir->get_next(); if (file == "") break; // Ignore special dirs and hidden dirs (such as .git and .import) if (file == "." || file == ".." || file.begins_with(".")) continue; if (dir->current_is_dir()) out_folders.append(file); else { String file_ext = file.get_extension(); if (_extension_filter.has(file_ext)) { _files_to_scan.push_back(path.plus_file(file)); } } } }
Error DocData::load_classes(const String &p_dir) { Error err; DirAccessRef da = DirAccess::open(p_dir, &err); if (!da) { return err; } da->list_dir_begin(); String path; bool isdir; path = da->get_next(&isdir); while (path != String()) { if (!isdir && path.ends_with("xml")) { Ref<XMLParser> parser = memnew(XMLParser); Error err = parser->open(p_dir.plus_file(path)); if (err) return err; _load(parser); } path = da->get_next(&isdir); } da->list_dir_end(); return OK; }
void _import() { Vector<String> samples = import_path->get_text().split(","); if (samples.size()==0) { error_dialog->set_text(TTR("No samples to import!")); error_dialog->popup_centered(Size2(200,100)); } if (save_path->get_text().strip_edges()=="") { error_dialog->set_text(TTR("Target path is empty.")); error_dialog->popup_centered_minsize(); return; } if (!save_path->get_text().begins_with("res://")) { error_dialog->set_text(TTR("Target path must be full resource path.")); error_dialog->popup_centered_minsize(); return; } if (!DirAccess::exists(save_path->get_text())) { error_dialog->set_text(TTR("Target path must exist.")); error_dialog->popup_centered_minsize(); return; } for(int i=0;i<samples.size();i++) { Ref<ResourceImportMetadata> imd = memnew( ResourceImportMetadata ); List<PropertyInfo> pl; options->_get_property_list(&pl); for(List<PropertyInfo>::Element *E=pl.front();E;E=E->next()) { Variant v; String opt=E->get().name; options->_get(opt,v); imd->set_option(opt,v); } imd->add_source(EditorImportPlugin::validate_source_path(samples[i])); String dst = save_path->get_text(); if (dst=="") { error_dialog->set_text(TTR("Save path is empty!")); error_dialog->popup_centered(Size2(200,100)); } dst = dst.plus_file(samples[i].get_file().basename()+".smp"); Error err = plugin->import(dst,imd); } hide(); }
bool GodotSharpBuilds::build_api_sln(const String &p_name, const String &p_api_sln_dir, const String &p_config) { String api_sln_file = p_api_sln_dir.plus_file(p_name + ".sln"); String api_assembly_dir = p_api_sln_dir.plus_file("bin").plus_file(p_config); String api_assembly_file = api_assembly_dir.plus_file(p_name + ".dll"); if (!FileAccess::exists(api_assembly_file)) { MonoBuildInfo api_build_info(api_sln_file, p_config); api_build_info.custom_props.push_back("NoWarn=1591"); // Ignore missing documentation warnings if (!GodotSharpBuilds::get_singleton()->build(api_build_info)) { show_build_error_dialog("Failed to build " + p_name + " solution."); return false; } } return true; }
bool GodotSharpBuilds::copy_api_assembly(const String &p_src_dir, const String &p_dst_dir, const String &p_assembly_name) { String assembly_file = p_assembly_name + ".dll"; String assembly_src = p_src_dir.plus_file(assembly_file); String assembly_dst = p_dst_dir.plus_file(assembly_file); if (!FileAccess::exists(assembly_dst) || FileAccess::get_modified_time(assembly_src) > FileAccess::get_modified_time(assembly_dst)) { DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); String xml_file = p_assembly_name + ".xml"; if (da->copy(p_src_dir.plus_file(xml_file), p_dst_dir.plus_file(xml_file)) != OK) WARN_PRINTS("Failed to copy " + xml_file); String pdb_file = p_assembly_name + ".pdb"; if (da->copy(p_src_dir.plus_file(pdb_file), p_dst_dir.plus_file(pdb_file)) != OK) WARN_PRINTS("Failed to copy " + pdb_file); Error err = da->copy(assembly_src, assembly_dst); memdelete(da); if (err != OK) { show_build_error_dialog("Failed to copy " API_ASSEMBLY_NAME ".dll"); return false; } } return true; }
Error DirAccess::make_dir_recursive(String p_dir) { if (p_dir.length() < 1) { return OK; }; String full_dir; if (p_dir.is_rel_path()) { //append current full_dir = get_current_dir().plus_file(p_dir); } else { full_dir = p_dir; } full_dir = full_dir.replace("\\", "/"); //int slices = full_dir.get_slice_count("/"); String base; if (full_dir.begins_with("res://")) base = "res://"; else if (full_dir.begins_with("user://")) base = "user://"; else if (full_dir.begins_with("/")) base = "/"; else if (full_dir.find(":/") != -1) { base = full_dir.substr(0, full_dir.find(":/") + 2); } else { ERR_FAIL_V(ERR_INVALID_PARAMETER); } full_dir = full_dir.replace_first(base, "").simplify_path(); Vector<String> subdirs = full_dir.split("/"); String curpath = base; for (int i = 0; i < subdirs.size(); i++) { curpath = curpath.plus_file(subdirs[i]); Error err = make_dir(curpath); if (err != OK && err != ERR_ALREADY_EXISTS) { ERR_FAIL_V(err); } } return OK; }
void _import() { Vector<String> bitmasks = import_path->get_text().split(","); if (bitmasks.size() == 0) { error_dialog->set_text(TTR("No bit masks to import!")); error_dialog->popup_centered(Size2(200, 100)*EDSCALE); } if (save_path->get_text().strip_edges() == "") { error_dialog->set_text(TTR("Target path is empty.")); error_dialog->popup_centered_minsize(); return; } if (!save_path->get_text().begins_with("res://")) { error_dialog->set_text(TTR("Target path must be a complete resource path.")); error_dialog->popup_centered_minsize(); return; } if (!DirAccess::exists(save_path->get_text())) { error_dialog->set_text(TTR("Target path must exist.")); error_dialog->popup_centered_minsize(); return; } for (int i = 0; i<bitmasks.size(); i++) { Ref<ResourceImportMetadata> imd = memnew(ResourceImportMetadata); imd->add_source(EditorImportPlugin::validate_source_path(bitmasks[i])); String dst = save_path->get_text(); if (dst == "") { error_dialog->set_text(TTR("Save path is empty!")); error_dialog->popup_centered(Size2(200, 100)*EDSCALE); } dst = dst.plus_file(bitmasks[i].get_file().get_basename() + ".pbm"); plugin->import(dst, imd); } hide(); }
void _import() { Vector<String> meshes = import_path->get_text().split(","); if (meshes.size()==0) { error_dialog->set_text(TTR("No meshes to import!")); error_dialog->popup_centered_minsize(); return; } String dst = save_path->get_text(); if (dst=="") { error_dialog->set_text(TTR("Save path is empty!")); error_dialog->popup_centered_minsize(); return; } for(int i=0;i<meshes.size();i++) { Ref<ResourceImportMetadata> imd = memnew( ResourceImportMetadata ); List<PropertyInfo> pl; options->_get_property_list(&pl); for(List<PropertyInfo>::Element *E=pl.front();E;E=E->next()) { Variant v; String opt=E->get().name; options->_get(opt,v); imd->set_option(opt,v); } imd->add_source(EditorImportPlugin::validate_source_path(meshes[i])); String file_path = dst.plus_file(meshes[i].get_file().get_basename()+".msh"); plugin->import(file_path,imd); } hide(); }
void ProjectManager::_load_recent_projects() { while(scroll_childs->get_child_count()>0) { memdelete( scroll_childs->get_child(0)); } List<PropertyInfo> properties; EditorSettings::get_singleton()->get_property_list(&properties); Color font_color = get_color("font_color","Tree"); for(List<PropertyInfo>::Element *E=properties.front();E;E=E->next()) { String _name = E->get().name; if (!_name.begins_with("projects/")) continue; String project = _name.get_slice("/",1); String path = EditorSettings::get_singleton()->get(_name); String conf=path.plus_file("engine.cfg"); Ref<ConfigFile> cf = memnew( ConfigFile ); Error err = cf->load(conf); ERR_CONTINUE(err!=OK); Ref<Texture> icon; String project_name="Unnamed Project"; if (cf->has_section_key("application","icon")) { String appicon = cf->get_value("application","icon"); if (appicon!="") { Image img; Error err = img.load(appicon.replace_first("res://",path+"/")); if (err==OK) { img.resize(64,64); Ref<ImageTexture> it = memnew( ImageTexture ); it->create_from_image(img); icon=it; } } } if (cf->has_section_key("application","name")) { project_name = cf->get_value("application","name"); } if (icon.is_null()) { icon=get_icon("DefaultProjectIcon","EditorIcons"); } String main_scene; if (cf->has_section_key("application","main_scene")) { main_scene = cf->get_value("application","main_scene"); } HBoxContainer *hb = memnew( HBoxContainer ); hb->set_meta("name",project); hb->set_meta("main_scene",main_scene); hb->connect("draw",this,"_panel_draw",varray(hb)); hb->connect("input_event",this,"_panel_input",varray(hb)); TextureFrame *tf = memnew( TextureFrame ); tf->set_texture(icon); hb->add_child(tf); VBoxContainer *vb = memnew(VBoxContainer); hb->add_child(vb); EmptyControl *ec = memnew( EmptyControl ); ec->set_minsize(Size2(0,1)); vb->add_child(ec); Label *title = memnew( Label(project_name) ); title->add_font_override("font",get_font("large","Fonts")); title->add_color_override("font_color",font_color); vb->add_child(title); Label *fpath = memnew( Label(path) ); vb->add_child(fpath); fpath->set_opacity(0.5); fpath->add_color_override("font_color",font_color); scroll_childs->add_child(hb); } erase_btn->set_disabled(selected==""); open_btn->set_disabled(selected==""); if (selected=="") run_btn->set_disabled(true); }
void ok_pressed() { if (!_test_path()) return; String dir; if (import_mode) { dir=project_path->get_text(); } else { DirAccess *d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); if (d->change_dir(project_path->get_text())!=OK) { error->set_text("Invalid Path for Project (changed anything?)"); memdelete(d); return; } dir=d->get_current_dir(); memdelete(d); FileAccess *f = FileAccess::open(dir.plus_file("/engine.cfg"),FileAccess::WRITE); if (!f) { error->set_text("Couldn't create engine.cfg in project path"); } else { f->store_line("; Engine configuration file."); f->store_line("; It's best to edit using the editor UI, not directly,"); f->store_line("; becausethe parameters that go here are not obvious."); f->store_line("; "); f->store_line("; Format: "); f->store_line("; [section] ; section goes between []"); f->store_line("; param=value ; assign values to parameters"); f->store_line("\n"); f->store_line("[application]"); f->store_line("name=\""+project_name->get_text()+"\""); f->store_line("icon=\"icon.png\""); memdelete(f); ResourceSaver::save(dir.plus_file("/icon.png"),get_icon("DefaultProjectIcon","EditorIcons")); } } dir=dir.replace("\\","/"); if (dir.ends_with("/")) dir=dir.substr(0,dir.length()-1); String proj=dir.replace("/","::"); EditorSettings::get_singleton()->set("projects/"+proj,dir); EditorSettings::get_singleton()->save(); hide(); emit_signal("project_created"); }
void EditorFileSystem::_scan_fs_changes(EditorFileSystemDirectory *p_dir,const ScanProgress& p_progress) { uint64_t current_mtime = FileAccess::get_modified_time(p_dir->get_path()); bool updated_dir=false; //print_line("dir: "+p_dir->get_path()+" MODTIME: "+itos(p_dir->modified_time)+" CTIME: "+itos(current_mtime)); if (current_mtime!=p_dir->modified_time) { updated_dir=true; p_dir->modified_time=current_mtime; //ooooops, dir changed, see what's going on //first mark everything as veryfied for(int i=0;i<p_dir->files.size();i++) { p_dir->files[i]->verified=false; } for(int i=0;i<p_dir->subdirs.size();i++) { p_dir->get_subdir(i)->verified=false; } //then scan files and directories and check what's different DirAccess *da = DirAccess::create(DirAccess::ACCESS_RESOURCES); String cd = p_dir->get_path(); da->change_dir(cd); da->list_dir_begin(); while (true) { bool isdir; String f = da->get_next(&isdir); if (f=="") break; if (isdir) { if (f.begins_with(".")) //ignore hidden and . / .. continue; int idx = p_dir->find_dir_index(f); if (idx==-1) { if (FileAccess::exists(cd.plus_file(f).plus_file("engine.cfg"))) // skip if another project inside this continue; EditorFileSystemDirectory *efd = memnew( EditorFileSystemDirectory ); efd->parent=p_dir; efd->name=f; DirAccess *d = DirAccess::create(DirAccess::ACCESS_RESOURCES); d->change_dir(cd.plus_file(f)); _scan_new_dir(efd,d,p_progress.get_sub(1,1)); memdelete(d); ItemAction ia; ia.action=ItemAction::ACTION_DIR_ADD; ia.dir=p_dir; ia.file=f; ia.new_dir=efd; scan_actions.push_back(ia); } else { p_dir->subdirs[idx]->verified=true; } } else { String ext = f.extension().to_lower(); if (!valid_extensions.has(ext)) continue; //invalid int idx = p_dir->find_file_index(f); if (idx==-1) { //never seen this file, add actition to add it EditorFileSystemDirectory::FileInfo *fi = memnew( EditorFileSystemDirectory::FileInfo ); fi->file=f; String path = cd.plus_file(fi->file); fi->modified_time=FileAccess::get_modified_time(path); fi->meta=_get_meta(path); fi->type=ResourceLoader::get_resource_type(path); { ItemAction ia; ia.action=ItemAction::ACTION_FILE_ADD; ia.dir=p_dir; ia.file=f; ia.new_file=fi; scan_actions.push_back(ia); } //take the chance and scan sources if (_check_meta_sources(fi->meta)) { ItemAction ia; ia.action=ItemAction::ACTION_FILE_SOURCES_CHANGED; ia.dir=p_dir; ia.file=f; scan_actions.push_back(ia); } } else { p_dir->files[idx]->verified=true; } } } da->list_dir_end(); memdelete(da); } for(int i=0;i<p_dir->files.size();i++) { if (updated_dir && !p_dir->files[i]->verified) { //this file was removed, add action to remove it ItemAction ia; ia.action=ItemAction::ACTION_FILE_REMOVE; ia.dir=p_dir; ia.file=p_dir->files[i]->file; scan_actions.push_back(ia); continue; } if (_check_meta_sources(p_dir->files[i]->meta)) { ItemAction ia; ia.action=ItemAction::ACTION_FILE_SOURCES_CHANGED; ia.dir=p_dir; ia.file=p_dir->files[i]->file; scan_actions.push_back(ia); } } for(int i=0;i<p_dir->subdirs.size();i++) { if (updated_dir && !p_dir->subdirs[i]->verified) { //this directory was removed, add action to remove it ItemAction ia; ia.action=ItemAction::ACTION_DIR_REMOVE; ia.dir=p_dir->subdirs[i]; scan_actions.push_back(ia); continue; } _scan_fs_changes(p_dir->get_subdir(i),p_progress); } }
void EditorFileSystem::_scan_new_dir(EditorFileSystemDirectory *p_dir,DirAccess *da,const ScanProgress& p_progress) { List<String> dirs; List<String> files; String cd = da->get_current_dir(); p_dir->modified_time = FileAccess::get_modified_time(cd); da->list_dir_begin(); while (true) { bool isdir; String f = da->get_next(&isdir); if (f=="") break; if (isdir) { if (f.begins_with(".")) //ignore hidden and . / .. continue; if (FileAccess::exists(cd.plus_file(f).plus_file("engine.cfg"))) // skip if another project inside this continue; dirs.push_back(f); } else { files.push_back(f); } } da->list_dir_end(); dirs.sort(); files.sort(); int total = dirs.size()+files.size(); int idx=0; for (List<String>::Element *E=dirs.front();E;E=E->next(),idx++) { if (da->change_dir(E->get())==OK) { EditorFileSystemDirectory *efd = memnew( EditorFileSystemDirectory ); efd->parent=p_dir; efd->name=E->get(); _scan_new_dir(efd,da,p_progress.get_sub(idx,total)); int idx=0; for(int i=0;i<p_dir->subdirs.size();i++) { if (efd->name<p_dir->subdirs[i]->name) break; idx++; } if (idx==p_dir->subdirs.size()) { p_dir->subdirs.push_back(efd); } else { p_dir->subdirs.insert(idx,efd); } da->change_dir(".."); } else { ERR_PRINTS("Can't go into subdir: "+E->get()); } p_progress.update(idx,total); } for (List<String>::Element*E=files.front();E;E=E->next(),idx++) { String ext = E->get().extension().to_lower(); if (!valid_extensions.has(ext)) continue; //invalid EditorFileSystemDirectory::FileInfo *fi = memnew( EditorFileSystemDirectory::FileInfo ); fi->file=E->get(); String path = cd.plus_file(fi->file); FileCache *fc = file_cache.getptr(path); uint64_t mt = FileAccess::get_modified_time(path); if (fc && fc->modification_time == mt) { fi->meta=fc->meta; fi->type=fc->type; fi->modified_time=fc->modification_time; } else { fi->meta=_get_meta(path); fi->type=ResourceLoader::get_resource_type(path); fi->modified_time=mt; } if (fi->meta.enabled) { if (_check_meta_sources(fi->meta)) { ItemAction ia; ia.action=ItemAction::ACTION_FILE_SOURCES_CHANGED; ia.dir=p_dir; ia.file=E->get(); scan_actions.push_back(ia); } } p_dir->files.push_back(fi); p_progress.update(idx,total); } }
void EditorFileSystem::_scan_filesystem() { ERR_FAIL_COND(!scanning || new_filesystem); //read .fscache String cpath; sources_changed.clear(); file_cache.clear(); String project=Globals::get_singleton()->get_resource_path(); String fscache = EditorSettings::get_singleton()->get_project_settings_path().plus_file("filesystem_cache"); FileAccess *f =FileAccess::open(fscache,FileAccess::READ); if (f) { //read the disk cache while(!f->eof_reached()) { String l = f->get_line().strip_edges(); if (l==String()) continue; if (l.begins_with("::")) { Vector<String> split = l.split("::"); ERR_CONTINUE( split.size() != 3); String name = split[1]; cpath=name; } else { Vector<String> split = l.split("::"); ERR_CONTINUE( split.size() != 5); String name = split[0]; String file; file=name; name=cpath.plus_file(name); FileCache fc; fc.type=split[1]; fc.modification_time=split[2].to_int64(); String meta = split[3].strip_edges(); fc.meta.enabled=false; if (meta.find("<>")!=-1){ Vector<String> spl = meta.split("<>"); int sc = spl.size()-1; if (sc%3==0){ fc.meta.enabled=true; fc.meta.import_editor=spl[0]; fc.meta.sources.resize(sc/3); for(int i=0;i<fc.meta.sources.size();i++) { fc.meta.sources[i].path=spl[1+i*3+0]; fc.meta.sources[i].md5=spl[1+i*3+1]; fc.meta.sources[i].modified_time=spl[1+i*3+2].to_int64(); } } } String deps = split[4].strip_edges(); if (deps.length()) { Vector<String> dp = deps.split("<>"); for(int i=0;i<dp.size();i++) { String path=dp[i]; fc.meta.deps.push_back(path); } } file_cache[name]=fc; } } f->close(); memdelete(f); } EditorProgressBG scan_progress("efs","ScanFS",1000); ScanProgress sp; sp.low=0; sp.hi=1; sp.progress=&scan_progress; new_filesystem = memnew( EditorFileSystemDirectory ); new_filesystem->parent=NULL; DirAccess *d = DirAccess::create(DirAccess::ACCESS_RESOURCES); d->change_dir("res://"); _scan_new_dir(new_filesystem,d,sp); file_cache.clear(); //clear caches, no longer needed memdelete(d); //save back the findings // String fscache = EditorSettings::get_singleton()->get_project_settings_path().plus_file("file_cache"); f=FileAccess::open(fscache,FileAccess::WRITE); _save_filesystem_cache(new_filesystem,f); f->close(); memdelete(f); scanning=false; }
void ok_pressed() { if (!_test_path()) return; String dir; if (mode==MODE_IMPORT) { dir=project_path->get_text(); } else { DirAccess *d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); if (d->change_dir(project_path->get_text())!=OK) { error->set_text(TTR("Invalid project path (changed anything?).")); memdelete(d); return; } dir=d->get_current_dir(); memdelete(d); if (mode==MODE_NEW) { FileAccess *f = FileAccess::open(dir.plus_file("/engine.cfg"),FileAccess::WRITE); if (!f) { error->set_text(TTR("Couldn't create engine.cfg in project path.")); } else { f->store_line("; Engine configuration file."); f->store_line("; It's best edited using the editor UI and not directly,"); f->store_line("; since the parameters that go here are not all obvious."); f->store_line("; "); f->store_line("; Format: "); f->store_line("; [section] ; section goes between []"); f->store_line("; param=value ; assign values to parameters"); f->store_line("\n"); f->store_line("[application]"); f->store_line("\n"); f->store_line("name=\""+project_name->get_text()+"\""); f->store_line("icon=\"res://icon.png\""); memdelete(f); ResourceSaver::save(dir.plus_file("/icon.png"),get_icon("DefaultProjectIcon","EditorIcons")); } } else if (mode==MODE_INSTALL) { FileAccess *src_f=NULL; zlib_filefunc_def io = zipio_create_io_from_file(&src_f); unzFile pkg = unzOpen2(zip_path.utf8().get_data(), &io); if (!pkg) { dialog_error->set_text("Error opening package file, not in zip format."); return; } int ret = unzGoToFirstFile(pkg); Vector<String> failed_files; int idx=0; while(ret==UNZ_OK) { //get filename unz_file_info info; char fname[16384]; ret = unzGetCurrentFileInfo(pkg,&info,fname,16384,NULL,0,NULL,0); String path=fname; int depth=1; //stuff from github comes with tag bool skip=false; while(depth>0) { int pp = path.find("/"); if (pp==-1) { skip=true; break; } path=path.substr(pp+1,path.length()); depth--; } if (skip || path==String()) { // } else if (path.ends_with("/")) { // a dir path=path.substr(0,path.length()-1); DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); da->make_dir(dir.plus_file(path)); memdelete(da); } else { Vector<uint8_t> data; data.resize(info.uncompressed_size); //read unzOpenCurrentFile(pkg); unzReadCurrentFile(pkg,data.ptr(),data.size()); unzCloseCurrentFile(pkg); FileAccess *f=FileAccess::open(dir.plus_file(path),FileAccess::WRITE); if (f) { f->store_buffer(data.ptr(),data.size()); memdelete(f); } else { failed_files.push_back(path); } } idx++; ret = unzGoToNextFile(pkg); } unzClose(pkg); if (failed_files.size()) { String msg=TTR("The following files failed extraction from package:")+"\n\n"; for(int i=0;i<failed_files.size();i++) { if (i>15) { msg+="\nAnd "+itos(failed_files.size()-i)+" more files."; break; } msg+=failed_files[i]+"\n"; } dialog_error->set_text(msg); dialog_error->popup_centered_minsize(); } else { dialog_error->set_text(TTR("Package Installed Successfully!")); dialog_error->popup_centered_minsize(); } } } dir=dir.replace("\\","/"); if (dir.ends_with("/")) dir=dir.substr(0,dir.length()-1); String proj=dir.replace("/","::"); EditorSettings::get_singleton()->set("projects/"+proj,dir); EditorSettings::get_singleton()->save(); hide(); emit_signal("project_created"); }
void EditorFileSystem::_scan_fs_changes(EditorFileSystemDirectory *p_dir, const ScanProgress &p_progress) { uint64_t current_mtime = FileAccess::get_modified_time(p_dir->get_path()); bool updated_dir = false; String cd = p_dir->get_path(); //print_line("dir: "+p_dir->get_path()+" MODTIME: "+itos(p_dir->modified_time)+" CTIME: "+itos(current_mtime)); if (current_mtime != p_dir->modified_time) { updated_dir = true; p_dir->modified_time = current_mtime; //ooooops, dir changed, see what's going on //first mark everything as veryfied for (int i = 0; i < p_dir->files.size(); i++) { p_dir->files[i]->verified = false; } for (int i = 0; i < p_dir->subdirs.size(); i++) { p_dir->get_subdir(i)->verified = false; } //then scan files and directories and check what's different DirAccess *da = DirAccess::create(DirAccess::ACCESS_RESOURCES); da->change_dir(cd); da->list_dir_begin(); while (true) { bool isdir; String f = da->get_next(&isdir); if (f == "") break; if (isdir) { if (f.begins_with(".")) //ignore hidden and . / .. continue; int idx = p_dir->find_dir_index(f); if (idx == -1) { if (FileAccess::exists(cd.plus_file(f).plus_file("project.godot"))) // skip if another project inside this continue; if (FileAccess::exists(cd.plus_file(f).plus_file(".gdignore"))) // skip if another project inside this continue; EditorFileSystemDirectory *efd = memnew(EditorFileSystemDirectory); efd->parent = p_dir; efd->name = f; DirAccess *d = DirAccess::create(DirAccess::ACCESS_RESOURCES); d->change_dir(cd.plus_file(f)); _scan_new_dir(efd, d, p_progress.get_sub(1, 1)); memdelete(d); ItemAction ia; ia.action = ItemAction::ACTION_DIR_ADD; ia.dir = p_dir; ia.file = f; ia.new_dir = efd; scan_actions.push_back(ia); } else { p_dir->subdirs[idx]->verified = true; } } else { String ext = f.get_extension().to_lower(); if (!valid_extensions.has(ext)) continue; //invalid int idx = p_dir->find_file_index(f); if (idx == -1) { //never seen this file, add actition to add it EditorFileSystemDirectory::FileInfo *fi = memnew(EditorFileSystemDirectory::FileInfo); fi->file = f; String path = cd.plus_file(fi->file); fi->modified_time = FileAccess::get_modified_time(path); fi->import_modified_time = 0; fi->type = ResourceLoader::get_resource_type(path); { ItemAction ia; ia.action = ItemAction::ACTION_FILE_ADD; ia.dir = p_dir; ia.file = f; ia.new_file = fi; scan_actions.push_back(ia); } if (import_extensions.has(ext)) { //if it can be imported, and it was added, it needs to be reimported print_line("REIMPORT: file was not found before, reimport"); print_line("at dir: " + p_dir->get_path() + " file: " + f); for (int i = 0; i < p_dir->files.size(); i++) { print_line(itos(i) + ": " + p_dir->files[i]->file); } ItemAction ia; ia.action = ItemAction::ACTION_FILE_REIMPORT; ia.dir = p_dir; ia.file = f; scan_actions.push_back(ia); } } else { p_dir->files[idx]->verified = true; } } } da->list_dir_end(); memdelete(da); } for (int i = 0; i < p_dir->files.size(); i++) { if (updated_dir && !p_dir->files[i]->verified) { //this file was removed, add action to remove it ItemAction ia; ia.action = ItemAction::ACTION_FILE_REMOVE; ia.dir = p_dir; ia.file = p_dir->files[i]->file; scan_actions.push_back(ia); continue; } if (import_extensions.has(p_dir->files[i]->file.get_extension().to_lower())) { //check here if file must be imported or not String path = cd.plus_file(p_dir->files[i]->file); uint64_t mt = FileAccess::get_modified_time(path); bool reimport = false; if (mt != p_dir->files[i]->modified_time) { print_line("REIMPORT: modified time changed, reimport"); reimport = true; //it was modified, must be reimported. } else if (!FileAccess::exists(path + ".import")) { print_line("REIMPORT: no .import exists, reimport"); reimport = true; //no .import file, obviously reimport } else { uint64_t import_mt = FileAccess::get_modified_time(path + ".import"); //print_line(itos(import_mt) + " vs " + itos(p_dir->files[i]->import_modified_time)); if (import_mt != p_dir->files[i]->import_modified_time) { print_line("REIMPORT: import modified changed, reimport"); reimport = true; } else if (!_check_missing_imported_files(path)) { print_line("REIMPORT: imported files removed"); reimport = true; } } if (reimport) { ItemAction ia; ia.action = ItemAction::ACTION_FILE_REIMPORT; ia.dir = p_dir; ia.file = p_dir->files[i]->file; scan_actions.push_back(ia); } } EditorResourcePreview::get_singleton()->check_for_invalidation(p_dir->get_file_path(i)); } for (int i = 0; i < p_dir->subdirs.size(); i++) { if (updated_dir && !p_dir->subdirs[i]->verified) { //this directory was removed, add action to remove it ItemAction ia; ia.action = ItemAction::ACTION_DIR_REMOVE; ia.dir = p_dir->subdirs[i]; scan_actions.push_back(ia); continue; } _scan_fs_changes(p_dir->get_subdir(i), p_progress); } }
void EditorFileSystem::_scan_filesystem() { ERR_FAIL_COND(!scanning || new_filesystem); //read .fscache String cpath; sources_changed.clear(); file_cache.clear(); String project = ProjectSettings::get_singleton()->get_resource_path(); String fscache = EditorSettings::get_singleton()->get_project_settings_path().plus_file("filesystem_cache2"); FileAccess *f = FileAccess::open(fscache, FileAccess::READ); if (f) { //read the disk cache while (!f->eof_reached()) { String l = f->get_line().strip_edges(); if (l == String()) continue; if (l.begins_with("::")) { Vector<String> split = l.split("::"); ERR_CONTINUE(split.size() != 3); String name = split[1]; cpath = name; } else { Vector<String> split = l.split("::"); ERR_CONTINUE(split.size() != 5); String name = split[0]; String file; file = name; name = cpath.plus_file(name); FileCache fc; fc.type = split[1]; fc.modification_time = split[2].to_int64(); fc.import_modification_time = split[3].to_int64(); String deps = split[4].strip_edges(); if (deps.length()) { Vector<String> dp = deps.split("<>"); for (int i = 0; i < dp.size(); i++) { String path = dp[i]; fc.deps.push_back(path); } } file_cache[name] = fc; } } f->close(); memdelete(f); } String update_cache = EditorSettings::get_singleton()->get_project_settings_path().plus_file("filesystem_update2"); print_line("try to see fs update2"); if (FileAccess::exists(update_cache)) { print_line("it exists"); { FileAccessRef f = FileAccess::open(update_cache, FileAccess::READ); String l = f->get_line().strip_edges(); while (l != String()) { print_line("erased cache for: " + l + " " + itos(file_cache.has(l))); file_cache.erase(l); //erase cache for this, so it gets updated l = f->get_line().strip_edges(); } } DirAccessRef d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); d->remove(update_cache); //bye bye update cache } EditorProgressBG scan_progress("efs", "ScanFS", 1000); ScanProgress sp; sp.low = 0; sp.hi = 1; sp.progress = &scan_progress; new_filesystem = memnew(EditorFileSystemDirectory); new_filesystem->parent = NULL; DirAccess *d = DirAccess::create(DirAccess::ACCESS_RESOURCES); d->change_dir("res://"); _scan_new_dir(new_filesystem, d, sp); file_cache.clear(); //clear caches, no longer needed memdelete(d); //save back the findings //String fscache = EditorSettings::get_singleton()->get_project_settings_path().plus_file("file_cache"); f = FileAccess::open(fscache, FileAccess::WRITE); _save_filesystem_cache(new_filesystem, f); f->close(); memdelete(f); scanning = false; }
Node *EditorOBJImporter::import_scene(const String &p_path, uint32_t p_flags, int p_bake_fps, List<String> *r_missing_deps, Error *r_err) { FileAccessRef f = FileAccess::open(p_path, FileAccess::READ); if (r_err) { *r_err = ERR_CANT_OPEN; } ERR_FAIL_COND_V(!f, NULL); if (r_err) { *r_err = OK; } Spatial *scene = memnew(Spatial); Ref<ArrayMesh> mesh; mesh.instance(); Map<String, Ref<Material> > name_map; bool generate_tangents = p_flags & IMPORT_GENERATE_TANGENT_ARRAYS; bool flip_faces = false; //bool flip_faces = p_options["force/flip_faces"]; //bool force_smooth = p_options["force/smooth_shading"]; //bool weld_vertices = p_options["force/weld_vertices"]; //float weld_tolerance = p_options["force/weld_tolerance"]; Vector<Vector3> vertices; Vector<Vector3> normals; Vector<Vector2> uvs; String name; Map<String, Map<String, Ref<SpatialMaterial> > > material_map; Ref<SurfaceTool> surf_tool = memnew(SurfaceTool); surf_tool->begin(Mesh::PRIMITIVE_TRIANGLES); String current_material_library; String current_material; String current_group; while (true) { String l = f->get_line().strip_edges(); if (l.begins_with("v ")) { //vertex Vector<String> v = l.split(" ", false); ERR_FAIL_COND_V(v.size() < 4, NULL); Vector3 vtx; vtx.x = v[1].to_float(); vtx.y = v[2].to_float(); vtx.z = v[3].to_float(); vertices.push_back(vtx); } else if (l.begins_with("vt ")) { //uv Vector<String> v = l.split(" ", false); ERR_FAIL_COND_V(v.size() < 3, NULL); Vector2 uv; uv.x = v[1].to_float(); uv.y = 1.0 - v[2].to_float(); uvs.push_back(uv); } else if (l.begins_with("vn ")) { //normal Vector<String> v = l.split(" ", false); ERR_FAIL_COND_V(v.size() < 4, NULL); Vector3 nrm; nrm.x = v[1].to_float(); nrm.y = v[2].to_float(); nrm.z = v[3].to_float(); normals.push_back(nrm); } else if (l.begins_with("f ")) { //vertex Vector<String> v = l.split(" ", false); ERR_FAIL_COND_V(v.size() < 4, NULL); //not very fast, could be sped up Vector<String> face[3]; face[0] = v[1].split("/"); face[1] = v[2].split("/"); ERR_FAIL_COND_V(face[0].size() == 0, NULL); ERR_FAIL_COND_V(face[0].size() != face[1].size(), NULL); for (int i = 2; i < v.size() - 1; i++) { face[2] = v[i + 1].split("/"); ERR_FAIL_COND_V(face[0].size() != face[2].size(), NULL); for (int j = 0; j < 3; j++) { int idx = j; if (!flip_faces && idx < 2) { idx = 1 ^ idx; } if (face[idx].size() == 3) { int norm = face[idx][2].to_int() - 1; if (norm < 0) norm += normals.size() + 1; ERR_FAIL_INDEX_V(norm, normals.size(), NULL); surf_tool->add_normal(normals[norm]); } if (face[idx].size() >= 2 && face[idx][1] != String()) { int uv = face[idx][1].to_int() - 1; if (uv < 0) uv += uvs.size() + 1; ERR_FAIL_INDEX_V(uv, uvs.size(), NULL); surf_tool->add_uv(uvs[uv]); } int vtx = face[idx][0].to_int() - 1; if (vtx < 0) vtx += vertices.size() + 1; ERR_FAIL_INDEX_V(vtx, vertices.size(), NULL); Vector3 vertex = vertices[vtx]; //if (weld_vertices) // vertex.snap(Vector3(weld_tolerance, weld_tolerance, weld_tolerance)); surf_tool->add_vertex(vertex); } face[1] = face[2]; } } else if (l.begins_with("s ")) { //smoothing String what = l.substr(2, l.length()).strip_edges(); if (what == "off") surf_tool->add_smooth_group(false); else surf_tool->add_smooth_group(true); } else if (/*l.begins_with("g ") ||*/ l.begins_with("usemtl ") || (l.begins_with("o ") || f->eof_reached())) { //commit group to mesh //groups are too annoying if (surf_tool->get_vertex_array().size()) { //another group going on, commit it if (normals.size() == 0) { surf_tool->generate_normals(); } if (generate_tangents && uvs.size()) { surf_tool->generate_tangents(); } surf_tool->index(); print_line("current material library " + current_material_library + " has " + itos(material_map.has(current_material_library))); print_line("current material " + current_material + " has " + itos(material_map.has(current_material_library) && material_map[current_material_library].has(current_material))); if (material_map.has(current_material_library) && material_map[current_material_library].has(current_material)) { surf_tool->set_material(material_map[current_material_library][current_material]); } mesh = surf_tool->commit(mesh); if (current_material != String()) { mesh->surface_set_name(mesh->get_surface_count() - 1, current_material.get_basename()); } else if (current_group != String()) { mesh->surface_set_name(mesh->get_surface_count() - 1, current_group); } print_line("Added surface :" + mesh->surface_get_name(mesh->get_surface_count() - 1)); surf_tool->clear(); surf_tool->begin(Mesh::PRIMITIVE_TRIANGLES); } if (l.begins_with("o ") || f->eof_reached()) { MeshInstance *mi = memnew(MeshInstance); mi->set_name(name); mi->set_mesh(mesh); scene->add_child(mi); mi->set_owner(scene); mesh.instance(); current_group = ""; current_material = ""; } if (f->eof_reached()) { break; } if (l.begins_with("o ")) { name = l.substr(2, l.length()).strip_edges(); } if (l.begins_with("usemtl ")) { current_material = l.replace("usemtl", "").strip_edges(); } if (l.begins_with("g ")) { current_group = l.substr(2, l.length()).strip_edges(); } } else if (l.begins_with("mtllib ")) { //parse material current_material_library = l.replace("mtllib", "").strip_edges(); if (!material_map.has(current_material_library)) { Map<String, Ref<SpatialMaterial> > lib; Error err = _parse_material_library(current_material_library, lib, r_missing_deps); if (err == ERR_CANT_OPEN) { String dir = p_path.get_base_dir(); err = _parse_material_library(dir.plus_file(current_material_library), lib, r_missing_deps); } if (err == OK) { material_map[current_material_library] = lib; } } } } /* TODO, check existing materials and merge? //re-apply materials if exist for(int i=0;i<mesh->get_surface_count();i++) { String n = mesh->surface_get_name(i); if (name_map.has(n)) mesh->surface_set_material(i,name_map[n]); } */ return scene; }
void EditorFileDialog::_action_pressed() { if (mode == MODE_OPEN_FILES) { String fbase = dir_access->get_current_dir(); PoolVector<String> files; for (int i = 0; i < item_list->get_item_count(); i++) { if (item_list->is_selected(i)) files.push_back(fbase.plus_file(item_list->get_item_text(i))); } if (files.size()) { _save_to_recent(); emit_signal("files_selected", files); hide(); } return; } String f = dir_access->get_current_dir().plus_file(file->get_text()); if ((mode == MODE_OPEN_ANY || mode == MODE_OPEN_FILE) && dir_access->file_exists(f)) { _save_to_recent(); emit_signal("file_selected", f); hide(); } else if (mode == MODE_OPEN_ANY || mode == MODE_OPEN_DIR) { String path = dir_access->get_current_dir(); path = path.replace("\\", "/"); for (int i = 0; i < item_list->get_item_count(); i++) { if (item_list->is_selected(i)) { Dictionary d = item_list->get_item_metadata(i); if (d["dir"]) { path = path.plus_file(d["name"]); break; } } } _save_to_recent(); emit_signal("dir_selected", path); hide(); } if (mode == MODE_SAVE_FILE) { bool valid = false; if (filter->get_selected() == filter->get_item_count() - 1) { valid = true; //match none } else if (filters.size() > 1 && filter->get_selected() == 0) { // match all filters for (int i = 0; i < filters.size(); i++) { String flt = filters[i].get_slice(";", 0); for (int j = 0; j < flt.get_slice_count(","); j++) { String str = flt.get_slice(",", j).strip_edges(); if (f.match(str)) { valid = true; break; } } if (valid) break; } } else { int idx = filter->get_selected(); if (filters.size() > 1) idx--; if (idx >= 0 && idx < filters.size()) { String flt = filters[idx].get_slice(";", 0); int filterSliceCount = flt.get_slice_count(","); for (int j = 0; j < filterSliceCount; j++) { String str = (flt.get_slice(",", j).strip_edges()); if (f.match(str)) { valid = true; break; } } if (!valid && filterSliceCount > 0) { String str = (flt.get_slice(",", 0).strip_edges()); f += str.substr(1, str.length() - 1); _request_single_thumbnail(get_current_dir().plus_file(f.get_file())); file->set_text(f.get_file()); valid = true; } } else { valid = true; } } if (!valid) { exterr->popup_centered_minsize(Size2(250, 80) * EDSCALE); return; } if (dir_access->file_exists(f) && !disable_overwrite_warning) { confirm_save->set_text(TTR("File Exists, Overwrite?")); confirm_save->popup_centered(Size2(200, 80)); } else { _save_to_recent(); emit_signal("file_selected", f); hide(); } } }
void FileDialog::_action_pressed() { if (mode == MODE_OPEN_FILES) { TreeItem *ti = tree->get_next_selected(NULL); String fbase = dir_access->get_current_dir(); PoolVector<String> files; while (ti) { files.push_back(fbase.plus_file(ti->get_text(0))); ti = tree->get_next_selected(ti); } if (files.size()) { emit_signal("files_selected", files); hide(); } return; } String f = dir_access->get_current_dir().plus_file(file->get_text()); if ((mode == MODE_OPEN_ANY || mode == MODE_OPEN_FILE) && dir_access->file_exists(f)) { emit_signal("file_selected", f); hide(); } else if (mode == MODE_OPEN_ANY || mode == MODE_OPEN_DIR) { String path = dir_access->get_current_dir(); path = path.replace("\\", "/"); TreeItem *item = tree->get_selected(); if (item) { Dictionary d = item->get_metadata(0); if (d["dir"] && d["name"] != "..") { path = path.plus_file(d["name"]); } } emit_signal("dir_selected", path); hide(); } if (mode == MODE_SAVE_FILE) { bool valid = false; if (filter->get_selected() == filter->get_item_count() - 1) { valid = true; // match none } else if (filters.size() > 1 && filter->get_selected() == 0) { // match all filters for (int i = 0; i < filters.size(); i++) { String flt = filters[i].get_slice(";", 0); for (int j = 0; j < flt.get_slice_count(","); j++) { String str = flt.get_slice(",", j).strip_edges(); if (f.match(str)) { valid = true; break; } } if (valid) break; } } else { int idx = filter->get_selected(); if (filters.size() > 1) idx--; if (idx >= 0 && idx < filters.size()) { String flt = filters[idx].get_slice(";", 0); int filterSliceCount = flt.get_slice_count(","); for (int j = 0; j < filterSliceCount; j++) { String str = (flt.get_slice(",", j).strip_edges()); if (f.match(str)) { valid = true; break; } } if (!valid && filterSliceCount > 0) { String str = (flt.get_slice(",", 0).strip_edges()); f += str.substr(1, str.length() - 1); file->set_text(f.get_file()); valid = true; } } else { valid = true; } } if (!valid) { exterr->popup_centered_minsize(Size2(250, 80)); return; } if (dir_access->file_exists(f)) { confirm_save->set_text(RTR("File Exists, Overwrite?")); confirm_save->popup_centered(Size2(200, 80)); } else { emit_signal("file_selected", f); hide(); } } }
void ProjectManager::_load_recent_projects() { while(scroll_childs->get_child_count()>0) { memdelete( scroll_childs->get_child(0)); } List<PropertyInfo> properties; EditorSettings::get_singleton()->get_property_list(&properties); Color font_color = get_color("font_color","Tree"); List<ProjectItem> projects; List<ProjectItem> favorite_projects; for(List<PropertyInfo>::Element *E=properties.front();E;E=E->next()) { String _name = E->get().name; if (!_name.begins_with("projects/") && !_name.begins_with("favorite_projects/")) continue; bool favorite = (_name.begins_with("favorite_projects/"))?true:false; String project = _name.get_slice("/",1); String path = EditorSettings::get_singleton()->get(_name); String conf=path.plus_file("engine.cfg"); uint64_t last_modified = 0; if (FileAccess::exists(conf)) last_modified = FileAccess::get_modified_time(conf); String fscache = path.plus_file(".fscache"); if (FileAccess::exists(fscache)) { uint64_t cache_modified = FileAccess::get_modified_time(fscache); if ( cache_modified > last_modified ) last_modified = cache_modified; } ProjectItem item(project, path, conf, last_modified, favorite); if (favorite) favorite_projects.push_back(item); else projects.push_back(item); } projects.sort(); favorite_projects.sort(); for(List<ProjectItem>::Element *E=projects.front();E;) { List<ProjectItem>::Element *next = E->next(); if (favorite_projects.find(E->get()) != NULL) projects.erase(E->get()); E=next; } for(List<ProjectItem>::Element *E=favorite_projects.back();E;E=E->prev()) { projects.push_front(E->get()); } Ref<Texture> favorite_icon = get_icon("Favorites","EditorIcons"); for(List<ProjectItem>::Element *E=projects.front();E;E=E->next()) { ProjectItem &item = E->get(); String project = item.project; String path = item.path; String conf = item.conf; bool is_favorite = item.favorite; Ref<ConfigFile> cf = memnew( ConfigFile ); Error err = cf->load(conf); ERR_CONTINUE(err!=OK); Ref<Texture> icon; String project_name="Unnamed Project"; if (cf->has_section_key("application","icon")) { String appicon = cf->get_value("application","icon"); if (appicon!="") { Image img; Error err = img.load(appicon.replace_first("res://",path+"/")); if (err==OK) { img.resize(64,64); Ref<ImageTexture> it = memnew( ImageTexture ); it->create_from_image(img); icon=it; } } } if (cf->has_section_key("application","name")) { project_name = cf->get_value("application","name"); } if (icon.is_null()) { icon=get_icon("DefaultProjectIcon","EditorIcons"); } String main_scene; if (cf->has_section_key("application","main_scene")) { main_scene = cf->get_value("application","main_scene"); } HBoxContainer *hb = memnew( HBoxContainer ); hb->set_meta("name",project); hb->set_meta("main_scene",main_scene); hb->set_meta("favorite",is_favorite); hb->connect("draw",this,"_panel_draw",varray(hb)); hb->connect("input_event",this,"_panel_input",varray(hb)); VBoxContainer *favorite_box = memnew( VBoxContainer ); TextureButton *favorite = memnew( TextureButton ); favorite->set_normal_texture(favorite_icon); if (!is_favorite) favorite->set_opacity(0.2); favorite->set_v_size_flags(SIZE_EXPAND); favorite->connect("pressed",this,"_favorite_pressed",varray(hb)); favorite_box->add_child(favorite); hb->add_child(favorite_box); TextureFrame *tf = memnew( TextureFrame ); tf->set_texture(icon); hb->add_child(tf); VBoxContainer *vb = memnew(VBoxContainer); hb->add_child(vb); EmptyControl *ec = memnew( EmptyControl ); ec->set_minsize(Size2(0,1)); vb->add_child(ec); Label *title = memnew( Label(project_name) ); title->add_font_override("font",get_font("large","Fonts")); title->add_color_override("font_color",font_color); vb->add_child(title); Label *fpath = memnew( Label(path) ); vb->add_child(fpath); fpath->set_opacity(0.5); fpath->add_color_override("font_color",font_color); scroll_childs->add_child(hb); } erase_btn->set_disabled(selected_list.size()<1); open_btn->set_disabled(selected_list.size()<1); run_btn->set_disabled(selected_list.size()<1 || (selected_list.size()==1 && single_selected_main=="")); }
static void _compress_image(Image::CompressMode p_mode, Image *p_image) { String ttpath = EditorSettings::get_singleton()->get("filesystem/import/pvrtc_texture_tool"); if (ttpath.strip_edges() == "" || !FileAccess::exists(ttpath)) { switch (p_mode) { case Image::COMPRESS_PVRTC2: if (_base_image_compress_pvrtc2_func) _base_image_compress_pvrtc2_func(p_image); else if (_base_image_compress_pvrtc4_func) _base_image_compress_pvrtc4_func(p_image); break; case Image::COMPRESS_PVRTC4: if (_base_image_compress_pvrtc4_func) _base_image_compress_pvrtc4_func(p_image); break; default: ERR_FAIL(); } return; } String tmppath = EditorSettings::get_singleton()->get_cache_dir(); List<String> args; String src_img = tmppath.plus_file("_tmp_src_img.png"); String dst_img = tmppath.plus_file("_tmp_dst_img.pvr"); args.push_back("-i"); args.push_back(src_img); args.push_back("-o"); args.push_back(dst_img); args.push_back("-f"); switch (p_mode) { case Image::COMPRESS_PVRTC2: args.push_back("PVRTC2"); break; case Image::COMPRESS_PVRTC4: args.push_back("PVRTC4"); break; case Image::COMPRESS_ETC: args.push_back("ETC"); break; default: ERR_FAIL(); } if (EditorSettings::get_singleton()->get("filesystem/import/pvrtc_fast_conversion").operator bool()) { args.push_back("-pvrtcfast"); } if (p_image->has_mipmaps()) args.push_back("-m"); Ref<ImageTexture> t = memnew(ImageTexture); t->create_from_image(Ref<Image>(p_image), 0); ResourceSaver::save(src_img, t); Error err = OS::get_singleton()->execute(ttpath, args, true); ERR_EXPLAIN(TTR("Could not execute PVRTC tool:") + " " + ttpath); ERR_FAIL_COND(err != OK); t = ResourceLoader::load(dst_img, "Texture"); ERR_EXPLAIN(TTR("Can't load back converted image using PVRTC tool:") + " " + dst_img); ERR_FAIL_COND(t.is_null()); p_image->copy_internals_from(t->get_data()); }
void ProjectManager::_load_recent_projects() { ProjectListFilter::FilterOption filter_option = project_filter->get_filter_option(); String search_term = project_filter->get_search_term(); while(scroll_childs->get_child_count()>0) { memdelete( scroll_childs->get_child(0)); } Map<String, String> selected_list_copy = selected_list; List<PropertyInfo> properties; EditorSettings::get_singleton()->get_property_list(&properties); Color font_color = gui_base->get_color("font_color","Tree"); List<ProjectItem> projects; List<ProjectItem> favorite_projects; for(List<PropertyInfo>::Element *E=properties.front();E;E=E->next()) { String _name = E->get().name; if (!_name.begins_with("projects/") && !_name.begins_with("favorite_projects/")) continue; String path = EditorSettings::get_singleton()->get(_name); if (filter_option == ProjectListFilter::FILTER_PATH && search_term!="" && path.findn(search_term)==-1) continue; String project = _name.get_slice("/",1); String conf=path.plus_file("engine.cfg"); bool favorite = (_name.begins_with("favorite_projects/"))?true:false; uint64_t last_modified = 0; if (FileAccess::exists(conf)) { last_modified = FileAccess::get_modified_time(conf); String fscache = path.plus_file(".fscache"); if (FileAccess::exists(fscache)) { uint64_t cache_modified = FileAccess::get_modified_time(fscache); if ( cache_modified > last_modified ) last_modified = cache_modified; } ProjectItem item(project, path, conf, last_modified, favorite); if (favorite) favorite_projects.push_back(item); else projects.push_back(item); } else { //project doesn't exist on disk but it's in the XML settings file EditorSettings::get_singleton()->erase(_name); //remove it } } projects.sort(); favorite_projects.sort(); for(List<ProjectItem>::Element *E=projects.front();E;) { List<ProjectItem>::Element *next = E->next(); if (favorite_projects.find(E->get()) != NULL) projects.erase(E->get()); E=next; } for(List<ProjectItem>::Element *E=favorite_projects.back();E;E=E->prev()) { projects.push_front(E->get()); } Ref<Texture> favorite_icon = get_icon("Favorites","EditorIcons"); for(List<ProjectItem>::Element *E=projects.front();E;E=E->next()) { ProjectItem &item = E->get(); String project = item.project; String path = item.path; String conf = item.conf; bool is_favorite = item.favorite; Ref<ConfigFile> cf = memnew( ConfigFile ); Error err = cf->load(conf); ERR_CONTINUE(err!=OK); String project_name=TTR("Unnamed Project"); if (cf->has_section_key("application","name")) { project_name = static_cast<String>(cf->get_value("application","name")).xml_unescape(); } if (filter_option==ProjectListFilter::FILTER_NAME && search_term!="" && project_name.findn(search_term)==-1) continue; Ref<Texture> icon; if (cf->has_section_key("application","icon")) { String appicon = cf->get_value("application","icon"); if (appicon!="") { Image img; Error err = img.load(appicon.replace_first("res://",path+"/")); if (err==OK) { img.resize(64,64); Ref<ImageTexture> it = memnew( ImageTexture ); it->create_from_image(img); icon=it; } } } if (icon.is_null()) { icon=get_icon("DefaultProjectIcon","EditorIcons"); } String main_scene; if (cf->has_section_key("application","main_scene")) { main_scene = cf->get_value("application","main_scene"); } selected_list_copy.erase(project); HBoxContainer *hb = memnew( HBoxContainer ); hb->set_meta("name",project); hb->set_meta("main_scene",main_scene); hb->set_meta("favorite",is_favorite); hb->connect("draw",this,"_panel_draw",varray(hb)); hb->connect("input_event",this,"_panel_input",varray(hb)); hb->add_constant_override("separation",10*EDSCALE); VBoxContainer *favorite_box = memnew( VBoxContainer ); TextureButton *favorite = memnew( TextureButton ); favorite->set_normal_texture(favorite_icon); if (!is_favorite) favorite->set_opacity(0.2); favorite->set_v_size_flags(SIZE_EXPAND); favorite->connect("pressed",this,"_favorite_pressed",varray(hb)); favorite_box->add_child(favorite); hb->add_child(favorite_box); TextureFrame *tf = memnew( TextureFrame ); tf->set_texture(icon); hb->add_child(tf); VBoxContainer *vb = memnew(VBoxContainer); hb->add_child(vb); Control *ec = memnew( Control ); ec->set_custom_minimum_size(Size2(0,1)); vb->add_child(ec); Label *title = memnew( Label(project_name) ); title->add_font_override("font", gui_base->get_font("large","Fonts")); title->add_color_override("font_color",font_color); vb->add_child(title); Label *fpath = memnew( Label(path) ); vb->add_child(fpath); fpath->set_opacity(0.5); fpath->add_color_override("font_color",font_color); scroll_childs->add_child(hb); } for (Map<String,String>::Element *E = selected_list_copy.front();E;E = E->next()) { String key = E->key(); selected_list.erase(key); } scroll->set_v_scroll(0); _update_project_buttons(); EditorSettings::get_singleton()->save(); tabs->set_current_tab(0); }
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(); }
void EditorFileSystem::_scan_new_dir(EditorFileSystemDirectory *p_dir, DirAccess *da, const ScanProgress &p_progress) { List<String> dirs; List<String> files; String cd = da->get_current_dir(); p_dir->modified_time = FileAccess::get_modified_time(cd); da->list_dir_begin(); while (true) { bool isdir; String f = da->get_next(&isdir); if (f == "") break; if (isdir) { if (f.begins_with(".")) //ignore hidden and . / .. continue; if (FileAccess::exists(cd.plus_file(f).plus_file("project.godot"))) // skip if another project inside this continue; if (FileAccess::exists(cd.plus_file(f).plus_file(".gdignore"))) // skip if another project inside this continue; dirs.push_back(f); } else { files.push_back(f); } } da->list_dir_end(); dirs.sort_custom<NaturalNoCaseComparator>(); files.sort_custom<NaturalNoCaseComparator>(); int total = dirs.size() + files.size(); int idx = 0; for (List<String>::Element *E = dirs.front(); E; E = E->next(), idx++) { if (da->change_dir(E->get()) == OK) { String d = da->get_current_dir(); if (d == cd || !d.begins_with(cd)) { da->change_dir(cd); //avoid recursion } else { EditorFileSystemDirectory *efd = memnew(EditorFileSystemDirectory); efd->parent = p_dir; efd->name = E->get(); _scan_new_dir(efd, da, p_progress.get_sub(idx, total)); int idx = 0; for (int i = 0; i < p_dir->subdirs.size(); i++) { if (efd->name < p_dir->subdirs[i]->name) break; idx++; } if (idx == p_dir->subdirs.size()) { p_dir->subdirs.push_back(efd); } else { p_dir->subdirs.insert(idx, efd); } da->change_dir(".."); } } else { ERR_PRINTS("Cannot go into subdir: " + E->get()); } p_progress.update(idx, total); } for (List<String>::Element *E = files.front(); E; E = E->next(), idx++) { String ext = E->get().get_extension().to_lower(); if (!valid_extensions.has(ext)) { continue; //invalid } EditorFileSystemDirectory::FileInfo *fi = memnew(EditorFileSystemDirectory::FileInfo); fi->file = E->get(); String path = cd.plus_file(fi->file); FileCache *fc = file_cache.getptr(path); uint64_t mt = FileAccess::get_modified_time(path); if (import_extensions.has(ext)) { //is imported uint64_t import_mt = 0; if (FileAccess::exists(path + ".import")) { import_mt = FileAccess::get_modified_time(path + ".import"); } if (fc && fc->modification_time == mt && fc->import_modification_time == import_mt && _check_missing_imported_files(path)) { fi->type = fc->type; fi->deps = fc->deps; fi->modified_time = fc->modification_time; fi->import_modified_time = fc->import_modification_time; if (fc->type == String()) { fi->type = ResourceLoader::get_resource_type(path); //there is also the chance that file type changed due to reimport, must probably check this somehow here (or kind of note it for next time in another file?) //note: I think this should not happen any longer.. } } else { if (!fc) { print_line("REIMPORT BECAUSE: not previously found"); } else if (fc->modification_time != mt) { print_line("REIMPORT BECAUSE: modified resource time " + itos(fc->modification_time) + " vs " + itos(mt)); } else if (fc->import_modification_time != import_mt) { print_line("REIMPORT BECAUSE: modified .import time" + itos(fc->import_modification_time) + " vs " + itos(import_mt)); } else { print_line("REIMPORT BECAUSE: missing imported files"); } fi->type = ResourceFormatImporter::get_singleton()->get_resource_type(path); //fi->deps = ResourceLoader::get_dependencies(path); pointless because it will be reimported, but.. print_line("import extension tried resource type for " + path + " and its " + fi->type); fi->modified_time = 0; fi->import_modified_time = 0; ItemAction ia; ia.action = ItemAction::ACTION_FILE_REIMPORT; ia.dir = p_dir; ia.file = E->get(); scan_actions.push_back(ia); } } else { if (fc && fc->modification_time == mt) { //not imported, so just update type if changed fi->type = fc->type; fi->modified_time = fc->modification_time; fi->deps = fc->deps; fi->import_modified_time = 0; } else { //new or modified time fi->type = ResourceLoader::get_resource_type(path); fi->deps = _get_dependencies(path); print_line("regular import tried resource type for " + path + " and its " + fi->type); fi->modified_time = mt; fi->import_modified_time = 0; } } p_dir->files.push_back(fi); p_progress.update(idx, total); } }