void CFYSPrintDoc::Initialize() { if (m_strFYSTempPath.IsEmpty()) m_strFYSTempPath = Get4YourSoulPath(); CString strSep("\\"); int nLen = m_strFYSTempPath.GetLength(); if (m_strFYSTempPath[nLen-1] != strSep) m_strFYSTempPath += strSep; m_strErrorMsg = ""; m_bError = false; CleanUp(); CString strPath = m_strFYSTempPath; CleanDirectory(strPath); strPath = m_strFYSTempPath + IMAGES_PATH; CleanDirectory(strPath); strPath = m_strFYSTempPath + FONTS_PATH; CleanDirectory(strPath); strPath = m_strFYSTempPath + XML_PATH; CleanDirectory(strPath); }
bool CFYSPrintDoc::CreateSendFile() { CString strSendFile = m_strFYSTempPath + FORYOURSOUL_TXT; FILE* output = NULL; errno_t err = fopen_s(&output, strSendFile, "wb"); if (!output || err != 0) { SetError(String("Failed to open %s.", strSendFile)); return false; } DWORD dwchkSum = 0; CString strSep("\\"); CString strInputFile; CString strMiniHdr; // mini header for StreamHeader CString strPath = m_strFYSTempPath + XML_PATH + strSep; strInputFile = strPath + STREAMHDR_XML; int nSize = FileSize(strInputFile); CCRC32::FileCrc32Assembly(strInputFile, dwchkSum); strMiniHdr.Format("[%ld,%X]", nSize, dwchkSum); fwrite((VOID*)(LPCSTR)strMiniHdr, sizeof(char), strMiniHdr.GetLength(), output); // stream Header if (!CopyFiles(strInputFile, output)) return false; // create and print xml strInputFile = strPath + CREATEPRINT_XML; if (!CopyFiles(strInputFile, output)) return false; // resources for (int i=0; i<m_arFileSpecs.m_nSize; i++) { if (m_arFileSpecs[i]->Type == "Image") strInputFile = m_strFYSTempPath + IMAGES_PATH + strSep; if (m_arFileSpecs[i]->Type == "Font") strInputFile = m_strFYSTempPath + FONTS_PATH + strSep; strInputFile += m_arFileSpecs[i]->FileName; if (!CopyFiles(strInputFile, output)) return false; } fclose(output); return true; }
// CFileOpenDlg::GetFullPath // // Returns the full path of a node // CString CFileOpenDlg::GetFullPath(HTREEITEM hItem) { CString strFullPath, strFolder, strSep(_T("\\")); if(hItem) { while(hItem) { strFolder = m_treeFolder.GetItemText(hItem); if(strFolder != strSep) strFullPath = strFolder + strSep + strFullPath; hItem = m_treeFolder.GetParentItem(hItem); } strFullPath = strSep + strFullPath; } return strFullPath; }
void CFYSPrintDoc::UnpackFiles() { CString strTemp; CString strSep("\\"); CString strFileName = m_strFYSTempPath + FORYOURSOUL_TXT; FILE* input = NULL; errno_t err = fopen_s(&input, strFileName, "rb"); if (!input || err != 0) { SetError(String("Failed to open %s", strFileName)); return; } HGLOBAL hMemory; BYTE* pMemory; // unpack the mini header hMemory = ::GlobalAlloc(GMEM_MOVEABLE, sizeof(BYTE)); pMemory = (BYTE*)::GlobalLock(hMemory); char xz = ']'; do { fread(pMemory, sizeof(BYTE), 1, input); strTemp += (char)*pMemory; }while((*(char*)pMemory) != xz); ::GlobalUnlock(hMemory); ::GlobalFree(hMemory); // unpack streamheader strTemp = strTemp.Mid(1, strTemp.Find(',', 0)-1); DWORD dwSize = atoi(strTemp); hMemory = ::GlobalAlloc(GMEM_MOVEABLE, dwSize); pMemory = (BYTE*)::GlobalLock(hMemory); fread(pMemory, sizeof(BYTE), dwSize, input); CString strPath = m_strFYSTempPath + XML_PATH + strSep; strTemp.Format("%sXP_%s", strPath, STREAMHDR_XML); FILE* output = NULL; err = fopen_s(&output, strTemp, "wb"); if (!output || err != 0) { SetError(String("Failed to open %s", strTemp)); } else { fwrite(pMemory, sizeof(BYTE), dwSize, output); fclose(output); output = NULL; } ::GlobalUnlock(hMemory); ::GlobalFree(hMemory); // time to read the stream header into a xml class CXMLDocument* pXMLDoc = new CXMLDocument; pXMLDoc->Load(strTemp, false); CString strCount = pXMLDoc->GetStringValue("//FYS_DataStreamHeader//Files", "Count"); int nFileCount = atoi(strCount); for (int i=0, offset=0; i<nFileCount; i++) { CString strSrch = String("//FYS_DataStreamHeader//Files//File[@StartOffset = '%ld']", offset); CString strType = pXMLDoc->GetStringValue(strSrch, "Type"); CString strName = pXMLDoc->GetStringValue(strSrch, "Name"); CString strSize = pXMLDoc->GetStringValue(strSrch, "Size"); DWORD dwSize = atoi(strSize); hMemory = ::GlobalAlloc(GMEM_MOVEABLE, dwSize); pMemory = (BYTE*)::GlobalLock(hMemory); fread(pMemory, sizeof(BYTE), dwSize, input); if (strType == "DataEnvelope") strPath = m_strFYSTempPath + XML_PATH + strSep; if (strType == "Image") strPath = m_strFYSTempPath + IMAGES_PATH + strSep; if (strType == "Font") strPath = m_strFYSTempPath + FONTS_PATH + strSep; strTemp.Format("%sXP_%s", strPath, strName); err = fopen_s(&output, strTemp, "wb"); if (!output || err != 0) { SetError(String("Failed to open %s", strTemp)); } else { fwrite(pMemory, sizeof(BYTE), dwSize, output); fclose(output); output = NULL; } ::GlobalUnlock(hMemory); ::GlobalFree(hMemory); offset += dwSize; } fclose(input); delete pXMLDoc; }
bool CFYSPrintDoc::CreateXmlDoc(CString& strOrderId, CString& strCorrId, CString& strFYSInfo, bool bUnpackFiles) { if (!m_pAGDoc) return false; CWaitCursor Wait; Initialize(); if (!CreateDirAndSubDirs()) return false; // Documents element CString strDocFileName; { // strip the last "\" int nLen = m_strFYSTempPath.GetLength(); CString strTempPath = m_strFYSTempPath.Left(nLen-1); strDocFileName = TempFileName(strTempPath, "4YS", "txt"); strDocFileName = m_strFYSTempPath + strDocFileName; FILE* docout = NULL; errno_t err = fopen_s(&docout, strDocFileName, "wb"); if (!docout || err != 0) { SetError(String("Failed to open %s", strDocFileName)); return false; } SIZE PageSize = {0,0}; m_pAGDoc->GetPageSize(PageSize); double dx = DINCHES(PageSize.cx); double dy = DINCHES(PageSize.cy); fprintf(docout, " <Documents Count='1'>\r\n"); fprintf(docout, " <Document CLT_CorrelationID='%s' FYS_CorrelationID='%s'>\r\n", strOrderId, strCorrId); fprintf(docout, " <GreetingCard PageWidth='%0.5G' PageHeight='%0.5G' />\r\n", dx, dy); int nPages = m_pAGDoc->GetNumPages(); for (int nPage = 0; nPage < nPages; nPage++) { CAGPage* pPage = m_pAGDoc->GetPage(nPage); if (!pPage) continue; if (!PageHasSymbols(pPage)) continue; fprintf(docout, "\t\t\t<Page PageNumber='%d'>\r\n", nPage+1); int nLayers = pPage->GetNumLayers(); for (int nLayer = 0; nLayer < nLayers; nLayer++) { CAGLayer* pLayer = pPage->GetLayer(nLayer); if (!pLayer) continue; int nSymbols = pLayer->GetNumSymbols(); for (int nSymbol = nSymbols - 1; nSymbol >= 0; nSymbol--) { bool bRetVal = true; CAGSym* pSym = pLayer->GetSymbol(nSymbol); if (!pSym || pSym->IsHidden()) continue; pSym->RegisterFileSpecsCallback(fnFileSpecs, (LPARAM)this); int idSym = pSym->GetID(); bool bReposition = (idSym == IDR_AGLOGO || idSym == IDR_CARDBACK_COPYRIGHT); if (bReposition) { // Move these symbols up to make room for the FYS logo CAGMatrix Matrix = pSym->GetMatrix(); Matrix.Translate(0, -(INCHES(0.5))); pSym->SetMatrix(Matrix); } pSym->WriteFYSXml(docout, 4); if (bReposition) { CAGMatrix Matrix = pSym->GetMatrix(); Matrix.Translate(0, INCHES(0.5)); pSym->SetMatrix(Matrix); } if (pSym->IsImage()) { CAGSymImage* pSymImage = (CAGSymImage*)pSym; CString strSep("\\"); CString strImagePath = m_strFYSTempPath + IMAGES_PATH + strSep; bRetVal = DumpImageFile(pSymImage, strImagePath); if (bRetVal) { SIZE PageSize; pPage->GetPageSize(PageSize); if (pSymImage->DoCoverDraw() && pSymImage->IsCoverAllowed()) pSymImage->WriteXmlRects(docout, PageSize, 4); } } pSym->UnregisterFileSpecsCallback(); if (!bRetVal) return false; } } fprintf(docout, "\t\t\t</Page>\r\n"); } fprintf(docout, " </Document>\r\n"); fprintf(docout, " </Documents>\r\n"); fclose(docout); } CString strSep("\\"); CString strFontsPath = m_strFYSTempPath + FONTS_PATH + strSep; DumpFontFiles(strFontsPath); // Get Configuration element if (!GetConfigurationElement(strFYSInfo)) { CleanUpEx(strDocFileName); return false; } // Get Resources element if (!GetResourcesElement()) { CleanUpEx(strDocFileName); return false; } // Write CreateAndPrint.xml file CString strXmlPath = m_strFYSTempPath + XML_PATH + strSep; if (!WriteCreatePrintXml(strDocFileName, strXmlPath)) { CleanUpEx(strDocFileName); return false; } // Write StreamHdr.xml file if (!WriteXmlStreamHeader(strXmlPath)) { CleanUp(); return false; } // Write 4YourSoul.txt file if (!CreateSendFile()) { CleanUp(); return false; } if (bUnpackFiles) UnpackFiles(); CleanUp(); return true; }