00001
00002
00003 #include "MFCio.h"
00004
00005
00006 using namespace jbxl;
00007 using namespace jbxwl;
00008
00009
00024 int jbxwl::copyFileWithCounter(LPCTSTR src, LPCTSTR dst)
00025 {
00026 unsigned long int sz = file_size_t(src);
00027 if (sz<=0) return -1;
00028
00029 FILE* sfp = tfopen(src, _T("rb"));
00030 if (sfp==NULL) return -2;
00031
00032 FILE* dfp = tfopen(dst, _T("wb"));
00033 if (dfp==NULL) {
00034 fclose(sfp);
00035 return -3;
00036 }
00037
00038 int ret = copyFPWithCounter(sfp, dfp, sz);
00039
00040 fclose(dfp);
00041 fclose(sfp);
00042
00043 if (ret<=0) ret -= 10;
00044 return ret;
00045 }
00046
00047
00048
00058 int jbxwl::copyFPWithCounter(FILE* src, FILE* dst, unsigned long int sz)
00059 {
00060
00061
00062 CProgressBarDLG* counter = NULL;
00063
00064 int count_max = 20;
00065 int count_intvl = sz/MAXBUFSZ/count_max;
00066
00067 if (sz>MAXBUFSZ && count_intvl>0) {
00068 counter = new CProgressBarDLG(IDD_PROGBAR, NULL, TRUE);
00069 if (counter!=NULL) {
00070 SetGlobalCounter(counter);
00071 CString mesg;
00072 mesg.LoadString(IDS_STR_WRTNG_FILE);
00073
00074 char* mbstr = ts2mbs(mesg);
00075 counter->Start(0, mbstr);
00076 ::free(mbstr);
00077 }
00078 }
00079
00080 if (counter!=NULL) {
00081 counter->SetMax(count_max);
00082 counter->SetPos(0);
00083 }
00084
00085
00086 unsigned char buf[MAXBUFSZ];
00087 int sum = 0;
00088 int cnt = 0;
00089 size_t rsz = 0;
00090 size_t wsz = 0;
00091
00092
00093 do {
00094 rsz = fread(buf, 1, MAXBUFSZ, src);
00095 wsz = fwrite(buf, rsz, 1, dst);
00096 sum += (int)rsz;
00097
00098 cnt++;
00099 if (counter!=NULL) {
00100 if (cnt%count_intvl==0) {
00101 counter->StepIt();
00102 if (counter->isCanceled()) {
00103 sum = -1;
00104 break;
00105 }
00106 }
00107 }
00108 } while (!feof(src) && rsz>0 && wsz>0);
00109
00110
00111 if (counter!=NULL) {
00112 counter->Stop();
00113 ClearGlobalCounter();
00114 delete counter;
00115 }
00116
00117
00118 if (sum!=0) {
00119 if (!feof(src) && (rsz==0||wsz==0)) sum = -2;
00120 else if (sum!=sz) {
00121 DEBUG_ERROR("jbxwl::copyFPWithCounter(): WARNING: File Size is %d, but Write Size is %d\n", sz, sum);
00122 sum = -3;
00123 }
00124 }
00125
00126 return sum;
00127 }
00128
00129
00130
00131 int jbxwl::writeGraphicFileWithCounter(LPCTSTR fname, MSGraph<sWord> vp, int frmt, BOOL mlt, int fn, int tn)
00132 {
00133
00134 CProgressBarDLG* counter = NULL;
00135 if (vp.zs>=10) {
00136 counter = new CProgressBarDLG(IDD_PROGBAR, NULL, TRUE);
00137 if (counter!=NULL) {
00138 SetGlobalCounter(counter);
00139 CString mesg;
00140 mesg.LoadString(IDS_STR_WRTNG_FILE);
00141
00142 char* mbstr = ts2mbs(mesg);
00143 counter->Start(0, mbstr);
00144 ::free(mbstr);
00145 }
00146 }
00147
00148
00149 char* mbstr = ts2mbs(fname);
00150 int ret = writeGraphicFile(mbstr, vp, frmt, mlt, fn, tn, true);
00151 ::free(mbstr);
00152
00153
00154 if (counter!=NULL) {
00155 counter->Stop();
00156 ClearGlobalCounter();
00157 delete counter;
00158 }
00159
00160 return ret;
00161 }
00162
00163