示例#1
0
int
OggSoundFile::cb_seek(void* source, ogg_int64_t offset, int whence)
{
  PHYSFS_file* file = reinterpret_cast<PHYSFS_file*> (source);

  switch(whence) {
    case SEEK_SET:
      if(PHYSFS_seek(file, static_cast<PHYSFS_uint64> (offset)) == 0)
        return -1;
      break;
    case SEEK_CUR:
      if(PHYSFS_seek(file, PHYSFS_tell(file) + offset) == 0)
        return -1;
      break;
    case SEEK_END:
      if(PHYSFS_seek(file, PHYSFS_fileLength(file) + offset) == 0)
        return -1;
      break;
    default:
#ifdef DEBUG
      assert(false);
#else
      return -1;
#endif
  }
  return 0;
}
示例#2
0
int OSBasics::seek(OSFILE * stream, long int offset, int origin ) {
	switch(stream->fileType) {
		case OSFILE::TYPE_FILE:
			return fseek(stream->file, offset, origin);
			break;
		case OSFILE::TYPE_ARCHIVE_FILE:
			switch(origin) {
				case SEEK_SET:
					return PHYSFS_seek(stream->physFSFile, offset);
				break;
				case SEEK_CUR: {
					PHYSFS_sint64 curoffset = PHYSFS_tell(stream->physFSFile);					
					return PHYSFS_seek(stream->physFSFile, curoffset+offset);				
				}
				break;
				case SEEK_END: {
					PHYSFS_sint64 fileLength =  PHYSFS_fileLength(stream->physFSFile);
					return PHYSFS_seek(stream->physFSFile, fileLength-offset);
				}
				break;
			}
			break;			
	}
	return 0;	
}
示例#3
0
        bool FileReadObject::seek(long finalPos, bool relativeMovement)
        {
            if (relativeMovement)
                finalPos += PHYSFS_tell(mFileHandle);

            return PHYSFS_seek(mFileHandle, finalPos);
        }
示例#4
0
文件: physFile.cpp 项目: icedman/lov8
	int File::tell()
	{
		if(file == 0)
			return -1;

		return (int)PHYSFS_tell(file);
	}
