Update contrib.
2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
23 #include "filecompare.h"
25 #include "cryptospi/cryptospidef.h"
30 const TInt KCompareBlockSize = 0xff;
32 //const TInt KCompareEqual = 0;
33 const TInt KCompareGreaterThan = 1;
34 const TInt KCompareLessThan = -1;
36 // a simple utility class to compare 2 files, returns
37 TInt TFileCompare::CompareL(TPtrC aFile1Path, TPtrC aFile2Path)
39 // assume is all well, compare always
46 User::LeaveIfError(rFs.Connect());
47 CleanupClosePushL(rFs);
48 User::LeaveIfError(file1.Open(rFs, aFile1Path, EFileRead));
49 CleanupClosePushL(file1);
50 User::LeaveIfError(file2.Open(rFs, aFile2Path, EFileRead));
51 CleanupClosePushL(file2);
54 file1.Size(file1Size);
57 file2.Size(file2Size);
59 // bail out if the sizes of the 2 files are different
60 if(file1Size == file2Size)
63 TBuf8<KCompareBlockSize> tempBuf1;
64 TBuf8<KCompareBlockSize> tempBuf2;
66 TInt compareBlockSize;
69 if(file1Size > KCompareBlockSize)
71 compareBlockSize = KCompareBlockSize;
72 loopCount = file1Size / compareBlockSize;
77 compareBlockSize = file1Size;
81 // read through the files comparing each block
82 for(TInt i = 0; i < loopCount; i++)
85 file1.Read(tempBuf1, compareBlockSize);
86 file2.Read(tempBuf2, compareBlockSize);
88 // remember, 0 is return value for a successful comparison
90 retVal = tempBuf1.Compare(tempBuf2);
93 //if files fail to match, break out of the loop
100 if(file1Size > file2Size)
101 retVal = KCompareGreaterThan;
103 retVal = KCompareLessThan;
106 CleanupStack::PopAndDestroy(&file2);
107 CleanupStack::PopAndDestroy(&file1);
109 CleanupStack::PopAndDestroy(&rFs);