void Img::load( const String &filename ) { if ( filename.ends_with( ".tif" ) or filename.ends_with( ".tiff" ) or filename.ends_with( ".TIF" ) or filename.ends_with( ".TIFF" ) ) load_tiff( filename ); else load_qimg( filename ); }
String CompilationEnvironment::obj_cmd( const String &obj, const String &cpp, bool dyn ) const { String cmd; bool cu = cpp.ends_with( ".cu" ); if ( cu ) { cmd << get_NVCC(); // basic flags if ( dyn ) cmd << " -Xcompiler -fPIC"; if ( maxrregcount > 0 ) cmd << " --maxrregcount=" << maxrregcount; if ( get_device_emulation() > 0 ) cmd << " --device-emulation -G"; // if ( sizeof( void * ) == 8 and not want_m32() ) cmd << " --machine 64"; else cmd << " --machine 32"; } else { cmd << ( cpp.ends_with( ".c" ) ? get_CC() : get_CXX() ); // basic flags if ( dyn ) cmd << " -fpic"; } // -L... -l... -g... extra_obj_cmd( cmd, dyn, cu, cpp ); // input / output cmd << " -c -o '" << obj << "' '" << cpp << "'"; return cmd; }
void ScriptTextEditor::trim_trailing_whitespace() { TextEdit *tx = code_editor->get_text_edit(); bool trimed_whitespace = false; for (int i = 0; i < tx->get_line_count(); i++) { String line = tx->get_line(i); if (line.ends_with(" ") || line.ends_with("\t")) { if (!trimed_whitespace) { tx->begin_complex_operation(); trimed_whitespace = true; } int end = 0; for (int j = line.length() - 1; j > -1; j--) { if (line[j] != ' ' && line[j] != '\t') { end = j+1; break; } } tx->set_line(i, line.substr(0, end)); } } if (trimed_whitespace) { tx->end_complex_operation(); tx->update(); } }
String CompilationEnvironment::mex_for( const String &cpp ) { const char *suffix = ".mexglx"; if ( cpp.ends_with( ".cpp" ) ) return cpp.rstrip( 4 ) + suffix; if ( cpp.ends_with( ".cxx" ) ) return cpp.rstrip( 4 ) + suffix; if ( cpp.ends_with( ".cc" ) ) return cpp.rstrip( 3 ) + suffix; return cpp + suffix; }
MonoAssembly *gdmono_MonoAssemblyPreLoad(MonoAssemblyName *aname, char **assemblies_path, void *user_data) { (void)user_data; // UNUSED MonoAssembly *assembly_loaded = mono_assembly_loaded(aname); if (assembly_loaded) // Already loaded return assembly_loaded; static Vector<String> search_dirs; if (search_dirs.empty()) { search_dirs.push_back(GodotSharpDirs::get_res_temp_assemblies_dir()); search_dirs.push_back(GodotSharpDirs::get_res_assemblies_dir()); search_dirs.push_back(OS::get_singleton()->get_resource_dir()); search_dirs.push_back(OS::get_singleton()->get_executable_path().get_base_dir()); const char *rootdir = mono_assembly_getrootdir(); if (rootdir) { search_dirs.push_back(String(rootdir).plus_file("mono").plus_file("4.5")); } while (assemblies_path) { if (*assemblies_path) search_dirs.push_back(*assemblies_path); ++assemblies_path; } } String name = mono_assembly_name_get_name(aname); bool has_extension = name.ends_with(".dll") || name.ends_with(".exe"); String path; for (int i = 0; i < search_dirs.size(); i++) { const String &search_dir = search_dirs[i]; if (has_extension) { path = search_dir.plus_file(name); if (FileAccess::exists(path)) return gdmono_load_assembly_from(name.get_basename(), path); } else { path = search_dir.plus_file(name + ".dll"); if (FileAccess::exists(path)) return gdmono_load_assembly_from(name, path); path = search_dir.plus_file(name + ".exe"); if (FileAccess::exists(path)) return gdmono_load_assembly_from(name, path); } } return NULL; }
void ProjectExportDialog::_export_pck_zip_selected(const String &p_path) { 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()); if (p_path.ends_with(".zip")) { platform->export_zip(current, export_pck_zip_debug->is_pressed(), p_path); } else if (p_path.ends_with(".pck")) { platform->export_pack(current, export_pck_zip_debug->is_pressed(), p_path); } }
bool FileSystemDock::_create_tree(TreeItem *p_parent,EditorFileSystemDirectory *p_dir) { TreeItem *item = tree->create_item(p_parent); String dname=p_dir->get_name(); if (dname=="") dname="res://"; item->set_text(0,dname); item->set_icon(0,get_icon("Folder","EditorIcons")); item->set_selectable(0,true); String lpath = p_dir->get_path(); if (lpath!="res://" && lpath.ends_with("/")) { lpath=lpath.substr(0,lpath.length()-1); } item->set_metadata(0,lpath); if (lpath==path) { item->select(0); } for(int i=0;i<p_dir->get_subdir_count();i++) _create_tree(item,p_dir->get_subdir(i)); return true; }
void RotatedFileLogger::clear_old_backups() { int max_backups = max_files - 1; // -1 for the current file String basename = base_path.get_file().get_basename(); String extension = "." + base_path.get_extension(); DirAccess *da = DirAccess::open(base_path.get_base_dir()); if (!da) { return; } da->list_dir_begin(); String f = da->get_next(); Set<String> backups; while (f != String()) { if (!da->current_is_dir() && f.begins_with(basename) && f.ends_with(extension) && f != base_path.get_file()) { backups.insert(f); } f = da->get_next(); } da->list_dir_end(); if (backups.size() > max_backups) { // since backups are appended with timestamp and Set iterates them in sorted order, // first backups are the oldest int to_delete = backups.size() - max_backups; for (Set<String>::Element *E = backups.front(); E && to_delete > 0; E = E->next(), --to_delete) { da->remove(E->get()); } } memdelete(da); }
void GDMonoLog::_delete_old_log_files(const String &p_logs_dir) { static const uint64_t MAX_SECS = 5 * 86400; DirAccessRef da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); ERR_FAIL_COND(!da); Error err = da->change_dir(p_logs_dir); ERR_FAIL_COND(err != OK); ERR_FAIL_COND(da->list_dir_begin() != OK); String current; while ((current = da->get_next()).length()) { if (da->current_is_dir()) continue; if (!current.ends_with(".txt")) continue; String name = current.get_basename(); uint64_t unixtime = (uint64_t)name.to_int64(); if (OS::get_singleton()->get_unix_time() - unixtime > MAX_SECS) { da->remove(current); } } da->list_dir_end(); }
void CompilationEnvironment::use_dylib( const String &cpp ) { BasicVec<String> pending( cpp ); set_comp_dir( directory_of( cpp ) + "/compilations" ); while ( pending.size() ) { String fpp = pending.back(); pending.pop_back(); parsed.push_back_unique( absolute_filename( fpp ) ); CompilationCppParser cpp_parser( *this, fpp, dep_for( fpp ) ); // .h -> .cpp or .cu ? for( int i = 0; i < cpp_parser.inc_files.size(); ++i ) { String h = absolute_filename( cpp_parser.inc_files[ i ] ); if ( h.ends_with( ".h" ) ) { String base = h.beg_upto( h.size() - 2 ); if ( file_exists( base + ".cpp" ) and not parsed.contains( base + ".cpp" ) ) pending.push_back_unique( base + ".cpp" ); if ( file_exists( base + ".cu" ) and not parsed.contains( base + ".cu" ) ) pending.push_back_unique( base + ".cu" ); } } } dylibs << lib_for( cpp, true ); }
Error DocData::erase_classes(const String &p_dir) { Error err; DirAccessRef da = DirAccess::open(p_dir, &err); if (!da) { return err; } List<String> to_erase; da->list_dir_begin(); String path; bool isdir; path = da->get_next(&isdir); while (path != String()) { if (!isdir && path.ends_with("xml")) { to_erase.push_back(path); } path = da->get_next(&isdir); } da->list_dir_end(); while (to_erase.size()) { da->remove(to_erase.front()->get()); to_erase.pop_front(); } return OK; }
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; }
MonoAssembly *GDMonoAssembly::_search_hook(MonoAssemblyName *aname, void *user_data) { (void)user_data; // UNUSED String name = mono_assembly_name_get_name(aname); bool has_extension = name.ends_with(".dll") || name.ends_with(".exe"); if (no_search) return NULL; GDMonoAssembly **loaded_asm = GDMono::get_singleton()->get_loaded_assembly(has_extension ? name.get_basename() : name); if (loaded_asm) return (*loaded_asm)->get_assembly(); no_search = true; // Avoid the recursion madness String path; MonoAssembly *res = NULL; for (int i = 0; i < search_dirs.size(); i++) { const String &search_dir = search_dirs[i]; if (has_extension) { path = search_dir.plus_file(name); if (FileAccess::exists(path)) { res = _load_assembly_from(name.get_basename(), path); break; } } else { path = search_dir.plus_file(name + ".dll"); if (FileAccess::exists(path)) { res = _load_assembly_from(name, path); break; } path = search_dir.plus_file(name + ".exe"); if (FileAccess::exists(path)) { res = _load_assembly_from(name, path); break; } } } no_search = false; return res; }
void CompilationEnvironment::add_inc_path( const String &path ) { String a = absolute_filename( path ); if ( a.size() ) { if ( not a.ends_with( "/" ) ) a += '/'; inc_paths.push_back_unique( a ); } }
String EditorImportPlugin::validate_source_path(const String& p_path) { String gp = Globals::get_singleton()->globalize_path(p_path); String rp = Globals::get_singleton()->get_resource_path(); if (!rp.ends_with("/")) rp+="/"; return rp.path_to_file(gp); }
HtmlUnit HtmlUnit::fromString(String value) { value.trim(); if(value.ends_with(_S("%"))) { value.trim_right(_S("%")); return HtmlUnit(conversions::from_utf16<int32>(value), utPercent); } if(value.ends_with(_S("px"))) { value.trim_right(_S("px")); return HtmlUnit(conversions::from_utf16<int32>(value), utPixels); } return HtmlUnit(conversions::from_utf16<int32>(value), utPure); }
Error ResourceFormatSaverText::save(const String &p_path,const RES& p_resource,uint32_t p_flags) { if (p_path.ends_with(".sct") && p_resource->get_type()!="PackedScene") { return ERR_FILE_UNRECOGNIZED; } ResourceFormatSaverTextInstance saver; return saver.save(p_path,p_resource,p_flags); }
void CompilationEnvironment::add_lib_path( const String &path ) { if ( child ) child->add_lib_path( path ); else { String a = absolute_filename( path ); if ( a.size() ) { if ( not a.ends_with( "/" ) ) a += '/'; lib_paths.push_back_unique( a ); } } }
String FilePath::create(const char * directory, const char * base) { if (!directory || StringLength(directory) == 0) return base; if (!base || StringLength(base) == 0) return directory; String result = directory; if (!result.ends_with(separator) && base[0] != separator[0]) { result += separator; } result += base; return result; }
void _file_selected(const String& p_path) { String p = p_path; if (import_mode) { if (p.ends_with("engine.cfg")) { p=p.get_base_dir(); } } String sp = p.simplify_path(); project_path->set_text(sp); _path_text_changed(p); }
void EditorQuickOpen::_parse_fs(EditorFileSystemDirectory *efsd) { if (!add_directories) { for(int i=0;i<efsd->get_subdir_count();i++) { _parse_fs(efsd->get_subdir(i)); } } TreeItem *root = search_options->get_root(); if (add_directories) { String path = efsd->get_path(); if (!path.ends_with("/")) path+="/"; if (path!="res://") { path=path.substr(6,path.length()); if (path.findn(search_box->get_text())!=-1) { TreeItem *ti = search_options->create_item(root); ti->set_text(0,path); Ref<Texture> icon = get_icon("folder","FileDialog"); ti->set_icon(0,icon); } } } for(int i=0;i<efsd->get_file_count();i++) { String file = efsd->get_file_path(i); file=file.substr(6,file.length()); if (ObjectTypeDB::is_type(efsd->get_file_type(i),base_type) && (search_box->get_text()=="" || file.findn(search_box->get_text())!=-1)) { TreeItem *ti = search_options->create_item(root); ti->set_text(0,file); Ref<Texture> icon = get_icon( (has_icon(efsd->get_file_type(i),ei)?efsd->get_file_type(i):ot),ei); ti->set_icon(0,icon); if (root->get_children()==ti) ti->select(0); } } if (add_directories) { for(int i=0;i<efsd->get_subdir_count();i++) { _parse_fs(efsd->get_subdir(i)); } } }
void _file_selected(const String& p_path) { String p = p_path; if (mode==MODE_IMPORT) { if (p.ends_with("engine.cfg")) { p=p.get_base_dir(); } } String sp = p.simplify_path(); project_path->set_text(sp); _path_text_changed(p); get_ok()->call_deferred("grab_focus"); }
EditorFileSystemDirectory *EditorFileSystem::get_path(const String& p_path) { if (!filesystem || scanning) return NULL; String f = Globals::get_singleton()->localize_path(p_path); if (!f.begins_with("res://")) return NULL; f=f.substr(6,f.length()); f=f.replace("\\","/"); if (f==String()) return filesystem; if (f.ends_with("/")) f=f.substr(0,f.length()-1); Vector<String> path = f.split("/"); if (path.size()==0) return NULL; EditorFileSystemDirectory *fs=filesystem; for(int i=0;i<path.size();i++) { int idx=-1; for(int j=0;j<fs->get_subdir_count();j++) { if (fs->get_subdir(j)->get_name()==path[i]) { idx=j; break; } } if (idx==-1) { return NULL; } else { fs=fs->get_subdir(idx); } } return fs; }
static void _add_files_with_filter(DirAccess *da,const List<String>& p_filters,Set<StringName>& r_list) { List<String> files; List<String> dirs; da->list_dir_begin(); String f = da->get_next(); while(f!="") { print_line("HOHO: "+f); if (da->current_is_dir()) dirs.push_back(f); else files.push_back(f); f=da->get_next(); } String r = da->get_current_dir().replace("\\","/"); if (!r.ends_with("/")) r+="/"; print_line("AT: "+r); for(List<String>::Element *E=files.front();E;E=E->next()) { String fullpath=r+E->get(); for(const List<String>::Element *F=p_filters.front();F;F=F->next()) { if (fullpath.matchn(F->get())) { r_list.insert(fullpath); print_line("Added: "+fullpath); } } } da->list_dir_end(); for(List<String>::Element *E=dirs.front();E;E=E->next()) { if (E->get().begins_with(".")) continue; da->change_dir(E->get()); _add_files_with_filter(da,p_filters,r_list); da->change_dir(".."); } }
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; } } }
uint64_t FileAccessWindows::_get_modified_time(const String &p_file) { String file = fix_path(p_file); if (file.ends_with("/") && file != "/") file = file.substr(0, file.length() - 1); struct _stat st; int rv = _wstat(file.c_str(), &st); if (rv == 0) { return st.st_mtime; } else { ERR_EXPLAIN("Failed to get modified time for: " + file); ERR_FAIL_V(0); } }
String standardisePath(const String &path, bool terminator) { if(path.empty()) return path; String standard = path; /* std::replace(standard.begin(), standard.end(), chBackSlash, chForwardSlash); if(terminator && standard[standard.length() - 1] != chForwardSlash) standard += chForwardSlash; */ standard.replace_all(_S("\\"), _S("/")); if(terminator && standard.ends_with(_S("/")) == false) standard.append(_S("/")); return standard; }
uint64_t FileAccessWindows::_get_modified_time(const String &p_file) { String file = fix_path(p_file); if (file.ends_with("/") && file != "/") file = file.substr(0, file.length() - 1); struct _stat st; int rv = _wstat(file.c_str(), &st); if (rv == 0) { return st.st_mtime; } else { print_line("no access to " + file); } ERR_FAIL_V(0); };
virtual Vector<uint8_t> custom_export(String& p_path,const Ref<EditorExportPlatform> &p_platform) { //compile lua script to bytecode if (p_path.ends_with(".lua")) { // Vector<uint8_t> file = FileAccess::get_file_as_array(p_path); // if (file.empty()) // return file; // String txt; // txt.parse_utf8((const char*)file.ptr(),file.size()); // file = GDTokenizerBuffer::parse_code_string(txt); // if (!file.empty()) { // print_line("PREV: "+p_path); // p_path=p_path.basename()+".gdc"; // print_line("NOW: "+p_path); // return file; // } // } return Vector<uint8_t>(); }
bool ScenesDock::can_drop_data_fw(const Point2& p_point,const Variant& p_data,Control* p_from) const{ Dictionary drag_data = p_data; if (drag_data.has("type") && String(drag_data["type"])=="resource") { return true; } if (drag_data.has("type") && ( String(drag_data["type"])=="files" || String(drag_data["type"])=="files_and_dirs")) { Vector<String> fnames = drag_data["files"]; if (p_from==files) { int at_pos = files->get_item_at_pos(p_point); if (at_pos!=-1) { String dir = files->get_item_metadata(at_pos); if (dir.ends_with("/")) return true; } } if (p_from==tree) { TreeItem *ti = tree->get_item_at_pos(p_point); if (!ti) return false; String path = ti->get_metadata(0); if (path==String()) return false; return true; } } return false; }