/////////////////////////////////////////////////////////////////////////////// // DisplayStringToFCOName /////////////////////////////////////////////////////////////////////////////// bool cFSNameTranslator::DisplayStringToFCOName( const TSTRING& strC, cFCOName& name ) const { TSTRING str = strC; const TCHAR dq = _T('\"'); // do a little error checking. must have at least '""' if( str.size() < 1 ) return false; if( dq != str[0] ) return false; if( dq != str[str.size() - 1] ) return false; // get rid of beginning and trailing quote str = str.substr( 1, str.size() - 2 ); // // undo funky wide char encoding // cDisplayEncoder e( cDisplayEncoder::ROUNDTRIP ); if( ! e.Decode( str ) ) return false; // give to cFCOName name = str; return true; }
///////////////////////////////////////////////////////////////////////// // Function name : util_TrailingSep // Description : ensure that a path ( fLeaveSep ? "has" : "does not have" ) a trailing slash // // Return type : bool : was there a trailing slash? // Argument : TSTRING& str // Argument : bool fLeaveSep ///////////////////////////////////////////////////////////////////////////////// bool util_TrailingSep(TSTRING& str, bool fLeaveSep) { bool fWasSep = false; // if there's a trailing sep if (!str.empty() && str[str.size() - 1] == TW_SLASH) { if (!fLeaveSep) str.resize(str.size() - 1); fWasSep = true; } else // else no trailing sep { if (fLeaveSep) str += TW_SLASH; fWasSep = false; } return (fWasSep); }
unsigned __stdcall _OpFileMoveThread(void *pVoid) { OPERATIONSTRUCT os = *reinterpret_cast<POPERATIONSTRUCT>(pVoid); OPCALLBACKDATA ocd; TSTRINGLISTIT it = os.Files.begin(); UINT uiCurFile = 1U; bool bAskOverwrite = true; BOOL bCancelOp = FALSE; TSTRING tsTemp; /* * If the destination directory is invalid, * it's probably been moved, or renamed * since its association with the application. * Prompt the user to see if they'd like to * create it, or abort. */ if (FALSE == PathIsDirectory(os.tsDest.c_str())) { INT_PTR iChoice = PrintMsgBox(os.hWnd, _T("extFileCopy") _T(" : Directory not found"), MB_YESNO | MB_ICONWARNING, _T("The destination directory:\n\n") _T("%s\n\nhas either been moved") _T(" or renamed since its association") _T(" with extFileCopy. Would you like") _T(" to create it?"), os.tsDest.c_str()); switch (iChoice) { case IDYES: { /* * Attempt to create the directory. */ if (FALSE == CreateDirectory(os.tsDest.c_str(), NULL)) { /* * We've failed miserably. * Can't copy any files to a non-existant * directory; done. */ PrintMsgBox(os.hWnd, _T("extFileCopy : ERROR"), MB_OK | MB_ICONSTOP, _T("An error occurred while attempting") _T(" to create the directory:\n\n%s.\n\n") _T("The directory will be disassociated with") _T("extFileCopy.\n\n") _T("Win32 error: %d"), os.tsDest.c_str(), GetLastError()); RegUtil_RemAssociatedDirectory(ExtensionFromList(os.Files), os.tsDest); goto mtFinish; } } break; case IDNO: { /* * User doesn't want to bother creating * the directory; We have to remove * the association in the registry. */ PrintMsgBox(os.hWnd, _T("extFileCopy : Removing association"), MB_OK | MB_ICONWARNING, _T("The inaccessible directory:\n\n%s\n\nwill now") _T(" be disassociated with extFileCopy."), os.tsDest.c_str()); RegUtil_RemAssociatedDirectory(ExtensionFromList(os.Files), os.tsDest); goto mtFinish; } break; } } os.pDlg->SetCancelPtr(&bCancelOp); /* * Set up the dialog UI */ if (os.bCopy) { os.pDlg->SetWindowText(_T("Copying ...")); } else { os.pDlg->SetWindowText(_T("Moving ...")); } os.pDlg->SetElapsedTime(0); for(; it != os.Files.end(); it++) { /* * Check if the operation was cancelled * by the user */ os.pMutex->Lock(); if (TRUE == bCancelOp) { os.pMutex->Unlock(); goto mtFinish; } os.pMutex->Unlock(); /* * Update overall progress */ INT64 iOverallPct = ((uiCurFile * 100) / os.Files.size()); sprintf(tsTemp, _T("Overall Progress (file %d of %d) : %I64d%%"), uiCurFile++, os.Files.size(), iOverallPct); os.pDlg->SetOverallProgress(iOverallPct, tsTemp); /* * Update current file name */ TSTRING tsShortFile = GetFileFromPath((*it)); TSTRING tsDisplay = tsShortFile; /* * Truncate file name if necessary */ tsDisplay = FileGetCompactName(tsDisplay, PD_MAXCURFILE); sprintf(tsTemp, _T("Current file '%s' : %I64d%%"), tsDisplay.c_str(), 0LL); os.pDlg->SetCurrentProgress(0, tsTemp); /* * Reset transfer rate */ os.pDlg->SetTransferRate(_T("Transfer Rate: calculating...")); /* * If the resulting destination path is > MAX_PATH, * we've got to skip this file and tell the user. */ TSTRING tsDest = PathConcatFile(os.tsDest, tsShortFile); if (MAX_PATH < tsDest.size()) { PrintMsgBox(os.hWnd, _T("extFileCopy : Can't copy file"), MB_OK | MB_ICONWARNING, _T("The following destination path:\n\n") _T("%s\n\nis longer than MAX_PATH characters, and") _T(" cannot be created."), tsDest.c_str()); continue; } /* * Make sure the file doesn't exist; if it does, * we've got to prompt the user to overwrite. */ if (-1 != GetFileAttributes(tsDest.c_str())) { /* * Yeah, the file exists. */ if (bAskOverwrite) { OverwriteDlg dlg((*it), tsDest, 1 < os.Files.size()); if (!dlg.DoModal(static_cast<HINSTANCE>(g_hModule), MAKEINTRESOURCE(IDD_OVERWRITE), os.pDlg->m_hWnd)) { MessageBox(os.pDlg->m_hWnd, _T("A fatal internal error has occurred. Cannot continue.\n"), _T("extFileCopy : ERROR"), MB_OK | MB_ICONSTOP); os.pDlg->CleanUp(); _endthreadex(1); } /* * Find out what the user chose */ switch (dlg.Result()) { case YES: /* * Ok to overwrite, but don't touch * bAskOverwrite. */ break; case YESTOALL: /* * Ok to overwrite ALL files. */ bAskOverwrite = false; break; case NO: /* * Don't overwrite this file; * instead skip to the next. */ continue; break; case CANCEL: /* * Forget it. We're outta here. */ os.pMutex->Lock(); bCancelOp = TRUE; os.pMutex->Unlock(); goto mtFinish; break; } } } /* * File doesn't exist, or we don't * really care. Continue normally */ TSTRING tsCurFile = FileGetCompactName(tsShortFile.c_str(), PD_MAXCURFILE); ocd.pbCancel = &bCancelOp; ocd.dwStartTime = (2 == uiCurFile) ? GetTickCount() : ocd.dwStartTime; ocd.dwLastTime = (2 == uiCurFile) ? ocd.dwStartTime : ocd.dwLastTime; ocd.dwLastRate = GetTickCount(); ocd.iLastPct = 0LL; ocd.iThroughput = 0LL; ocd.pDlg = os.pDlg; ocd.pMutex = os.pMutex; ocd.szCurFile = tsCurFile.c_str(); if (os.bCopy) { /* * This is a copy operation */ if (0 == CopyFileEx((*it).c_str(), tsDest.c_str(), _Callback, &ocd, &bCancelOp, 0UL)) { /* * The copy operation has failed! * Let's tell the user, and then * if there's more than one file * being copied, ask the user if * they'd like to continue with * the next file. (If the error * didn't result from user abortion) */ if (ERROR_REQUEST_ABORTED != GetLastError()) { INT_PTR iUser = ErrorPrompt(os.pDlg->m_hWnd, (*it), tsDest, (1 < os.Files.size()) ? true : false, os.bCopy); if (1 < os.Files.size()) { if (IDYES == iUser) { /* * User wishes to try the next file. */ continue; } else if (IDNO == iUser) { break; } } else { continue; } } } } else { /* * This is a move operation */ if (0 == MoveFileWithProgress((*it).c_str(), tsDest.c_str(), _Callback, &ocd, MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH)) { /* * The move operation has failed! * Let's tell the user, and then * if there's more than one file * being copied, ask the user if * they'd like to continue with * the next file. (If the error * didn't result from user abortion) */ if (ERROR_REQUEST_ABORTED != GetLastError()) { INT_PTR iUser = ErrorPrompt(os.pDlg->m_hWnd, (*it), tsDest, (1 < os.Files.size()) ? true : false, os.bCopy); if (1 < os.Files.size()) { if (IDYES == iUser) { /* * User wishes to try the next file. */ continue; } else if (IDNO == iUser) { break; } } else { continue; } } } } } mtFinish: os.pDlg->CleanUp(); _endthreadex(0U); return 0U; }
bool cFSParserUtil::IsAbsolutePath( const TSTRING& strPath ) const { // IF there's a first character AND it is ( '/' OR '\\' ), THEN it's absolute return( strPath.size() > 0 && ( _T('/') == strPath[0] || _T('\\') == strPath[0] ) ); }
bool cGenreParseInfo::DoVarSubstitution( TSTRING &rval ) //throw( eParserHelper ) { cDebug d("cConfigFile::DoVarSubst()"); d.TraceDebug("ORIG: %s\n", rval.c_str()); // walk through string // look for $( // find matching ) // pick out subset // look up in symbol table // substitute subset // continue iterating // step through string // iterate to (slen-1), because we are looking for a two-character sentinel "$(" bool fEscaping = false; for (TSTRING::size_type i = 0; i < rval.size(); i++) { TCHAR c = rval[i]; // is it the "$(" sentinel? (an escaped '$' is not a variable) if (c == '$' && ! fEscaping ) { c = rval[i+1]; if (c == '(') { // ooh, wow! it's a variable! find the end bool found = false; TSTRING::size_type j; for (j = i+1; j < rval.size(); j++) { if (rval[j] == ')') { found = true; break; } } // did we find it? if (!found) { // TODO: throw error return false; } // otherwise, cut out the variable name TSTRING::size_type begin = i + 2; TSTRING::size_type size = j - i - 2; TSTRING varname; varname = rval.substr(begin, size); d.TraceDebug("symbol = %s\n", varname.c_str()); // look up in symbol table TSTRING varvalue; if ( ! LookupVariable( varname, varvalue ) ) throw eParserUseUndefVar( varname ); // replace varname with varvalue rval.replace(begin-2, size+3, varvalue); d.TraceDebug("POST: %s\n", rval.c_str()); // no no no // we should exit function, and get called again // update counters // we should bump the cursor over by the length of the // varvalue (minus one, to compensate for post-increment of index) i += varvalue.size() - 1; goto nextchar; } } else if (c == '\\') { fEscaping = ! fEscaping; } else { fEscaping = false; } nextchar: ; } d.TraceDebug("DONE: %s\n", rval.c_str()); // switch around return true; }
/// <summary> /// <para name='Name'>ResolveDisplayName</para> /// <para name='Purpose'>Get an email address from a Display Name</para> /// </summary> /// <param name='szName'>Display Name to resolve</param> /// <param name='szEmailAddress'>[out] Returned email address</param> /// <returns>HRESULT</returns> /// <remarks> /// <para name='Notes'></para> /// <para name='Author'>Kenn Guilstorf</para> /// <para name='LastModified'>28Jan2016</para> /// </remarks> STDMETHODIMP ZybraxiSoft::CMailbox::ResolveDisplayName(TSTRING szName, TSTRING &szEmailAddress) { HRESULT hr = S_OK; LPADRBOOK lpAdrBook = NULL; LPADRLIST lpAdrList = NULL; TSTRING szEX = TSTRING(_T("EX")); bool isExchange = false; enum { prDISPLAY_NAME, NUM_PROPS }; // Check to make sure we have something in szName if (szName.empty() || szName.size() <= 0) { hr = MAPI_E_INVALID_PARAMETER; goto EXIT; } // Log what we're trying to resolve m_log << output::both << level::Informational << "Attempting to resolve '" << szName.c_str() << "'" << endl; // Open the address book // See: https://msdn.microsoft.com/en-us/library/office/cc815381.aspx if (SUCCEEDED(hr = m_lpSession->OpenAddressBook( NULL, // ulUIParam [may be NULL] NULL, // lpInterface [may be NULL; returns IAddrBook:IMAPIProp] NULL, // ulFlags [NULL means no flags] &lpAdrBook))) // lppAdrBook [out] { // Allocate the address list // Note: I like to use 'this' so I know which functions I'm responsible // for if I ever have to work on this... if (SUCCEEDED(hr = this->AllocAdrList( NUM_PROPS, &lpAdrList))) { // Even though we succeeded, do a check to make sure we have // an address list if (lpAdrList) { lpAdrList->cEntries = 1; // only looking for 1 entry lpAdrList->aEntries[0].cValues = NUM_PROPS; // Number of props // Set the SPropValue to whom we're looking for lpAdrList->aEntries[0].rgPropVals[prDISPLAY_NAME].ulPropTag = PR_DISPLAY_NAME; lpAdrList->aEntries[0].rgPropVals[prDISPLAY_NAME].Value.LPSZ = (LPTSTR)szName.c_str(); // Let's try to resolve the name now if (SUCCEEDED(hr = lpAdrBook->ResolveName( 0L, MAPI_UNICODE, NULL, lpAdrList))) { m_log << output::both << level::Informational << "Resolve name yielded " << lpAdrList->aEntries[0].cValues << " properties." << endl; for (UINT i = 0; i < lpAdrList->aEntries[0].cValues; i++) { // Store the property so I don't have to type so much... SPropValue spvCurrent = lpAdrList->aEntries[0].rgPropVals[i]; m_log << output::both << level::Informational << "Found Property '0x" << setfill(_T('0')) << setw(8) << setbase(16) << spvCurrent.ulPropTag << "'"; switch (spvCurrent.ulPropTag) { case PR_ADDRTYPE: if (szEX.compare(spvCurrent.Value.LPSZ) == 0) isExchange = true; break; case PR_DISPLAY_NAME: m_log << ": " << spvCurrent.Value.LPSZ; break; case PR_EMAIL_ADDRESS: m_log << ": " << spvCurrent.Value.LPSZ; szEmailAddress = TSTRING(spvCurrent.Value.LPSZ); break; default: if (((spvCurrent.ulPropTag & 0x1f) == 0x1f) || ((spvCurrent.ulPropTag & 0x1e) == 0x1e)) m_log << ": " << spvCurrent.Value.LPSZ; break; } m_log << endl; } if (!isExchange || (szEmailAddress.empty())) { hr = MAPI_E_NOT_FOUND; goto CLEANUP; } } else { FATAL(_T("lpAdrBook->ResolveName()"), hr); goto CLEANUP; } } } else { FATAL(_T("AllocAdrList()"), hr); goto CLEANUP; } } else { FATAL(_T("OpenAddressBook()"), hr); } CLEANUP: if (lpAdrList) { FreePadrlist(lpAdrList); lpAdrList = NULL; } if (lpAdrBook) { lpAdrBook->Release(); lpAdrBook = NULL; } EXIT: return hr; }