|
1 /* |
|
2 * Copyright (c) 2002, 2006 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <f32file.h> |
|
20 #include <s32mem.h> |
|
21 #include <ImplementationProxy.h> |
|
22 #include "GameRecognizer.h" |
|
23 |
|
24 // |
|
25 // CGameRecognizer |
|
26 // |
|
27 CGameRecognizer::CGameRecognizer () |
|
28 :CApaDataRecognizerType(KUidMimeGameDataRecognizerValue, CApaDataRecognizerType::EHigh) |
|
29 { |
|
30 iCountDataTypes= KSupportedGameDataMimetypes; |
|
31 } |
|
32 |
|
33 TUint CGameRecognizer::PreferredBufSize() |
|
34 { |
|
35 // no buffer recognition yet |
|
36 return 128; |
|
37 } |
|
38 |
|
39 TDataType CGameRecognizer::SupportedDataTypeL(TInt aIndex) const |
|
40 { |
|
41 __ASSERT_DEBUG(aIndex>=0 && aIndex < KSupportedGameDataMimetypes, User::Invariant()); |
|
42 switch (aIndex) |
|
43 { |
|
44 case 0: |
|
45 default: |
|
46 return TDataType( KGameDataMimeType ); |
|
47 } |
|
48 } |
|
49 |
|
50 void CGameRecognizer::DoRecognizeL( const TDesC& aName, const TDesC8& aBuffer) |
|
51 { |
|
52 TBool nameOk( EFalse ); |
|
53 TBool headerOk( EFalse ); |
|
54 |
|
55 iConfidence = ENotRecognized; |
|
56 if ( aBuffer.Length() < 10 ) |
|
57 { |
|
58 return; |
|
59 } |
|
60 |
|
61 // First try the name. Then the data. |
|
62 nameOk = NameRecognizedL( aName ); |
|
63 headerOk = HeaderRecognized( aBuffer ); |
|
64 |
|
65 if ( nameOk && headerOk ) |
|
66 { |
|
67 iConfidence = ECertain; |
|
68 } |
|
69 else if ( !nameOk && headerOk) |
|
70 { |
|
71 iConfidence = EProbable; |
|
72 } |
|
73 else if ( nameOk && !headerOk ) |
|
74 { |
|
75 iConfidence = EPossible; |
|
76 } |
|
77 else |
|
78 { |
|
79 return; |
|
80 } |
|
81 |
|
82 iDataType = TDataType( KGameDataMimeType ); |
|
83 } |
|
84 |
|
85 TBool CGameRecognizer::HeaderRecognized( const TDesC8& aBuffer ) const |
|
86 { |
|
87 if ( aBuffer.Find( KGndHeader ) > 10 ) |
|
88 { |
|
89 return ETrue; |
|
90 } |
|
91 else |
|
92 { |
|
93 return EFalse; |
|
94 } |
|
95 } |
|
96 |
|
97 TBool CGameRecognizer::NameRecognizedL( const TDesC& aName) const |
|
98 { |
|
99 TBool ret = EFalse; |
|
100 if ( aName.Length() > 5 ) |
|
101 { |
|
102 TInt dotPos = aName.LocateReverse( '.' ); |
|
103 if (dotPos != KErrNotFound) |
|
104 { |
|
105 TInt extLength = aName.Length() - dotPos; |
|
106 HBufC* ext = aName.Right( extLength ).AllocL(); |
|
107 CleanupStack::PushL( ext ); |
|
108 if ( ext->CompareF( KDotNGD )==0 ) |
|
109 { |
|
110 ret = ETrue; |
|
111 } |
|
112 CleanupStack::PopAndDestroy( ext ); |
|
113 } |
|
114 } |
|
115 return ret; |
|
116 } |
|
117 |
|
118 CApaDataRecognizerType* CGameRecognizer::CreateRecognizerL() |
|
119 { |
|
120 return new (ELeave) CGameRecognizer(); |
|
121 } |
|
122 |
|
123 const TImplementationProxy ImplementationTable[] = |
|
124 { |
|
125 IMPLEMENTATION_PROXY_ENTRY(KMimeGameDataRecognizerImplementationUid, |
|
126 CGameRecognizer::CreateRecognizerL) |
|
127 }; |
|
128 |
|
129 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount) |
|
130 { |
|
131 aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy); |
|
132 return ImplementationTable; |
|
133 } |
|
134 |
|
135 // End of File |