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