📄 fdb.cpp
字号:
#include <io.h>
#include <stdio.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <errno.h>
#include "StdInc.h"
#include "FDB.h"
CFDB::CFDB()
{
m_wSize = sizeof(ACCOUNT_CHAR_INFO);
}
CFDB::~CFDB()
{
}
void CFDB::GetAccountPath(char *pszAccName, char *pszPath)
{
int n = 0, len = strlen(pszAccName);
int i = -1;
while(++i < len)
{
n += (BYTE)pszAccName[i] * (BYTE)pszAccName[i];
}
n = n % HASH_VALUE;
wsprintf (pszPath, "%s\\%03d\\%s", ACCOUNT_ROOT_PATH, n, pszAccName);
}
BOOL CFDB::LoadAccCharInfo(char * pszAccName)
{
char szFilePath[64];
GetAccountPath(pszAccName, szFilePath);
int fd, n;
if ((fd = _open(szFilePath, _O_RDONLY | _O_BINARY)) < 0) return FALSE;
n = _read(fd, &m_AccountCharInfo, m_wSize);
_close(fd);
if (n < m_wSize) return FALSE;
return TRUE;
}
BOOL CFDB::LoadAccInfo(char * pszAccName, ACCOUNT_CHAR_INFO * pInfo)
{
char szFilePath[64];
GetAccountPath(pszAccName, szFilePath);
int fd, n;
if ((fd = _open(szFilePath, _O_RDONLY | _O_BINARY)) < 0)
{
if(errno == ENOENT)
{
// 货肺款 颇老 父甸扁
if ((fd = _open(szFilePath, _O_WRONLY | _O_TRUNC | _O_CREAT | _O_BINARY, _S_IREAD | _S_IWRITE)) < 0) return FALSE;
ACCOUNT_CHAR_INFO tmpACInfo;
ZeroMemory(&tmpACInfo, sizeof(ACCOUNT_CHAR_INFO));
for (int i=0; i < MAX_CHARACTER; i++)
{
tmpACInfo.CharInfo[i].byType = 0xff;
}
n = _write(fd, &tmpACInfo, sizeof(ACCOUNT_CHAR_INFO));
_close(fd);
if (n < m_wSize)
{
_close(fd);
return FALSE;
}
if ((fd = _open(szFilePath, _O_RDONLY | _O_BINARY)) < 0) return FALSE;
}
else
{
return FALSE;
}
}
n = _read(fd, pInfo, m_wSize);
_close(fd);
if (n < m_wSize) return FALSE;
return TRUE;
}
BOOL CFDB::SaveAccCharInfo(char * pszAccName)
{
char szFilePath[64];
GetAccountPath(pszAccName, szFilePath);
int fd, n;
if ((fd = _open(szFilePath, _O_WRONLY | _O_TRUNC | _O_CREAT | _O_BINARY, _S_IREAD | _S_IWRITE)) < 0) return FALSE;
n = _write(fd, &m_AccountCharInfo, m_wSize);
_close(fd);
if (n < m_wSize) return FALSE;
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -