void TestRelatingDocsForW3::TestRelateSynergyDocPutsItInDMSFolder() { LFSDMSHelper dmsHelper; assertTest(!dmsHelper.DoesDMSStructureExist(TEST_FILE)); LOCALFILESTORELib::IWSDocumentProvider2Ptr pDocProv; pDocProv.CreateInstance(_PROGID_LFSDocProvider); WSDOCUMENTPROVIDERLib::ISynergyDocumentRelatorPtr pRelator; pRelator = pDocProv; WSDOCUMENTPROVIDERLib::tagWSDOCUMENT wsDoc; ZeroMemory(&wsDoc, sizeof(wsDoc)); wsDoc.bstrLocalFile = ::SysAllocString(CStdStringW(TEST_FILE_TO_ATTACH)); wsDoc.bstrExtension = ::SysAllocString(L"FRG"); assertTest(pRelator->RelateSynergyDocument(&wsDoc, _bstr_t(TEST_DOCID)) == S_OK); assertTest(dmsHelper.DoesDMSStructureExist(TEST_FILE)); assertMessage(CGeneral::FileExists(SYNERGY_RELATION_PATTERN), _T("didn't put the relation in the .dms folder like it should")); WSDocCleaner::CleanWSDoc(wsDoc); assertTest(DMSHelper::GetTheDMSHelper().GetAllRelatedSynergyDocs(TEST_DOCID).size() == 1); }
void TestOnMappedNetworkDrives::TestGetStraightForwardID() { CStdString sMappedDriveLetter = m_NetDriveHelper.GetMapNetworkDriveLetter(); assertMessage(!sMappedDriveLetter.IsEmpty(), _T("Cannot map network drive - used to just skip test")); unsigned long ulSize = MAX_PATH; TCHAR szUserName[MAX_PATH + 1]; if (GetUserName((LPTSTR) &szUserName, &ulSize) == false) { assertMessage(0, _T("Unable to get user name")); } CStdString sLogedOnUser = szUserName; DocProviderWorker objWorker; CStdString sTemp; sTemp = sMappedDriveLetter + _T("\\") + TEST_DOC _T(".doc"); sTemp.Replace('\\', _T('/')); CStdString sDocID; sDocID = DocumentID::GetDocProviderId() + sTemp; WSDocNonCom wsDoc; HRESULT hr = objWorker.GetDocument(sDocID, DF_INFO_ONLY, wsDoc); assertTest(hr == S_OK); assertTest(wsDoc.GetDescription() == TEST_DOC); assertTest(wsDoc.GetDocId() == CStdStringW(sDocID)); assertTest(TestUtils::IsCorrectType(wsDoc.GetType())); assertTest(wsDoc.GetExtension() == _T("doc")); assertTest(wsDoc.GetOperator() == szUserName); }
void StreamFileReader::Read(CStdString sStreamName, int iOffset, int iCount, void* pData) { CComPtr<IStream> pStream; HRESULT hr = m_pRootStorage->OpenStream(CStdStringW(sStreamName), NULL, STGM_DIRECT|STGM_READ|STGM_SHARE_EXCLUSIVE, NULL, &pStream); if (FAILED(hr)) throw _com_error(hr); if (pStream==NULL) throw _com_error(E_FAIL); ULARGE_INTEGER ulPos; LARGE_INTEGER iSeek; iSeek.QuadPart = iOffset; hr = pStream->Seek(iSeek, STREAM_SEEK_SET, &ulPos); if (FAILED(hr)) throw _com_error(hr); if (ulPos.LowPart != iOffset) throw std::exception("Seek to position in stream failed - beyond end ?"); ULONG ulRead; hr = pStream->Read(pData, iCount, &ulRead); if (FAILED(hr)) throw _com_error(hr); if (ulRead != iCount) throw std::exception("Failed to read number of bytes requested from stream - asked for too many?"); }
int FacadeDocumentProviderImpl::CalculateFormatIndex(const std::wstring& formatString, std::wstring extension) { if (extension[0] == L'.') extension = extension.substr(1); std::wstring filter = L"*." + CStdStringW(extension).ToLower(); unsigned int iPos = (unsigned int) -1; int iIndex = 1; while (true) { iPos = (x64_int_cast)formatString.find(L"|", iPos+1); if (iPos == formatString.npos) return 1; int startPos = iPos; iPos = (x64_int_cast)formatString.find(L"|", iPos+1); if (iPos == formatString.npos) return 1; int endPos = iPos; std::wstring thisFormat = formatString.substr(startPos+1, endPos-startPos-1); if (thisFormat.find(filter) != thisFormat.npos) return iIndex; iIndex++; iPos++; } return 1; }
void FacadeDocumentProviderImpl::RelateDocument(WSDocNonCom& newDocument, const std::wstring& sExistingDocumentID) { Artifact artifact = GetArtifactByWorkshareId(sExistingDocumentID); Artifact related = artifact.CreateRelatedItem(newDocument.GetLocalFile(), CStdStringW(newDocument.GetExtension()), L"", false ); PopulateWSDocMembersFromArtifact(related, newDocument); newDocument.SetFlags(DOCUMENT_LOCKED_BY_US); related.Lock(); }
void TestCellInfo::TestConstruction() { ComparisonContext cContext; CCellInfo ci(1,3,5,7,L"cheesecake", true, 0); assertTest(ci.m_iX == 1); assertTest(ci.m_iY == 3); assertTest(ci.m_iXSize == 5); assertTest(ci.m_iYSize == 7); assertTest(CStdStringW(L"cheesecake") == ci.m_sCellText); assertTest(ci.m_bIsWhiteSpace); }
bool OfflineDataStore::IsVersionOfDocumentOffline(const CStdString& sDocID) { if(sDocID.IsEmpty()) return false; GetVersionList(sDocID); std::vector<WSDocumentVersionNoCom> vVersionList = GetVersionList(sDocID); if(vVersionList.size() == 0) return false; std::vector<WSDocumentVersionNoCom>::iterator itr; for(itr = vVersionList.begin(); itr != vVersionList.end(); itr++) { if(itr->GetWSDocument().GetDocId().CompareNoCase(CStdStringW(_T("offline://") + sDocID)) == 0) return true; } return false; }
void TestListCounter::TestLevelStartsAndRestarts() { RTFfile theFile(new RTFFileContext); AutoDocFileReaderImpl4Tests reader(GET_TEST_FILE_PATH(_T("nastylist.doc")), &theFile); reader.Read(); int i=1; assertMessage(NextParaHasListText(theFile, i, _T("4\t")), _T("ignored the start at 4 on the first list level")); assertMessage(NextParaHasListText(theFile, i, _T("4.6\t")), _T("ignored the start at 6 on the level override")); assertTest(NextParaHasListText(theFile, i, _T("4.7\t"))); assertTest(NextParaHasListText(theFile, i, _T("4.8\t"))); assertTest(NextParaHasListText(theFile, i, _T("5\t"))); assertMessage(NextParaHasListText(theFile, i, _T("5.9\t")), _T("ignored the no-restart flag on second level")); assertMessage(NextParaHasListText(theFile, i, _T("5.10\t")), _T("stepped incorrectly after non-restart")); assertMessage(NextParaHasListText(theFile, i, _T("5.11\t")), _T("stepped incorrectly after non-restart")); ListManager& mgr = reader.m_ListManager; assertTest(mgr.m_mapListCountersByListID[679622925] != 0); assertTest(mgr.m_mapListCountersByListID[679622925] == mgr.m_mapListCountersByName[CStdStringW(_T("cheese"))]); assertMessage(NextParaHasListText(theFile, i, _T("5.13\t")), _T("failed to spot that the listnum field should step the number")); assertMessage(NextParaHasListText(theFile, i, _T("5.13.1.19\t")), _T("failed to spot that the listnum field should restart the list")); }
wchar *GetExt(const wchar *Name) { CStdString strExtension; URIUtils::GetExtension(Name,strExtension); return((wchar *)wcsstr((wchar_t *)Name,CStdStringW(strExtension).c_str())); }
bool GameJoltAPI::SendRequest( CStdString &output, CStdString url ) { // The private key must be set to send a request. if ( m_GamePrivateKey == _T("") ) { m_ErrorMessage += _T("(You must put in your game's private key before you can use any of the API functions.)"); return false; } //////////////////////////////////// // Let's form the URL first. url = GJAPI_ROOT + GJAPI_VERSION + url; CStdString signature( md5( CStdStringA( _T("http://") + GJAPI_SERVER + url + m_GamePrivateKey ) ) ); url += _T("&signature=") + signature; // Now let's build the request. BOOL ret = FALSE; HINTERNET hSession = NULL; HINTERNET hConnect = NULL; HINTERNET hRequest = NULL; hSession = WinHttpOpen ( L"Game Jolt API Construct/1.0", WINHTTP_ACCESS_TYPE_DEFAULT_PROXY, WINHTTP_NO_PROXY_NAME, WINHTTP_NO_PROXY_BYPASS, 0 ); if ( hSession ) hConnect = WinHttpConnect ( hSession, CStdStringW( GJAPI_SERVER ), INTERNET_DEFAULT_PORT, 0 ); else m_ErrorMessage += _T("(Could not open HTTP session.)"); if ( hConnect ) hRequest = WinHttpOpenRequest ( hConnect, L"GET", CStdStringW( url ), NULL, WINHTTP_NO_REFERER, WINHTTP_DEFAULT_ACCEPT_TYPES, WINHTTP_FLAG_REFRESH ); else m_ErrorMessage += _T("(Could not connect to the HTTP session.)"); if ( hRequest ) ret = WinHttpSendRequest ( hRequest, WINHTTP_NO_ADDITIONAL_HEADERS, 0, WINHTTP_NO_REQUEST_DATA, 0, 0, 0 ); else m_ErrorMessage += _T("(Could not set up the HTTP request.)"); if ( ret ) ret = WinHttpReceiveResponse( hRequest, NULL ); else m_ErrorMessage += _T("(Could not send the HTTP request.)"); DWORD bufferSize = 0; DWORD outputDownloaded = 0; LPSTR outputBuffer = 0; // Keep checking for data until there is nothing left. if ( ret ) { do { // Check for available data. bufferSize = 0; WinHttpQueryDataAvailable( hRequest, &bufferSize ); // Allocate space for the buffer. outputBuffer = new char[bufferSize + 1]; if ( outputBuffer ) { // Read the data. ZeroMemory( outputBuffer, bufferSize + 1 ); if ( WinHttpReadData( hRequest, (LPVOID)outputBuffer, bufferSize, &outputDownloaded ) ) output += outputBuffer; // Free the memory allocated to the buffer. delete [] outputBuffer; } } while( bufferSize > 0 ); } else m_ErrorMessage += _T("(Did not get a response from the server.)"); if ( hRequest ) WinHttpCloseHandle( hRequest ); if ( hConnect ) WinHttpCloseHandle( hConnect ); if ( hSession ) WinHttpCloseHandle( hSession ); return true; }
HRESULT FacadeDocumentProviderImpl::GetSaveInfo(HWND hWnd, const std::wstring& formatString, long lFlags, long& lFormatIndex, WSDocNonCom& wsDoc) { //-- ArtifactImpl //TODO: Replace Existing Version //TODO: Create a relation //-- Connector // Create new artifact (Add Files) UNREFERENCED_PARAMETER(lFormatIndex); if(DF_NEW_DOCUMENT & lFlags) { std::wstring newFileName = wsDoc.GetDescription(); Artifact artifact = GetConnector().CreateArtifact(hWnd, formatString, newFileName); if (artifact.IsNull()) return E_DOCUMENT_NOT_FOUND; PopulateWSDocMembersFromArtifact(artifact, wsDoc); wsDoc.SetFlags(DOCUMENT_LOCKED_BY_US); lFormatIndex = CalculateFormatIndex(formatString, artifact.GetFileExtension()); artifact.Lock(); } // Create a relation else if(DF_ATTACH & lFlags) { Artifact existing = GetArtifactByWorkshareId(wsDoc.GetDocId()); if (existing.IsNull()) return E_DOCUMENT_NOT_FOUND; CStdString sDummyFile = CTempFileManager::GetTempFileName();; CStdString sExt; DocUtilities::GetExtensionFromFileName(sDummyFile,sExt); Artifact related = existing.CreateRelatedItem(CStdStringW(sDummyFile),GetDefaultSaveExtensionFromFormatString(formatString, lFormatIndex), formatString, true); if (related.IsNull()) return E_DOCUMENT_NOT_FOUND; related.Lock(); PopulateWSDocMembersFromArtifact(related, wsDoc); lFormatIndex = CalculateFormatIndex(formatString, related.GetFileExtension()); wsDoc.SetFlags(DOCUMENT_LOCKED_BY_US); } // Create a new version else if(DF_VERSION & lFlags) { std::wstring repositoryId; std::wstring artifactId; std::wstring versionLabel; DecodeWorkshareId(wsDoc.GetDocId().c_str(), artifactId, versionLabel, repositoryId); Repository repository = GetConnector().GetRepositoryById(repositoryId.c_str()); Artifact artifact = repository.GetArtifactById(artifactId.c_str(), versionLabel.c_str()); Artifact artifactVersion = artifact.CreateNewVersion(L"", formatString); PopulateWSDocMembersFromArtifact(artifactVersion, wsDoc); artifactVersion.Lock(); wsDoc.SetFlags(DOCUMENT_LOCKED_BY_US); lFormatIndex = CalculateFormatIndex(formatString, artifactVersion.GetFileExtension()); } return S_OK; }
bool CustomPropertyStorage::CopyTo( const CStdString& sDestinationFile ) const { try { USES_CONVERSION; HRESULT hr = S_OK; IPropertySetStoragePtr pPropSetStg = NULL; IPropertyStoragePtr pPropStg = NULL; hr = StgOpenStorageEx( CStdStringW(m_sFileName.c_str()), STGM_READ|STGM_SHARE_DENY_WRITE, STGFMT_ANY, 0, NULL, NULL, IID_IPropertySetStorage, reinterpret_cast<void**>(&pPropSetStg) ); if( FAILED(hr) || (pPropSetStg == NULL)) { LOG_WS_ERROR(_T("Failed StgOpenStorageEx")); return false; } hr = pPropSetStg->Open(FMTID_UserDefinedProperties, STGM_READ|STGM_SHARE_EXCLUSIVE, &pPropStg ); if( FAILED(hr) || (pPropStg == NULL)) { LOG_WS_ERROR(_T("Failed StgOpenStorageEx")); return false; } IEnumSTATPROPSTGPtr pEnumProp; hr = pPropStg->Enum( &pEnumProp ); if( FAILED( hr ) ) { LOG_WS_ERROR(_T("Failed pPropSetStg->Enum")); return false; } // Enumerate properties. CustomPropertyStorage copyToStorage( sDestinationFile ); STATPROPSTG sps; ULONG fetched; PROPSPEC propSpec[1]; PROPVARIANT propVar[1]; while(pEnumProp->Next(1, &sps, &fetched) == S_OK) { // Build a PROPSPEC for this property. ZeroMemory(&propSpec[0], sizeof(PROPSPEC)); propSpec[0].ulKind = PRSPEC_PROPID; propSpec[0].propid = sps.propid; // Read this property. hr = pPropStg->ReadMultiple(1, &propSpec[0], &propVar[0]); if(!FAILED(hr)) { if( sps.vt = VT_LPWSTR ) { copyToStorage.SetProperty( sps.lpwstrName, propVar[0].pwszVal ); } } } return true; } catch(...) { LOG_WS_ERROR(_T("Error") ); return false; } }
CStdString CustomPropertyStorage::GetProperty( const CStdString& sName ) const { if(sName.IsEmpty()) { LOG_WS_ERROR(_T("Property name passed as argument was empty.")); return _T(""); } try { HRESULT hr = S_OK; IPropertySetStoragePtr pPropSetStg = NULL; IPropertyStoragePtr pPropStg = NULL; hr = StgOpenStorageEx( CStdStringW(m_sFileName.c_str()), STGM_READ | STGM_SHARE_EXCLUSIVE, STGFMT_ANY, 0, NULL, NULL, IID_IPropertySetStorage, reinterpret_cast<void**>(&pPropSetStg) ); if( FAILED(hr) || (pPropSetStg == NULL) ) { LOG_WS_ERROR(_T("Failed StgOpenStorageEx")); return _T(""); } hr = pPropSetStg->Open(FMTID_UserDefinedProperties, STGM_READ|STGM_SHARE_EXCLUSIVE,&pPropStg ); if( FAILED(hr) || (pPropStg == NULL)) { LOG_WS_ERROR(_T("Failed IPropertySetStorage::Open")); return _T(""); } USES_CONVERSION; PROPVARIANT propvarRead; PropVariantInit(&propvarRead); PROPSPEC propspec; ZeroMemory(&propspec, sizeof(PROPSPEC)); propspec.ulKind = PRSPEC_LPWSTR; propspec.lpwstr = T2OLE((LPTSTR)sName.c_str()); hr = pPropStg->ReadMultiple( 1, &propspec, &propvarRead ); if( FAILED(hr) ) { LOG_WS_ERROR(_T("Failed IPropertyStorage::ReadMultiple")); return _T(""); } CStdString sValue = ComConvertUtils::PropVariantToString(propvarRead); return sValue; } catch(...) { CStdString sError; sError.Format(_T("Unexpected error while trying to GetCustomProperty for %s .") , sName.c_str()); LOG_WS_ERROR(sError); return _T(""); } }
bool CustomPropertyStorage::DoesPropertyExist(const CStdString sName) const { if(sName.IsEmpty()) { LOG_WS_ERROR(_T("we have been passed an empty custom document property.")); return false; } try { USES_CONVERSION; HRESULT hr = S_OK; IPropertySetStoragePtr pPropSetStg = NULL; IPropertyStoragePtr pPropStg = NULL; hr = StgOpenStorageEx( CStdStringW(m_sFileName.c_str()), STGM_READ|STGM_SHARE_DENY_WRITE, STGFMT_ANY, 0, NULL, NULL, IID_IPropertySetStorage, reinterpret_cast<void**>(&pPropSetStg) ); if( FAILED(hr) || (pPropSetStg == NULL)) { LOG_WS_ERROR(_T("Failed StgOpenStorageEx")); return false; } hr = pPropSetStg->Open(FMTID_UserDefinedProperties, STGM_READ|STGM_SHARE_EXCLUSIVE, &pPropStg ); if( FAILED(hr) || (pPropStg == NULL)) { LOG_WS_ERROR(_T("Failed StgOpenStorageEx")); return false; } PROPVARIANT propvar; PropVariantInit(&propvar); PROPSPEC propspec; ZeroMemory(&propspec, sizeof(PROPSPEC)); PropVariantInit( &propvar ); propspec.ulKind = PRSPEC_LPWSTR; propspec.lpwstr = T2W((LPTSTR)sName.c_str()); hr = pPropStg->ReadMultiple( 1, &propspec, &propvar ); if( FAILED(hr) ) { LOG_WS_ERROR(_T("Failed to ReadMultiple.")); return false; } CStdString sValue = ComConvertUtils::PropVariantToString(propvar); if(sValue.IsEmpty()) return false; return true; } catch(...) { CStdString sError; sError.Format(_T("Unexpected error while determining %s property exists ") , sName.c_str() ); LOG_WS_ERROR(sError); return false; } return false; }