//! return the current position of the source pointer
	virtual unsigned long tell() {

		if (!fa)
			return 0;

		return fa->get_pos();
	};
Esempio n. 2
0
long AudioStreamPlaybackOGGVorbis::_ov_tell_func(void *_f) {

	//printf("close %p\n",_f);

	FileAccess *fa = (FileAccess *)_f;
	return fa->get_pos();
}
Esempio n. 3
0
int AudioStreamPlaybackOGGVorbis::_ov_seek_func(void *_f, ogg_int64_t offs, int whence) {

//printf("seek to %p, offs %i, whence %i\n",_f,(int)offs,whence);

#ifdef SEEK_SET
	//printf("seek set defined\n");
	FileAccess *fa = (FileAccess *)_f;

	if (whence == SEEK_SET) {

		fa->seek(offs);
	} else if (whence == SEEK_CUR) {

		fa->seek(fa->get_pos() + offs);
	} else if (whence == SEEK_END) {

		fa->seek_end(offs);
	} else {

		ERR_PRINT("BUG, wtf was whence set to?\n");
	}
	int ret = fa->eof_reached() ? -1 : 0;
	//printf("returning %i\n",ret);
	return ret;

#else
	return -1; // no seeking
#endif
}
Esempio n. 4
0
Error DirAccess::copy(String p_from,String p_to) {

	//printf("copy %s -> %s\n",p_from.ascii().get_data(),p_to.ascii().get_data());
	Error err;
	FileAccess *fsrc = FileAccess::open(p_from, FileAccess::READ,&err);

	if (err) {

		ERR_FAIL_COND_V( err, err );
	}


	FileAccess *fdst = FileAccess::open(p_to, FileAccess::WRITE,&err );
	if (err) {

		fsrc->close();
		memdelete( fsrc );
		ERR_FAIL_COND_V( err, err );
	}

	fsrc->seek_end(0);
	int size = fsrc->get_pos();
	fsrc->seek(0);
	err = OK;
	while(size--) {

		if (fsrc->get_error()!=OK) {
			err= fsrc->get_error();
			break;
		}
		if (fdst->get_error()!=OK) {
			err= fdst->get_error();
			break;
		}

		fdst->store_8( fsrc->get_8() );
	}

	memdelete(fsrc);
	memdelete(fdst);

	return err;
}
Esempio n. 5
0
static long godot_seek(voidpf opaque, voidpf stream, uLong offset, int origin) {

	FileAccess* f = (FileAccess*)opaque;

	int pos = offset;
	switch (origin) {

	case ZLIB_FILEFUNC_SEEK_CUR:
		pos = f->get_pos() + offset;
		break;
	case ZLIB_FILEFUNC_SEEK_END:
		pos = f->get_len() + offset;
		break;
	default:
		break;
	};

	f->seek(pos);
	return 0;
};
Esempio n. 6
0
static long godot_tell (voidpf opaque, voidpf stream) {

	FileAccess* f = (FileAccess*)opaque;
	return f->get_pos();
};
Esempio n. 7
0
Error StreamTexture::_load_data(const String &p_path, int &tw, int &th, int &flags, Image &image, int p_size_limit) {

	FileAccess *f = FileAccess::open(p_path, FileAccess::READ);
	ERR_FAIL_COND_V(!f, ERR_CANT_OPEN);

	uint8_t header[4];
	f->get_buffer(header, 4);
	if (header[0] != 'G' || header[1] != 'D' || header[2] != 'S' || header[3] != 'T') {
		memdelete(f);
		ERR_FAIL_COND_V(header[0] != 'G' || header[1] != 'D' || header[2] != 'S' || header[3] != 'T', ERR_FILE_CORRUPT);
	}

	tw = f->get_32();
	th = f->get_32();
	flags = f->get_32(); //texture flags!
	uint32_t df = f->get_32(); //data format

	print_line("width: " + itos(tw));
	print_line("height: " + itos(th));
	print_line("flags: " + itos(flags));
	print_line("df: " + itos(df));

	if (request_3d_callback && df & FORMAT_BIT_DETECT_3D) {
		print_line("request detect 3D at " + p_path);
		VS::get_singleton()->texture_set_detect_3d_callback(texture, _requested_3d, this);
	} else {
		print_line("not requesting detect 3D at " + p_path);
		VS::get_singleton()->texture_set_detect_3d_callback(texture, NULL, NULL);
	}

	if (request_srgb_callback && df & FORMAT_BIT_DETECT_SRGB) {
		print_line("request detect srgb at " + p_path);
		VS::get_singleton()->texture_set_detect_srgb_callback(texture, _requested_srgb, this);
	} else {
		VS::get_singleton()->texture_set_detect_srgb_callback(texture, NULL, NULL);
		print_line("not requesting detect srgb at " + p_path);
	}

	if (!(df & FORMAT_BIT_STREAM)) {
		p_size_limit = 0;
	}

	if (df & FORMAT_BIT_LOSSLESS || df & FORMAT_BIT_LOSSY) {
		//look for a PNG or WEBP file inside

		int sw = tw;
		int sh = th;

		uint32_t mipmaps = f->get_32();
		uint32_t size = f->get_32();

		print_line("mipmaps: " + itos(mipmaps));

		while (mipmaps > 1 && p_size_limit > 0 && (sw > p_size_limit || sh > p_size_limit)) {

			f->seek(f->get_pos() + size);
			mipmaps = f->get_32();
			size = f->get_32();

			sw = MAX(sw >> 1, 1);
			sh = MAX(sh >> 1, 1);
			mipmaps--;
		}

		//mipmaps need to be read independently, they will be later combined
		Vector<Image> mipmap_images;
		int total_size = 0;

		for (int i = 0; i < mipmaps; i++) {

			if (i > 0) {
				size = f->get_32();
			}

			PoolVector<uint8_t> pv;
			pv.resize(size);
			{
				PoolVector<uint8_t>::Write w = pv.write();
				f->get_buffer(w.ptr(), size);
			}

			Image img;
			if (df & FORMAT_BIT_LOSSLESS) {
				img = Image::lossless_unpacker(pv);
			} else {
				img = Image::lossy_unpacker(pv);
			}

			if (img.empty()) {
				memdelete(f);
				ERR_FAIL_COND_V(img.empty(), ERR_FILE_CORRUPT);
			}
			total_size += img.get_data().size();

			mipmap_images.push_back(img);
		}

		print_line("mipmap read total: " + itos(mipmap_images.size()));

		memdelete(f); //no longer needed

		if (mipmap_images.size() == 1) {

			image = mipmap_images[0];
			return OK;

		} else {
			PoolVector<uint8_t> img_data;
			img_data.resize(total_size);

			{
				PoolVector<uint8_t>::Write w = img_data.write();

				int ofs = 0;
				for (int i = 0; i < mipmap_images.size(); i++) {

					PoolVector<uint8_t> id = mipmap_images[i].get_data();
					int len = id.size();
					PoolVector<uint8_t>::Read r = id.read();
					copymem(&w[ofs], r.ptr(), len);
					ofs += len;
				}
			}

			image = Image(sw, sh, true, mipmap_images[0].get_format(), img_data);
			return OK;
		}

	} else {
Esempio n. 8
0
bool PackedSourcePCK::try_open_pack(const String& p_path) {

	FileAccess *f = FileAccess::open(p_path,FileAccess::READ);
	if (!f)
		return false;

	uint32_t magic= f->get_32();

	if (magic != 0x4b435047) {
		//maybe at he end.... self contained exe
		f->seek_end();
		f->seek( f->get_pos() -4 );
		magic = f->get_32();
		if (magic != 0x4b435047) {

			memdelete(f);
			return false;
		}
		f->seek( f->get_pos() -12 );


		uint64_t ds = f->get_64();
		f->seek( f->get_pos() -ds-8 );

		magic = f->get_32();
		if (magic != 0x4b435047) {

			memdelete(f);
			return false;
		}

	}

	uint32_t ver_major = f->get_32();
	uint32_t ver_minor = f->get_32();
	uint32_t ver_rev = f->get_32();

	ERR_EXPLAIN("Pack created with a newer version of the engine: "+itos(ver_major)+"."+itos(ver_minor)+"."+itos(ver_rev));
	ERR_FAIL_COND_V( ver_major > VERSION_MAJOR || (ver_major == VERSION_MAJOR && ver_minor > VERSION_MINOR), ERR_INVALID_DATA);

	for(int i=0;i<16;i++) {
		//reserved
		f->get_32();
	}

	int file_count = f->get_32();

	for(int i=0;i<file_count;i++) {

		uint32_t sl = f->get_32();
		CharString cs;
		cs.resize(sl+1);
		f->get_buffer((uint8_t*)cs.ptr(),sl);
		cs[sl]=0;

		String path;
		path.parse_utf8(cs.ptr());

		uint64_t ofs = f->get_64();
		uint64_t size = f->get_64();
		uint8_t md5[16];
		f->get_buffer(md5,16);

		PackedData::get_singleton()->add_path(p_path, path, ofs, size, md5,this);
	};

	return true;
};