[转贴]如何让手机识别自定义的文件类型
2008-07-14 14:31
323 查看
/***********************************************************/ /* */ /* MyRecognizer.mmp */ /* */ /***********************************************************/ TARGET MyRecognizer.MDL TARGETTYPE MDL UID 0x10003A19 0x100530 TARGETPATH /system/recogs/ SOURCEPATH ../src SOURCE MyRecocnizer.cpp USERINCLUDE ../inc SYSTEMINCLUDE /epoc32/include LIBRARY EUSER.LIB LIBRARY APMIME.LIB /***********************************************************/ /* */ /* MyRecognizer.h */ /* */ /***********************************************************/ // includes #include <apmrec.h> // For CApaDataRecognizerType // Mime type string and the extension _LIT8( KMyMimeType, "application/vnd.mymime" ); _LIT( KDotMymime,".mym" ); // File header to look for from the data _LIT8( KMyMimeHeader, "#!MY" ); // TUid of the recognizer const TUid KUidMyMimeRecognizer( { 0x100530 } ); class CMyRecognizer : public CApaDataRecognizerType { public: // from CApaDataRecognizerType CMyRecognizer(); virtual TUint PreferredBufSize(); virtual TDataType SupportedDataTypeL( TInt aIndex ) const; private: // from CApaDataRecognizerType virtual void DoRecognizeL(const TDesC& aName, const TDesC8& aBuffer ); // New funtions private: // Check the file name extension TBool NameRecognized( const TDesC& aName ); // Look into the data TBool HeaderRecognized( const TDesC8& aName ); }; // End of file /***********************************************************/ /* */ /* MyRecognizer.cpp */ /* */ /***********************************************************/ // Includes #include "MyRecognizer.h" // // Constructor // MyRecognizer::MyRecognizer() :CApaDataRecognizerType( KUidMyMimeRecognizer, CApaDataRecognizerType::EHigh ) { iCountDataTypes = 1; } // // Preferred buffer size. // TUint MyRecognizer::PreferredBufSize() { return 128; } // // For the framework for collecting the supported mime types list. TDataType MyRecognizer::SupportedDataTypeL( TInt aIndex ) const { switch( aIndex ) { case 0: default: return TDataType( KMyMimeType ); break; } } // // The framework calls this function for recognition // void MyRecognizer::DoRecognizeL( const TDesC& aName, const TDesC8& aBuffer ) { TBool nameOk( EFalse ); TBool headerOk( EFalse ); iConfidence = ENotRecognized; if ( aBuffer.Length() < 10 ) return; // First try the name, then the data. nameOk = NameRecognized( aName ); headerOk = HeaderRecognized( aBuffer ); if ( nameOk && headerOk ) { iConfidence = ECertain; } else if ( !nameOk && headerOk ) { iConfidence = EProbable; } else if ( nameOk && !headerOk ) { iConfidence = EPossible; } else return; iDataType = TDataType( KMyMimeType ); } // // Check if the file header can be recognized // TBool MyRecognizer::HeaderRecognized( const TDesC8& aBuffer ) { if ( aBuffer.Find( KMyMimeHeader ) ) return ETrue; else return EFalse; } // // Check if the file name has ".mym" extension // TBool MyRecognizer::NameRecognized( const TDesC& aName ) { TBool ret = EFalse; if ( aName.Length() > 5 ) { TInt dotPos = aName.LocateReverse( '.' ); if (dotPos != KErrNotFound) { TInt extLength = aName.Length() - dotPos; HBufC* ext = aName.Right( extLength ).AllocL(); CleanupStack::PushL( ext ); if ( ext->CompareF( KMyMimeHeader ) == 0 ) { ret = ETrue; } CleanupStack::PopAndDestroy(); // ext } } return ret; } // // The gate function - ordinal 1 EXPORT_C CApaDataRecognizerType* CreateRecognizer() { CApaDataRecognizerType* thing = new MyRecognizer(); return thing; // NULL if new failed } // // DLL entry point // GLDEF_C TInt E32Dll(TDllReason /*aReason*/) { return KErrNone; } // End of file |
相关文章推荐
- 编码为multipart/form-data自定义类型(包括文件)如何自动绑定到webapi的action的参数里
- 如何创建自定义的文件类型关联
- 如何快速准确的识别出一个文件的具体类型
- 如何创建自定义的文件类型关联
- ASP.NET : 如何为网站添加自定义的文件类型
- 如何下载自定义类型文件。
- 虚拟机上如何创建自定义分区或格式化自定义文件系统类型
- (转贴)(愚翁)如何在数据库中保存不同类型的文件
- ASP.NET : 如何为网站添加自定义的文件类型
- 如何创建自定义的文件类型关联
- .net: 怎么 让VS 识别自定义的文件类型?
- [自定义jsp文件后缀名]如何让Eclipse识别非标准扩展名的文件
- Idea_学习_03_IDEA中使自定义类型的文件进行代码高亮识别
- adb如何获取手机data/data目录下的文件
- 如何使 FlashGet "正常合法" 下载 Session 中的自定义文件链接呢? JSP/Servlet 实现!
- myeclipse下如何设置指定类型文件的编码格式
- [图]迅雷是如何识别并偷偷上传文件的?
- 如何在EA(Enterprise Architect)中自定义数据类型(Data Type)
- 如何恢复手机删除数据文件
- mac 识别压缩文件类型