Example #1
0
CString CInput::GetInput()
{
	char szInputBuffer[512]; // Buffer MUST be 3 or more (input char, \n, \0)
	CString strInputString;

	// Wait for input from the console
	fgets(szInputBuffer, sizeof(szInputBuffer), stdin);

	// Do we have anything in the input?
	if(szInputBuffer[0] != '\n')
	{
		// Append the input to the input string
		strInputString += szInputBuffer;

		// Get the input string length
		size_t sLength = strInputString.GetLength();

		// Is this the last of the input?
		if(strInputString[sLength - 1] == '\n')
		{
#ifdef _WIN32
			// Replace '\n' with '\0'
			strInputString.Truncate(sLength - 1);
#else
			// Replace '\r\n' with '\0'
			strInputString.Truncate(sLength - 2);
#endif

			// Return the input
			return strInputString;
		}
	}
	return strInputString;
}
Example #2
0
bool GitAdminDir::HasAdminDir(const CString& path, bool bDir, CString* ProjectTopDir, bool* IsAdminDirPath)
{
	if (path.IsEmpty())
		return false;
	CString sDirName = path;
	if (!bDir)
	{
		// e.g "C:\"
		if (path.GetLength() <= 3)
			return false;
		sDirName.Truncate(max(0, sDirName.ReverseFind(L'\\')));
	}

	// a .git dir or anything inside it should be left out, only interested in working copy files -- Myagi
	int n = 0;
	for (;;)
	{
		n = sDirName.Find(L"\\.git", n);
		if (n < 0)
			break;

		// check for actual .git dir (and not .gitignore or something else), continue search if false match
		n += 5;
		if (sDirName[n] == L'\\' || sDirName[n] == 0)
		{
			if (IsAdminDirPath)
				*IsAdminDirPath = true;
			return false;
		}
	}

	for (;;)
	{
		if (CGit::GitPathFileExists(sDirName + L"\\.git"))
		{
			if(ProjectTopDir)
			{
				*ProjectTopDir=sDirName;
				// Make sure to add the trailing slash to root paths such as 'C:'
				if (sDirName.GetLength() == 2 && sDirName[1] == L':')
					(*ProjectTopDir) += L'\\';
			}
			return true;
		}
		else if (IsBareRepo(sDirName))
			return false;

		int x = sDirName.ReverseFind(L'\\');
		if (x < 2)
			break;

		sDirName.Truncate(x);
		// don't check for \\COMPUTERNAME\.git
		if (sDirName[0] == L'\\' && sDirName[1] == L'\\' && sDirName.Find(L'\\', 2) < 0)
			break;
	}

	return false;
}
Example #3
0
// Takes access to a string, default peek false to move a line from the buffer to the string, and default CP_ACP to read ASCII text
// Looks for bytes like "line\r\n" in the buffer, and moves them from the buffer to the string, throwing away the "\r\n" part
// Returns true if a line was found and moved from the buffer to the string, false if there isn't a '\n' in the buffer right now
BOOL CBuffer::ReadLine(CString& strLine, BOOL bPeek, UINT nCodePage)
{
    // Empty the string, making it blank
    strLine.Empty();

    // If this buffer is empty, tell the caller we didn't find a complete line
    if ( ! m_nLength ) return FALSE;

    // Scan down each byte in the buffer
    DWORD nLength;
    for ( nLength = 0 ; nLength < m_nLength ; nLength++ )
    {
        // If the byte at this length is the newline character '\n', exit the loop
        if ( m_pBuffer[ nLength ] == '\n' ) break;
    }

    // If the loop didn't find a '\n' and instead stopped because nLength grew to equal m_nLength
    if ( nLength >= m_nLength ) return FALSE; // There isn't an '\n' in the buffer, tell the caller we didn't find a complete line

    // Convert the nLength ASCII characters in the buffer into wide characters in strLine
    int nWide = MultiByteToWideChar( nCodePage, 0, (LPCSTR)m_pBuffer, nLength, NULL, 0 );
    MultiByteToWideChar( nCodePage, 0, (LPCSTR)m_pBuffer, nLength, strLine.GetBuffer( nWide ), nWide );
    strLine.ReleaseBuffer( nWide );

    // Find the last carriage return '\r' character in the string
    int nCR = strLine.ReverseFind( '\r' );   // Find the distance to the last \r, "hello\r" would be 5
    if ( nCR >= 0 ) strLine.Truncate( nCR ); // Cut the string to that length, like "hello"

    // Now that the line has been copied into the string, remove it and the '\n' from the buffer
    if ( ! bPeek ) Remove( nLength + 1 ); // Unless we're peeking, then leave it in the buffer

    // Report that we found a line and moved it from the buffer to the string
    return TRUE;
}
Example #4
0
void CTableTitle::ExtractOHReplayFrameNumber(const CString *s) {
  if (s->GetLength() < 8) {
    return;
  }
  if (RightCharacter(*s) != ']') {
    return;
  }
  if (RightCharacter(*s, 7) != '[') {
    return;
  }
  // Title-format: #################[003141]
  // Extract frame-number
  int length = s->GetLength();
  int start_pos = length - 7;
  CString framenumber = s->Mid(start_pos);
  framenumber.Truncate(6);
  _ohreplay_framenumber = atoi(framenumber);
}
Example #5
0
CString FormatNumber(CString szNumber, bool bNoFractionalDigits /*= true*/)
{
    CString ret;

    int nChars = GetNumberFormat(LOCALE_USER_DEFAULT, 0, szNumber, nullptr, nullptr, 0);
    GetNumberFormat(LOCALE_USER_DEFAULT, 0, szNumber, nullptr, ret.GetBuffer(nChars), nChars);
    ret.ReleaseBuffer();

    if (bNoFractionalDigits) {
        TCHAR szNumberFractionalDigits[2] = {0};
        GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_IDIGITS, szNumberFractionalDigits, _countof(szNumberFractionalDigits));
        int nNumberFractionalDigits = _tcstol(szNumberFractionalDigits, nullptr, 10);
        if (nNumberFractionalDigits) {
            ret.Truncate(ret.GetLength() - nNumberFractionalDigits - 1);
        }
    }

    return ret;
}
Example #6
0
void CBabelData::CleanUp (void)

