/* Miranda IM: the free IM client for Microsoft* Windows* Copyright 2000-2003 Miranda ICQ/IM project, all portions of this codebase are copyrighted to the people listed in contributors.txt. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "commonheaders.h" int CDb3x::FindSectionForOffset(const DWORD ofs) { for (int i = 0; i < CACHESECTIONCOUNT; i++) if (ofs >= cacheSectionInfo[i].ofsBase && ofs= cacheSectionInfo[i].ofsBase && ofs= cacheSectionInfo[i].ofsBase+CACHESECTIONSIZE) //don't finish at end CopyMemory(m_pDbCache+i*CACHESECTIONSIZE,(PBYTE)pData+cacheSectionInfo[i].ofsBase-ofs,CACHESECTIONSIZE); else CopyMemory(m_pDbCache+i*CACHESECTIONSIZE,(PBYTE)pData+cacheSectionInfo[i].ofsBase-ofs,bytes-(cacheSectionInfo[i].ofsBase-ofs)); } else { //start at beginning if (ofs+bytes >= cacheSectionInfo[i].ofsBase+CACHESECTIONSIZE) //don't finish at end CopyMemory(m_pDbCache+i*CACHESECTIONSIZE+ofs-cacheSectionInfo[i].ofsBase,pData,cacheSectionInfo[i].ofsBase+CACHESECTIONSIZE-ofs); else CopyMemory(m_pDbCache+i*CACHESECTIONSIZE+ofs-cacheSectionInfo[i].ofsBase,pData,bytes); } } } } void CDb3x::DBMoveChunk(DWORD ofsDest,DWORD ofsSource,int bytes) { DWORD bytesRead; PBYTE buf; log3("move %d %08x->%08x",bytes,ofsSource,ofsDest); buf = (PBYTE)mir_alloc(bytes); SetFilePointer(m_hDbFile,ofsSource,NULL,FILE_BEGIN); ReadFile(m_hDbFile,buf,bytes,&bytesRead,NULL); DBWrite(ofsDest,buf,bytes); mir_free(buf); logg(); } static VOID CALLBACK DoBufferFlushTimerProc(HWND hwnd,UINT message,UINT_PTR idEvent,DWORD dwTime) { for (int i=0; i < g_Dbs.getCount(); i++) { CDb3x* db = g_Dbs[i]; KillTimer(NULL, db->m_flushBuffersTimerId); log0("tflush1"); FlushFileBuffers(db->getFile()); log0("tflush2"); } } void CDb3x::DBFlush(int setting) { if (!setting) { log0("nflush1"); if (m_safetyMode) FlushFileBuffers(m_hDbFile); log0("nflush2"); return; } KillTimer(NULL,m_flushBuffersTimerId); m_flushBuffersTimerId = SetTimer(NULL,m_flushBuffersTimerId,50,DoBufferFlushTimerProc); } void CDb3x::DBFill(DWORD ofs,int bytes) { } int CDb3x::InitCache(void) { m_pDbCache = (PBYTE)mir_alloc(CACHESECTIONSIZE*CACHESECTIONCOUNT); m_lastUseCounter = CACHESECTIONCOUNT; for(int i = 0; i < CACHESECTIONCOUNT; i++) { cacheSectionInfo[i].ofsBase = 0; cacheSectionInfo[i].lastUsed = i; SetFilePointer(m_hDbFile,cacheSectionInfo[i].ofsBase,NULL,FILE_BEGIN); DWORD bytesRead; ReadFile(m_hDbFile,m_pDbCache+i*CACHESECTIONSIZE,CACHESECTIONSIZE,&bytesRead,NULL); } return 0; }