Example #1
0
String ResourceFormatLoaderDynamicFont::get_resource_type(const String &p_path) const {

	String el = p_path.extension().to_lower();
	if (el == "ttf")
		return "DynamicFontData";
	return "";
}
Example #2
0
String ResourceFormatLoaderTheme::get_resource_type(const String &p_path) const {

    if (p_path.extension().to_lower()=="theme")
        return "Theme";
    return "";
}
Example #3
0
String ResourceFormatLoaderAudioStreamSpeex::get_resource_type(const String &p_path) const {

	if (p_path.extension().to_lower() == "spx")
		return "AudioStreamSpeex";
	return "";
}
Example #4
0
String ResourceFormatLoaderShader::get_resource_type(const String &p_path) const {

    if (p_path.extension().to_lower()=="shader")
        return "Shader";
    return "";
}
void EditorAssetInstaller::open(const String& p_path,int p_depth) {


	package_path=p_path;
	Set<String> files_sorted;

	FileAccess *src_f=NULL;
	zlib_filefunc_def io = zipio_create_io_from_file(&src_f);

	unzFile pkg = unzOpen2(p_path.utf8().get_data(), &io);
	if (!pkg) {

		error->set_text("Error opening package file, not in zip format.");
		return;
	}

	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 name=fname;
		files_sorted.insert(name);

		ret = unzGoToNextFile(pkg);
	}


	Map<String,Ref<Texture> > extension_guess;
	{
		extension_guess["png"]=get_icon("Texture","EditorIcons");
		extension_guess["jpg"]=get_icon("Texture","EditorIcons");
		extension_guess["tex"]=get_icon("Texture","EditorIcons");
		extension_guess["atex"]=get_icon("Texture","EditorIcons");
		extension_guess["dds"]=get_icon("Texture","EditorIcons");
		extension_guess["scn"]=get_icon("PackedScene","EditorIcons");
		extension_guess["tscn"]=get_icon("PackedScene","EditorIcons");
		extension_guess["xml"]=get_icon("PackedScene","EditorIcons");
		extension_guess["xscn"]=get_icon("PackedScene","EditorIcons");
		extension_guess["mtl"]=get_icon("Material","EditorIcons");
		extension_guess["shd"]=get_icon("Shader","EditorIcons");
		extension_guess["gd"]=get_icon("GDScript","EditorIcons");
	}

	Ref<Texture> generic_extension = get_icon("Object","EditorIcons");


	unzClose(pkg);

	updating=true;
	tree->clear();
	TreeItem *root=tree->create_item();
	root->set_cell_mode(0,TreeItem::CELL_MODE_CHECK);
	root->set_checked(0,true);
	root->set_icon(0,get_icon("folder","FileDialog"));
	root->set_text(0,"res://");
	root->set_editable(0,true);
	Map<String,TreeItem*> dir_map;

	for(Set<String>::Element *E=files_sorted.front();E;E=E->next()) {

		String path = E->get();
		int depth=p_depth;
		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())
			continue;

		bool isdir=false;

		if (path.ends_with("/")) {
			//a directory
			path=path.substr(0,path.length()-1);
			isdir=true;
		}

		int pp = path.find_last("/");


		TreeItem *parent;
		if (pp==-1) {
			parent=root;
		} else {
			String ppath=path.substr(0,pp);
			print_line("PPATH IS: "+ppath);
			ERR_CONTINUE(!dir_map.has(ppath));
			parent=dir_map[ppath];

		}

		TreeItem *ti = tree->create_item(parent);
		ti->set_cell_mode(0,TreeItem::CELL_MODE_CHECK);
		ti->set_checked(0,true);
		ti->set_editable(0,true);
		if (isdir) {
			dir_map[path]=ti;
			ti->set_text(0,path.get_file()+"/");
			ti->set_icon(0,get_icon("folder","FileDialog"));
		} else {
			String file = path.get_file();
			String extension = file.extension().to_lower();
			if (extension_guess.has(extension)) {
				ti->set_icon(0,extension_guess[extension]);
			} else {
				ti->set_icon(0,generic_extension);
			}
			ti->set_text(0,file);


			String res_path = "res://"+path;
			if (FileAccess::exists(res_path)) {
				ti->set_custom_color(0,Color(1,0.3,0.2));
				ti->set_tooltip(0,res_path+" (Already Exists)");
				ti->set_checked(0,false);
			} else {
				ti->set_tooltip(0,res_path);

			}

			ti->set_metadata(0,res_path);

		}

		status_map[E->get()]=ti;



	}
	popup_centered_ratio();
	updating=false;

}
Example #6
0
String TranslationLoaderPO::get_resource_type(const String &p_path) const {

	if (p_path.extension().to_lower() == "po")
		return "Translation";
	return "";
}
Example #7
0
void ScriptCreateDialog::_path_changed(const String& p_path) {

    path_valid=false;
    String p =p_path;

    if (p=="")	 {

        path_error_label->set_text("Path is Empty");
        path_error_label->add_color_override("font_color",Color(1,0.4,0.0,0.8));
        return;

    }

    p = Globals::get_singleton()->localize_path(p);
    if (!p.begins_with("res://")) {

        path_error_label->set_text("Path is not local");
        path_error_label->add_color_override("font_color",Color(1,0.4,0.0,0.8));
        return;
    }

    if (p.find("/") || p.find("\\")) {
        DirAccess *d = DirAccess::create(DirAccess::ACCESS_RESOURCES);

        if (d->change_dir(p.get_base_dir())!=OK) {

            path_error_label->set_text("Base Path Invalid");
            path_error_label->add_color_override("font_color",Color(1,0.4,0.0,0.8));
            memdelete(d);
            return;

        }
        memdelete(d);
    }



    FileAccess *f = FileAccess::create(FileAccess::ACCESS_RESOURCES);

    if (f->file_exists(p)) {

        path_error_label->set_text("File Exists");
        path_error_label->add_color_override("font_color",Color(1,0.4,0.0,0.8));
        memdelete(f);
        return;
    }

    memdelete(f);

    String extension=p.extension();
    List<String> extensions;

    int l=language_menu->get_selected();
    ScriptServer::get_language( l )->get_recognized_extensions(&extensions);

    bool found=false;
    for(List<String>::Element *E=extensions.front(); E; E=E->next()) {
        if (E->get().nocasecmp_to(extension)==0) {
            found=true;
            break;
        }
    }

    if (!found) {

        path_error_label->set_text("Invalid Extension");
        path_error_label->add_color_override("font_color",Color(1,0.4,0.0,0.8));
        return;
    }


    path_error_label->set_text("Path is Valid");
    path_error_label->add_color_override("font_color",Color(0,1.0,0.8,0.8));

    path_valid=true;

}
EditorFileSystem::DirItem* EditorFileSystem::_scan_dir(DirAccess *da,Set<String> &extensions,String p_name,float p_from,float p_range,const String& p_path,HashMap<String,FileCache> &file_cache,HashMap<String,DirCache> &dir_cache,EditorProgressBG& p_prog) {

	if (abort_scan)
		return NULL;

	if (p_path!=String()) {
		if (FileAccess::exists(("res://"+p_path).plus_file("engine.cfg"))) {
			return NULL;
		}
	}

	List<String> dirs;
	List<String> files;
	Set<String> pngs;

	String path=p_path;
	if (path.ends_with("/"))
		path=path.substr(0,path.length()-1);
	String global_path = Globals::get_singleton()->get_resource_path().plus_file(path);

	path="res://"+path;
	uint64_t mtime = FileAccess::get_modified_time(global_path);

	DirCache *dc = dir_cache.getptr(path);


	if (false && dc && dc->modification_time==mtime) {
		//use the cached files, since directory did not change
		for (Set<String>::Element *E=dc->subdirs.front();E;E=E->next()) {
			dirs.push_back(E->get());
		}
		for (Set<String>::Element *E=dc->files.front();E;E=E->next()) {
			files.push_back(E->get());
		}

	} else {
		//use the filesystem, some files may have changed
		Error err = da->change_dir(global_path);
		if (err!=OK) {
			print_line("Can't change to: "+path);
			ERR_FAIL_COND_V(err!=OK,NULL);
		}


		da->list_dir_begin();
		while (true) {

			bool isdir;
			String f = da->get_next(&isdir);
			if (f=="")
				break;
			if (isdir) {
				dirs.push_back(f);
			} else {
				String ext = f.extension().to_lower();
				if (extensions.has(ext))
					files.push_back(f);

			}

		}

		da->list_dir_end();
		files.sort();
		dirs.sort();

	}



	//print_line(da->get_current_dir()+": dirs: "+itos(dirs.size())+" files:"+itos(files.size()) );

	//find subdirs
	Vector<DirItem*> subdirs;

	//String current = da->get_current_dir();
	float idx=0;
	for (List<String>::Element *E=dirs.front();E;E=E->next(),idx+=1.0) {

		String d = E->get();
		if (d.begins_with(".")) //ignore hidden and . / ..
			continue;

		//ERR_CONTINUE( da->change_dir(d)!= OK );
		DirItem *sdi = _scan_dir(da,extensions,d,p_from+(idx/dirs.size())*p_range,p_range/dirs.size(),p_path+d+"/",file_cache,dir_cache,p_prog);
		if (sdi) {
			subdirs.push_back(sdi);
		}
		//da->change_dir(current);
	}


	if (subdirs.empty() && files.empty()) {
		total=p_from+p_range;
		p_prog.step(total*100);
		return NULL; //give up, nothing to do here
	}

	DirItem *di = memnew( DirItem );
	di->path=path;
	di->name=p_name;
	di->dirs=subdirs;
	di->modified_time=mtime;

	//add files
	for (List<String>::Element *E=files.front();E;E=E->next()) {

		SceneItem * si = memnew( SceneItem );
		si->file=E->get();
		si->path="res://"+p_path+si->file;
		FileCache *fc = file_cache.getptr(si->path);
		uint64_t mt = FileAccess::get_modified_time(si->path);

		if (fc && fc->modification_time == mt) {

			si->meta=fc->meta;
			si->type=fc->type;
			si->modified_time=fc->modification_time;
		} else {
			si->meta=_get_meta(si->path);
			si->type=ResourceLoader::get_resource_type(si->path);
			si->modified_time=mt;

		}

		if (si->meta.enabled) {
			md_count++;
			if (_check_meta_sources(si->meta)) {
				sources_changed.push_back(si->path);
			}
		}
		di->files.push_back(si);
	}

	total=p_from+p_range;
	p_prog.step(total*100);

	return di;
}