//	CleanUp
//
//	Deallocates appropriately but does not reset the member
//	variables.

{
    switch (m_Type)
    {
    case dtNil:
    case dtInteger:
        break;

    case dtString:
    case dtCode:
    {
        CString *pString = (CString *)&m_dwData;
        pString->Truncate(0);
        break;
    }

    case dtList:
    {
        ListData *pData = (ListData *)m_dwData;
        if (--pData->iRefCount == 0)
            delete pData;
        break;
    }

    case dtStructure:
    {
        StructData *pData = (StructData *)m_dwData;
        if (--pData->iRefCount == 0)
            delete pData;
        break;
    }

    default:
        ASSERT(false);
    }
}
Example #7
0
int DBInterface::CreateProjectSupplyTable(CString& project_supply_table)
{
	project_supply_table.Replace('\\','_');			// replace the backslash with _
	project_supply_table.Replace('\'', '_');		// replace the single quote "'" with _
	project_supply_table.Replace(' ', '_');
	project_supply_table.Replace('-', '_');
	project_supply_table.Replace('&', '_');
	project_supply_table.Replace('!', '_');
	project_supply_table.Replace('$', '_');
	project_supply_table.Replace('@', '_');
	project_supply_table.Replace('%', '_');
	project_supply_table.Replace('(', '_');
	project_supply_table.Replace(')', '_');
	project_supply_table.Replace('+', '_');
	project_supply_table.Replace('~', '_');
	project_supply_table.Replace('*', '_');
	project_supply_table.Replace('.', '_');
	project_supply_table.Replace(',', '_');
	project_supply_table.Replace('?', '_');
	project_supply_table.Replace(':', '_');
	project_supply_table.Replace(';', '_');
	project_supply_table.Replace('"', '_');
	project_supply_table.Replace('/', '_');
	project_supply_table.Replace('#', '_');

	//truncate the project name if its length is greater than 50
	if(project_supply_table.GetLength() > 50)
	{
		project_supply_table.Truncate(50);
	}

	CString table = "SUPPLY_TABLE_";
	table += project_supply_table;


	int ret;
	//create table IF NOT EXISTS table_name (track tinyint unsigned, query varchar(255), timestamp timestamp, index (track,timestamp), index(timestamp,track))
	CString query = "create table IF NOT EXISTS ";
	query += table;
	query += " (timestamp timestamp,sha1 varchar(32),track tinyint,ip int,primary key (sha1,ip,track))";

	ret = mysql_query(p_supply_conn, query);
	if(mysql_error(p_supply_conn)[0] != '\0')
	{
		CStdioFile file;
		if( file.Open("SQL_Error_Log.txt", CFile::modeCreate|CFile::modeNoTruncate|CFile::modeWrite, NULL) != 0)
		{
			file.SeekToEnd();

			CString log;
			log = CTime::GetCurrentTime().Format("%Y-%m-%d %H:%M:%S");
			log += " CreateProjectSupplyTable(...) ";
			log += query;
			log += "\n";
			log += "Error: ";
			log += mysql_error(p_supply_conn);
			log += "\n\n";

			file.WriteString(log);
			file.Close();
		}
		else
		{
			DWORD error = GetLastError();
			MessageBox(NULL, "File Open Error: SQL_Error_Log.txt", "File Open Error", MB_OK);
		}

		TRACE(mysql_error(p_supply_conn));
		TRACE("\n");
		TRACE(query);
		TRACE("\n");
	}
	return ret;
}
Example #8
0
int DBInterface::InsertRawGnutellaSupply(vector<QueryHit>& query_hits)
{
//	file_name.Replace("\\","\\\\");
//	file_name.Replace("'", "\\'");

	//truncate the project name if its length is greater than 50
	CString project = query_hits[0].m_project;
	if(project.GetLength() > 50)
	{
		project.Truncate(50);
	}

	CString table = "SUPPLY_TABLE_";
	table += project;

	table.Replace('\\','_');			// replace the backslash with _
	table.Replace('\'', '_');		// replace the single quote "'" with _
	table.Replace(' ', '_');
	table.Replace('-', '_');
	table.Replace('&', '_');
	table.Replace('!', '_');
	table.Replace('$', '_');
	table.Replace('@', '_');
	table.Replace('%', '_');
	table.Replace('(', '_');
	table.Replace(')', '_');
	table.Replace('+', '_');
	table.Replace('~', '_');
	table.Replace('*', '_');
	table.Replace('.', '_');
	table.Replace(',', '_');
	table.Replace('?', '_');
	table.Replace(':', '_');
	table.Replace(';', '_');
	table.Replace('"', '_');
	table.Replace('/', '_');
	table.Replace('#', '_');

	
	int ret;
	char temp[32];
	memset(temp, 0, sizeof(temp));
	CString query = "INSERT IGNORE INTO ";
	query += table;
	query += " (timestamp,sha1,track,ip) VALUES ";

	for(UINT i=0; i<query_hits.size(); i++)
	{
		query += "('";
		CString timestamp = query_hits[i].m_timestamp.Format("%Y%m%d%H%M%S");
		query += timestamp;
		query += "','";
		CString sha1 = query_hits[i].m_sha1;
		sha1.Replace("\\", "\\\\");
		sha1.Replace("'", "''");
		query += sha1;
		query += "',";
		query += itoa(query_hits[i].m_track,temp,10);
		query += ",";
		query += itoa(query_hits[i].m_ip,temp,10);
		query += ")";
		if(i != query_hits.size()-1)
		{
			query += ",";
		}
	}
	ret = mysql_query(p_supply_conn,query);
	if(mysql_error(p_supply_conn)[0] != '\0')
	{
		CStdioFile file;
		if( file.Open("SQL_Error_Log.txt", CFile::modeCreate|CFile::modeNoTruncate|CFile::modeWrite, NULL) != 0)
		{
			file.SeekToEnd();

			CString log;
			log = CTime::GetCurrentTime().Format("%Y-%m-%d %H:%M:%S");
			log += " InsertRawGnutellaSupply(...) ";
			log += query;
			log += "\n";
			log += "Error: ";
			log += mysql_error(p_supply_conn);
			log += "\n\n";

			file.WriteString(log);
			file.Close();
			if(log.Find("doesn't exist")>=0)
			{
				CreateProjectSupplyTable(project);
				mysql_query(p_supply_conn,query);
			}

		}
		else
		{
			DWORD error = GetLastError();
			MessageBox(NULL, "File Open Error: SQL_Error_Log.txt", "File Open Error", MB_OK);
		}

		TRACE(mysql_error(p_supply_conn));
		TRACE("\n");
		TRACE(query);
		TRACE("\n");
	}
	return ret;
}
Example #9
0
int DBInterface::InsertRawGnutellaSupply(/*CString& file_name,UINT file_size,*/ 
			int ip, CString& timestamp, char* sha1,/* GUID& guid,*/ CString& project,int track/*, bool spoof*/)
{

	//file_name.Replace("\\","\\\\");
	//file_name.Replace("'", "\\'");

	//truncate the project name if its length is greater than 50
	if(project.GetLength() > 50)
	{
		project.Truncate(50);
	}
	

	CString table = "SUPPLY_TABLE_";
	table += project;
	table.Replace('\\','_');			// replace the backslash with _
	table.Replace('\'', '_');		// replace the single quote "'" with _
	table.Replace(' ', '_');
	table.Replace('-', '_');
	table.Replace('&', '_');
	table.Replace('!', '_');
	table.Replace('$', '_');
	table.Replace('@', '_');
	table.Replace('%', '_');
	table.Replace('(', '_');
	table.Replace(')', '_');
	table.Replace('+', '_');
	table.Replace('~', '_');
	table.Replace('*', '_');
	table.Replace('.', '_');
	table.Replace(',', '_');
	table.Replace('?', '_');
	table.Replace(':', '_');
	table.Replace(';', '_');
	table.Replace('"', '_');
	table.Replace('/', '_');
	table.Replace('#', '_');


	//UINT guid_index = GetGUIDIndex(guid); //get the guid index from the guid index table;
	int ret;
	char temp[32];
	memset(temp, 0, sizeof(temp));

	CString query = "INSERT IGNORE INTO ";
	query += table;
	query += " (timestamp,sha1,track,ip) VALUES ('";
	query += timestamp;
	query += "','";
	query += sha1;
	query += "',";
	query += itoa(track,temp,10);
	query += ",";
	query += itoa(ip,temp,10);
	query += ")";
	ret = mysql_query(p_supply_conn,query);




	if(mysql_error(p_supply_conn)[0] != '\0')
	{
		CStdioFile file;
		if( file.Open("SQL_Error_Log.txt", CFile::modeCreate|CFile::modeNoTruncate|CFile::modeWrite, NULL) != 0)
		{
			file.SeekToEnd();

			CString log;
			log = CTime::GetCurrentTime().Format("%Y-%m-%d %H:%M:%S");
			log += " InsertRawGnutellaSupply(...) ";
			log += query;
			log += "\n";
			log += "Error: ";
			log += mysql_error(p_supply_conn);
			log += "\n\n";

			file.WriteString(log);
			file.Close();
			if(log.Find("doesn't exist")>=0)
			{
				CreateProjectSupplyTable(project);
				mysql_query(p_supply_conn,query);
			}
		}
		else
		{
			DWORD error = GetLastError();
			MessageBox(NULL, "File Open Error: SQL_Error_Log.txt", "File Open Error", MB_OK);
		}

		TRACE(mysql_error(p_supply_conn));
		TRACE("\n");
		TRACE(query);
		TRACE("\n");

	}
	return ret;
}
Example #10
0
CString CSZCommandLineEx::FormatParamUsage(
    LPCTSTR         lpszParamName,
    CParamUsage&    usage, 
    int             nParamNameWidth,
    int             nValueNameWidth)
{
    assert(0 <= nParamNameWidth && nParamNameWidth <= 80);
    assert(0 <= nValueNameWidth && nValueNameWidth <= 80);


    CString strParamUsage;

    if (nValueNameWidth)
        nValueNameWidth += 3;   // for :<>

    // indent
    int nTruncateLength = 4;
    strParamUsage.AppendChar(_T(' '));
    strParamUsage.AppendChar(_T(' '));
    strParamUsage.AppendChar(_T(' '));
    strParamUsage.AppendChar(_T('-'));

    // param name
    nTruncateLength += nParamNameWidth;
    strParamUsage.Append(lpszParamName);
    for (int i = strParamUsage.GetLength(); i <= nTruncateLength; ++i)
    {
        strParamUsage.AppendChar(_T(' '));
    }
    strParamUsage.Truncate(nTruncateLength);


    // space
    nTruncateLength += 2;
    strParamUsage.AppendChar(_T(' '));
    strParamUsage.AppendChar(_T(' '));


    // param value
    nTruncateLength += nValueNameWidth;
    if (!usage.m_strParamValueName.IsEmpty())
        strParamUsage.AppendFormat(_T(":<%s>"), usage.m_strParamValueName);
    for (int i = strParamUsage.GetLength(); i <= nTruncateLength; ++i)
    {
        strParamUsage.AppendChar(_T(' '));
    }
    strParamUsage.Truncate(nTruncateLength);


    // space
    nTruncateLength += 4;
    strParamUsage.AppendChar(_T(' '));
    strParamUsage.AppendChar(_T(' '));
    strParamUsage.AppendChar(_T(' '));
    strParamUsage.AppendChar(_T(' '));


    // param usage
    strParamUsage.Append(usage.m_strUsage);
    return strParamUsage;
}
Example #11
0
CChatItem* CChatSelector::StartSession(CUpDownClient* pClient, bool bForceFocus /* true */)
{
	if (pClient == NULL || !g_App.m_pMDlg->IsRunning())
		return NULL;

	EMULE_TRY

	if (GetTabByClient(pClient) != (uint16)-1)
	{
		SetCurSel(GetTabByClient(pClient));
		if (bForceFocus)
			ShowChat();
		return NULL;
	}

	CChatItem	*pChatItem = new CChatItem();
	CRect		rcRect;

	pChatItem->m_pClient = pClient;
	pChatItem->m_pLog = new CHTRichEditCtrl;

	GetClientRect(&rcRect);
	AdjustRect(false, rcRect);
	rcRect.left += 3;
	rcRect.top += 4;
	rcRect.right -= 3;
	rcRect.bottom -= 3;

	if (GetItemCount() == 0)
		rcRect.top += 20;

	pChatItem->m_pLog->Create(WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_HSCROLL | WS_VSCROLL | ES_MULTILINE | ES_READONLY | ES_NOHIDESEL, rcRect, this, (UINT)-1);
	pChatItem->m_pLog->ModifyStyleEx(0, WS_EX_STATICEDGE, SWP_FRAMECHANGED);
	pChatItem->m_pLog->SendMessage(EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(3, 3));
	pChatItem->m_pLog->SetFont(&g_App.m_pMDlg->m_fontDefault);
	pChatItem->m_pLog->m_dwFlags |= HTC_ISWORDWRAP;
	pChatItem->m_pLog->SetTargetDevice(NULL, 0);

	COleDateTime	timelog(COleDateTime::GetCurrentTime());
	CString			strName = pClient->GetUserName(), strCountry, strTemp;

	if (g_App.m_pIP2Country->IsIP2Country())
		strCountry.Format(_T(" (%s)"), pClient->GetCountryName());
	strTemp.Format(_T("*** %s: %s (%s: %s:%u%s) - %s\n"), 
		GetResString(IDS_CHAT_START),
		strName,
		GetResString(IDS_IP), pClient->GetFullIP(), pClient->GetUserPort(), strCountry,
		timelog.Format(_T("%c")));
	pChatItem->m_pLog->AppendText(strTemp, RGB(255, 0, 0));
	pClient->SetChatState(MS_CHATTING);
	if (pClient->IsFriend())
		pClient->m_pFriend->m_dwLastChatted = time(NULL);

	if (strName.GetLength() > 30)
	{
		strName.Truncate(30);
		strName += _T("...");
	}
	else if (strName.IsEmpty())
		strName.Format(_T("[%s]"), GetResString(IDS_UNKNOWN));

	TCITEM	tcitem;

	tcitem.mask = TCIF_PARAM | TCIF_TEXT | TCIF_IMAGE;
	tcitem.lParam = (LPARAM)pChatItem;
	tcitem.pszText = (TCHAR*)strName.GetString();
	tcitem.iImage = 0;
	
	int	iResult = InsertItem(GetItemCount(), &tcitem);

	g_App.m_pMDlg->m_wndChat.m_ctlCloseButton.EnableWindow(true);
	g_App.m_pMDlg->m_wndChat.m_ctlSendButton.EnableWindow(true);

	if (iResult != -1 && IsWindowVisible())
	{
		SetCurSel(iResult);
		pChatItem->m_pLog->SetTitle(pClient->GetUserName());
		if (bForceFocus)
			ShowChat();
	}

	return pChatItem;

	EMULE_CATCH

	return NULL;
}