VOID FileLockThread::Run() { StartWatchingLocalDrives(); HANDLE waitHandles[] = { m_StartStopEvent, changes.GetWaitHandle() }; while (!isTerminate) { DWORD rc = ::WaitForMultipleObjectsEx(_countof(waitHandles), waitHandles, FALSE, INFINITE, true); switch (rc) { case WAIT_OBJECT_0 + 0: // Termination signal m_StartStopEvent.ResetEvent(); break; case WAIT_OBJECT_0 + 1: // Change notification { DWORD dwAction; CStringW wstrFilename; wstrFilename.Empty(); if (changes.CheckOverflow()) AfxMessageBox(L"Queue overflowed.\n"); else { changes.Pop(dwAction, wstrFilename); PushPathToImageProcessThread(wstrFilename); } // signal to main thread(UI) to add additional file path to list control break; } case WAIT_IO_COMPLETION: break; } } isTerminate = false; }
void File::ParseTypes(InputStream& s, CAtlList<CStringW>& types) { types.RemoveAll(); CStringW str; for(int c = s.SkipWhiteSpace(); iswcsym(c) || c == '.' || c == '@'; c = s.PeekChar()) { c = s.GetChar(); if(c == '.') { if(str.IsEmpty()) s.ThrowError(_T("'type' cannot be an empty string")); if(!iswcsym(s.PeekChar())) s.ThrowError(_T("unexpected dot after type '%s'"), CString(str)); types.AddTail(str); str.Empty(); } else { if(str.IsEmpty() && iswdigit(c)) s.ThrowError(_T("'type' cannot start with a number")); if((!str.IsEmpty() || !types.IsEmpty()) && c == '@') s.ThrowError(_T("unexpected @ in 'type'")); str += (WCHAR)c; } } if(!str.IsEmpty()) { types.AddTail(str); } }
void CShortcut::FormatKeyLabel(VirtualKeyName* pVirtualKeyNames,BYTE bKey,BYTE bModifiers,BOOL bScancode,CStringW& str) { if (bKey==0) { str.LoadString(IDS_SHORTCUTNONE); return; } // Formatting modifiers if (bModifiers&MOD_WIN) str.LoadString(IDS_SHORTCUTMODEXT); else str.Empty(); if (bModifiers&MOD_CONTROL) str.AddString(IDS_SHORTCUTMODCTRL); if (bModifiers&MOD_ALT) str.AddString(IDS_SHORTCUTMODALT); if (bModifiers&MOD_SHIFT) str.AddString(IDS_SHORTCUTMODSHIFT); if (bScancode) { CStringW str2; str2.Format(IDS_SHORTCUTSCANCODE,(int)bKey); str << str2; return; } int i; for (i=0;pVirtualKeyNames[i].bKey!=0 && pVirtualKeyNames[i].bKey!=bKey;i++); if (pVirtualKeyNames[i].iFriendlyNameId!=0) { str.AddString(pVirtualKeyNames[i].iFriendlyNameId); return; } BYTE pKeyState[256]; ZeroMemory(pKeyState,256); WORD wChar; int nRet=ToAscii(bKey,0,pKeyState,&wChar,0); if (nRet==1) { MakeUpper((LPSTR)&wChar,1); str << char(wChar); } else if (nRet==2) { MakeUpper((LPSTR)&wChar,2); str << (LPSTR(&wChar))[0] << (LPSTR(&wChar))[0]; } else if (pVirtualKeyNames[i].pName!=NULL) str << pVirtualKeyNames[i].pName; else str << (int) bKey; }
void File::ParseName(InputStream& s, CStringW& name) { name.Empty(); for(int c = s.SkipWhiteSpace(); iswcsym(c); c = s.PeekChar()) { if(name.IsEmpty() && iswdigit(c)) s.ThrowError(_T("'name' cannot start with a number")); name += (WCHAR)s.GetChar(); } }
BOOL CRegKey::QueryValue(LPCWSTR lpszValueName,CStringW& strData) const { if (!IsUnicodeSystem()) { CString strA; if (QueryValue(W2A(lpszValueName),strA)) { strData=strA; return TRUE; } return FALSE; } DWORD dwLength=0; DWORD dwType=REG_SZ; if (::RegQueryValueExW(m_hKey,lpszValueName,NULL,&dwType,NULL,&dwLength)!=ERROR_SUCCESS) { strData.Empty(); return FALSE; } if (dwType!=REG_SZ && dwType!=REG_EXPAND_SZ) { strData.Empty(); return FALSE; } if (dwLength<=1) { strData.Empty(); return TRUE; } if (::RegQueryValueExW(m_hKey,lpszValueName,NULL,NULL,(LPBYTE)strData.GetBuffer(dwLength/2-1),&dwLength)!=ERROR_SUCCESS) { strData.Empty(); return FALSE; } return TRUE; }
void MakeReverse() { CStringW strTmp; CStringW::iterator iter; iter = this->end(); iter--; for(; iter != this->begin(); iter--) { strTmp += *iter; } strTmp += *iter; *this = strTmp; strTmp.Empty(); }
BOOL CListCtrl::GetItemText(CStringW& str,int nItem, int nSubItem) const { LV_ITEMW li; li.mask=LVIF_TEXT; li.iItem=nItem; li.iSubItem=nSubItem; li.pszText=str.GetBuffer(1000); li.cchTextMax=1000; int nRet=(int)::SendMessage(m_hWnd,LVM_GETITEMTEXTW,nItem,(LPARAM)&li); if (nRet>0) str.FreeExtra(nRet); else str.Empty(); return nRet>0; }
LPCWSTR StringUTF8ToWChar(LPCSTR sUTF8, CStringW &sWChar, int iChars/* = -1*/) { if (!sUTF8) return NULL; sWChar.Empty(); int iLen = MultiByteToWideChar(CP_UTF8, 0, sUTF8, iChars, NULL, 0); if (iLen > 0) { LPWSTR sBuf = sWChar.GetBufferSetLength(iLen); iLen = MultiByteToWideChar(CP_UTF8, 0, sUTF8, iChars, sBuf, iLen); sWChar.ReleaseBufferSetLength(sBuf[iLen - 1] ? iLen : iLen - 1); return (iLen > 0) ? sWChar.GetString() : NULL; } return *sUTF8 != 0 ? sWChar.GetString() : NULL; }
LPCWSTR StringCharToWChar(LPCSTR sChar, CStringW &sWChar, int iChars/* = -1*/, UINT codepage/* = CP_ACP*/) { if (!sChar) return NULL; sWChar.Empty(); int iLen = MultiByteToWideChar(codepage, 0, sChar, iChars, NULL, 0); if (iLen > 0) { LPWSTR sBuf = sWChar.GetBufferSetLength(iLen); MultiByteToWideChar(codepage, 0, sChar, iChars, sBuf, iLen); sWChar.ReleaseBufferSetLength(sBuf[iLen - 1] ? iLen : iLen - 1); return (iLen > 0) ? sWChar.GetString() : NULL; } return (*sChar != 0) ? sWChar.GetString() : NULL; }
bool SourceEdit::GetNextLine(const CStringW& text, CStringW& line, int& i) { if (i == text.GetLength()) { // If at the very end, the final line must be blank line = ""; i++; return true; } else if (i > text.GetLength()) { // Past the end of the text, so stop reading lines return false; } line.Empty(); while (i < text.GetLength()) { WCHAR c = text.GetAt(i); i++; switch (c) { case L'\r': // Check for a "\r\n" sequence if (i < text.GetLength()) { if (text.GetAt(i) == L'\n') i++; } return true; case L'\n': return true; default: line.AppendChar(c); break; } } // Having got here a line must have ended without a trailing carriage return, // so move beyond the end of text to make sure this is the last line. i++; return true; }
//******************************************************************* void CBCGKeyHelper::Format (CStringW& str) const { str.Empty (); if (m_lpAccel == NULL) { ASSERT (FALSE); return; } if (m_lpAccel->fVirt & FCONTROL) { //AddVirtKeyStr (str, VK_CONTROL); str += _T("Ctrl+"); } if (m_lpAccel->fVirt & FSHIFT) { //AddVirtKeyStr (str, VK_SHIFT); str += _T("Shift+"); } if (m_lpAccel->fVirt & FALT) { //AddVirtKeyStr (str, VK_MENU); str += _T("Alt+"); } if (m_lpAccel->fVirt & FVIRTKEY) { TCHAR keyname[64]; UINT vkey = MapVirtualKey(m_lpAccel->key, 0)<<16; GetKeyNameText(vkey, keyname, sizeof(keyname)); str += keyname; } else if (m_lpAccel->key != 27) // Don't print esc { str += (char) m_lpAccel->key; } }
void GenTextFromPat(const STRARRAY &Pat, const STRARRAY &Var, CStringW &strOut) { if (!Pat.empty() || Pat.size() % 2 != 1) { strOut.Empty(); STRARRAY::const_iterator i = Pat.begin(); strOut.Append(*i++); for (; i != Pat.end(); ++i) { BOOL bFile = FALSE; CStringW strCurVar = *i; if (strCurVar[0] == _T('f') || strCurVar[0] == _T('F')) { bFile = TRUE; strCurVar.Delete(0, 1); } UINT nNum = atoi(CStringA(strCurVar)); if (nNum < Var.size()) { if (bFile) { CStringW strFile; if (0 == LoadTextFile(CString(Var[nNum]), CODEPAGE_GB2312, strFile)) { strOut.Append(strFile); } } else { strOut.Append(Var[nNum]); } } strOut.Append(*++i); } } }
HRESULT ProfileInfo::Read() { HRESULT hr = S_OK; LFile profileFile(m_csFilename); if (!profileFile.Exists()) hr = E_PM_FILE_NOTEXIST; if (SUCCEEDED(hr)) { LURESULT lr = profileFile.Open(); if (lr == LFILE_ERR_OPEN || lr == LFILE_ERR_ALREADY_OPEN) hr = E_PM_FILE_OPEN; } if (SUCCEEDED(hr)) { LBuffer fileBuffer(256); DWORD dwBytesRead; CStringW csLine; UINT uiLinesRead = 0; // Read BOM (first 2 bytes) LURESULT lr = profileFile.ReadRaw(&fileBuffer, 0, 2, &dwBytesRead); if (lr != S_OK) hr = E_PM_FILE_READ; bool bFirstBlock = true; if (SUCCEEDED(hr)) { do { lr = profileFile.ReadRaw(&fileBuffer, 0, fileBuffer.GetSize(), &dwBytesRead); if (lr != S_OK) hr = E_PM_FILE_READ; if (SUCCEEDED(hr) && bFirstBlock) { WCHAR *pIdent = (WCHAR *)fileBuffer.GetBuffer(); if (wcsncmp(pIdent, L"lpp_", 4) != 0) hr = E_PM_WRONG_FORMAT; bFirstBlock = false; } if (SUCCEEDED(hr)) { WCHAR *pBuffer = (WCHAR *)fileBuffer.GetBuffer(); UINT dwCharsRead = dwBytesRead / sizeof(WCHAR); for (int i = 0; i < dwCharsRead; ++i) { if (pBuffer[i] == L'\n') { CString csKey; CString csValue; //Ignore lines which begins with % or # if (csLine[0] != L'%' && csLine[0] != L'#') { int iBlankPos = csLine.Find(L'='); if (iBlankPos >= 0) { #ifdef _UNICODE csKey = csLine.Left(iBlankPos); csValue = csLine.Right(csLine.GetLength() - (iBlankPos+1)); #else CStringW csKeyW = csLine.Left(iBlankPos); int nLen = csKeyW.GetLength(); char *szRet = new char[nLen + 1]; WideCharToMultiByte(CP_ACP, 0, csKeyW, -1, szRet, nLen + 1, NULL, NULL); csKey = szRet; delete szRet; CStringW csValueW = csLine.Right(csLine.GetLength() - (iBlankPos+1)); nLen = csValueW.GetLength(); szRet = new char[nLen + 1]; WideCharToMultiByte(CP_ACP, 0, csValueW, -1, szRet, nLen + 1, NULL, NULL); csValue = szRet; delete szRet; #endif if (csKey == _T("lpp_id")) { m_iProfileID = _ttoi64((LPCTSTR)csValue); } else if (csKey == _T("lpp_version")) { m_iProfileVersion = _ttoi((LPCTSTR)csValue); } else if (csKey == _T("lpp_title")) { m_csTitle = csValue; } else if (csKey == _T("lpp_type")) { m_iProfileType = _ttoi((LPCTSTR)csValue); } else { m_aKeys.Add(csKey); m_aValues.Add(csValue); } } } csLine.Empty(); } else { csLine += pBuffer[i]; } } } } while (dwBytesRead == fileBuffer.GetSize()); } profileFile.Close(); } ExtractTargetFormat(); ExtractStorageDistribution(); return hr; }