00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "Notify.h"
00017
00018 _LIT(KStarted,"Copy started\n");
00019 _LIT(KComplete,"Copy complete\n");
00020 _LIT(KProgress,"%d bytes copied\n");
00021
00022
00023
00024
00025
00026 TFileCopyProgressMonitor::TFileCopyProgressMonitor(CFileMan& aFileMan)
00027 :iFileMan(aFileMan)
00028 {
00029 }
00030
00031
00032 MFileManObserver::TControl TFileCopyProgressMonitor::NotifyFileManStarted()
00033 {
00034 console->Printf(KStarted);
00035 return EContinue;
00036 }
00037
00038
00039 MFileManObserver::TControl TFileCopyProgressMonitor::NotifyFileManOperation()
00040 {
00041 console->Printf(KProgress,iFileMan.BytesTransferredByCopyStep());
00042 return EContinue;
00043 }
00044
00045
00046 MFileManObserver::TControl TFileCopyProgressMonitor::NotifyFileManEnded()
00047 {
00048 console->Printf(KComplete);
00049 return EContinue;
00050 }
00051
00052
00053
00054
00055
00056
00057 LOCAL_C void doExampleL()
00058 {
00059 _LIT(KSourcePath,"dataFile\\");
00060 _LIT(KDestinationPath,"dataFileCopy\\");
00061
00062 TInt err;
00063
00064
00065 RFs fsSession;
00066 User::LeaveIfError(fsSession.Connect());
00067
00068
00069 User::LeaveIfError(fsSession.CreatePrivatePath(RFs::GetSystemDrive()));
00070
00071
00072 User::LeaveIfError(fsSession.SetSessionToPrivate(RFs::GetSystemDrive()));
00073
00074
00075 TFileName path;
00076 fsSession.PrivatePath(path);
00077
00078
00079 RBuf pathSource;
00080 RBuf pathDestination;
00081
00082 pathSource.CreateL(sizeof(TFileName));
00083 pathSource.CleanupClosePushL();
00084 pathSource.Append(path);
00085 pathSource.Append(KSourcePath);
00086
00087 pathDestination.CreateL(sizeof(TFileName));
00088 pathDestination.CleanupClosePushL();
00089 pathDestination.Append(path);
00090 pathDestination.Append(KDestinationPath);
00091
00092 err=fsSession.MkDir(pathSource);
00093 if (err!=KErrAlreadyExists)
00094 User::LeaveIfError(err);
00095
00096 err=fsSession.MkDir(pathDestination);
00097 if (err!=KErrAlreadyExists)
00098 User::LeaveIfError(err);
00099
00100
00101
00102 _LIT(KFile1,"dataFile1.txt");
00103 _LIT(KFile2,"dataFile2.txt");
00104 _LIT8(KFile1Data,"File data qwertyu");
00105 _LIT8(KFile2Data,"File data iop");
00106
00107 fsSession.SetSessionPath(pathSource);
00108 RFile file;
00109
00110 User::LeaveIfError(file.Replace(fsSession,KFile1,EFileWrite));
00111 User::LeaveIfError(file.Write(KFile1Data));
00112 User::LeaveIfError(file.Flush());
00113 file.Close();
00114
00115 User::LeaveIfError(file.Replace(fsSession,KFile2,EFileWrite));
00116 User::LeaveIfError(file.Write(KFile2Data));
00117 User::LeaveIfError(file.Flush());
00118 file.Close();
00119
00120
00121 CFileMan* fileMan = CFileMan::NewL(fsSession);
00122 CleanupStack::PushL(fileMan);
00123
00124
00125 TFileCopyProgressMonitor fileCopyProgressMonitor(*fileMan);
00126 fileMan->SetObserver(&fileCopyProgressMonitor);
00127
00128
00129 fileMan->Copy(pathSource,pathDestination);
00130
00131
00132 CleanupStack::PopAndDestroy(3);
00133
00134
00135
00136 fsSession.Close();
00137 }
00138