harvester/server/src/restorewatcher.cpp
branchRCL_3
changeset 15 3cebc1a84278
parent 1 acef663c1218
equal deleted inserted replaced
14:646a02f170b9 15:3cebc1a84278
    64 // Standard C++ destructor.
    64 // Standard C++ destructor.
    65 // -----------------------------------------------------------------------------
    65 // -----------------------------------------------------------------------------
    66 //
    66 //
    67 CRestoreWatcher::~CRestoreWatcher()
    67 CRestoreWatcher::~CRestoreWatcher()
    68 	{
    68 	{
    69 	
       
    70 	if( iPropertyWatcher )
    69 	if( iPropertyWatcher )
    71 		{
    70 		{
    72 		iPropertyWatcher->StopListeningKeyChanges( 
    71 		iPropertyWatcher->StopListeningKeyChanges( 
    73 				KUidSystemCategory,
    72 				KUidSystemCategory,
    74 				conn::KUidBackupRestoreKey, this );
    73 				conn::KUidBackupRestoreKey, this );
    78 				KPSRestoreWatcherCategory,
    77 				KPSRestoreWatcherCategory,
    79 				KPSRestoreWatcherClientsKey, this );
    78 				KPSRestoreWatcherClientsKey, this );
    80 		
    79 		
    81 		iPropertyWatcher->Delete(); // Release connection to TLS object.
    80 		iPropertyWatcher->Delete(); // Release connection to TLS object.
    82 		}
    81 		}
       
    82 	
       
    83 	iFs.Close();
    83 	}
    84 	}
    84 
    85 
    85 // -----------------------------------------------------------------------------
    86 // -----------------------------------------------------------------------------
    86 // CRestoreWatcher::ConstructL
    87 // CRestoreWatcher::ConstructL
    87 // Symbian 2nd phase constructor.
    88 // Symbian 2nd phase constructor.
    89 //
    90 //
    90 void CRestoreWatcher::ConstructL()
    91 void CRestoreWatcher::ConstructL()
    91 	{
    92 	{
    92 	WRITELOG("CRestoreWatcher::ConstructL()");
    93 	WRITELOG("CRestoreWatcher::ConstructL()");
    93 
    94 
       
    95     User::LeaveIfError( iFs.Connect() );
       
    96 	
    94 	CreateFileNameL();
    97 	CreateFileNameL();
    95 	CheckRestoreL();
    98 	CheckRestoreL();
    96     WRITELOG1("CRestoreWatcher::ConstructL() - iRestoreDone: %d", iRestoreDone );
    99     WRITELOG1("CRestoreWatcher::ConstructL() - iRestoreDone: %d", iRestoreDone );
    97 	
   100 	
    98 	WRITELOG("CRestoreWatcher::ConstructL() - creating restore watcher PS key");
   101 	WRITELOG("CRestoreWatcher::ConstructL() - creating restore watcher PS key");
   134 void CRestoreWatcher::CreateFileNameL() 
   137 void CRestoreWatcher::CreateFileNameL() 
   135 	{
   138 	{
   136 	TInt drive ( 0 );
   139 	TInt drive ( 0 );
   137 	User::LeaveIfError( 
   140 	User::LeaveIfError( 
   138 			DriveInfo::GetDefaultDrive( DriveInfo::EDefaultSystem, drive ) );
   141 			DriveInfo::GetDefaultDrive( DriveInfo::EDefaultSystem, drive ) );
   139 
       
   140     RFs fsSession;
       
   141     User::LeaveIfError( fsSession.Connect() );
       
   142   
   142   
   143     TChar driveLetter;
   143     TChar driveLetter;
   144     fsSession.DriveToChar( drive, driveLetter );
   144     iFs.DriveToChar( drive, driveLetter );
   145 	
   145 	
   146     iFileName.Append( driveLetter );
   146     iFileName.Append( driveLetter );
   147     iFileName.Append( KRestoreFile );  // result-> C:\\private\\200009F5\\restoredone
   147     iFileName.Append( KRestoreFile );  // result-> C:\\private\\200009F5\\restoredone
   148  
       
   149     fsSession.Close();
       
   150 	}
   148 	}
   151 
   149 
   152 
   150 
   153 // -----------------------------------------------------------------------------
   151 // -----------------------------------------------------------------------------
   154 // CRestoreWatcher::NotifyKeyL
   152 // CRestoreWatcher::NotifyKeyL
   272 // Sets restore flag on.
   270 // Sets restore flag on.
   273 // -----------------------------------------------------------------------------
   271 // -----------------------------------------------------------------------------
   274 //
   272 //
   275 void CRestoreWatcher::SetRestoreFlagL( TBool aRestoreDone )
   273 void CRestoreWatcher::SetRestoreFlagL( TBool aRestoreDone )
   276 	{	
   274 	{	
   277 	RFs fs;
       
   278 	User::LeaveIfError( fs.Connect() );
       
   279 	
       
   280 	iRestoreDone = aRestoreDone;
   275 	iRestoreDone = aRestoreDone;
   281 	if( aRestoreDone )
   276 	if( aRestoreDone )
   282 		{	
   277 		{	
   283 		RFile64 file;
   278 		RFile64 file;
   284 		file.Replace( fs, iFileName, EFileWrite );
   279 		file.Replace( iFs, iFileName, EFileWrite );
   285 		file.Close();
   280 		file.Close();
   286 		}
   281 		}
   287 	else
   282 	else
   288 		{
   283 		{
   289 		fs.Delete( iFileName );
   284 		iFs.Delete( iFileName );
   290 		}
   285 		}
   291 	
       
   292 	fs.Close();
       
   293 	}
   286 	}
   294 
   287 
   295 // -----------------------------------------------------------------------------
   288 // -----------------------------------------------------------------------------
   296 // CRestoreWatcher::CheckRestoreL
   289 // CRestoreWatcher::CheckRestoreL
   297 // Check if restore has done when booting up harvester server.
   290 // Check if restore has done when booting up harvester server.
   298 // -----------------------------------------------------------------------------
   291 // -----------------------------------------------------------------------------
   299 //
   292 //
   300 void CRestoreWatcher::CheckRestoreL()
   293 void CRestoreWatcher::CheckRestoreL()
   301 	{
   294 	{
   302 	RFs fs;
       
   303 	RFile64 file;
   295 	RFile64 file;
   304 	User::LeaveIfError( fs.Connect() );
       
   305 	TInt fileError( KErrNotFound );
   296 	TInt fileError( KErrNotFound );
   306 	fileError = file.Open( fs, iFileName, EFileRead );
   297 	fileError = file.Open( iFs, iFileName, EFileRead );
   307 	file.Close();
   298 	file.Close();
   308 	fs.Close();
       
   309     
   299     
   310 	WRITELOG1("CRestoreWatcher::StartMonitoring - fileError: %d", fileError);
   300 	WRITELOG1("CRestoreWatcher::StartMonitoring - fileError: %d", fileError);
   311 	
   301 	
   312     if ( fileError == KErrNone )
   302     if ( fileError == KErrNone )
   313     	{
   303     	{