示例#5
0
bool
vsFile::PeekRecord( vsRecord *r )
{
	vsAssert(r != NULL, "Called vsFile::Record with a NULL vsRecord!");

	if ( m_mode == MODE_Write )
	{
		vsAssert( m_mode != MODE_Write, "Error:  Not legal to PeekRecord() when writing a file!" );
		return false;
	}
	else
	{
		bool succeeded = false;
		vsString line;

		r->Init();

		PHYSFS_sint64 filePos = PHYSFS_tell(m_file);
		if ( r->Parse(this) )
			succeeded = true;

		PHYSFS_seek(m_file, filePos);

		return succeeded;
	}

	return false;
}
示例#6
0
uint FileStream::tell()
{
    if(!m_caching)
        return PHYSFS_tell(m_fileHandle);
    else
        return m_pos;
}
size_t
WavSoundFile::read(void* buffer, size_t buffer_size)
{
  PHYSFS_sint64 end = datastart + size;
  PHYSFS_sint64 cur = PHYSFS_tell(file);
  if(cur >= end)
    return 0;

  size_t readsize = std::min(static_cast<size_t> (end - cur), buffer_size);
  if(PHYSFS_read(file, buffer, readsize, 1) != 1)
    throw SoundError("read error while reading samples");

#ifdef WORDS_BIGENDIAN
  if (bits_per_sample != 16)
    return readsize;
  char *tmp = (char*)buffer;

  size_t i;
  char c;
  for (i = 0; i < readsize / 2; i++)
  {
    c          = tmp[2*i];
    tmp[2*i]   = tmp[2*i+1];
    tmp[2*i+1] = c;
  }

  buffer = tmp;
#endif

  return readsize;
}
示例#8
0
bool physfsFile::prepareRead() {
	PHYSFS_uint64 pos = PHYSFS_tell(fhandle);
	PHYSFS_close(fhandle);
	fhandle = PHYSFS_openRead(pname);
	PHYSFS_seek(fhandle, pos);
	//LOG_MSG("Goto read (%s at %i)",pname,PHYSFS_tell(fhandle));
    return true;
}
示例#9
0
bool
vsFile::PeekLine( vsString *line )
{
	PHYSFS_sint64 filePos = PHYSFS_tell(m_file);
	bool result = ReadLine(line);
	PHYSFS_seek(m_file, filePos);
	return result;
}
示例#10
0
int PHYSFS_fixedEof(PHYSFS_File *handle) {
    if((PHYSFS_eof(handle)) ||
       (PHYSFS_fileLength(handle) == PHYSFS_tell(handle))) {
        return 1;
    }

    return 0;
}
示例#11
0
static void PhysFSSkip( void* user, int offset )
{
    PHYSFS_File* file = (PHYSFS_File*)user;
    const int currentPosition = PHYSFS_tell(file);
    assert(currentPosition >= 0);
    const int newPosition = currentPosition + offset;
    const int success = PHYSFS_seek(file, newPosition);
    assert(success);
}
示例#12
0
static int wz_oggVorbis_seek(void *datasource, ogg_int64_t offset, int whence)
{
	PHYSFS_file* fileHandle;
	BOOL allowSeeking;
	int newPos;

	ASSERT(datasource != NULL, "NULL decoder passed!");

	fileHandle = ((struct OggVorbisDecoderState*)datasource)->fileHandle;
	ASSERT(fileHandle != NULL, "Bad PhysicsFS file handle passed in");

	allowSeeking = ((struct OggVorbisDecoderState*)datasource)->allowSeeking;

	if (!allowSeeking)
		return -1;

	switch (whence)
	{
		// Seek to absolute position
		case SEEK_SET:
			newPos = offset;
			break;

		// Seek `offset` ahead
		case SEEK_CUR:
		{
			int curPos = PHYSFS_tell(fileHandle);
			if (curPos == -1)
				return -1;

			newPos = curPos + offset;
			break;
		}

		// Seek backwards from the end of the file
		case SEEK_END:
		{
			int fileSize = PHYSFS_fileLength(fileHandle);
			if (fileSize == -1)
				return -1;

			newPos = fileSize - 1 - offset;
			break;
		}

		// unrecognized seek instruction
		default:
			// indicate failure
			return -1;
	}

	// PHYSFS_seek return value of non-zero means success
	if (PHYSFS_seek(fileHandle, newPos) != 0)
		return newPos;   // success
	else
		return -1;  // failure
}
示例#13
0
	pos_type seekpos(pos_type pos, std::ios_base::openmode mode) {
		PHYSFS_seek(file, pos);
		if (mode & std::ios_base::in) {
			setg(egptr(), egptr(), egptr());
		}
		if (mode & std::ios_base::out) {
			setp(buffer, buffer);
		}
		return PHYSFS_tell(file);
	}
示例#14
0
uint32_t File::tell() const
{
	check_file_open();

	PHYSFS_sint64 tp = PHYSFS_tell( reinterpret_cast<PHYSFS_file*> (mHandle) );

	if(tp == -1)
		BOOST_THROW_EXCEPTION( PhysfsFileException(mFileName) );

	return tp;
}
示例#15
0
long OSBasics::tell(OSFILE * stream) {
	switch(stream->fileType) {
		case OSFILE::TYPE_FILE:
			return ftell(stream->file);
			break;
		case OSFILE::TYPE_ARCHIVE_FILE:
			return PHYSFS_tell(stream->physFSFile);
			break;			
	}
	return 0;
}
示例#16
0
static long wz_oggVorbis_tell(void *datasource)
{
	PHYSFS_file* fileHandle;

	ASSERT(datasource != NULL, "NULL decoder passed!");

	fileHandle = ((struct OggVorbisDecoderState*)datasource)->fileHandle;
	ASSERT(fileHandle != NULL, "Bad PhysicsFS file handle passed in");

	return PHYSFS_tell(fileHandle);
}
示例#17
0
std::size_t File::CurrentPosition() const
{
   PHYSFS_sint64 position = PHYSFS_tell(impl->physfsFileHandle);

   if (position == -1)
   {
      throw Exception(std::string("Could not obtain current position of file ") + mountedFilePath.path + "\n" + PHYSFS_getLastError());
   }

   return LossyCast<std::size_t, PHYSFS_sint64>(position);
}
示例#18
0
	pos_type seekoff(off_type pos, ios_base::seekdir dir, ios_base::openmode mode) {
		switch (dir) {
		case std::ios_base::beg:
			PHYSFS_seek(file, pos);
			break;
		case std::ios_base::cur:
			// subtract characters currently in buffer from seek position
			PHYSFS_seek(file, (PHYSFS_tell(file) + pos) - (egptr() - gptr()));
			break;
		case std::ios_base::end:
			PHYSFS_seek(file, PHYSFS_fileLength(file) + pos);
			break;
		}
		if (mode & std::ios_base::in) {
			setg(egptr(), egptr(), egptr());
		}
		if (mode & std::ios_base::out) {
			setp(buffer, buffer);
		}
		return PHYSFS_tell(file);
	}
示例#19
0
bool physfsFile::Seek(Bit32u * pos,Bit32u type) {
	PHYSFS_sint64 mypos = (Bit32s)*pos;
	switch (type) {
	case DOS_SEEK_SET:break;
	case DOS_SEEK_CUR:mypos += PHYSFS_tell(fhandle); break;
	case DOS_SEEK_END:mypos += PHYSFS_fileLength(fhandle); break;
	default:
	//TODO Give some doserrorcode;
		return false;//ERROR
	}

	if (!PHYSFS_seek(fhandle,mypos)) {
		// Out of file range, pretend everythings ok 
		// and move file pointer top end of file... ?! (Black Thorne)
		PHYSFS_seek(fhandle,PHYSFS_fileLength(fhandle));
	};
	//LOG_MSG("Seek to %i (%i at %x) of %s (%s)",(int)mypos,(int)*pos,type,name,PHYSFS_getLastError());

	*pos=(Bit32u)PHYSFS_tell(fhandle);
	return true;
}
static int64_t file_phys_ftell(ALLEGRO_FILE *f)
{
   ALLEGRO_FILE_PHYSFS *fp = cast_stream(f);
   PHYSFS_sint64 n;

   n = PHYSFS_tell(fp->phys);
   if (n < 0) {
      phys_set_errno(fp);
      return -1;
   }

   return n;
}
示例#21
0
bool physfsFile::Write(Bit8u * data,Bit16u * size) {
	if ((this->flags & 0xf) == OPEN_READ) { // check if file opened in read-only mode
		DOS_SetError(DOSERR_ACCESS_DENIED);
		return false;
	}
	if (last_action==READ) prepareWrite();
	last_action=WRITE;
	if (*size==0) {
		if (PHYSFS_tell(fhandle) == 0) {
			PHYSFS_close(PHYSFS_openWrite(pname));
            return false;
			//LOG_MSG("Truncate %s (%s)",name,PHYSFS_getLastError());
		} else {
			LOG_MSG("PHYSFS TODO: truncate not yet implemented (%s at %lld)",pname,PHYSFS_tell(fhandle));
			return false;
		}
	} else {
		PHYSFS_sint64 mysize = PHYSFS_write(fhandle,data,1,(PHYSFS_uint32)*size);
		//LOG_MSG("Wrote %i bytes (wanted %i) at %i of %s (%s)",(int)mysize,(int)*size,(int)PHYSFS_tell(fhandle),name,PHYSFS_getLastError());
		*size = (Bit16u)mysize;
		return true;
	}
}
示例#22
0
static Sint64 physfsrwops_seek(SDL_RWops *rw, Sint64 offset, int whence)
{
    PHYSFS_file *handle = (PHYSFS_file *) rw->hidden.unknown.data1;
    int pos = 0;

    if (whence == SEEK_SET)
    {
        pos = offset;
    }
    else if (whence == SEEK_CUR)
    {
        int current = PHYSFS_tell(handle);
        if (current == -1)
        {
            SDL_SetError("Can't find position in file: %s",
                          PHYSFS_getLastError());
            return(-1);
        }

        if (offset == 0)  // this is a "tell" call. We're done.
            return( current );

        pos = current + offset;
    }
    else if (whence == SEEK_END)
    {
        int len = PHYSFS_fileLength(handle);
        if (len == -1)
        {
            SDL_SetError("Can't find end of file: %s", PHYSFS_getLastError());
            return(-1);
        }

        pos = len + offset;
    }
    else
    {
        SDL_SetError("Invalid 'whence' parameter.");
        return(-1);
    }

    if (!PHYSFS_seek(handle, pos))
    {
        SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError());
        return(-1);
    }

    return(pos);
}
示例#23
0
bool
vsFile::ReadLine( vsString *line )
{
	// const int c_bufSize = 1024;
	// char buf[c_bufSize];

	PHYSFS_sint64 filePos = PHYSFS_tell(m_file);
	char peekChar = 'a';
	bool done = false;

	while ( !done && !AtEnd() && peekChar != '\n' && peekChar != 0 )
	{
		if ( PHYSFS_read(m_file, &peekChar, 1, 1) <= 0 )
			done = true;
	}
	PHYSFS_sint64 afterFilePos = PHYSFS_tell(m_file);
	PHYSFS_uint32 bytes = PHYSFS_uint32(afterFilePos - filePos);
	PHYSFS_seek(m_file, filePos);
	if ( bytes > 0 )
	{
		char* buffer = (char*)malloc(bytes+1);
		PHYSFS_uint32 bytesRead = PHYSFS_read(m_file, buffer, 1, bytes);
		vsAssert(bytesRead == bytes, "Didn't read as many bytes as we expected?");
		buffer[bytes-1] = 0;

		*line = buffer;
		while (line->find('\r') != vsString::npos)
		{
			line->erase( line->find('\r') );
		}
		free(buffer);

		return true;
	}
	return false;
}
示例#24
0
文件: file.cpp 项目: Maka7879/Epiar
/**Gets the current offset from the beginning of the file.
 * \return Offset in bytes from the beginning of the file.*/
long File::Tell( void ){
	long offset;
	offset = static_cast<long>(
#ifdef USE_PHYSICSFS
		PHYSFS_tell( fp )
#else
		ftell(fp)
#endif
		);
	if ( offset == -1 ){
		LogMsg(ERR,"%s: Error using file tell. %s",
			validName.c_str(), PHYSFS_getLastError());
	}
	return offset;
}
示例#25
0
/*
 * PhysicsFS::File#tell
 *
 * tells current position in file
 */
VALUE physfs_file_tell (VALUE self)
{
    int result;
    PHYSFS_File *file;

    Data_Get_Struct (self, PHYSFS_File, file);
    if (file == 0)
	return Qnil;

    result = PHYSFS_tell (file);

    if (result == -1)
        return Qnil;

    return INT2FIX(result);
}    
示例#26
0
static off_t file_seek(stream_t *stream, off_t pos, int whence)
{
  PHYSFS_sint64 new_pos;
  PHYSFS_File *file;

  if (file_check_context(stream))
    return -1;

  file = stream->context.pfs.file;
  new_pos = PHYSFS_tell(file);

  if (new_pos == -1) {
    s_log_error("Error getting file position: %s. (File: %s)",
      pfs_get_error(), stream->context.pfs.file_path);

    stream->error = STREAM_ERROR_FAILURE;

    return -1;
  }

  if (pos == 0 && whence == SEEK_CUR)
    return new_pos;

  switch (whence) {
    case SEEK_CUR:
      new_pos += pos;
      break;
    case SEEK_SET:
      new_pos = pos;
      break;
    case SEEK_END:
      new_pos = PHYSFS_fileLength(file) + pos;
      break;
  }

  if ( ! PHYSFS_seek(file, new_pos)) {
    s_log_error("Error seeking in file: %s. (File: %s)",
      pfs_get_error(), stream->context.pfs.file_path);

    stream->error = STREAM_ERROR_FAILURE;

    return -1;
  }

  return new_pos;
}
示例#27
0
bool physfsFile::prepareWrite() {
	const char *wdir = PHYSFS_getWriteDir();
	if (wdir == NULL) {
		LOG_MSG("PHYSFS could not fulfill write request: no write directory set.");
		return false;
	}
	//LOG_MSG("Goto write (%s at %i)",pname,PHYSFS_tell(fhandle));
	const char *fdir = PHYSFS_getRealDir(pname);
	PHYSFS_uint64 pos = PHYSFS_tell(fhandle);
	char *slash = strrchr(pname,'/');
	if (slash && slash != pname) {
		*slash = 0;
		PHYSFS_mkdir(pname);
		*slash = '/';
	}
	if (strcmp(fdir,wdir)) { /* we need COW */
		//LOG_MSG("COW",pname,PHYSFS_tell(fhandle));
		PHYSFS_file *whandle = PHYSFS_openWrite(pname);
		if (whandle == NULL) {
			LOG_MSG("PHYSFS copy-on-write failed: %s.",PHYSFS_getLastError());
			return false;
		}
		char buffer[65536];
		PHYSFS_sint64 size;
		PHYSFS_seek(fhandle, 0);
		while ((size = PHYSFS_read(fhandle,buffer,1,65536)) > 0) {
			if (PHYSFS_write(whandle,buffer,1,(PHYSFS_uint32)size) != size) {
				LOG_MSG("PHYSFS copy-on-write failed: %s.",PHYSFS_getLastError());
				PHYSFS_close(whandle);
				return false;
			}
		}
		PHYSFS_seek(whandle, pos);
		PHYSFS_close(fhandle);
		fhandle = whandle;
	} else { // megayuck - physfs on posix platforms uses O_APPEND. We illegally access the fd directly and clear that flag.
		//LOG_MSG("noCOW",pname,PHYSFS_tell(fhandle));
		PHYSFS_close(fhandle);
		fhandle = PHYSFS_openAppend(pname);
#ifndef WIN32
		fcntl(**(int**)fhandle->opaque,F_SETFL,0);
#endif
		PHYSFS_seek(fhandle, pos);
	}
	return true;
}
示例#28
0
void FileStream::cache()
{
    m_caching = true;

    if(!m_writeable) {
        if(!m_fileHandle)
            return;

        // cache entire file into data buffer
        m_pos = PHYSFS_tell(m_fileHandle);
        PHYSFS_seek(m_fileHandle, 0);
        int size = PHYSFS_fileLength(m_fileHandle);
        m_data.resize(size);
        if(PHYSFS_read(m_fileHandle, m_data.data(), size, 1) == -1)
            throwError("unable to read file data", true);
        PHYSFS_close(m_fileHandle);
        m_fileHandle = nullptr;
    }
}
示例#29
0
std::streampos CInputStreamBuffer::seekoff(std::streamoff off, std::ios_base::seekdir way, std::ios_base::openmode which)
{
    /* A bit of explanation:
       We are reading file by m_bufferSize parts so our 3 internal pointers will be
       * eback (not used here) - start of block
       * gptr - position of read cursor in block
       * egtpr - end of block
       off argument is relative to way */

    std::streamoff new_position{};

    switch (way)
    {
        case std::ios_base::beg:
            new_position = off;
            break;

        case std::ios_base::cur:
            // tell will give cursor at begining of block so we have to add where in block we currently are
            new_position = off + static_cast<off_type>(PHYSFS_tell(m_file)) - static_cast<off_type> (egptr() - gptr());
            break;

        case std::ios_base::end:
            new_position = off + static_cast<off_type>(PHYSFS_fileLength(m_file));
            break;

        default:
            break;
    }

    if (PHYSFS_seek(m_file, new_position))
    {
        setg(m_buffer.get(), m_buffer.get(), m_buffer.get()); // reset buffer

        return pos_type(new_position);
    }

    return pos_type(off_type(-1));
}
static bool file_phys_seek(ALLEGRO_FILE *f, int64_t offset, int whence)
{
   ALLEGRO_FILE_PHYSFS *fp = cast_stream(f);
   PHYSFS_sint64 base;

   switch (whence) {
      case ALLEGRO_SEEK_SET:
         base = 0;
         break;

      case ALLEGRO_SEEK_CUR:
         base = PHYSFS_tell(fp->phys);
         if (base < 0) {
            phys_set_errno(fp);
            return false;
         }
         break;

      case ALLEGRO_SEEK_END:
         base = PHYSFS_fileLength(fp->phys);
         if (base < 0) {
            phys_set_errno(fp);
            return false;
         }
         break;

      default:
         al_set_errno(EINVAL);
         return false;
   }

   if (!PHYSFS_seek(fp->phys, base + offset)) {
      phys_set_errno(fp);
      return false;
   }
   
   return true;
}