|
1 /* |
|
2 * Copyright (c) 2010 Ixonos Plc. |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the "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 * Ixonos Plc |
|
14 * |
|
15 * Description: |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDES |
|
22 #include <s32file.h> |
|
23 #include <bautils.h> |
|
24 #include <eikenv.h> |
|
25 |
|
26 #include "ImageEditorPluginLocator.h" |
|
27 #include "ImageEditorPluginScanner.h" |
|
28 #include "ImageEditorPluginStorage.h" |
|
29 #include "PluginInfo.h" |
|
30 #include "ImageEditorUIDs.hrh" |
|
31 |
|
32 // CONSTANTS |
|
33 _LIT( KPluginStorageExternalizeFile, "c:\\private\\101FFA91\\PluginStorage.ini"); |
|
34 |
|
35 |
|
36 //============================================================================= |
|
37 EXPORT_C CPluginLocator * CPluginLocator::NewL () |
|
38 { |
|
39 CPluginLocator * self = new (ELeave) CPluginLocator; |
|
40 CleanupStack::PushL (self); |
|
41 self->ConstructL (); |
|
42 CleanupStack::Pop (); // self |
|
43 return self; |
|
44 } |
|
45 |
|
46 //============================================================================= |
|
47 EXPORT_C CPluginLocator::~CPluginLocator () |
|
48 { |
|
49 delete iScanner; |
|
50 delete iStorage; |
|
51 } |
|
52 |
|
53 //============================================================================= |
|
54 EXPORT_C void CPluginLocator::ScanPluginsL () |
|
55 { |
|
56 LOG(KImageEditorLogFile, "CPluginLocator: Scanning plugins"); |
|
57 |
|
58 ASSERT( iScanner ); |
|
59 ASSERT( iStorage ); |
|
60 |
|
61 // Internalize the plug-in storage |
|
62 RFs& fs = CEikonEnv::Static()->FsSession(); |
|
63 BaflUtils::EnsurePathExistsL( fs, KPluginStorageExternalizeFile() ); |
|
64 if( BaflUtils::FileExists(fs, KPluginStorageExternalizeFile()) ) |
|
65 { |
|
66 RFileReadStream stream; |
|
67 stream.PushL(); |
|
68 |
|
69 LOGFMT(KImageEditorLogFile, "CPluginLocator: Internalizing plug-in storage from %S", &KPluginStorageExternalizeFile()); |
|
70 |
|
71 User::LeaveIfError ( |
|
72 stream.Open ( |
|
73 fs, |
|
74 KPluginStorageExternalizeFile(), |
|
75 EFileRead | EFileShareReadersOnly |
|
76 )); |
|
77 |
|
78 stream >> *iStorage; |
|
79 |
|
80 stream.Release(); |
|
81 stream.Pop(); |
|
82 } |
|
83 |
|
84 // Scan for plug-ins |
|
85 TBool pluginStorageNeedsUpdate = EFalse; |
|
86 iScanner->ScanPluginsL ( pluginStorageNeedsUpdate ); |
|
87 |
|
88 // If the plugin content has changed compared to the previously |
|
89 // internalized one, we need to externalize the plug-in storage |
|
90 if( pluginStorageNeedsUpdate ) |
|
91 { |
|
92 LOGFMT(KImageEditorLogFile, "CPluginLocator: Externalizing plug-in storage to %S", &KPluginStorageExternalizeFile()); |
|
93 |
|
94 RFileWriteStream stream; |
|
95 stream.PushL(); |
|
96 |
|
97 User::LeaveIfError ( |
|
98 stream.Replace ( |
|
99 fs, |
|
100 KPluginStorageExternalizeFile(), |
|
101 EFileWrite |
|
102 )); |
|
103 |
|
104 stream << *iStorage; |
|
105 |
|
106 stream.Close(); |
|
107 stream.Pop(); |
|
108 } |
|
109 |
|
110 // iScanner is not needed after this |
|
111 delete iScanner; |
|
112 iScanner = NULL; |
|
113 } |
|
114 |
|
115 //============================================================================= |
|
116 EXPORT_C TInt CPluginLocator::CountPlugins() const |
|
117 { |
|
118 return iStorage->CountPlugins(); |
|
119 } |
|
120 |
|
121 //============================================================================= |
|
122 EXPORT_C CPluginInfo * CPluginLocator::GetPluginInfo (const TInt aID) |
|
123 { |
|
124 return iStorage->GetPluginInfo (aID); |
|
125 } |
|
126 |
|
127 //============================================================================= |
|
128 CPluginLocator::CPluginLocator () |
|
129 { |
|
130 |
|
131 } |
|
132 |
|
133 //============================================================================= |
|
134 void CPluginLocator::ConstructL () |
|
135 { |
|
136 LOG(KImageEditorLogFile, "CPluginLocator: Creating locator"); |
|
137 |
|
138 // Create a new plug-in storage |
|
139 iStorage = CPluginStorage::NewL (); |
|
140 |
|
141 // Create a new plug-in locator |
|
142 iScanner = CPluginScanner::NewL (); |
|
143 |
|
144 // Set storage |
|
145 iScanner->SetPluginStorage (iStorage); |
|
146 } |
|
147 |
|
148 // End of File |