📄 buffermgr.h
字号:
/*
* Openmysee
*
* 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
*
*/
#ifndef __BUFFERMGR_H_
#define __BUFFERMGR_H_
#include "BaseResource.h"
namespace NPLayer1 {
class BufferMgr {
public:
// 构造函数
BufferMgr();
// 析构函数
~BufferMgr();
// 是否已经初始化
bool HasInited() {return (blockArray != NULL);};
// 取得缓冲文件的大小
UINT GetBufferFileSize() { return bufferFileSize; };
// 取得缓冲文件名
string GetBufferFileName() { return bufferFileName; };
// 初始化缓冲文件,只能调用一次
P2P_RETURN_TYPE Init(string fullPath, bool& bufFileModified, UINT randNum, UINT bufferSize = BUFFER_SPACE);
// 取得一个未使用的块, 并将其置为已使用
UINT GetEmptyIndex(UINT randNum);
// 将一个块置为未使用
void EraseIndex(UINT index);
// 获取剩余空间大小
UINT GetEmptySpace();
// 取得一个块的数据
P2P_RETURN_TYPE GetIndexData(UINT index, UINT offset, LPVOID data, UINT size);
// 填充一个块
P2P_RETURN_TYPE PutIndexData(UINT index, LPVOID data, UINT size);
public:
static BOOL ExCreateFile(HANDLE&, LPCTSTR lpFileName, DWORD dwDesiredAccess,
DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes,
DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes,
HANDLE hTemplateFile);
static BOOL ExCreateFile(HANDLE&, LPCTSTR lpFileName, DWORD dwCreationDisposition);
static UINT ExReadFile(HANDLE, LPVOID buf, UINT toBeRead);
static UINT ExWriteFile(HANDLE, LPCVOID buf, UINT toBeWrite);
static BOOL ExSetFilePointer(HANDLE, UINT offset);
static BOOL ExSetFileSize(HANDLE, UINT size);
static BOOL GetSelfModulePath(LPTSTR buf, DWORD nSize);
private:
enum {
// 默认缓冲文件大小24MB
BUFFER_SPACE = 1048576*24,
};
// 缓冲文件的句柄
HANDLE hBufferFile;
// 缓冲文件名
string bufferFileName;
// 缓冲文件大小
UINT bufferFileSize;
// 记录缓冲文件的使用情况,按分块
bool* blockArray;
// 缓冲文件的分块个数
UINT blockNum;
};
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -