本文整理汇总了C++中CString::GetLength方法的典型用法代码示例。如果您正苦于以下问题:C++ CString::GetLength方法的具体用法?C++ CString::GetLength怎么用?C++ CString::GetLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CString
的用法示例。
在下文中一共展示了CString::GetLength方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ReadString
BOOL CStdioFileEx::ReadString(CString& rString)
{
const int nMAX_LINE_CHARS = 4096;
BOOL bReadData = FALSE;
LPTSTR lpsz;
int nLen = 0;
wchar_t* pszUnicodeString = NULL;
char * pszMultiByteString= NULL;
int nChars = 0;
try
{
// If at position 0, discard byte-order mark before reading
if (!m_pStream || (GetPosition() == 0 && m_bIsUnicodeText))
{
wchar_t cDummy;
// Read(&cDummy, sizeof(_TCHAR));
Read(&cDummy, sizeof(wchar_t));
}
// If compiled for Unicode
#ifdef _UNICODE
if (m_bIsUnicodeText)
{
// Do standard stuff - Unicode to Unicode. Seems to work OK.
bReadData = CStdioFile::ReadString(rString);
}
else
{
pszUnicodeString = new wchar_t[nMAX_LINE_CHARS];
pszMultiByteString= new char[nMAX_LINE_CHARS];
// Initialise to something safe
memset(pszUnicodeString, 0, sizeof(wchar_t) * nMAX_LINE_CHARS);
memset(pszMultiByteString, 0, sizeof(char) * nMAX_LINE_CHARS);
// Read the string
bReadData = (NULL != fgets(pszMultiByteString, nMAX_LINE_CHARS, m_pStream));
if (bReadData)
{
// Convert multibyte to Unicode, using the specified code page
nChars = GetUnicodeStringFromMultiByteString(pszMultiByteString, pszUnicodeString, nMAX_LINE_CHARS, m_nFileCodePage);
if (nChars > 0)
{
rString = (CString)pszUnicodeString;
}
}
}
#else
if (!m_bIsUnicodeText)
{
// Do standard stuff -- read ANSI in ANSI
bReadData = CStdioFile::ReadString(rString);
// Get the current code page
UINT nLocaleCodePage = GetCurrentLocaleCodePage();
// If we got it OK...
if (nLocaleCodePage > 0)
{
// if file code page does not match the system code page, we need to do a double conversion!
if (nLocaleCodePage != (UINT)m_nFileCodePage)
{
int nStringBufferChars = rString.GetLength() + 1;
pszUnicodeString = new wchar_t[nStringBufferChars];
// Initialise to something safe
memset(pszUnicodeString, 0, sizeof(wchar_t) * nStringBufferChars);
// Convert to Unicode using the file code page
nChars = GetUnicodeStringFromMultiByteString(rString, pszUnicodeString, nStringBufferChars, m_nFileCodePage);
// Convert back to multibyte using the system code page
// (This doesn't really confer huge advantages except to avoid "mangling" of non-convertible special
// characters. So, if a file in the E.European code page is displayed on a system using the
// western European code page, special accented characters which the system cannot display will be
// replaced by the default character (a hash or something), rather than being incorrectly mapped to
// other, western European accented characters).
if (nChars > 0)
{
// Calculate how much we need for the MB buffer (it might be larger)
nStringBufferChars = GetRequiredMultiByteLengthForUnicodeString(pszUnicodeString,nLocaleCodePage);
pszMultiByteString= new char[nStringBufferChars];
nChars = GetMultiByteStringFromUnicodeString(pszUnicodeString, pszMultiByteString, nStringBufferChars, nLocaleCodePage);
rString = (CString)pszMultiByteString;
}
}
}
}
else
{
pszUnicodeString = new wchar_t[nMAX_LINE_CHARS];
// Initialise to something safe
memset(pszUnicodeString, 0, sizeof(wchar_t) * nMAX_LINE_CHARS);
//.........这里部分代码省略.........
示例2: ShowSpeedLimit
void COptionsSpeedLimitPage::ShowSpeedLimit(CListBox &listBox, SPEEDLIMITSLIST &list)
{
listBox.ResetContent();
for (unsigned int i = 0; i < list.size(); i++)
{
CString str;
str.Format(_T( "%dkB/s"), list[i].m_Speed);
CString help;
if (list[i].m_DateCheck)
{
CTime t(list[i].m_Date.y, list[i].m_Date.m, list[i].m_Date.d, 0, 0, 0);
help += t.Format(_T("%x"));
}
if (list[i].m_FromCheck)
{
if (help.GetLength() > 0)
help += _T( "; ");
CTime t(2003, 1, 1, list[i].m_FromTime.h, list[i].m_FromTime.m, list[i].m_FromTime.s);
help += _T("F:") + t.Format( _T("%X"));
}
if (list[i].m_ToCheck)
{
if (help.GetLength() > 0)
help += _T( "; ");
CTime t(2003, 1, 1, list[i].m_ToTime.h, list[i].m_ToTime.m, list[i].m_ToTime.s);
help += _T("T:") + t.Format( _T("%X"));
}
for (int j = 0; j < 7; j++)
if (!(list[i].m_Day & (1<<j)))
{
if (help.GetLength() > 0)
help += _T( "; ");
bool was = false;
for ( int k = 0; k < 7; k++)
{
if ((list[i].m_Day & (1<<k)))
{
if (was)
help += _T(", ");
was = true;
CTime time(2001, 1, k + 1, 0, 0, 0);
help += time.Format(_T("%a"));
}
}
break;
}
str += _T(" [") + help + _T("]");
listBox.AddString(str);
}
}
示例3: StartRedirect
void CRedirectHTTPS_Thread::StartRedirect()
{ m_sServerSocket=INVALID_SOCKET; m_iConnections=0;
int iErr=1; bool bFinished=false; while(!bFinished && g_pMainCtrl->m_bRunning) {
url uURL; char szBuffer[MAX_PATH]; bool bGet=false;
// Receive the proxy request
if(!m_sClientSocket.RecvLineIRC(szBuffer, MAX_PATH)) { bFinished=true; break; }
CString sBuffer(szBuffer);
// Fail if there is no url
// if(!sBuffer.Token(1, " ").Compare("")) { bFinished=true; break; }
if(!sBuffer.Compare("")) { bFinished=true; break; }
if(!sBuffer.Token(0, " ").CompareNoCase("GET")) { // GET method
bGet=true;
// Parse the url
if(!ParseURL(sBuffer.Token(1, " ").CStr(), &uURL)) { bFinished=true; break; }
// Fail if the protocol isnt http
if(uURL.sProto.Compare("http")) { bFinished=true; break; }
} else if(!sBuffer.Token(0, " ").CompareNoCase("CONNECT")) { // CONNECT method
bGet=false;
// Parse the host
uURL.sProto.Assign("connect");
uURL.sReq.Assign("");
uURL.sHost.Assign(sBuffer.Token(1, " ").Token(0, ":"));
if(!sBuffer.Token(1, " ").Token(1, ":").CStr()) { bFinished=true; break; }
uURL.iPort=atoi(sBuffer.Token(1, " ").Token(1, ":").CStr());
if(!uURL.iPort) uURL.iPort=80; }
// Get the rest of the request
CString sMethod(sBuffer.Token(0, " ")); if(!sMethod.Compare("")) { bFinished=true; break; }
CString sHTTPSVer(sBuffer.Token(2, " ")); if(!sHTTPSVer.Compare("")) { bFinished=true; break; }
CString sOldHost(uURL.sHost);
#ifdef DBGCONSOLE
if(bGet)
g_pMainCtrl->m_cConsDbg.Log(5, "CRedirectHTTPS(0x%8.8Xh): %s %s %s...\n", m_pRedirHTTPS, sMethod.CStr(), uURL.sReq.CStr(), sHTTPSVer.CStr());
else
g_pMainCtrl->m_cConsDbg.Log(5, "CRedirectHTTPS(0x%8.8Xh): %s %s:%d %s...\n", m_pRedirHTTPS, sMethod.CStr(), uURL.sHost.CStr(), uURL.iPort, sHTTPSVer.CStr());
#endif
char szBuf[4096]; strcpy(szBuf, "bla");
if(bGet) {
if(!m_sClientSocket.Recv(szBuf, sizeof(szBuf)))
{ m_sClientSocket.Disconnect(); return; }
} else {
while(strcmp(szBuf, "")) // Loop while headers arent finished
if(!m_sClientSocket.RecvLineIRC(szBuf, 4096)) { bFinished=true; break; }
if(bFinished) break; }
CString sReqBuf;
if(bGet)
sReqBuf.Format("%s %s %s\r\n%s", sMethod.CStr(), uURL.sReq.CStr(), sHTTPSVer.CStr(), szBuf);
else
sReqBuf.Format("HTTP/1.0 200 Connection established\r\n\r\n");
m_sServerSocket=socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if(!m_sServerSocket.IsConnected())
{ m_sClientSocket.Disconnect(); return; }
// Connect to the server
if(!m_sServerSocket.Connect(uURL.sHost.CStr(), uURL.iPort)) // Connect failed, exit
{
#ifdef DBGCONSOLE
g_pMainCtrl->m_cConsDbg.Log(5, "CRedirectHTTPS(0x%8.8Xh): Cannot connect to %s:%d (%s)...\n", m_pRedirHTTPS, uURL.sHost.CStr(), uURL.iPort, uURL.sReq.CStr());
#endif
m_sClientSocket.Disconnect(); m_sServerSocket.Disconnect(); return; }
if(bGet) {
if(!m_sServerSocket.Write(sReqBuf.CStr(), sReqBuf.GetLength()))
{ m_sClientSocket.Disconnect(); m_sServerSocket.Disconnect(); return; }
} else {
if(!m_sClientSocket.Write(sReqBuf.CStr(), sReqBuf.GetLength()))
{ m_sClientSocket.Disconnect(); m_sServerSocket.Disconnect(); return; }
}
int iLen; fd_set fd;
SET_SOCK_BLOCK(m_sClientSocket.GetSocket(), 0);
SET_SOCK_BLOCK(m_sServerSocket.GetSocket(), 0);
if(bGet) {
while(true)
{ memset(szBuffer, 0, sizeof(szBuffer));
if(!m_sClientSocket.RecvLineIRC(szBuffer, sizeof(szBuffer))) { Sleep(10); break; }
if(strcmp(szBuffer, "")) {
sBuffer.Assign(szBuffer);
if(!sBuffer.Token(0, " ").Compare("GET"))
{ // Fail if there is no url
if(!sBuffer.Token(1, " ").Compare("")) { bFinished=true; break; }
// Parse the url
if(!ParseURL(sBuffer.Token(1, " ").CStr(), &uURL)) break;
// Fail if the protocol isnt http
if(uURL.sProto.Compare("http")) { bFinished=true; break; }
// Get the rest of the request
CString sMethod(sBuffer.Token(0, " ")); if(!sMethod.Compare("")) { bFinished=true; break; }
CString sHTTPSVer(sBuffer.Token(2, " ")); if(!sHTTPSVer.Compare("")) { bFinished=true; break; }
sBuffer.Format("%s %s %s\r\n", sMethod.CStr(), uURL.sReq.CStr(), sHTTPSVer.CStr());
if(uURL.sHost.Compare(sOldHost))
{ m_sServerSocket.Disconnect();
//.........这里部分代码省略.........
示例4: ParseChangeMode
void CIrcWnd::ParseChangeMode(const CString& sChannel, const CString& sChanger, CString sCommands, const CString& sParams)
{
CString sCommandsOrig = sCommands;
CString sParamsOrig = sParams;
try
{
if( sCommands.GetLength() >= 2 )
{
CString sDir;
int iParamIndex = 0;
while( !sCommands.IsEmpty() )
{
if (sCommands[0] == _T('+') || sCommands[0] == _T('-'))
{
sDir = sCommands.Left(1);
sCommands = sCommands.Right(sCommands.GetLength()-1);
}
if( !sCommands.IsEmpty() && !sDir.IsEmpty() )
{
CString sCommand = sCommands.Left(1);
sCommands = sCommands.Right(sCommands.GetLength()-1);
if(m_wndNicks.m_sUserModeSettings.Find(sCommand) != -1 )
{
//This is a user mode change and must have a param!
CString sParam = sParams.Tokenize(_T(" "), iParamIndex);
m_wndNicks.ChangeNickMode( sChannel, sParam, sDir + sCommand);
}
if(m_wndChanSel.m_sChannelModeSettingsTypeA.Find(sCommand) != -1)
{
//We do not use these messages yet.. But we can display them for the user to see
//These modes always have a param and will add or remove a user from some type of list.
CString sParam = sParams.Tokenize(_T(" "), iParamIndex);
m_wndChanSel.ChangeChanMode( sChannel, sParam, sDir, sCommand);
}
if(m_wndChanSel.m_sChannelModeSettingsTypeB.Find(sCommand) != -1)
{
//We do not use these messages yet.. But we can display them for the user to see
//These modes will always have a param..
CString sParam = sParams.Tokenize(_T(" "), iParamIndex);
m_wndChanSel.ChangeChanMode( sChannel, sParam, sDir, sCommand);
}
if(m_wndChanSel.m_sChannelModeSettingsTypeC.Find(sCommand) != -1 )
{
//We do not use these messages yet.. But we can display them for the user to see
//These modes will only have a param if your setting it!
CString sParam;
if (sDir == _T("+"))
sParam = sParams.Tokenize(_T(" "), iParamIndex);
m_wndChanSel.ChangeChanMode( sChannel, sParam, sDir, sCommand);
}
if(m_wndChanSel.m_sChannelModeSettingsTypeD.Find(sCommand) != -1 )
{
//We do not use these messages yet.. But we can display them for the user to see
//These modes will never have a param for it!
CString sParam;
m_wndChanSel.ChangeChanMode( sChannel, sParam, sDir, sCommand);
}
}
}
if (!thePrefs.GetIRCIgnoreMiscMessages())
AddInfoMessageF(sChannel, GetResString(IDS_IRC_SETSMODE), sChanger, sCommandsOrig, sParamsOrig);
}
}
catch(...)
{
AddInfoMessage(sChannel, GetResString(IDS_IRC_NOTSUPPORTED));
ASSERT(0);
}
}
示例5: OnTimer
void CTabNFC::OnTimer(UINT nIDEvent)
{
char intro[NFC_HEADER_LEN+4], intro2[NFC_HEADER_LEN+4];
if (nIDEvent == 3) {
NfcMakeAtest();
return;
}
if (nIDEvent != m_iNFCTimerID) return;
portSetScanMode();
int nn = portScan(intro, NFC_HEADER_LEN);
if (nn == -1) {
KillTimer(m_iNFCTimerID);
return;
}
if (! nn) return;
char *p;
if (! (p = strchr(intro, '[')))
return;
p += 1;
int xlen;
xlen = p - &intro[0];
strcpy(intro2, p);
strcpy(intro, intro2);
#if ! LOG_AND_DELAY
portSetFastMode();
#endif
nn = portRead(intro2, xlen);
if (nn == -1) {
KillTimer(m_iNFCTimerID);
return;
}
strcat(intro, intro2);
// Suspend timer
#if ! LOG_AND_DELAY
portSetXFastMode();
#endif
char data[2*NFC_TOTBUF_LEN+64], pfbbuf[4];
int iintro, len, more, toFile = 0, isFile, isTest, noMore, pfb, pfb0, n;
int retry = NFC_RETRY, tot = 0, size = 0, val;
CString fname = m_sNFCDirName;
if (fname.GetLength())
fname += "\\";
ofstream out;
pfbbuf[2] = 0;
p = intro;
//char msg[256];
// logAdd("000", 0, 0);
int iter = 0;
while (1) {
iter++;
#if USE_PFB
pfbbuf[0] = *p++;
pfbbuf[1] = *p++;
sscanf(pfbbuf, "%X", &pfb);
#endif
sscanf(p, "%X", &iintro);
len = iintro & NFC_LEN_MASK;
isTest = iintro & NFC_TEST_MASK;
isFile = iintro & NFC_FILE_MASK;
more = iintro & NFC_MORE_MASK;
len++; // Get closing brace ]
//if (iter > 2) portWrite("0", 9);
//sprintf(msg, "..001 len=%d, more = %d", len, more);
//logAdd(msg, 0, 0);
retry--;
if ((! (n = portRead(data, len)) ||
(n != len && n != (len+4)))
#if USE_PFB
&& pfb != pfb0
#endif
) {
#if RS232_ONLY
portWrite(INITIATOR_NAK, 9, 0);
#else
portWrite(TARGET_NAK, 0, 0);
//logAdd(TARGET_NAK, 0, 0);
#endif
if (retry)
goto skip2;
else
break;
}
#if USE_PFB
if (pfb == pfb0)
goto skip;
#endif
//if (iter > 1) portWrite("0", 9);
if (iter > 1)
iter++;
//data[len] = 0;
//sprintf(msg, "..002 data=%s", data);
//logAdd(msg, 0, 0);
hex2data(data, &len);
//data[len] = 0;
//sprintf(msg, "..002+ data=%s", data);
//logAdd(msg, 0, 0);
if (! strncmp(data, NFC_FILE, strlen(NFC_FILE))) {
//.........这里部分代码省略.........
示例6: OnMessage
//.........这里部分代码省略.........
pDuiMenu->LoadXmlFile(strXmlFile, pParentDlg, point, WM_DUI_MENU);
pDuiMenu->ShowWindow(SW_SHOW);
pDuiMenu->SetAutoClose(TRUE);
}else
if(m_strAction.Find(_T("link:")) == 0) // 动作:打开一个页面链接
{
if(uMsg == MSG_BUTTON_UP) // 鼠标放开事件才处理
{
CString strLink = m_strAction;
strLink.Delete(0, 5);
if(!strLink.IsEmpty())
{
ShellExecute(NULL, TEXT("open"), strLink, NULL,NULL,SW_NORMAL);
}
}
}else
if(m_strAction.Find(_T("run:")) == 0) // 动作:执行一个进程
{
if(uMsg == MSG_BUTTON_UP) // 鼠标放开事件才处理
{
CString strProcess = m_strAction;
strProcess.Delete(0, 4);
strProcess.MakeLower();
if(!strProcess.IsEmpty())
{
strProcess.MakeLower();
BOOL bForceAdmin = FALSE;
if(strProcess.Find(_T("[email protected]")) == 0)
{
bForceAdmin = TRUE;
strProcess.Delete(0, 6);
}
BOOL bWaitProcess = FALSE;
if(strProcess.Find(_T("&")) == (strProcess.GetLength()-1))
{
bWaitProcess = TRUE;
strProcess.Delete(strProcess.GetLength()-1, 1);
}
if(strProcess.Find(_T(".exe")) == -1)
{
strProcess = DuiSystem::Instance()->GetString(strProcess);
}
if(strProcess.Find(_T("{platpath}")) == 0)
{
strProcess.Delete(0, 10);
strProcess = DuiSystem::GetExePath() + strProcess;
}
CString strCmdLine = _T("");
int nPos = strProcess.Find(_T("|"));
if(nPos != -1)
{
strCmdLine = strProcess;
strCmdLine.Delete(0, nPos+1);
strProcess = strProcess.Left(nPos);
}
DuiSystem::PathCanonicalize(strProcess); // 路径标准化
DuiSystem::ExecuteProcess(strProcess, strCmdLine, bForceAdmin, bWaitProcess);
}
}
}else
if(m_strAction.Find(ACTION_CLOSE_WINDOW) == 0) // 动作:关闭指定的窗口
{
if(uMsg == MSG_BUTTON_UP) // 鼠标放开事件才处理
{
CString strWndName = m_strAction;
strWndName.Delete(0, 13);
示例7: OnBnClickedButtonSearch
void CLookupForm::OnBnClickedButtonSearch()
{
CString searchText;
m_editSearch.GetWindowText(searchText);
if(searchText.GetLength() <= 0)
return;
searchText.MakeLower(); // itemData is also lower
CString guidSearchText;
if (!m_isHR) {
guidSearchText = searchText;
guidSearchText.Replace(_T("0x"), _T(""));
const TCHAR delimiters[] = _T(" \t-,{}()=/;ul"); // remove commonly used GUID delimiters and match by remaining hex digits
for (int n=0; n<sizeof(delimiters)/sizeof(delimiters[0]) - 1; n++)
guidSearchText.Remove(delimiters[n]);
}
int selItem = -1, selCol = -1;
const int start = m_listCtrl.GetSelectionMark() + 1;
CString item_text;
const int count = m_listCtrl.GetItemCount();
bool allowWrap = true;
for(int i=start; ;i++)
{
if (i >= count) { // beyond end of list
if (start > 0 && allowWrap) {
allowWrap = false;
i = 0; // restart at beginning
}
else
break; // started at beginning or already wrapped so stop looping now
}
const CStringArray * const arData = (const CStringArray*)m_listCtrl.GetItemData(i);
for(int j=0; j<arData->GetCount(); j++)
{
int find;
if (!m_isHR && j==1) // GUID column - strip out hyphens for easier hex matching
{
item_text = arData->GetAt(j);
item_text.Remove(_T('-'));
find = item_text.Find(guidSearchText);
} else
{
find = arData->GetAt(j).Find(searchText);
}
if(find >= 0)
{
selItem = i;
selCol = j;
i=count; // terminate looping without wrapping
allowWrap = false;
break;
}
}
if (i == start-1) // about to hit start for second time round - stop looping
break;
}
if(selItem != -1)
{
m_listCtrl.SetItemState(selItem, LVIS_SELECTED, LVIS_SELECTED);
m_listCtrl.SetSelectionMark(selItem);
m_listCtrl.EnsureVisible(selItem, FALSE);
m_listCtrl.SetFocus();
}
}
示例8: GetCacheStats
gbool GUrlCache::GetCacheStats(const char *directory, time_t &oldest,DWORD &spaceInUse, int &filesInUse)
{
CFileFind finder;
CString dir = directory;
// add separator
int l = dir.GetLength();
if (l == 0) return FALSE;
if ( !((dir[l-1] == '\\') || (dir[l-1] == '/'))) dir += '\\';
dir += "*.*";
CString path;
CTime creationTime((time_t)0);
CTime accessTime((time_t)0);
CTime writeTime((time_t)0);
// setup the find structure
BOOL bWorking = finder.FindFile(dir);
while (bWorking) { // for all entrys
if (stop) break;
bWorking = finder.FindNextFile();
path = finder.GetFilePath();
creationTime = (time_t)0;
accessTime = (time_t)0;
writeTime = (time_t)0;
BOOL ret=finder.GetCreationTime(creationTime);
finder.GetLastAccessTime(accessTime);
finder.GetLastWriteTime(writeTime);
time_t t = creationTime.GetTime();
if (accessTime.GetTime()>0) t = max(t,accessTime.GetTime());
if (finder.IsDots( )) { // ignore . ..
} else if (finder.IsDirectory( )) { // recursively step down
GetCacheStats(path,oldest,spaceInUse,filesInUse);
}
else {
DWORD length = finder.GetLength();
TRACE("F %s c %ld a %ld w %ld size %ld \n",(const char *) path, creationTime.GetTime(),accessTime.GetTime(),writeTime.GetTime(),length);
oldest = min(oldest,t);
filesInUse++;
spaceInUse += length;
}
}
finder.Close();
return TRUE;
}
示例9: Combine
// combine directory + relFilePath to fullpathname
gbool GUrlCache::Combine(const CString &directory,const CString relFilePath,CString &absFilePath)
{
if (directory.GetLength() == 0) return FALSE;
absFilePath = directory+relFilePath;
return TRUE;
}
示例10: AddFiles
// add files to list
gbool GFileSorter::AddFiles(const char *directory,time_t &maxFileTime,BOOL &stop)
{
CFileFind finder;
CString dir = directory;
// add separator
int l = dir.GetLength();
if (l == 0) return FALSE;
if ( !((dir[l-1] == '\\') || (dir[l-1] == '/'))) dir += '\\';
dir += "*.*";
CString path;
CTime creationTime((time_t)0);
CTime accessTime((time_t)0);
CTime writeTime((time_t)0);
// setup the find structure
BOOL bWorking = finder.FindFile(dir);
while (bWorking) { // for all entrys
if (stop) break;
bWorking = finder.FindNextFile();
path = finder.GetFilePath();
creationTime = (time_t)0;
accessTime = (time_t)0;
writeTime = (time_t)0;
BOOL ret=finder.GetCreationTime(creationTime);
finder.GetLastAccessTime(accessTime);
finder.GetLastWriteTime(writeTime);
time_t t = creationTime.GetTime();
if (writeTime.GetTime()>0) t = max(t,writeTime.GetTime()); // HG wg Kristof
if (accessTime.GetTime()>0) t = max(t,accessTime.GetTime());
if (finder.IsDots( )) { // ignore . ..
} else if (finder.IsDirectory( )) { // recursively step down
t=0; // we want to delete empty directories new 20.10.98
AddFiles(path,t,stop);
DWORD length = 0;
// to do get date of latest
TRACE("D %s c %ld a %ld w %ld size %ld \n",(const char *) path, creationTime.GetTime(),accessTime.GetTime(),writeTime.GetTime(),length);
// time is the max of the child time +1
GFSortEntry *e = new GFSortEntry(path,t+1,length,gtrue);
if (!e) break;
if (!Add(e)) break;
if (t>maxFileTime) maxFileTime = t;
}
else {
DWORD length = finder.GetLength(); // get length 64
fileSum += length;
TRACE("F %s c %ld a %ld w %ld size %ld \n",(const char *) path, creationTime.GetTime(),accessTime.GetTime(),writeTime.GetTime(),length);
GFSortEntry *e = new GFSortEntry(path,t,length);
if (t>maxFileTime) maxFileTime = t;
if (!e) break;
if (!Add(e)) break;
}
}
finder.Close();
//TRACE("%ld bytes \n",(long)fileSum);
return TRUE;
}
示例11: RemoveFiles
// recursively remove a file branch
gbool GUrlCache::RemoveFiles(const char *directory,time_t olderThan)
{
CFileFind finder;
CString dir = directory;
// add separator
int l = dir.GetLength();
if (l == 0) return FALSE;
if ( !((dir[l-1] == '\\') || (dir[l-1] == '/'))) dir += '\\';
dir += "*.*";
CString path;
CTime creationTime((time_t)0);
CTime accessTime((time_t)0);
CTime writeTime((time_t)0);
// setup the find structure
BOOL bWorking = finder.FindFile(dir);
LONGLONG fileSum=0;
while (bWorking) { // for all entrys
if (stop) break;
bWorking = finder.FindNextFile();
path = finder.GetFilePath();
creationTime = (time_t)0;
accessTime = (time_t)0;
writeTime = (time_t)0;
BOOL ret=finder.GetCreationTime(creationTime);
finder.GetLastAccessTime(accessTime);
finder.GetLastWriteTime(writeTime);
time_t t = creationTime.GetTime();
// if (accessTime.GetTime()>0) t = max(t,accessTime.GetTime());
if (finder.IsDots( )) { // ignore . ..
} else if (finder.IsDirectory( )) { // recursively step down
RemoveFiles(path,olderThan);
RemoveDirectory(path);
}
else {
DWORD length = finder.GetLength();
TRACE("F %s c %ld a %ld w %ld size %ld \n",(const char *) path, creationTime.GetTime(),accessTime.GetTime(),writeTime.GetTime(),length);
if (olderThan >0 ) {
if (t < olderThan) {
if (RemoveFile(path))
fileSum += length;
}
} else {
if (RemoveFile(path))
fileSum += length;
}
}
}
finder.Close();
TRACE("%ld bytes deleted \n",(long) fileSum);
return TRUE;
}
示例12: ExcludeTag
//***************************************************************************************
static BOOL ExcludeTag (CString& strBuffer,
LPCTSTR lpszTag,
CString& strTag)
{
const int iBufLen = strBuffer.GetLength ();
CString strTagStart = _T("<");
strTagStart += lpszTag;
strTagStart += _T(">");
const int iTagStartLen = strTagStart.GetLength ();
int iStart = -1;
int iIndexStart = strBuffer.Find (strTagStart);
if (iIndexStart < 0)
{
return FALSE;
}
iStart = iIndexStart + iTagStartLen;
CString strTagEnd = _T("</");
strTagEnd += lpszTag;
strTagEnd += _T('>');
const int iTagEndLen = strTagEnd.GetLength ();
int iIndexEnd = -1;
int nBalanse = 1;
for (int i = iStart; i < iBufLen - iTagEndLen + 1; i ++)
{
if (strBuffer [i] != '<')
{
continue;
}
if (i < iBufLen - iTagStartLen &&
_tcsncmp (strBuffer.Mid (i), strTagStart, iTagStartLen) == 0)
{
i += iTagStartLen - 1;
nBalanse ++;
continue;
}
if (_tcsncmp (strBuffer.Mid (i), strTagEnd, iTagEndLen) == 0)
{
nBalanse --;
if (nBalanse == 0)
{
iIndexEnd = i;
break;
}
i += iTagEndLen - 1;
}
}
if (iIndexEnd == -1 || iStart > iIndexEnd)
{
return FALSE;
}
strTag = strBuffer.Mid (iStart, iIndexEnd - iStart);
strTag.TrimLeft ();
strTag.TrimRight ();
strBuffer.Delete (iIndexStart, iIndexEnd + iTagEndLen - iIndexStart);
return TRUE;
}
示例13: ReadFromBuffer
//***************************************************************************************
BOOL CBCGPXMLNode::ReadFromBuffer (CString& strBuffer)
{
m_strValue.Empty ();
while (!m_lstChildren.IsEmpty ())
{
delete m_lstChildren.RemoveHead ();
}
if (strBuffer [0] != '<')
{
ASSERT(FALSE);
return FALSE;
}
int iTagEnd = strBuffer.Find ('>');
if (iTagEnd < 0)
{
ASSERT(FALSE);
return FALSE;
}
m_strName = strBuffer.Mid (1, iTagEnd - 1);
CString strTag;
if (!ExcludeTag (strBuffer, m_strName, strTag))
{
ASSERT (FALSE);
return FALSE;
}
if (strTag.IsEmpty ())
{
return TRUE;
}
if (strTag [0] == '\"')
{
ASSERT (strTag [strTag.GetLength () - 1] == '\"');
m_strValue = strTag.Mid (1, strTag.GetLength () - 2);
return TRUE;
}
if (strTag [0] != '<')
{
ASSERT(FALSE);
return FALSE;
}
while (!strTag.IsEmpty ())
{
CBCGPXMLNode* pChild = new CBCGPXMLNode;
if (!pChild->ReadFromBuffer (strTag))
{
delete pChild;
return FALSE;
}
AddChild (pChild);
}
return TRUE;
}
示例14: StartRedirect
void CRedirectHTTP_Thread::StartRedirect()
{ m_sServerSocket=INVALID_SOCKET; m_iConnections=0;
int iErr=1; bool bFinished=false; while(!bFinished) {
url uURL; char szBuffer[MAX_PATH]; bool bGet=false;
// Receive the proxy request
if(!recv_line_irc(m_sClientSocket, szBuffer, MAX_PATH, NULL)) { bFinished=true; break; }
CString sBuffer(szBuffer);
// Fail if there is no url
// if(!sBuffer.Token(1, " ").Compare("")) { bFinished=true; break; }
if(!sBuffer.Compare("")) { bFinished=true; break; }
if(!sBuffer.Token(0, " ").CompareNoCase("GET")) { // GET method
bGet=true;
// Parse the url
if(!ParseURL(sBuffer.Token(1, " ").CStr(), &uURL)) { bFinished=true; break; }
// Fail if the protocol isnt http
if(uURL.sProto.Compare("http")) { bFinished=true; break; }
} else if(!sBuffer.Token(0, " ").CompareNoCase("CONNECT")) { // CONNECT method
bGet=false;
// Parse the host
uURL.sProto.Assign("connect");
uURL.sReq.Assign("");
uURL.sHost.Assign(sBuffer.Token(1, " ").Token(0, ":"));
if(!sBuffer.Token(1, " ").Token(1, ":").CStr()) { bFinished=true; break; }
uURL.iPort=atoi(sBuffer.Token(1, " ").Token(1, ":").CStr());
if(!uURL.iPort) uURL.iPort=80; }
// Get the rest of the request
CString sMethod(sBuffer.Token(0, " ")); if(!sMethod.Compare("")) { bFinished=true; break; }
CString sHTTPVer(sBuffer.Token(2, " ")); if(!sHTTPVer.Compare("")) { bFinished=true; break; }
CString sOldHost(uURL.sHost);
#ifdef DBGCONSOLE
if(bGet)
g_cMainCtrl.m_cConsDbg.Log(5, "CRedirectHTTP(0x%8.8Xh): %s %s %s...\n", m_pRedirHTTP, sMethod.CStr(), uURL.sReq.CStr(), sHTTPVer.CStr());
else
g_cMainCtrl.m_cConsDbg.Log(5, "CRedirectHTTP(0x%8.8Xh): %s %s:%d %s...\n", m_pRedirHTTP, sMethod.CStr(), uURL.sHost.CStr(), uURL.iPort, sHTTPVer.CStr());
#endif
char szBuf[4096]; strcpy(szBuf, "bla");
if(bGet) {
if(xRead(m_sClientSocket, szBuf, sizeof(szBuf))<1)
{ xClose(m_sClientSocket); return; }
} else {
while(strcmp(szBuf, "")) // Loop while headers arent finished
if(!recv_line_irc(m_sClientSocket, szBuf, 4096, NULL)) { bFinished=true; break; }
if(bFinished) break; }
CString sReqBuf;
if(bGet)
sReqBuf.Format("%s %s %s\r\n%s", sMethod.CStr(), uURL.sReq.CStr(), sHTTPVer.CStr(), szBuf);
else
sReqBuf.Format("HTTP/1.0 200 Connection established\r\n\r\n");
m_sServerSocket=socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if(m_sServerSocket==SOCKET_ERROR || m_sServerSocket==INVALID_SOCKET)
{ xClose(m_sClientSocket); return; }
// Fill in sockaddr and resolve the host
sockaddr_in ssin; memset(&ssin, 0, sizeof(ssin));
ssin.sin_family=AF_INET; ssin.sin_port=htons(uURL.iPort);
ssin.sin_addr.s_addr=ResolveAddress(uURL.sHost.CStr());
if(ssin.sin_addr.s_addr==INADDR_NONE) // The host couldn't be resolved, exit
{
#ifdef DBGCONSOLE
g_cMainCtrl.m_cConsDbg.Log(5, "CRedirectHTTP(0x%8.8Xh): %s could not be resolved (%s)...\n", m_pRedirHTTP, uURL.sHost.CStr(), uURL.sReq.CStr());
#endif
xClose(m_sClientSocket); xClose(m_sServerSocket); return; }
// Connect to the server
iErr=connect(m_sServerSocket, (sockaddr*)&ssin, sizeof(sockaddr_in));
if(iErr==SOCKET_ERROR) // Connect failed, exit
{
#ifdef DBGCONSOLE
g_cMainCtrl.m_cConsDbg.Log(5, "CRedirectHTTP(0x%8.8Xh): Cannot connect to %s:%d (%s)...\n", m_pRedirHTTP, uURL.sHost.CStr(), uURL.iPort, uURL.sReq.CStr());
#endif
xClose(m_sClientSocket); xClose(m_sServerSocket); return; }
if(bGet) {
iErr=xWrite(m_sServerSocket, sReqBuf.CStr(), sReqBuf.GetLength());
if(!iErr || iErr==SOCKET_ERROR) { xClose(m_sClientSocket); xClose(m_sServerSocket); return; }
} else {
iErr=xWrite(m_sClientSocket, sReqBuf.CStr(), sReqBuf.GetLength());
if(!iErr || iErr==SOCKET_ERROR) { xClose(m_sClientSocket); xClose(m_sServerSocket); return; }
}
int iLen; fd_set fd;
SET_SOCK_BLOCK(m_sClientSocket, 0); SET_SOCK_BLOCK(m_sServerSocket, 0);
if(bGet) {
while(true)
{ memset(szBuffer, 0, sizeof(szBuffer));
if(!recv_line_irc(m_sClientSocket, szBuffer, sizeof(szBuffer), NULL)) { Sleep(10); break; }
if(strcmp(szBuffer, "")) {
sBuffer.Assign(szBuffer);
if(!sBuffer.Token(0, " ").Compare("GET"))
{ // Fail if there is no url
if(!sBuffer.Token(1, " ").Compare("")) { bFinished=true; break; }
//.........这里部分代码省略.........
示例15: DrawItem
void CHSShadeButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
ASSERT (lpDrawItemStruct);
//TRACE("* Captured: %08X\n", ::GetCapture());
//Check if the button state in not in inconsistent mode...
POINT mouse_position;
if ((m_button_down) && (::GetCapture() == m_hWnd) && (::GetCursorPos(&mouse_position)))
{
if (::WindowFromPoint(mouse_position) == m_hWnd)
{
if ((GetState() & BST_PUSHED) != BST_PUSHED)
{
//TRACE("* Inconsistency up detected! Fixing.\n");
SetState(TRUE);
return;
}
}
else
{
if ((GetState() & BST_PUSHED) == BST_PUSHED)
{
//TRACE("* Inconsistency up detected! Fixing.\n");
SetState(FALSE);
return;
}
}
}
//TRACE("* Drawing: %08x\n", lpDrawItemStruct->itemState);
CString sCaption;
TEXTMETRIC tm;
CDC *pDC = CDC::FromHandle(lpDrawItemStruct->hDC); // get device context
RECT r = lpDrawItemStruct->rcItem; // context rectangle
int cx = r.right - r.left ; // get width
int cy = r.bottom - r.top ; // get height
GetWindowText(sCaption); // get button text
pDC->SetBkMode(TRANSPARENT);
pDC->SelectObject(GetStockObject(DEFAULT_GUI_FONT)); //get text font
pDC->GetTextMetrics(&tm); // get font metrics
// get top-left corner to draw the text centered on the button
int tx = (cx-tm.tmAveCharWidth*sCaption.GetLength())/2;
int ty = (cy-tm.tmHeight)/2;
// Select the correct skin
if (lpDrawItemStruct->itemState & ODS_DISABLED)
{
Draw(pDC->GetSafeHdc(),r);
// if needed, draw the standard 3D rectangular border
if (m_Border) pDC->DrawEdge(&r,EDGE_RAISED,BF_RECT);
// paint the etched button text
pDC->SetTextColor(GetSysColor(COLOR_3DHILIGHT));
pDC->DrawText(sCaption,&r,DT_CENTER|DT_SINGLELINE|DT_VCENTER);
//pDC->ExtTextOut(tx+1,ty+1,ETO_CLIPPED,&r,sCaption,NULL);
pDC->SetTextColor(GetSysColor(COLOR_GRAYTEXT));
pDC->DrawText(sCaption,&r,DT_CENTER|DT_SINGLELINE|DT_VCENTER);
//pDC->ExtTextOut(tx,ty,ETO_CLIPPED,&r,sCaption,NULL);
}
else
{
if (lpDrawItemStruct->itemState & ODS_SELECTED)
{
Draw(pDC->GetSafeHdc(),r);
// if needed, draw the standard 3D rectangular border
if (m_Border)
pDC->DrawEdge(&r,EDGE_SUNKEN,BF_RECT);
}
else
{
Draw(pDC->GetSafeHdc(),r,m_tracking);
// if needed, draw the standard 3D rectangular border
if (m_Border)
{
if (lpDrawItemStruct->itemState & ODS_DEFAULT)
{
pDC->DrawEdge(&r,EDGE_SUNKEN,BF_RECT);
r.left += 1;
r.top += 1;
r.right -= 1;
r.bottom -= 1;
pDC->DrawEdge(&r,EDGE_RAISED,BF_RECT);
}
else
{
pDC->DrawEdge(&r,EDGE_RAISED,BF_RECT);
}
}
}
if ((lpDrawItemStruct->itemState & ODS_FOCUS) /*&& (m_FocusRectMargin > 0)*/)
{
Draw(pDC->GetSafeHdc(),r,2);
}
//.........这里部分代码省略.........