metadataengine/server/src/mdsmaintenanceengine.cpp
changeset 54 a3cc46f37772
parent 31 81125601ee77
--- a/metadataengine/server/src/mdsmaintenanceengine.cpp	Tue Jul 06 14:44:37 2010 +0300
+++ b/metadataengine/server/src/mdsmaintenanceengine.cpp	Fri Sep 17 16:54:49 2010 +0300
@@ -16,8 +16,6 @@
 */
 
 // INCLUDE FILES
-#include <driveinfo.h>
-
 #include "mdsmaintenanceengine.h"
 #include "mdslogger.h"
 #include "mdsmanipulationengine.h"
@@ -79,6 +77,7 @@
 CMdSMaintenanceEngine::~CMdSMaintenanceEngine()
     {
     delete iMaintenance;
+    iMaintenance = NULL;
     }
 
 // ------------------------------------------------
@@ -117,7 +116,17 @@
 void CMdSMaintenanceEngine::InstallL( CMdSManipulationEngine& aManipulate, CMdsSchema& aSchema )
     {
     __LOG1( ELogAlways, "Trying to validate MDS DB, error expected if not created(first boot): %d", 0 );
-    if ( !(iMaintenance->ValidateL( ) ) )
+	
+    TBool isValid(EFalse);
+    TRAPD(err, isValid = iMaintenance->ValidateL( ));
+    
+    if( err == KErrCorrupt )
+        {
+        DeleteDatabase();
+        User::Leave( err );
+        }
+    
+    else if ( !isValid )
         {
         // Pump up priority to load the MDS DB up as fast as possible to
         // enable client side session connections
@@ -165,11 +174,6 @@
 				User::Leave( schemaError );
 				}
 			}
-
-		if ( FailedImports() != 0 )
-  			{
-	       	User::Leave( KErrBadName );
-       		}
 		
 		// try to read default import file from C drive
        	TRAPD( err, ImportMetadataL( aManipulate, aSchema, KMdsDefaultImportFile ) );
@@ -179,6 +183,13 @@
        		// and ignore errors
        		TRAP_IGNORE( ImportMetadataL( aManipulate, aSchema, KMdsDefaultRomImportFile ) );
        		}
+
+#ifdef _DEBUG
+        if ( FailedImports() != 0 )
+            {
+            User::Leave( KErrBadName );
+            }
+#endif
        	
        	__LOG1( ELogAlways, "MDS DB tables created %d", 0 );
 
@@ -197,6 +208,12 @@
 			DeleteDatabase();
 			User::Leave( err );
         	}
+        
+        if( !iMaintenance->CheckForCorruptionL() )
+            {
+            DeleteDatabase();
+            User::Leave( KErrCorrupt );
+            }
         }
     __LOG1( ELogAlways, "CMdSMaintenanceEngine::InstallL complete: %d", 0 );
     }
@@ -272,31 +289,6 @@
     User::LeaveIfError( fs.Volume( volumeInfo, EDriveC ) );
     MMdsPreferences::InsertL( KCMediaIdKey, MMdsPreferences::EPreferenceValueSet,
     		(TUint32) volumeInfo.iUniqueID );
-
-    TInt drive( -1 );
-    TInt massStorageError( DriveInfo::GetDefaultDrive( DriveInfo::EDefaultMassStorage, drive ) );
-    if( massStorageError == KErrNone )
-        {
-        TVolumeInfo massStorageVolumeInfo;
-        massStorageError = fs.Volume( massStorageVolumeInfo, drive );
-        if( massStorageError == KErrNone )
-            {
-            const TUint32 massStorageMediaId( massStorageVolumeInfo.iUniqueID );
-            massStorageError = DriveInfo::GetDefaultDrive( DriveInfo::EDefaultRemovableMassStorage, drive );
-            if( massStorageError == KErrNone )
-                {
-                massStorageError = fs.Volume( massStorageVolumeInfo, drive );
-                // Update mass storage media id if the mass storage is not memory card
-                if( massStorageError == KErrNone &&
-                    massStorageVolumeInfo.iUniqueID != massStorageMediaId &&
-                    massStorageMediaId != 0 )
-                    {
-                    MMdsPreferences::InsertL( KMassStorageMediaIdKey, MMdsPreferences::EPreferenceValueSet,
-                            (TUint32) massStorageMediaId );
-                    }        
-                }
-            }
-        }
     
     CleanupStack::PopAndDestroy( &fs );
 	}