📄 blueshare_precopy.cpp
字号:
// blueshare_precopy.cpp
//
#include <e32base.h>
#include <e32cons.h>
#include <coemain.h>
#include <msvapi.h>
#include <msvids.h>
#include <btmsgtypeuid.h>
#include <mmsvattachmentmanager.h>
#include <f32file.h>
#include "blueshareconstants.h"
class CDummyObserver : public CBase, public MMsvSessionObserver
{
public:
void HandleSessionEventL(TMsvSessionEvent, TAny*, TAny*, TAny*) {};
};
LOCAL_D CConsoleBase* console; // write all your messages to this
LOCAL_C void doExampleL(); // code this function for the real example
LOCAL_C void callExampleL(); // initialize with cleanup stack, then do example
GLDEF_C TInt E32Main() // main function called by E32
{
__UHEAP_MARK;
CTrapCleanup* cleanup=CTrapCleanup::New(); // get clean-up stack
TRAPD(error,callExampleL()); // more initialization, then do example
__ASSERT_ALWAYS(!error,User::Panic(KTxtEPOC32EX,error));
delete cleanup; // destroy clean-up stack
__UHEAP_MARKEND;
return 0; // and return
}
LOCAL_C void callExampleL() // initialize and call example code under cleanup stack
{
console=Console::NewL(KTxtExampleCode,TSize(KConsFullScreen,KConsFullScreen));
CleanupStack::PushL(console);
TRAPD(error,doExampleL()); // perform example function
if (error)
console->Printf(KFormatFailed, error);
else
console->Printf(KTxtOK);
console->Printf(KTxtPressAnyKey);
console->Getch(); // get and ignore character
CleanupStack::PopAndDestroy(); // close console
}
LOCAL_C void doExampleL()
{
//! create and install active scheduler if needed!
//CActiveScheduler* scheduler = new (ELeave) CActiveScheduler;
//CleanupStack::PushL(scheduler);
//CActiveScheduler::Install(scheduler);
CDummyObserver *aDummyObserver = new(ELeave) CDummyObserver;
CleanupStack::PushL(aDummyObserver);
/**
* CMsvSession::OpenSyncL() Creates a session synchronously.
* The session can be used once the function returns.
*/
CMsvSession* aSession = CMsvSession::OpenSyncL(*aDummyObserver);
if(aSession)
{
TMsvSelectionOrdering sort;
sort.SetShowInvisibleEntries(ETrue);
sort.SetSorting(EMsvSortByDate);
// Take a handle to the folder entry
CMsvEntry* parentEntry = CMsvEntry::NewL(*aSession,KMsvGlobalInBoxIndexEntryId, sort);
CleanupStack::PushL(parentEntry);
// A selection of all BT entries
CMsvEntrySelection* entries = parentEntry->ChildrenWithMtmL(KUidMsgTypeBt);
CleanupStack::PushL(entries);
//Process all entries
for(TInt i = 0; i < entries->Count(); i++)
{
//Get entry
CMsvEntry* btEntry = aSession->GetEntryL((*entries)[i]);
CleanupStack::PushL(btEntry);
//Then get entrys child
CMsvEntrySelection* btChildren = btEntry->ChildrenL();
CleanupStack::PushL(btChildren);
TInt childc = btChildren->Count();
if (childc>0)
{
for(TInt i=0; i<childc; i++)
{
TMsvId btAtt = (*btChildren)[i];
btEntry->SetEntryL(btAtt);
if (btEntry->HasStoreL())
{
CMsvStore* store = btEntry->ReadStoreL();
CleanupStack::PushL(store);
MMsvAttachmentManager& attMngr = store->AttachmentManagerL();
TInt attcount = attMngr.AttachmentCount();
//! Retrive the attachments and locate the file
for(TInt j=0; j<attcount; j++)
{
CMsvAttachment* attachment = attMngr.GetAttachmentInfoL(j);
if(attachment->AttachmentName().Match(KMatchSis))
{
RFile file = attMngr.GetAttachmentFileL(j);
TInt size;
file.Size(size);
RFs session;
session.Connect();
TFileName copyfileName;
copyfileName.Copy(KBSAppFileName);
RFile toFile;
TInt delerr = session.Delete(copyfileName);
if(delerr == KErrNotFound || delerr == KErrNone)
{
toFile.Create(session,copyfileName,EFileWrite);
CleanupClosePushL(toFile);
HBufC8* bufferDes = NULL;
bufferDes = HBufC8::NewLC(size);
TPtr8 aBDPointer(bufferDes->Des());
User::LeaveIfError(file.Read(aBDPointer, size));
toFile.Write(aBDPointer,size);
toFile.Flush();
CleanupStack::PopAndDestroy(); //toFile
}
else
{
}
file.Close(); //RFile
session.Close();//RFs
CleanupStack::Pop();//bufferDes
}
}
CleanupStack::PopAndDestroy(store);
}
}
}
CleanupStack::PopAndDestroy(2); //btEntry, btChildren
}
CleanupStack::PopAndDestroy(2); // parentEngry, entries
}
CleanupStack::PopAndDestroy(aDummyObserver);
//CleanupStack::PopAndDestroy(scheduler);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -