Esempio n. 1
0
 ~C_file_write(){
    if(hnd){
                            //flushing must be done before without error
       if(WriteFlush()){
          //Fatal("Write error");
          LOG_RUN("C_file::WriteFlush error");
       }
       win::CloseHandle(hnd);
    }
 }
Esempio n. 2
0
// Close the stream, cleans up.
CNCSError CNCSJPCFileIOStream::Close()
{
	WriteFlush();
	*(CNCSError*)this = NCSFileClose(m_hFile);
	m_hFile = NCS_NULL_FILE_HANDLE;
	*(CNCSError*)this = CNCSJPCIOStream::Close();

	NCSFree(m_pIOCache);
	m_pIOCache = NULL;
	m_nIOWriteCache = 0;
	m_iIOReadCache = 0;

	return(*(CNCSError*)this);
}
Esempio n. 3
0
   virtual C_file::E_WRITE_STATUS Write(const void *mem, dword len){

                              //put into cache
      while(curr_pos+len > CACHE_SIZE){
         dword sz = CACHE_SIZE - curr_pos;
         MemCpy(cache+curr_pos, mem, sz);
         curr_pos += sz;
         (byte*&)mem += sz;
         len -= sz;
         C_file::E_WRITE_STATUS ws = WriteFlush();
         if(ws)
            return ws;
      }
      MemCpy(cache+curr_pos, mem, len);
      curr_pos += len;
      return C_file::WRITE_OK;
   }
Esempio n. 4
0
// Write some data to the stream
bool CNCSJPCFileIOStream::Write(void* buffer, UINT32 count)
{
	if(count + m_nIOWriteCache > m_nMaxIOCache) {
		WriteFlush();
	}
	if(count >= m_nMaxIOCache) {
		// Single write too big for cache, write straight out.
		NCSError eError = NCSFileWrite(m_hFile, buffer, count, &count);
		if(eError == NCS_SUCCESS) {
			m_nOffset += count;
			m_nFileSize = NCSMax(m_nFileSize, m_nOffset);
			return(true);
		}
		*(CNCSError*)this = eError;
		return(false);
	} else {
		// Copy to cache
		memcpy(m_pIOCache + m_nIOWriteCache, buffer, count);
		m_nIOWriteCache += count;
		return(true);
	}
}
Esempio n. 5
0
// Seek the stream to the specified offset, from the specified origin
bool CNCSJPCFileIOStream::Seek(INT64 offset, CNCSJPCIOStream::Origin origin)
{
	if(offset == 0 && origin == CURRENT) {
		return(Seek());
	}
	if(origin == START && m_nOffset == offset) {
		return(Seek());
	}
	
	WriteFlush();
	ReadFlush();

	if(origin == START) {
		m_nOffset = offset;
	} else if(origin == CURRENT) {
		m_nOffset += offset;
	} else {
		m_nOffset = NCSFileTellNative(m_hFile);
	}
	if(m_bWrite) {
		m_nFileSize = NCSMax(m_nFileSize, m_nOffset);
	}
#ifdef NCSJPC_USE_IO_BUFFER
	if(NCSFileSeekNative(m_hFile, m_nOffset, START) == -1) {
		*(CNCSError*)this = NCS_FILEIO_ERROR;
		m_nOffset = -1;
	} else {
		*(CNCSError*)this = NCS_SUCCESS;
	}
#else
	if(NCSFileSeekNative(m_hFile, offset, origin) == -1) {
		*(CNCSError*)this = NCS_FILEIO_ERROR;
		m_nOffset = -1;
	} else {
		*(CNCSError*)this = NCS_SUCCESS;
	}
#endif
	return(GetErrorNumber() == NCS_SUCCESS ? true : false);
}
Esempio n. 6
0
INT64 CNCSJPCFileIOStream::Tell()
{
	WriteFlush();
	return(CNCSJPCIOStream::Tell());
}
Esempio n. 7
0
 virtual bool SetPos(dword pos){
    WriteFlush();
    win::SetFilePointer(hnd, pos, NULL, FILE_BEGIN);
    return true;
 }