myfilehandler.cpp

来自「UIQ3 P990 Camera使用实例」· C++ 代码 · 共 152 行

CPP
152
字号
/***************************************************************************** 
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 <f32file.h>
#include <eikenv.h>
#include <ecam.h>


_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;
  }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?