home *** CD-ROM | disk | FTP | other *** search
/ PSION CD 2 / PsionCDVol2.iso / Programs / 720 / PDF090B4-SorceCode / filerec / Pdffilerecognizer.cpp next >
Encoding:
C/C++ Source or Header  |  2000-09-30  |  2.7 KB  |  111 lines

  1. // PDFFileRecognizer.cpp
  2. //
  3. // Recognise pdf files (EPOC R3)
  4. //
  5. // Copyright (c) 2000 Sander van der Wal
  6. //
  7. // $Id: Pdffilerecognizer.cpp 1.2 2000-09-21 14:07:00+02 svdwal Exp svdwal $
  8. //
  9. // $Log: Pdffilerecognizer.cpp $
  10. // Revision 1.2  2000-09-21 14:07:00+02  svdwal
  11. // Some small changes
  12. //
  13. // Revision 1.1  2000-09-17 15:11:31+02  svdwal
  14. // Initial checkin
  15. //
  16.  
  17. #include "PDFFileRecognizer.h"
  18.  
  19. #ifndef __E32SVR_H__
  20. #include <e32svr.h>
  21. #endif
  22. #ifndef __S32FILE_H__
  23. #include <s32file.h>
  24. #endif
  25. #ifndef __F32FILE_H__
  26. #include <f32file.h>
  27. #endif
  28.  
  29. // -- APPARC
  30. #ifndef __APAID_H__
  31. #include <apaid.h>
  32. #endif
  33. #ifndef __APACMDLN_H__
  34. #include <apacmdln.h>
  35. #endif
  36. #ifndef __APGCLI_H__
  37. #include <apgcli.h>
  38. #endif
  39.  
  40.  
  41. const TInt KPDFViewerUidValue = 0x10005D2C;
  42. const TUid KUidPDFViewer={KPDFViewerUidValue};
  43.  
  44. // Recognises PDF files - by examining the file's contents
  45. CApaFileRecognizerType::TRecognizedType CPDFFileRecognizer::DoRecognizeFileL(RFs& aFs, TUidType /*aType*/)
  46. {
  47.   iRecognizedType=ENotRecognized;
  48.   //Pdf files are only recognized by contet, not by extension!
  49.   
  50.   RFile file;
  51.   if (file.Open(aFs, *iFullFileName, EFileShareReadersOnly)!=KErrNone)
  52.     return iRecognizedType;
  53.   TBuf8<1024> buf; // keep in step with pdf/Stream.cpp
  54.   TInt err = file.Read(buf);
  55.   file.Close();
  56.   if (err!=KErrNone)
  57.     return iRecognizedType;
  58.   if (buf.FindF(_L("%PDF-"))!=KErrNotFound) {
  59.     iRecognizedType=EDoc;
  60.     iAppUid=KUidPDFViewer;
  61.     return iRecognizedType;
  62.   }
  63.   return iRecognizedType;
  64. }
  65.  
  66. TThreadId CPDFFileRecognizer::RunL(TApaCommand aCommand,const TDesC* aDocFileName,const TDesC* aTailEnd) const
  67. {
  68.   CApaCommandLine* commandLine=CApaCommandLine::NewLC();
  69.   commandLine->SetCommandL(aCommand);
  70.   if (iRecognizedType==EDoc) {
  71.     // We've recognised a doc so we need to scan for its associated app
  72.     TApaAppEntry appEntry;
  73.     User::LeaveIfError(iFileRecognizer->AppLocator()->GetAppEntryByUid(appEntry,iAppUid));
  74.     commandLine->SetLibraryNameL(appEntry.iFullName);
  75.     if (aDocFileName)
  76.       commandLine->SetDocumentNameL(*iFullFileName);
  77.   }
  78.   else {
  79.     User::Leave(KErrNotSupported);
  80.   }
  81.   if (aTailEnd)
  82.     commandLine->SetTailEndL(*aTailEnd);
  83.   TThreadId id=AppRunL(*commandLine);
  84.   CleanupStack::PopAndDestroy(); // commandLine
  85.   return id;
  86. }
  87.  
  88. //
  89. // DLL stuff...
  90. //
  91.  
  92. // The gate function - ordinal 1
  93. EXPORT_C CApaFileRecognizerType* CreateRecognizer()
  94. {
  95.   return new CPDFFileRecognizer(); // NULL if failed
  96. }
  97.  
  98.  
  99. // DLL entry point
  100. GLDEF_C TInt E32Dll(TDllReason /*aReason*/)
  101. {
  102.   return KErrNone;
  103. }
  104.  
  105.  
  106. #ifdef __WINS__
  107.  
  108. // MS VC++ 6.0 Introductionary edition version needs this to link
  109. extern "C" void __pfnBkCheck() {}
  110.  
  111. #endif