mtpdataproviders/mtppictbridgedp/pictbridgeengine/src/dpsfile.cpp
branchRCL_3
changeset 19 0aa8cc770c8a
equal deleted inserted replaced
18:453dfc402455 19:0aa8cc770c8a
       
     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:  This class reads and writes the file content. 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "dpsfile.h"
       
    20 #include "dpsdefs.h"
       
    21 #include "dpsconst.h"
       
    22 
       
    23 #ifdef _DEBUG
       
    24 #	define IF_DEBUG(t) {RDebug::t;}
       
    25 #else
       
    26 #	define IF_DEBUG(t)
       
    27 #endif
       
    28 
       
    29     
       
    30 // --------------------------------------------------------------------------
       
    31 // 
       
    32 // --------------------------------------------------------------------------
       
    33 //
       
    34 CDpsFile* CDpsFile::NewL()
       
    35 	{
       
    36 	IF_DEBUG(Print(_L("CDpsFile::NewL")));
       
    37 	CDpsFile* self = new (ELeave) CDpsFile();
       
    38 	CleanupStack::PushL(self);
       
    39     self->ConstructL();
       
    40     CleanupStack::Pop(); 
       
    41 	return self;
       
    42 	}
       
    43 
       
    44 // --------------------------------------------------------------------------
       
    45 // 
       
    46 // --------------------------------------------------------------------------
       
    47 //
       
    48 void CDpsFile::ConstructL()
       
    49     {
       
    50     IF_DEBUG(Print(_L(">>>CDpsFile::ConstructL")));    
       
    51 	User::LeaveIfError(iFs.Connect());
       
    52     IF_DEBUG(Print(_L("<<<CDpsFile::ConstructL")));    
       
    53     }
       
    54     
       
    55 // --------------------------------------------------------------------------
       
    56 // 
       
    57 // --------------------------------------------------------------------------
       
    58 //
       
    59 CDpsFile::~CDpsFile()
       
    60 	{
       
    61 	IF_DEBUG(Print(_L(">>>CDpsFile::~")));        
       
    62 	iFs.Close();
       
    63 	IF_DEBUG(Print(_L("<<<CDpsFile::~")));        
       
    64     }
       
    65 
       
    66 // ---------------------------------------------------------------------------
       
    67 // 
       
    68 // ---------------------------------------------------------------------------
       
    69 //
       
    70 TInt CDpsFile::CreateScriptFile(const TDesC& aFileName, const TDesC8& aScript,
       
    71 								const TInt aFileSize)
       
    72     {
       
    73     IF_DEBUG(Print(_L(">>>CDpsFile::CreateScriptFile size %d"), aFileSize));            
       
    74     RFile file;
       
    75     TInt err = file.Replace(iFs, aFileName, EFileShareExclusive);
       
    76     IF_DEBUG(Print(_L("---the error is %d"), err));
       
    77     if (err != KErrNone)
       
    78         {
       
    79         return err;
       
    80         }
       
    81         
       
    82     TInt fileSize = aScript.Size();
       
    83     if (!fileSize)
       
    84         {
       
    85         err = file.Write(_L8(""), 0);
       
    86         }
       
    87     else if ( fileSize <= aFileSize)
       
    88         {
       
    89         err = file.Write(aScript, fileSize);
       
    90         }
       
    91     else
       
    92         {
       
    93         err = file.Write(aScript, aFileSize);
       
    94         }
       
    95         
       
    96     file.Close();
       
    97     IF_DEBUG(Print(_L("<<<CDpsFile::CreateScriptFile %d"), err));            
       
    98     return err;   
       
    99     }
       
   100 
       
   101 // ---------------------------------------------------------------------------
       
   102 // 
       
   103 // ---------------------------------------------------------------------------
       
   104 //
       
   105 void CDpsFile::GetContentL(const TDesC& aFileName, TDes8& aScript)
       
   106     {
       
   107     IF_DEBUG(Print(_L(">>>CDpsFile::GetContent %S"), &aFileName));                
       
   108     RFile file;
       
   109     CleanupClosePushL(file);
       
   110     User::LeaveIfError(file.Open(iFs, aFileName, EFileRead));
       
   111     User::LeaveIfError(file.Read(aScript));
       
   112     CleanupStack::PopAndDestroy();
       
   113     IF_DEBUG(Print(_L("<<<CDpsFile::GetContent")));                       
       
   114     }
       
   115 
       
   116 // ---------------------------------------------------------------------------
       
   117 // 
       
   118 // ---------------------------------------------------------------------------
       
   119 //    
       
   120 void CDpsFile::FileSizeL(const TDesC& aFileName, TInt& aSize)
       
   121     {
       
   122     IF_DEBUG(Print(_L(">>>CDpsFile::FileSize %S"), &aFileName));       
       
   123     RFile file;
       
   124     CleanupClosePushL(file);
       
   125     User::LeaveIfError(file.Open(iFs, aFileName, EFileRead)); 
       
   126     User::LeaveIfError(file.Size(aSize));    
       
   127     CleanupStack::PopAndDestroy();
       
   128     IF_DEBUG(Print(_L("<<<CDpsFile::FileSize %d"), aSize));                
       
   129     }
       
   130     
       
   131 // ---------------------------------------------------------------------------
       
   132 // 
       
   133 // ---------------------------------------------------------------------------
       
   134 //    
       
   135 TInt CDpsFile::Delete(const TDesC& aFileName)
       
   136     {
       
   137     IF_DEBUG(Print(_L("CDpsFile::Delete")));                    
       
   138     return iFs.Delete(aFileName);
       
   139     }