|
1 /* |
|
2 * Copyright (c) 2007 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 the License "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: Pre installs widgets on system startup |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <SWInstUIPluginAPI.h> |
|
19 #include <centralrepository.h> |
|
20 #include "WidgetInstaller.h" |
|
21 #include "SWInstWidgetUid.h" |
|
22 #include "WidgetPreInstaller.h" |
|
23 #include "WidgetInstallerInternalCRKeys.h" |
|
24 |
|
25 // CONSTANTS |
|
26 _LIT(KWidgetPreInstallPath, "z:\\data\\WidgetPreInstall\\"); |
|
27 |
|
28 // ============================================================================ |
|
29 // CWidgetPreInstaller::ConstructL() |
|
30 // Constructs and start installs |
|
31 // |
|
32 // @since 3.1 |
|
33 // ============================================================================ |
|
34 // |
|
35 void CWidgetPreInstaller::ConstructL() |
|
36 { |
|
37 |
|
38 BaseConstructL( ENonStandardResourceFile | ENoScreenFurniture ); |
|
39 |
|
40 CRepository* cenRep(NULL); |
|
41 TBool preInstall(EFalse); |
|
42 |
|
43 TRAPD(cenRepError, cenRep = CRepository::NewL( TUid::Uid( KSWInstWidgetUIUid ) )); |
|
44 if (!cenRepError) |
|
45 { |
|
46 CleanupStack::PushL(cenRep); |
|
47 TInt preInstallVal; |
|
48 if (cenRep->Get( KWidgetPreInstall, preInstallVal ) == KErrNone) |
|
49 { |
|
50 preInstall = (preInstallVal == 1); |
|
51 } |
|
52 } |
|
53 |
|
54 // Start the installs |
|
55 if (preInstall) |
|
56 { |
|
57 DoInstallL(); |
|
58 } |
|
59 |
|
60 if (!cenRepError) |
|
61 { |
|
62 // reset since we only do this once |
|
63 cenRep->Set(KWidgetPreInstall,0); |
|
64 CleanupStack::PopAndDestroy(); // cenRep |
|
65 } |
|
66 |
|
67 Exit(); |
|
68 } |
|
69 |
|
70 // ============================================================================ |
|
71 // CWidgetPreInstaller::CWidgetPreInstaller() |
|
72 // C++ constructor |
|
73 // |
|
74 // @since 3.1 |
|
75 // ============================================================================ |
|
76 // |
|
77 CWidgetPreInstaller::CWidgetPreInstaller() |
|
78 { |
|
79 } |
|
80 |
|
81 |
|
82 // ----------------------------------------------------------------------------- |
|
83 // CWidgetPreInstaller::~CWidgetPreInstaller |
|
84 // C++ destructor |
|
85 // |
|
86 // ----------------------------------------------------------------------------- |
|
87 // |
|
88 CWidgetPreInstaller::~CWidgetPreInstaller() |
|
89 { |
|
90 iFs.Close(); |
|
91 } |
|
92 |
|
93 // ============================================================================ |
|
94 // CWidgetPreInstaller::DoInstallL |
|
95 // Perform installation. |
|
96 // (other items were commented in a header). |
|
97 // |
|
98 // ============================================================================ |
|
99 // |
|
100 void CWidgetPreInstaller::DoInstallL() |
|
101 { |
|
102 CDir* dir = NULL; |
|
103 User::LeaveIfError( iFs.Connect() ); |
|
104 |
|
105 if ( iFs.GetDir( KWidgetPreInstallPath, KEntryAttMatchMask, EDirsFirst, dir ) == KErrNone ) |
|
106 { |
|
107 CleanupStack::PushL(dir); |
|
108 |
|
109 CWidgetInstaller* installer = NULL; |
|
110 TRAPD( err , installer = CWidgetInstaller::NewL() ); |
|
111 User::LeaveIfError( err ); |
|
112 if ( !installer ) |
|
113 { |
|
114 User::Leave( KErrGeneral ); |
|
115 } |
|
116 CleanupStack::PushL(installer); |
|
117 |
|
118 for (TInt i=0; i<dir->Count(); i++) |
|
119 { |
|
120 const TEntry& fileEntry = (*dir)[i]; |
|
121 |
|
122 // check for directory entries, i.e. "com.nokia.widget" |
|
123 if (fileEntry.IsDir()) |
|
124 { |
|
125 // e.g. restorePath = "\data\WidgetPreInstall\com.nokia.widget" |
|
126 TFileName restorePath( KWidgetPreInstallPath ); |
|
127 restorePath.Append(fileEntry.iName); |
|
128 |
|
129 // installer will move the restorePath to widgetUI private area |
|
130 TRAPD( err, installer->InstallL( restorePath ) ); |
|
131 if ( err ) |
|
132 { |
|
133 installer->RunError( err ); |
|
134 if ( err == KErrNoMemory || err == KErrDiskFull ) |
|
135 { |
|
136 User::Leave( err ); |
|
137 } |
|
138 } |
|
139 } // end of if (fileEntry |
|
140 else |
|
141 { |
|
142 // only care about dir |
|
143 break; |
|
144 } |
|
145 } // end of for ( |
|
146 |
|
147 CleanupStack::PopAndDestroy(2); // dir, installer |
|
148 |
|
149 } // end of if ( iFs.GetDir |
|
150 } |
|
151 |
|
152 // End of File |