BOOL CDCache::file_is_cacheable(LPCSTR name, BOOL fCheckSize /*=FALSE*/) { BOOL fCacheable = FALSE; // If we don't have a database, we don't have anything. if (m_database != NULL) { long lMaxSize = m_database->get_maximum_size()/3; switch (m_pPathManager->GetPathBindingType(name)) { case PBT_HomeDataPath: case PBT_RemovableDrive: case PBT_CDDrive: { if (fCheckSize) { // The file is of the correct type. // Make sure it is not too big. // If the file gets an error, say we can cache it (this allows // us to still read missing files from the cache). CString csName; TRY { // Build a real name. csName = m_pPathManager->ExpandPath(name); CFileStatus Status; if (!CFile::GetStatus(csName, Status) || Status.m_size < lMaxSize) { fCacheable = TRUE; } } END_TRY } else { // Assume size is OK. fCacheable = TRUE; } break; } case PBT_CollectionItem: { if (fCheckSize) { // Extract the collection name. CString csName; CString csCollection; VERIFY(m_pPathManager->BindPath(name, csName, &csCollection) == PBT_CollectionItem); CPMWCollection* pCollection = GetGlobalCollectionManager()->FindCollection(csCollection); // Lookup the file to get its size. if (pCollection != NULL) { CFileContent* pContent; if (pCollection->NewContentStream(&pContent) == ERRORCODE_None) { CContentDirEntry Dir; CContentDataEntry Data; Dir.SetKey(csName); TRY { if (pContent->Find(&Dir, &Data) == ERRORCODE_None) { long lSize = (long)((CCompressInfo*)Data.GetHeader())->GetUnCompressedSize(); fCacheable = (lSize < lMaxSize); } } END_TRY pCollection->ReleaseContentStream(pContent); } } }
void CPmwView::DoFileSaveAsGraphic() { BOOL fRet = FALSE; CPmwDoc *pDoc = GetDocument (); CString Filter; Filter.LoadString (IDS_SAVE_AS_GRAPHIC_FILT); // this array must match the order in the above string! SaveGraphicType graphicTypes[] = { None, Pmo, Bmp8, Bmp24, Jpeg, Png, Gif, Pcx, Tiff, WMeta }; CString InitialDir = pDoc->GetPathManager()->ExpandPath("[[P]]"); CString defExt = "*.pmo"; // This must match the first selection in the filter string CFileSaveAsGraphicDlg fileDlg(pDoc->something_selected(), Filter, defExt, InitialDir, this); PBOX WorldAll, WorldSel; pDoc->get_panel_world (&WorldAll, pDoc->get_current_panel()); if (pDoc->GetSelectBound (&WorldSel) != TRUE) WorldSel = WorldAll; CDC *pDC = GetDC(); if (!pDC) { return; // just bail... } int LogPixX = pDC->GetDeviceCaps (LOGPIXELSX); int LogPixY = pDC->GetDeviceCaps (LOGPIXELSY); fileDlg.SetDimensions(&WorldAll, &WorldSel, LogPixX, LogPixY); ReleaseDC (pDC); if (fileDlg.DoModal () == IDOK) { CString Filename = fileDlg.GetPathName (); CPoint cpDims; cpDims.x = fileDlg.m_Width; cpDims.y = fileDlg.m_Height; enum SaveGraphicType gt; gt = graphicTypes[fileDlg.GetGraphicTypeIndex ()]; ASSERT ((gt > None) && (gt < Invalid)); BOOL fSelected = fileDlg.IsSaveSelected(); ERRORCODE error = ERRORCODE_Memory; if (gt == Pmo) { // save as "PrintMaster Objects" file error = SavePMObjectsToFile(Filename, pDoc, fSelected); } else { CDibToGraphicFile pDibToGraphicFile(Filename); pDibToGraphicFile.CreateGraphicFile (pDoc, gt, cpDims, fSelected, NULL, LogPixX); error = pDibToGraphicFile.GetErrorCode(); } if (error != ERRORCODE_None) AfxMessageBox (IDS_ERROR_SAVING); else { if (fileDlg.AddToGallery() == TRUE) { CPMWCollection* pCollection = GetGlobalCollectionManager()->GetUserCollection(CPMWCollection::typeArt); if (pCollection != NULL) { int nResult = pCollection->ImportItem(Filename, NULL, NULL, fileDlg.m_strCategory, FALSE); if (nResult != ERRORCODE_None) AfxMessageBox (IDS_ERROR_SAVING); } } } } }