Exemple #1
0
//将变量保存到文件中
VOID CVariableSystem::SaveVariable(LPCTSTR szFileName, VARIABLE_MAP& mapBuf)
{
	const CHAR* szSystemCfg = "./WXSystem.cfg";
	UINT dwFileAttr = GetFileAttributes(szSystemCfg);

	if(FILE_ATTRIBUTE_READONLY & dwFileAttr)
	{
		SetFileAttributes(szSystemCfg, dwFileAttr&(~FILE_ATTRIBUTE_READONLY));
	}
	VARIABLE_MAP::iterator it;
	for(it=mapBuf.begin(); it!=mapBuf.end(); it++)
	{
		if(it->second.bTemp == FALSE)
		{
			::WritePrivateProfileString("Variable", it->first.c_str(), it->second.vValue.c_str(), szSystemCfg);
		}
	}
	if(FILE_ATTRIBUTE_READONLY & dwFileAttr)
	{
		SetFileAttributes(szSystemCfg, dwFileAttr);
	}

}
Exemple #2
0
//从文件中读取变量
VOID CVariableSystem::LoadVariable(LPCTSTR szFileName, VARIABLE_MAP& mapBuf)
{
	TDAssert(szFileName);
	mapBuf.clear();

	//-----------------------------------------------------------
	//取得配置文件的大小
	HANDLE hFile = CreateFile(szFileName,
							GENERIC_READ,
							FILE_SHARE_READ | FILE_SHARE_WRITE,
							NULL,
							OPEN_EXISTING,
							FILE_ATTRIBUTE_NORMAL,
							NULL);
	
	if(INVALID_HANDLE_VALUE == hFile) return;

	DWORD dwHigh;
	DWORD dwFileSize = GetFileSize(hFile, &dwHigh);
	CloseHandle(hFile); hFile = NULL;
	if(0==dwFileSize) return;

	//-----------------------------------------------------------
	//分配足够的内存
	CHAR* pTempBuf = new CHAR[dwFileSize+32];
	if(!pTempBuf) return;

	//-----------------------------------------------------------
	//从配置文件中读取"Variable"节
	::GetPrivateProfileSection("Variable", pTempBuf, dwFileSize, szFileName);
	//分解
	std::vector< STRING > vRet;
	ConvertSectionInVector(pTempBuf, dwFileSize, vRet);

	delete[] pTempBuf; pTempBuf=NULL;

	//加入变量定义
	for(INT i=0; i<(INT)vRet.size(); i++)
	{
		STRING& strLine = vRet[i];

		STRING::size_type tEqu = strLine.find_first_of("= \t");
		if(tEqu == STRING::npos) continue;

		STRING strName = strLine.substr(0, tEqu);

		CHAR szTemp[1024];
		::GetPrivateProfileString("Variable", strName.c_str(), "", szTemp, 1024, szFileName);

		SetVariable(strName.c_str(), szTemp, FALSE);
	}

	//-----------------------------------------------------------
	//导出函数
	m_pMetaTable = new LuaPlus::LuaObject;
	*m_pMetaTable = CScriptSystem::GetMe()->GetLuaState()->GetGlobals().CreateTable("Variable");
	m_pMetaTable->SetObject("__index", *m_pMetaTable);

	m_pMetaTable->RegisterObjectFunctor("GetVariable", &CVariableSystem::Lua_GetGlobalVariable);
	m_pMetaTable->RegisterObjectFunctor("SetVariable", &CVariableSystem::Lua_SetGlobalVariable);
	m_pMetaTable->RegisterObjectFunctor("SetVariableDelay", &CVariableSystem::Lua_SetGlobalVariableDelay);
	LuaObject obj_Variable = CScriptSystem::GetMe()->GetLuaState()->BoxPointer(this);
	obj_Variable.SetMetaTable(*m_pMetaTable);
	CScriptSystem::GetMe()->GetLuaState()->GetGlobals().SetObject("Variable", obj_Variable);
}
Exemple #3
0
void CVariableSystem::SaveAcountVariables(void)
{
	if(GetAs_Int("GameServer_ConnectDirect") == 1)
		return;
	STRING szAccount,szUser,szGame_Connect;
	VARIABLE_MAP userCfgMap;
	VARIABLE_MAP::const_iterator it = m_mapCurrent.begin();
	for(;it != m_mapCurrent.end();it++)
	{
		STRING key = (*it).first;
		VARIABLE val  = (*it).second;
		userCfgMap[key] = val;
	}
	VARIABLE_MAP::iterator itFind = userCfgMap.find("View_Fanhunjiao");
	if(itFind != userCfgMap.end())
		userCfgMap.erase(userCfgMap.find("View_Fanhunjiao"));

	itFind = userCfgMap.find("View_Aplomb");
	if(itFind != userCfgMap.end())
		userCfgMap.erase(userCfgMap.find("View_Aplomb"));

	itFind = userCfgMap.find("Login_Area");
	if(itFind != userCfgMap.end())
		userCfgMap.erase(userCfgMap.find("Login_Area"));

	itFind = userCfgMap.find("Login_Server");
	if(itFind != userCfgMap.end())
		userCfgMap.erase(userCfgMap.find("Login_Server"));

	itFind = userCfgMap.find("Login_Provider");
	if(itFind != userCfgMap.end())
		userCfgMap.erase(userCfgMap.find("Login_Provider"));

	itFind = userCfgMap.find("View_Resoution");
	if(itFind != userCfgMap.end())
		userCfgMap.erase(userCfgMap.find("View_Resoution"));

	itFind = userCfgMap.find("View_PiFeng");
	if(itFind != userCfgMap.end())
		userCfgMap.erase(userCfgMap.find("View_PiFeng"));

	itFind = userCfgMap.find("View_FullScreen");
	if(itFind != userCfgMap.end())
		userCfgMap.erase(userCfgMap.find("View_FullScreen"));

	itFind = userCfgMap.find("View_MaxWindow");
	if(itFind != userCfgMap.end())
		userCfgMap.erase(userCfgMap.find("View_MaxWindow"));

	GetVariable("Game_Account",szAccount);
	GetVariable("Character_Name",szUser);
	if(szAccount.empty() || szUser.empty()) return;

	char szFullPath[MAX_PATH] = {0};

	STRING szAccEncrypt;
	StringEncrypt( szAccount, szAccEncrypt ); //加密帐号名
	_snprintf(szFullPath, MAX_PATH, "..\\Accounts\\%s", szAccEncrypt.c_str());
	//_snprintf(szFullPath, MAX_PATH, "..\\Accounts\\%s", szAccount.c_str());
	::CreateDirectory(szFullPath, NULL);

	char szFullFileName[MAX_PATH] = {0};
	STRING szUserEncrypt;
	StringEncrypt( szUser, szUserEncrypt ); //加密帐号名
	_snprintf(szFullFileName, MAX_PATH, "%s\\%s.pfc", szFullPath, szUserEncrypt.c_str());
	//_snprintf(szFullFileName, MAX_PATH, "%s\\%s.pfc", 
	//	szFullPath, szUser.c_str());
	::DeleteFile(szFullFileName);
	SaveVariable(szFullFileName, userCfgMap);
}