/** @param sFolder Folder to combine @param sPathname Path to combine (probably relative to sFolder) @param bAllowAbsoluteOverride true to allow sPathname to have an absolute path, false to make sure it's relative @return The combined path */ std::tstring ConcatPaths(const std::tstring& sFolder, const std::tstring& sPathname, bool bAllowAbsoluteOverride /* = true */) { // Do we have a folder? if (sFolder.empty()) // No, return the second part alone return sPathname; // Do we have a path? if (sPathname.empty()) // No, return the first part alone return sFolder; // Allow overriding paths by using a drive letter and colon (c:) or a UNC path (\\) if (bAllowAbsoluteOverride) if ((sPathname.size() > 2) && (sPathname[1] == ':') || ((sPathname[0] == '\\') && (sPathname[1] == '\\'))) return sPathname; std::tstring sRet = sFolder; // Make sure we have a slash at the end of the folder part CHAR c = sFolder[sFolder.size()-1]; if ((c != '\\') && (c != '/')) sRet += _T("\\"); // Make sure we don't have a slash at the beginning of the path part: c = sPathname[0]; if ((c == '\\') || (c == '/')) // We do, jump over it sRet += sPathname.substr(1); else // Just add them sRet += sPathname; return sRet; }
bool save_url(HANDLE hNetlib,const std::string &url,const std::tstring &filename) { NETLIBHTTPREQUEST req = {sizeof(req)}; req.requestType = REQUEST_GET; req.flags = NLHRF_HTTP11 | NLHRF_REDIRECT; req.szUrl = const_cast<char*>(url.c_str()); NETLIBHTTPREQUEST *resp = reinterpret_cast<NETLIBHTTPREQUEST*>(CallService(MS_NETLIB_HTTPTRANSACTION, reinterpret_cast<WPARAM>(hNetlib), reinterpret_cast<LPARAM>(&req))); if (resp) { bool success = (resp->resultCode == 200); if (success) { // Create folder if necessary std::tstring dir = filename.substr(0,filename.rfind('\\')); if( _taccess(dir.c_str(),0)) CreateDirectoryTreeT(dir.c_str()); // Write to file FILE *f = _tfopen(filename.c_str(), _T("wb")); fwrite(resp->pData,1,resp->dataLength,f); fclose(f); } CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT,0,(LPARAM)resp); return success; } else return false; }
IDispatchPtr FindLinkedEmail(IDispatchPtr spDispOutlook, IDispatchPtr spDispNameSpace, Workshare::Mail::Mapi::MapiSession& session, const std::tstring& sMessageId) { if(spDispOutlook == 0) throw Workshare::ArgumentNullException(_T("spDispOutlook"), _T("Outlook Application pointer is null.")); if(spDispNameSpace == 0) throw Workshare::ArgumentNullException(_T("spDispNameSpace"), _T("MAPI NameSpace pointer is null.")); if(sMessageId.empty()) throw Workshare::ArgumentException(_T("sMessageId"), _T("The message ID of the email to find was not specified.")); size_t pos = sMessageId.find(_T(';')); if(-1 == pos) throw Workshare::ArgumentException(_T("sMessageId"), _T("Invalid message ID (should be in format EntryId;SearchKey[;InternetId])")); std::tstring sEntryId = sMessageId.substr(0, pos); std::tstring sSearchKeyAndInternetId = sMessageId.substr(pos + 1); std::tstring sSearchKey; std::tstring sInternetId; pos = sSearchKeyAndInternetId.find(_T(';')); if(-1 != pos) { sSearchKey = sSearchKeyAndInternetId.substr(0, pos); sInternetId = sSearchKeyAndInternetId.substr(pos + 1); } else sSearchKey = sSearchKeyAndInternetId; Outlook::_ApplicationPtr spOutlook = spDispOutlook; Outlook::_NameSpacePtr spNameSpace = spDispNameSpace; IDispatchPtr spLinkedEmail; HRESULT hr = spNameSpace->raw_GetItemFromID(_bstr_t(sEntryId.c_str()), vtMissing, &spLinkedEmail); if(FAILED(hr)) { std::tstring sStoreId; Workshare::Mail::Mapi::FindItemBySearchKey(session, sSearchKey, sEntryId, sStoreId); _variant_t vtStoreId(sStoreId.c_str()); hr = spNameSpace->raw_GetItemFromID(_bstr_t(sEntryId.c_str()), vtStoreId, &spLinkedEmail); if(FAILED(hr)) throw Workshare::Com::ComException(_T("Outlook failed to open email"), hr, spNameSpace); //If this fails we could create a function FindItemByInternetId(session, sInternetId, sEntryId, sStoreId); } return spLinkedEmail; }
std::tstring GetFileExtension(const std::tstring& fileName) { size_t extensionPosition = fileName.rfind(_T('.')); if(0 < extensionPosition) return fileName.substr(extensionPosition + 1); return _T(""); }
std::tstring GetFilenameWithoutExtension(const std::tstring& fileName) { size_t extensionPosition = fileName.rfind(_T('.')); if(0 < extensionPosition) return fileName.substr(0, extensionPosition); return fileName; }
std::tstring NormalizedSubject(const std::tstring& subject) { #pragma warning(disable:4996) if(0 == _tcsnicmp(subject.c_str(), _T("Re: "), 4)) return subject.substr(4); #pragma warning(default:4996) return subject; }
bool facebook_client::save_url(const std::string &url,const std::tstring &filename, HANDLE &nlc) { NETLIBHTTPREQUEST req = {sizeof(req)}; NETLIBHTTPREQUEST *resp; req.requestType = REQUEST_GET; req.szUrl = const_cast<char*>(url.c_str()); req.flags = NLHRF_HTTP11 | NLHRF_REDIRECT | NLHRF_PERSISTENT | NLHRF_NODUMP; req.nlc = nlc; resp = reinterpret_cast<NETLIBHTTPREQUEST*>(CallService(MS_NETLIB_HTTPTRANSACTION, reinterpret_cast<WPARAM>(this->parent->m_hNetlibUser), reinterpret_cast<LPARAM>(&req))); bool ret = false; if (resp) { nlc = resp->nlc; parent->debugLogA("@@@@@ Saving avatar URL %s to path %s", url.c_str(), _T2A(filename.c_str())); // Create folder if necessary std::tstring dir = filename.substr(0,filename.rfind('\\')); if (_taccess(dir.c_str(), 0)) CreateDirectoryTreeT(dir.c_str()); // Write to file FILE *f = _tfopen(filename.c_str(), _T("wb")); if (f != NULL) { fwrite(resp->pData,1,resp->dataLength,f); fclose(f); ret = _taccess(filename.c_str(), 0) == 0; } CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)resp); } else { nlc = NULL; } return ret; }
ScriptComponent::ScriptComponent(const std::tstring& filename) { m_pScript = MyServiceLocator::GetInstance()->GetService<ResourceService>()->Load<LuaScript>(filename); auto slashIdx = filename.find_last_of(_T('/')); m_ShortFilename = TstringToString(filename.substr(slashIdx+1, filename.find_last_of(_T('.')) - slashIdx - 1)); }