102 lines
2.4 KiB
C++
102 lines
2.4 KiB
C++
#include "stdafx.h"
|
|
#include "SLocalCommandDB.h"
|
|
#include <Windows.h>
|
|
#include <kfile/KStream.h>
|
|
#include "KResourceManager.h"
|
|
#include <kfile/KFileManager.h>
|
|
|
|
SLocalCommandDB* SLocalCommandDB::m_pThis = NULL;
|
|
SLocalCommandDB& GetLocalCommandDB()
|
|
{
|
|
if( NULL == SLocalCommandDB::m_pThis )
|
|
SLocalCommandDB::m_pThis = new SLocalCommandDB;
|
|
|
|
return *SLocalCommandDB::m_pThis;
|
|
// static SLocalCommandDB db;
|
|
// return db;
|
|
}
|
|
|
|
SLocalCommandDB::SLocalCommandDB()
|
|
{
|
|
Load();
|
|
}
|
|
|
|
void SLocalCommandDB::Parse( const char* pContents, size_t sz )
|
|
{
|
|
const char* p = pContents;
|
|
std::string strKey;
|
|
std::string strCommand;
|
|
while ( p < pContents + sz )
|
|
{
|
|
strKey.clear();
|
|
while ( (p < pContents + sz) && (*p != ' ') && (*p != '\t') )
|
|
strKey += *p++;
|
|
while ( (p < pContents + sz) && ((*p == ' ') || (*p == '\t')) )
|
|
++p;
|
|
strCommand.clear();
|
|
while ( (p < pContents + sz) && (*p != '\r') && (*p != '\n'))
|
|
strCommand += *p++;
|
|
while ( (p < pContents + sz) && ((*p == '\r') || (*p == '\n')) )
|
|
++p;
|
|
|
|
m_mapLocalCommand.insert( mapCommand::value_type( strKey, strCommand ) );
|
|
}
|
|
}
|
|
|
|
void SLocalCommandDB::Load()
|
|
{
|
|
std::string strResourceFileName = "db_LocalCommand.rdb";
|
|
|
|
KStream * pRes = KFileManager::Instance().CreateStreamFromResource( strResourceFileName.c_str() );
|
|
if( !pRes )
|
|
return;
|
|
|
|
size_t sz = pRes->Size();
|
|
char* buf;
|
|
buf = new char[ sz ];
|
|
pRes->Read( buf, sz );
|
|
|
|
KFileManager::Instance().DeleteStream( pRes );
|
|
|
|
Parse( buf, sz );
|
|
delete [] buf;
|
|
|
|
HANDLE hFile = CreateFile( "Command.txt", GENERIC_READ , FILE_SHARE_READ , NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
|
|
if ( hFile == INVALID_HANDLE_VALUE )
|
|
return;
|
|
|
|
DWORD dwRead;
|
|
sz = (size_t)GetFileSize( hFile, NULL );
|
|
buf = new char[ sz ];
|
|
ReadFile( hFile, buf, sz, &dwRead, NULL );
|
|
CloseHandle( hFile );
|
|
|
|
Parse( buf, sz );
|
|
delete [] buf;
|
|
}
|
|
|
|
|
|
std::string SLocalCommandDB::Convert( const char* szCommand ) const
|
|
{
|
|
// sonador #2.3.1.1 파티 랜덤 분배 방식 오류 수정
|
|
std::string strToken;
|
|
const char* p = szCommand;
|
|
|
|
while ( *p == '/' && *p != NULL )
|
|
++p;
|
|
|
|
while ( *p != NULL && *p != ' ' && *p != '\t' )
|
|
strToken += *p++;
|
|
|
|
cimapCommand itor = m_mapLocalCommand.find( strToken );
|
|
if ( itor != m_mapLocalCommand.end() )
|
|
{
|
|
std::string strConverted = szCommand;
|
|
|
|
int n = strConverted.find( strToken );
|
|
strConverted.replace( n, strToken.size(), itor->second );
|
|
return strConverted;
|
|
}
|
|
else
|
|
return std::string( szCommand );
|
|
} |