1 /* |
|
2 * Copyright (c) 2006-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 "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: CMMCScBkupDriveAndOperationTypeManager implementation |
|
15 * |
|
16 * |
|
17 */ |
|
18 |
|
19 #include "CMMCScBkupDriveAndOperationTypeManager.h" |
|
20 |
|
21 // User includes |
|
22 #include "MMCScBkupLogger.h" |
|
23 #ifdef RD_MULTIPLE_DRIVE |
|
24 #include "BkupEngine.hrh" |
|
25 #include <driveinfo.h> |
|
26 #include <coemain.h> |
|
27 #endif // RD_MULTIPLE_DRIVE |
|
28 |
|
29 |
|
30 // ========================= MEMBER FUNCTIONS ================================ |
|
31 |
|
32 // --------------------------------------------------------------------------- |
|
33 // CMMCScBkupDriveAndOperationTypeManager::CMMCScBkupDriveAndOperationTypeManager() |
|
34 // |
|
35 // C++ constructor. |
|
36 // --------------------------------------------------------------------------- |
|
37 CMMCScBkupDriveAndOperationTypeManager::CMMCScBkupDriveAndOperationTypeManager() |
|
38 { |
|
39 iCalculatedDriveList.SetMax(); |
|
40 } |
|
41 |
|
42 |
|
43 // --------------------------------------------------------------------------- |
|
44 // CMMCScBkupDriveAndOperationTypeManager::CMMCScBkupDriveAndOperationTypeManager() |
|
45 // |
|
46 // C++ destructor. |
|
47 // --------------------------------------------------------------------------- |
|
48 EXPORT_C CMMCScBkupDriveAndOperationTypeManager::~CMMCScBkupDriveAndOperationTypeManager() |
|
49 { |
|
50 iEntries.Close(); |
|
51 } |
|
52 |
|
53 |
|
54 // --------------------------------------------------------------------------- |
|
55 // CMMCScBkupDriveAndOperationTypeManager::ConstructL() |
|
56 // |
|
57 // |
|
58 // --------------------------------------------------------------------------- |
|
59 void CMMCScBkupDriveAndOperationTypeManager::ConstructL( BkupDrivesAndOperationList *aDriveList ) |
|
60 { |
|
61 #ifdef RD_MULTIPLE_DRIVE |
|
62 RFs& fs( CCoeEnv::Static()->FsSession() ); |
|
63 |
|
64 // Get all user visible drives |
|
65 TInt numDrives( 0 ); |
|
66 TDriveList drvList; |
|
67 User::LeaveIfError( DriveInfo::GetUserVisibleDrives( |
|
68 fs, drvList, numDrives ) ); |
|
69 TInt drvListLen( drvList.Length() ); |
|
70 TMMCScBkupDriveAndOperationType op; |
|
71 TInt count( aDriveList->Count() ); |
|
72 |
|
73 // Get default system drive |
|
74 TInt sysDrive( 0 ); |
|
75 User::LeaveIfError( DriveInfo::GetDefaultDrive( |
|
76 DriveInfo::EDefaultSystem, sysDrive ) ); |
|
77 |
|
78 for( TInt i( 0 ); i < count; ++i ) |
|
79 { |
|
80 TBkupDrivesAndOperation *drvAndOp = &((*aDriveList)[i]); |
|
81 TUint drvCategories( drvAndOp->drvCategories() ); |
|
82 TMMCScBkupOwnerDataType dataType( |
|
83 static_cast< TMMCScBkupOwnerDataType >( drvAndOp->ownerDataType() ) ); |
|
84 |
|
85 if ( drvCategories & EBkupDeviceMemories ) |
|
86 { |
|
87 // Default system drive is always backed up when |
|
88 // device memories are defined |
|
89 op.SetDrive( static_cast< TDriveNumber >( sysDrive ) ); |
|
90 op.SetDataType( dataType ); |
|
91 iEntries.AppendL( op ); |
|
92 iCalculatedDriveList[ op.Drive() ] = ETrue; |
|
93 } |
|
94 |
|
95 for ( TInt j( 0 ); j < drvListLen; ++j ) |
|
96 { |
|
97 if ( sysDrive != j && drvList[ j ] ) |
|
98 { |
|
99 // Check for other drives |
|
100 TBool append( EFalse ); |
|
101 TUint drvStatus( 0 ); |
|
102 User::LeaveIfError( DriveInfo::GetDriveStatus( |
|
103 fs, j, drvStatus ) ); |
|
104 if ( ( drvCategories & EBkupDeviceMemories ) && |
|
105 ( drvStatus & DriveInfo::EDriveInternal ) && |
|
106 !( drvStatus & DriveInfo::EDriveExternallyMountable ) && |
|
107 !( drvStatus & DriveInfo::EDriveReadOnly ) ) |
|
108 { |
|
109 append = ETrue; // Allow additional device memory |
|
110 } |
|
111 else if ( ( drvCategories & EBkupInternalMassStorages ) && |
|
112 ( drvStatus & DriveInfo::EDriveInternal ) && |
|
113 ( drvStatus & DriveInfo::EDriveExternallyMountable ) ) |
|
114 { |
|
115 append = ETrue; // Allow internal mass storage |
|
116 } |
|
117 else if ( ( drvCategories & EBkupExternalMassStorages ) && |
|
118 ( drvStatus & DriveInfo::EDriveRemovable ) ) |
|
119 { |
|
120 append = ETrue; // Allow external mass storage |
|
121 } |
|
122 if ( append ) |
|
123 { |
|
124 op.SetDrive( static_cast< TDriveNumber >( j ) ); |
|
125 op.SetDataType( dataType ); |
|
126 iEntries.AppendL( op ); |
|
127 iCalculatedDriveList[ op.Drive() ] = ETrue; |
|
128 } |
|
129 } |
|
130 } |
|
131 } |
|
132 #else // RD_MULTIPLE_DRIVE |
|
133 TMMCScBkupDriveAndOperationType op; |
|
134 const TInt count = aReader.ReadInt8(); |
|
135 // |
|
136 for( TInt i=0; i<count; i++ ) |
|
137 { |
|
138 op.SetDrive( static_cast< TDriveNumber >( aReader.ReadInt8() ) ); |
|
139 op.SetDataType( static_cast< TMMCScBkupOwnerDataType >( aReader.ReadInt8() ) ); |
|
140 // |
|
141 iEntries.AppendL( op ); |
|
142 // |
|
143 iCalculatedDriveList[ op.Drive() ] = ETrue; |
|
144 } |
|
145 #endif // RD_MULTIPLE_DRIVE |
|
146 } |
|
147 |
|
148 |
|
149 // --------------------------------------------------------------------------- |
|
150 // CMMCScBkupDriveAndOperationTypeManager::NewL() |
|
151 // |
|
152 // |
|
153 // --------------------------------------------------------------------------- |
|
154 EXPORT_C CMMCScBkupDriveAndOperationTypeManager* CMMCScBkupDriveAndOperationTypeManager::NewL(\ |
|
155 BkupDrivesAndOperationList *aDriveList ) |
|
156 { |
|
157 CMMCScBkupDriveAndOperationTypeManager* self = new(ELeave) CMMCScBkupDriveAndOperationTypeManager(); |
|
158 CleanupStack::PushL( self ); |
|
159 self->ConstructL( aDriveList ); |
|
160 CleanupStack::Pop( self ); |
|
161 return self; |
|
162 } |
|
163 |
|
164 |
|
165 // --------------------------------------------------------------------------- |
|
166 // CMMCScBkupDriveAndOperationTypeManager::Count() |
|
167 // |
|
168 // |
|
169 // --------------------------------------------------------------------------- |
|
170 TInt CMMCScBkupDriveAndOperationTypeManager::Count() const |
|
171 { |
|
172 return iEntries.Count(); |
|
173 } |
|
174 |
|
175 |
|
176 // --------------------------------------------------------------------------- |
|
177 // CMMCScBkupDriveAndOperationTypeManager::At() |
|
178 // |
|
179 // |
|
180 // --------------------------------------------------------------------------- |
|
181 const TMMCScBkupDriveAndOperationType& CMMCScBkupDriveAndOperationTypeManager::At( TInt aIndex ) const |
|
182 { |
|
183 return iEntries[ aIndex ]; |
|
184 } |
|
185 |
|
186 |
|
187 // --------------------------------------------------------------------------- |
|
188 // CMMCScBkupDriveAndOperationTypeManager::IsDataTypeAllowedToAccessDrive() |
|
189 // |
|
190 // |
|
191 // --------------------------------------------------------------------------- |
|
192 TBool CMMCScBkupDriveAndOperationTypeManager::IsDataTypeAllowedToAccessDrive( TDriveNumber aDrive, TMMCScBkupOwnerDataType aDataType ) const |
|
193 { |
|
194 // __LOG2("CMMCScBkupDriveAndOperationTypeManager::IsDataTypeAllowedToAccessDrive() - START - aDrive: %c, aDataType: %S", aDrive + 'A', &MMCScBkupLogger::DataType( aDataType )); |
|
195 |
|
196 TBool allowed = EFalse; |
|
197 // |
|
198 const TInt count = iEntries.Count(); |
|
199 // |
|
200 for( TInt i=0; i<count; i++ ) |
|
201 { |
|
202 const TMMCScBkupDriveAndOperationType& entry = iEntries[ i ]; |
|
203 // |
|
204 if ( entry.DataType() == aDataType ) |
|
205 { |
|
206 // Check drive... |
|
207 if ( entry.Drive() == aDrive ) |
|
208 { |
|
209 allowed = ETrue; |
|
210 break; |
|
211 } |
|
212 } |
|
213 } |
|
214 // |
|
215 // __LOG1("CMMCScBkupDriveAndOperationTypeManager::IsDataTypeAllowedToAccessDrive() - END - allowed: %d", allowed); |
|
216 return allowed; |
|
217 } |
|
218 |
|