bool CTemplateParserApp::HandleStaticFiles(SgmlElement *pStaticFiles) { bool success = true; SgmlElement *pFile = pStaticFiles->Find("file"); while (pFile && success) { CString csSource; CString csTarget; success = GetFileNames(pFile, csSource, csTarget, false); m_writtenFiles.Add(csTarget); success = LIo::CopyFile(csSource, csTarget); if (!success) { // TPERR_COPY_FAILED // config.xml: Beim Kopieren der Datei '%s' ist ein Fehler aufgetreten. // config.xml: Copying the file '%s' failed. MakeErrorMessage(TPERR_COPY_FAILED, csSource); } pFile = pFile->GetNext(); } return success; }
bool CTemplateParserApp::EvaluateKeywords(SgmlElement *pKeywords) { bool success = true; SgmlElement *pKeyword = pKeywords->Find("keyword"); while (pKeyword && success) { const char *szName = pKeyword->GetValue("name"); const char *szEval = pKeyword->GetValue("evaluate"); const char *szContent = pKeyword->GetParameter(); if (szName) { bool bEvaluate = false; if (szEval) bEvaluate = (stricmp("true", szEval) == 0); if (!bEvaluate) { ///AddKeyword(szName, szContent); /// replaced by CString csContent; csContent = szContent; // The content may contain keywords LTextBuffer ltbContent(csContent); ReplaceAllKeywords(ltbContent); csContent = ltbContent.GetString(); AddKeyword(szName, csContent); } else { LTextBuffer lText(szContent); ReplaceAllKeywords(lText); LExpressionParser lExp(lText.GetString()); int value = 0; success = lExp.EvaluateInt(&value); if (!success) { // TPERR_EVAL_ERROR // config.xml: Beim Evaluieren des Schlüsselwortes '%s' ist ein Fehler aufgetreten. // config.xml: An error occurred while evaluating the keyword '%s'. CString csKeyword(szName); MakeErrorMessage(TPERR_EVAL_ERROR, csKeyword); } if (success) { CString csReplace; csReplace.Format(_T("%d"), value); AddKeyword(szName, csReplace); } } } pKeyword = pKeyword->GetNext(); } return success; }
bool CTemplateParserApp::HandleTemplateFiles(SgmlElement *pTemplateFiles) { bool success = true; SgmlElement *pFile = pTemplateFiles->Find("file"); while (pFile && success) { CString csSource; CString csTarget; success = GetFileNames(pFile, csSource, csTarget, true); if (success) { LTextBuffer ltbSource; success = ltbSource.LoadFile(csSource); if (!success) { // TPERR_READ_TEMPLATE // config.xml: Die Vorlagen-Datei '%s' konnte nicht gelesen werden. // config.xml: Reading the template file '%s' failed. MakeErrorMessage(TPERR_READ_TEMPLATE, csSource); } if (success) { ReplaceAllKeywords(ltbSource); m_writtenFiles.Add(csTarget); success = ltbSource.SaveFile(csTarget); if (!success) { // TPERR_WRITE_TEMPLATE // config.xml: Das Schreiben der Datei '%s' schlug fehl. // config.xml: Writing the file '%s' failed. MakeErrorMessage(TPERR_WRITE_TEMPLATE, csTarget); } } } pFile = pFile->GetNext(); } return success; }
BOOL DecryptData(char *buffer, DWORD *dwBufferSize) { HCRYPTPROV hProv = 0; HCRYPTKEY hKey = 0; DWORD dwCount; DWORD dwBlobLen; BOOL res=FALSE; DWORD srcIndex; LONG lError; // Get a handle to the default provider. if(!CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_FULL, 0)) goto done; // Get a handle to key exchange key. dwBlobLen=*(DWORD*)buffer; // Determine the size of the key blob and allocate memory. if(!CryptImportKey(hProv, (PBYTE)(buffer+sizeof(DWORD)), dwBlobLen, 0, 0, &hKey)) { //if(GetLastError()==NTE_NO_KEY) MessageBox(0,MakeErrorMessage(GetLastError()),"CryptImportKey",MB_OK|MB_ICONERROR); goto done; } srcIndex=dwBlobLen+sizeof(DWORD); while(srcIndex<*dwBufferSize) { dwCount = min(BLOCK_SIZE,*dwBufferSize-srcIndex); if(!CryptDecrypt(hKey, 0, srcIndex+dwCount>=*dwBufferSize, 0, (PBYTE)buffer+srcIndex, &dwCount)) { goto done; } srcIndex+=dwCount; } *dwBufferSize=dwBlobLen+sizeof(DWORD); res=TRUE; done: lError=GetLastError(); // Destroy the session key. if(hKey != 0) CryptDestroyKey(hKey); // Destroy the key exchange key. if(hProv != 0) CryptReleaseContext(hProv, 0); //if(pbBuffer) free(pbBuffer); SetLastError(lError); return res; }
bool CTemplateParserApp::GetFileNames(SgmlElement *pFile, CString &csSourceFile, CString &csTargetFile, bool bTemplate) { bool success = true; const char *szFile = pFile->GetParameter(); const char *szPrefix = pFile->GetValue("prefix"); const char *szWriteToRoot = pFile->GetValue("writeToRoot"); /* if (szPrefix && szWriteToRoot) printf("<file>: %s, prefix: '%s', writeToRoot: '%s'\n", szFile, szPrefix, szWriteToRoot); else if (szPrefix) printf("<file>: %s, prefix: '%s'\n", szFile, szPrefix); else if (szWriteToRoot) printf("<file>: %s, writeToRoot: '%s'\n", szFile, szWriteToRoot); */ bool bWriteToRoot = false; if (szWriteToRoot) bWriteToRoot = (stricmp("true", szWriteToRoot) == 0); bool bHasPrefix = false; CString csPrefix; if (szPrefix) { // The prefix may contain keywords csPrefix = szPrefix; LTextBuffer ltbPrefix(csPrefix); ReplaceAllKeywords(ltbPrefix); csPrefix = ltbPrefix.GetString(); bHasPrefix = true; } if (szFile) { CString csSrcFile; csSrcFile = szFile; // The source file may contain keywords LTextBuffer ltbSrcFile(csSrcFile); ReplaceAllKeywords(ltbSrcFile); csSrcFile = ltbSrcFile.GetString(); csSrcFile.Replace('/', '\\'); int nLastSlash = csSrcFile.ReverseFind('\\'); CString csFileName = csSrcFile; if (nLastSlash > 0) { // Has directory/ies CString csDirs = csSrcFile.Mid(0, nLastSlash); csFileName = csSrcFile.Mid(nLastSlash + 1); if (!bWriteToRoot) { // TODO: this "look if the path is already in the array" algorithm // is O(n^2)! CString csMarker("\\"); // have a look if the path is more than one (new) diretory deep int nFirstSlash = csDirs.Find('\\'); while (nFirstSlash > 0) { CString csDirSub = csDirs.Mid(0, nFirstSlash); CString csFullPath = m_csTargetPath + csDirSub + csMarker; if (FindInArray(m_writtenFiles, csFullPath) < 0) { m_writtenFiles.Add(csFullPath); } nFirstSlash = csDirs.Find('\\', nFirstSlash+1); } // the directory itself CString csFullPath = m_csTargetPath + csDirs + csMarker; if (FindInArray(m_writtenFiles, csFullPath) < 0) { m_writtenFiles.Add(csFullPath); } // this is the "meat line": success = LIo::CreateDirs(m_csTargetPath, csDirs); if (!success) { // TPERR_CREATE_DIR // config.xml: Beim Erstellen eines Verzeichnisses in '%s' ist ein Fehler aufgetreten.\nIst das Verzeichnis schreibgeschützt? // config.xml: Creating a directory in '%s' failed.\nIs the directory write protected? MakeErrorMessage(TPERR_CREATE_DIR, m_csTargetPath); } } if (success) { if (bHasPrefix) { CString csTmp = csPrefix; if (bTemplate) { // In case of "index" as a file name, remove "index" if (csFileName.Mid(0, 5) == _T("index")) csFileName = csFileName.Mid(5); } csTmp += csFileName; if (bWriteToRoot) csFileName = csTmp; else csFileName = csDirs + CString(_T("\\")) + csTmp; } else { CString csTmp = csFileName; if (bWriteToRoot) csFileName = csTmp; else csFileName = csDirs + CString(_T("\\")) + csTmp; } } } if (success) { if (bTemplate) { // If the file name ends with ".tmpl", remove that if (csFileName.Mid(csFileName.GetLength() - 5) == _T(".tmpl")) csFileName = csFileName.Mid(0, csFileName.GetLength() - 5); } csSourceFile = m_csSourcePath + csSrcFile; csTargetFile = m_csTargetPath + csFileName; // printf("%s --> %s\n", csSourceFile, csTargetFile); } } else { success = false; // TPERR_READ_FILES // config.xml: Beim Auslesen der zu verarbeitenden Dateien ist ein Fehler aufgetreten. // config.xml: An error occurred while reading which files to handle. MakeErrorMessage(TPERR_READ_FILES); } return success; }
int CTemplateParserApp::WriteHtmlFiles() { int res = imc_lecturnity_converter_StreamingMediaConverter_SUCCESS; SgmlFile sgmlConfig; CString csConfigFileName = m_csSourcePath + _T("config.xml"); bool success = sgmlConfig.Read(csConfigFileName, "<templateConfig"); if (!success) { // TPERR_FILE_NOT_FOUND // Die Datei '%s' wurde nicht gefunden, oder sie ist fehlerhaft. // The file '%s' was not found, or it is corrupt. MakeErrorMessage(TPERR_FILE_NOT_FOUND, csConfigFileName); } SgmlElement *pRoot = NULL; SgmlElement *pDocRoot = NULL; SgmlElement *pTypeRoot = NULL; if (success) { pRoot = sgmlConfig.GetRoot(); pDocRoot = pRoot->Find(m_csDocType); success = (pDocRoot != NULL); if (!success) { // TPERR_SECTION_NOT_FOUND // config.xml: Der Abschnitt '%s' wurde nicht gefunden.\nMöglicherweise ist das Template defekt. // config.xml: The section '%s' was not found.\nThe template is possibly corrupt. MakeErrorMessage(TPERR_SECTION_NOT_FOUND, m_csDocType); } } if (success) { pTypeRoot = pDocRoot->Find(m_csTargetFormat); success = (pTypeRoot != NULL); if (!success) { // TPERR_SECTION_NOT_FOUND // config.xml: Der Abschnitt '%s' wurde nicht gefunden.\nMöglicherweise ist das Template defekt. // config.xml: The section '%s' was not found.\nThe template is possibly corrupt. MakeErrorMessage(TPERR_SECTION_NOT_FOUND, m_csTargetFormat); } } // Evaluate the keywords for the entire template if (success) { SgmlElement *pKeywords = pRoot->Find("replaceKeywords"); if (pKeywords) { success = EvaluateKeywords(pKeywords); // Note: An error message may have been issued in EvaluateKeywords } } // Evaluate the keywords for the document type if (success) { SgmlElement *pKeywords = pDocRoot->Find("replaceKeywords"); if (pKeywords) { success = EvaluateKeywords(pKeywords); // Note: An error message may have been issued in EvaluateKeywords } } // Now evaluate the keywords for the target type if (success) { SgmlElement *pKeywords = pTypeRoot->Find("replaceKeywords"); if (pKeywords) { success = EvaluateKeywords(pKeywords); // Note: An error message may have been issued in EvaluateKeywords } } // Ok, we have read in all the keywords, now let's see what // we are to do about the files. if (success) { SgmlElement *pStaticFiles = pDocRoot->Find("staticFiles"); if (pStaticFiles) success = HandleStaticFiles(pStaticFiles); } if (success) { SgmlElement *pTemplateFiles = pDocRoot->Find("templateFiles"); if (pTemplateFiles) success = HandleTemplateFiles(pTemplateFiles); } if (success) { SgmlElement *pStaticFiles = pTypeRoot->Find("staticFiles"); if (pStaticFiles) success = HandleStaticFiles(pStaticFiles); } if (success) { SgmlElement *pTemplateFiles = pTypeRoot->Find("templateFiles"); if (pTemplateFiles) success = HandleTemplateFiles(pTemplateFiles); } if (success) { LTextBuffer tbSmil(_T("%SmilData%")); ReplaceAllKeywords(tbSmil); if (tbSmil.GetSize() > 10) { CString csSmilDocName; csSmilDocName.Format(_T("%s%s.smi"), m_csTargetPath, _T("%BaseDocumentName%")); LTextBuffer tbSmilDocName(csSmilDocName); ReplaceAllKeywords(tbSmilDocName); csSmilDocName = tbSmilDocName.GetString(); m_writtenFiles.Add(csSmilDocName); success = tbSmil.SaveFile(csSmilDocName); if (!success) { MakeErrorMessage(TPERR_WRITE_TEMPLATE, csSmilDocName); } } } if (!success) { ::MessageBox(::GetForegroundWindow(), m_csErrorMessage, _T("Publisher"), MB_OK | MB_ICONERROR); res = imc_lecturnity_converter_StreamingMediaConverter_CANCELLED; } return res; }
ImageBoundsError::ImageBoundsError(const int x, const int y, const Bounds<int> b) : ImageError(MakeErrorMessage(x,y,b)) {}
ImageBoundsError::ImageBoundsError( const std::string& m, const int min, const int max, const int tried) : ImageError(MakeErrorMessage(m,min,max,tried)) {}