www.pudn.com > MyP990Camera.zip > MyFileHandler.cpp
/***************************************************************************** COPYRIGHT All rights reserved Sony Ericsson Mobile Communications AB 2006. The software is the copyrighted work of Sony Ericsson Mobile Communications AB. The use of the software is subject to the terms of use or of the end-user license agreement which accompanies or is included with the software. The software is provided "as is" and Sony Ericsson specifically disclaim any warranty or condition whatsoever regarding merchantability or fitness for a specific purpose, title or non-infringement. No warranty of any kind is made in relation to the condition, suitability, availability, accuracy, reliability, merchantability and/or non-infringement of the software provided herein. *****************************************************************************/ // MyFileHandler.cpp #include "MyFileHandler.h" #include#include #include _LIT(KSaving,"Saving..."); _LIT(KFileFormat, "%S%S%S"); _LIT(KFileDigitFormat, "%S%S_%d%S"); _LIT(KExtJpg, ".jpg"); _LIT(KPathC, "c:\\Media Files\\Picture\\MyP990Camera\\"); _LIT(KPathD, "d:\\Picture\\MyP990Camera\\"); _LIT(KName, "MyCamPic"); CMyFileHandler* CMyFileHandler::NewLC() { CMyFileHandler* self = new (ELeave) CMyFileHandler(); CleanupStack::PushL(self); self->ConstructL(); return self; } CMyFileHandler::~CMyFileHandler() { } TBool CMyFileHandler::SetSaveDriveL(TBool aIsSetC) { if(aIsSetC) { iSaveToC = ETrue; return ETrue; } else { RFs fs; User::LeaveIfError(fs.Connect()); TDriveList driveList; // get drive list fs.DriveList(driveList); // additional test if D drive is valid CDir* entryList(0); _LIT(KDriveDPath, "d:\\"); TRAPD(err, fs.GetDir(KDriveDPath, KEntryAttNormal | KEntryAttHidden | KEntryAttSystem, ESortByName | EDirsFirst | EAscending, entryList)); fs.Close(); // check if drive is valid if( (driveList.operator[](EDriveD) != 0) && !err && entryList) { delete entryList; iSaveToC = EFalse; return EFalse; } else { delete entryList; iSaveToC = ETrue; return ETrue; } } } TInt CMyFileHandler::SaveDescToFileL(MCameraBuffer& aCameraBuffer) { if(iBusySaving) return KErrNotReady; iBusySaving = ETrue; CEikonEnv::Static()->BusyMsgL(KSaving); TFileName fileName; GetValidFileName(fileName, KExtJpg); //CEikonEnv::InfoWinL(_L("SaveFileName:"), fileName); RFs fs; fs.Connect(); RFile file; file.Replace(fs, fileName, EFileShareExclusive|EFileWrite); file.Write(*aCameraBuffer.DataL(aCameraBuffer.iIndexOfFirstFrameInBuffer)); file.Close(); fs.Close(); aCameraBuffer.Release(); iBusySaving = EFalse; CEikonEnv::Static()->BusyMsgCancel(); return KErrNone; } CMyFileHandler::CMyFileHandler() : iBusySaving(EFalse), iSaveToC(ETrue) { } void CMyFileHandler::ConstructL() { } void CMyFileHandler::GetValidFileName(TFileName& aFileName, const TDesC& aExt) { RFs& fs = CEikonEnv::Static()->FsSession(); TPtrC* path; if(iSaveToC) { fs.MkDirAll(KPathC); path = new TPtrC(KPathC); } else { fs.MkDirAll(KPathD); path = new TPtrC(KPathD); } TInt index = 0; TUint attValue; do { if( index == 0 ) aFileName.Format(KFileFormat, path, &KName, &aExt); else aFileName.Format(KFileDigitFormat, path, &KName, index, &aExt); if( fs.Att(aFileName, attValue) != KErrNone ) break; else index++; } while(index < 500); // if there are no valid files, remove one of the existing if(index >= 500) { aFileName.Format(KFileDigitFormat, path, &KName, 0, &aExt); CEikonEnv::Static()->FsSession().Delete(aFileName); } delete path; }