|
1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include <e32uid.h> |
|
17 #include <bautils.h> |
|
18 #include <barsread2.h> |
|
19 #include <baspi.h> |
|
20 #include <ecom/ecomerrorcodes.h> |
|
21 |
|
22 #include "Discoverer.h" |
|
23 #include "EComEntryBase.h" |
|
24 #include "EComUidCodes.h" |
|
25 #include "DriveInfo.h" |
|
26 |
|
27 const TInt KEcomResourceIndex=1; |
|
28 const TInt KEComDllExtensionLength=4; |
|
29 |
|
30 CPluginBase::CPluginBase():CBase() |
|
31 { |
|
32 } |
|
33 |
|
34 CPluginBase::~CPluginBase() |
|
35 { |
|
36 delete iDllName; |
|
37 delete iRscFile; |
|
38 } |
|
39 |
|
40 // |
|
41 CSecurePlugin::CSecurePlugin(const TEntry& aEntry):CPluginBase() |
|
42 { |
|
43 //only needs to copy the modified time here and construct the dll name |
|
44 iDllModifiedTime=aEntry.iModified; |
|
45 } |
|
46 |
|
47 CSecurePlugin* CSecurePlugin::NewL(RFs& aFs,const TEntry& aEntry,const TDriveName& aDriveName, TBool aIsRO) |
|
48 { |
|
49 CSecurePlugin* self=new (ELeave) CSecurePlugin(aEntry); |
|
50 CleanupStack::PushL(self); |
|
51 self->ConstructL(aFs,aEntry,aDriveName, aIsRO); |
|
52 CleanupStack::Pop(); |
|
53 return self; |
|
54 } |
|
55 |
|
56 void CSecurePlugin::ConstructL(RFs& aFs,const TEntry& aEntry,const TDriveName& aDriveName, TBool aIsRO) |
|
57 { |
|
58 TInt resourceNameOnlyLength=aEntry.iName.Length()-KExtensionLength; |
|
59 TPtrC resourceNameOnly(aEntry.iName.Left(resourceNameOnlyLength)); |
|
60 |
|
61 //constructing the dll file name |
|
62 iDllName=HBufC::NewL(KEComDllExtensionLength+resourceNameOnlyLength); |
|
63 TPtr namePtr=iDllName->Des(); |
|
64 namePtr.Append(resourceNameOnly); |
|
65 namePtr.Append(KDllExtension); |
|
66 |
|
67 //Constructing the rsc file name |
|
68 TFileName rscFileName; |
|
69 rscFileName.Append(aDriveName); |
|
70 rscFileName.Append(KResourcePlugins); |
|
71 rscFileName.Append(resourceNameOnly); |
|
72 rscFileName.Append(KRscExtension); |
|
73 |
|
74 //Construct the CResourceFile |
|
75 BaflUtils::NearestLanguageFile(aFs,rscFileName); |
|
76 iRscFile=CResourceFile::NewL(aFs,rscFileName,0,0); |
|
77 |
|
78 //Now get the secure id from resource and store in iDllThirdUid |
|
79 //In addition, store the correct Interface Implementation Collection Uid in iDllSecondUid |
|
80 RResourceReader theReader; |
|
81 theReader.OpenLC(iRscFile,KEcomResourceIndex); |
|
82 const TUid uid={theReader.ReadInt32L()}; |
|
83 if (uid == KUidEComResourceFormatV3) |
|
84 { |
|
85 // If the resource format is version 3, then the dll type must |
|
86 // be of type "plugin3". |
|
87 iDllSecondUid = KUidInterfaceImplementationCollection3; |
|
88 } |
|
89 else |
|
90 { |
|
91 iDllSecondUid = KUidInterfaceImplementationCollection; |
|
92 } |
|
93 |
|
94 if (uid==KUidEComResourceFormatV2 || uid==KUidEComResourceFormatV3) |
|
95 { |
|
96 iDllThirdUid.iUid=theReader.ReadInt32L(); |
|
97 } |
|
98 else |
|
99 iDllThirdUid=uid; |
|
100 |
|
101 //Construct resource file extension |
|
102 if(!aIsRO) |
|
103 { |
|
104 // rscFileName is sane so we can use TParsePtrC instead of TParse |
|
105 TParsePtrC fileNameParser(rscFileName); |
|
106 TPtrC fileNameParserPtr = fileNameParser.Ext(); |
|
107 iRscFileExt = fileNameParserPtr.AllocL(); |
|
108 } |
|
109 |
|
110 //Perform cleanup now |
|
111 CleanupStack::PopAndDestroy(&theReader); |
|
112 } |
|
113 |
|
114 CSecurePlugin::~CSecurePlugin() |
|
115 { |
|
116 delete iRscFileExt; |
|
117 } |
|
118 |
|
119 // |
|
120 CSpiPlugin::CSpiPlugin():CPluginBase() |
|
121 { |
|
122 } |
|
123 |
|
124 CSpiPlugin* CSpiPlugin::NewL(RResourceArchive& aRscArchive) |
|
125 { |
|
126 CSpiPlugin* self=new (ELeave) CSpiPlugin(); |
|
127 CleanupStack::PushL(self); |
|
128 self->ConstructL(aRscArchive); |
|
129 CleanupStack::Pop(); |
|
130 return self; |
|
131 } |
|
132 |
|
133 void CSpiPlugin::ConstructL(RResourceArchive& aRscArchive) |
|
134 { |
|
135 HBufC* resourceName = NULL; |
|
136 iRscFile=aRscArchive.NextL(resourceName); |
|
137 CleanupStack::PushL(resourceName); |
|
138 |
|
139 //Now set the iDllName |
|
140 iDllName=HBufC::NewL(KEComDllExtensionLength+resourceName->Length()); |
|
141 TPtr namePtr(iDllName->Des()); |
|
142 namePtr.Append(*resourceName); |
|
143 namePtr.Append(KDllExtension); |
|
144 |
|
145 //Now get the secure id from resource and store the uid in iDllThirdUid |
|
146 RResourceReader theReader; |
|
147 theReader.OpenLC(iRscFile,KEcomResourceIndex); |
|
148 const TUid uid={theReader.ReadInt32L()}; |
|
149 if (uid == KUidEComResourceFormatV3) |
|
150 { |
|
151 // If the resource format is version 3, then the dll type must |
|
152 // be of type "plugin3". |
|
153 iDllSecondUid = KUidInterfaceImplementationCollection3; |
|
154 } |
|
155 else |
|
156 { |
|
157 iDllSecondUid = KUidInterfaceImplementationCollection; |
|
158 } |
|
159 |
|
160 TUid dllUid; |
|
161 if (uid==KUidEComResourceFormatV2 || uid==KUidEComResourceFormatV3) |
|
162 { |
|
163 dllUid.iUid=theReader.ReadInt32L(); |
|
164 } |
|
165 else |
|
166 dllUid=uid; |
|
167 iDllThirdUid=dllUid; |
|
168 CleanupStack::PopAndDestroy(&theReader); |
|
169 |
|
170 //Now perform the necessary cleanup |
|
171 CleanupStack::PopAndDestroy(resourceName); |
|
172 } |
|
173 |
|
174 |
|
175 |