Ejemplo n.º 1
0
void CChat::GenerateChatName(CSString &sName, const CClient * pClient) // static
{
	if (pClient == nullptr)
		return;

	// decide upon 'base' name
	lpctstr pszName = nullptr;
	if (pClient->GetChar() != nullptr)
		pszName = pClient->GetChar()->GetName();
	else if (pClient->GetAccount() != nullptr)
		pszName = pClient->GetAccount()->GetName();

	if (pszName == nullptr)
		return;

	// try the base name
	CSString sTempName(pszName);
	if (g_Accounts.Account_FindChat(sTempName.GetPtr()) != nullptr)
	{
		sTempName.Empty();

		// append (n) to the name to make it unique
		for (uint attempts = 2; attempts <= g_Accounts.Account_GetCount(); attempts++)
		{
			sTempName.Format("%s (%u)", pszName, attempts);
			if (g_Accounts.Account_FindChat(static_cast<lpctstr>(sTempName)) == nullptr)
				break;

			sTempName.Empty();
		}
	}

	// copy name to output
	sName.Copy(sTempName.GetPtr());
}
Ejemplo n.º 2
0
bool SplitFilenameString_Priv (const char* pFilename, const size_t Length, CSString& Path, CSString& BaseFilename, CSString& Extension)
{
	const char* pParse = pFilename;
	int Index = Length - 1;
	int ExtensionIndex;
	
	Extension.Empty();
	BaseFilename.Empty();
	Path.Empty();

	if (Length == 0) return true;

	while (Index >= 0)
	{
		if (pParse[Index] == '.')
		{
			Extension = pParse + Index + 1;
			ExtensionIndex = Index;
			break;
		}
		else if (pParse[Index] == '\\' || pParse[Index] == '/' || pParse[Index] == ':')
		{
			ExtensionIndex = Length;
			Extension.Empty();
			break;
		}

		--Index;
	}

	while (Index >= 0)
	{
		if (pParse[Index] == '\\' || pParse[Index] == '/' || pParse[Index] == ':')
		{
			BaseFilename = pParse + Index + 1;
			BaseFilename.Truncate(ExtensionIndex - Index - 1);
			Path.Copy(pFilename, Index + 1);
			return true;
		}

		--Index;
	}

	BaseFilename.Copy(pFilename, ExtensionIndex - Index - 1);
	return true;
}
Ejemplo n.º 3
0
bool SrFindSubDataPath (const char* pFilename, CSString& OutputPath, CSString& OutputFilename, CSString& OutputExtension)
{
	CSString Path;
	int      Index;

	SplitFilenameString(pFilename, Path, OutputFilename, OutputExtension);

	Index = Path.FindRI("\\data\\");

	if (Index >= 0)
		++Index;
	else if (Index < 0 && Path.StartsWithI("data\\")) 
		Index = 0;

	if (Index < 0) 
	{
		OutputPath.Empty();
		return false;
	}

	OutputPath.Copy(Path.c_str() + Index + 5, Path.GetLength() - Index - 5);
	return true;
}