ImportPhoto.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807
  1. // ImportPhoto.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "ylgl.h"
  5. #include "ImportPhoto.h"
  6. #include "MyLock.h"
  7. #include "ZipTypeDlg.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. /////////////////////////////////////////////////////////////////////////////
  14. // ImportPhoto dialog 拷贝失败
  15. ImportPhoto::ImportPhoto(CWnd* pParent /*=NULL*/)
  16. : CDialog(ImportPhoto::IDD, pParent)
  17. {
  18. //{{AFX_DATA_INIT(ImportPhoto)
  19. // NOTE: the ClassWizard will add member initialization here
  20. m_mode=0;
  21. //}}AFX_DATA_INIT
  22. m_pArray2=NULL;
  23. m_pDesArray=NULL;
  24. m_exitcode=0;
  25. m_bOverWrite=1;
  26. m_bBeautifySkinFrom=0;
  27. m_bOrigin=0;
  28. m_bSaveUploadTask=0;
  29. m_bCopyToLocal=0;
  30. m_nOutputSize=0;
  31. m_bOfmat=0;
  32. m_nphototype=-1;
  33. m_bAddname=0;
  34. beginno=-1;
  35. m_bautono=1;
  36. }
  37. void ImportPhoto::DoDataExchange(CDataExchange* pDX)
  38. {
  39. CDialog::DoDataExchange(pDX);
  40. //{{AFX_DATA_MAP(ImportPhoto)
  41. DDX_Control(pDX, IDC_PROGRESS1, m_progress);
  42. //}}AFX_DATA_MAP
  43. }
  44. BEGIN_MESSAGE_MAP(ImportPhoto, CDialog)
  45. //{{AFX_MSG_MAP(ImportPhoto)
  46. ON_WM_CLOSE()
  47. //}}AFX_MSG_MAP
  48. END_MESSAGE_MAP()
  49. /////////////////////////////////////////////////////////////////////////////
  50. // ImportPhoto message handlers
  51. void ImportPhoto::OnOK()
  52. {
  53. // TODO: Add extra validation here
  54. }
  55. void ImportPhoto::OnCancel()
  56. {
  57. // TODO: Add extra cleanup here
  58. }
  59. int ImportPhoto::GetFileNo(CString dir)
  60. {
  61. if(m_bautono==0)
  62. {
  63. int a=beginno;
  64. beginno++;
  65. return a;
  66. }
  67. CString path;
  68. CString path2;
  69. CString path3;
  70. CString path4;
  71. int begin=1;
  72. CString temp;
  73. CStringArray array;
  74. using namespace helper_coffs;
  75. ffsco o;
  76. o.dirs(1);
  77. o.find(LPCSTR(dir), LPCSTR("*.*"));
  78. ffsco::typeT coo;
  79. ffsco::typeT::iterator it;
  80. coo = o.co_dir();
  81. for (it = coo.begin();coo.end() != it;it ++)
  82. {
  83. temp=(*it).c_str();
  84. if(::FindArray (&array, temp)==-1)
  85. array.Add (temp);
  86. }
  87. BOOL bFind=1;
  88. while(bFind)
  89. {
  90. bFind=0;
  91. for(int i=0; i<array.GetSize (); i++)
  92. {
  93. dir=array.ElementAt (i);
  94. path.Format ("%s%03d.jpg", dir, begin);
  95. path2.Format ("%s%03d.raw", dir, begin);
  96. path3.Format ("%s%03d.cr2", dir, begin);
  97. path4.Format ("%s%03d.NEF", dir, begin);
  98. while(::CheckFileExist (path) || ::CheckFileExist (path2) || ::CheckFileExist (path3) || ::CheckFileExist (path4))
  99. {
  100. begin++;
  101. path.Format ("%s%03d.jpg", dir, begin);
  102. path2.Format ("%s%03d.raw", dir, begin);
  103. path3.Format ("%s%03d.cr2", dir, begin);
  104. path4.Format ("%s%03d.NEF", dir, begin);
  105. bFind=1;
  106. }
  107. }
  108. }
  109. beginno=begin+1;
  110. return begin;
  111. }
  112. void FilterFileName(CString &str)
  113. {
  114. //printf("Jeff:保存目录old:%s\n\n",str);
  115. ///\:*?"<>|
  116. str.Replace("/", "");
  117. str.Replace("\\", "");
  118. str.Replace(":", "");
  119. str.Replace("*", "");
  120. str.Replace("?", "");
  121. str.Replace("\"", "");
  122. str.Replace("<", "");
  123. str.Replace(">", "");
  124. str.Replace("|", "");
  125. //printf("Jeff:保存目录last:%s\n\n",str);
  126. }
  127. UINT ImportPhotoThread( LPVOID lpParameter )
  128. {
  129. ImportPhoto *pThis=(ImportPhoto*)lpParameter;
  130. pThis->m_progress .SetRange (0, pThis->m_pArray->GetSize ());
  131. CString filename, filename2;
  132. CString temp;
  133. int pos;
  134. BOOL bNeedGet;
  135. CString temp2;
  136. int fileno;
  137. if(pThis->m_pArray2)
  138. {
  139. WriteTextLog("pThis->m_pArray2");
  140. if(pThis->m_bAddname)
  141. {
  142. WriteTextLog("pThis->m_bAddname");
  143. for(int i=0; i<pThis->m_pArray->GetSize (); i++)
  144. {
  145. filename=pThis->m_pArray->ElementAt (i);
  146. temp=filename.Right (filename.GetLength ()-filename.ReverseFind ('\\')-1);
  147. pos=temp.Find (".");
  148. temp=temp.Left(pos);
  149. temp+="("+pThis->m_name+",";
  150. temp2=pThis->m_pArray2->ElementAt (i)+").jpg";
  151. FilterFileName(temp2);
  152. // Jeff.add:拷贝文件失败,未做处理,最起码要日志记录失败原因;
  153. ::CopyFile (filename, pThis->m_savepath+temp+temp2, pThis->m_bOverWrite==0);
  154. WriteTextLog("pThis->m_bAddname:%s->%s", filename, pThis->m_savepath+temp+temp2);
  155. pThis->m_progress.SetPos (i+1);
  156. }
  157. }
  158. else
  159. {
  160. WriteTextLog("!pThis->m_bAddname");
  161. for(int i=0; i<pThis->m_pArray->GetSize (); i++)
  162. {
  163. filename=pThis->m_pArray->ElementAt (i);
  164. filename2=pThis->m_pArray2->ElementAt (i);
  165. pos=filename2.Find (";");
  166. while(pos!=-1)
  167. {
  168. temp=filename2.Left (pos);
  169. FilterFileName(temp);
  170. filename2=filename2.Right (filename2.GetLength ()-pos-1);
  171. pos=filename2.Find (";");
  172. ::CreateDirectory (pThis->m_savepath+temp, NULL);
  173. pThis->MyCopyFile (filename, pThis->m_savepath+temp+filename.Right (filename.GetLength ()-filename.ReverseFind ('\\')), pThis->m_bOverWrite==0);
  174. temp2=filename.Right (filename.GetLength ()-filename.ReverseFind ('\\')-1);
  175. int pos2=temp2.Find (".");
  176. if(pos2!=-1)
  177. {
  178. temp2=temp2.Left (pos2);
  179. CString filename2;
  180. }
  181. }
  182. temp=filename2;
  183. FilterFileName(temp);
  184. ::CreateDirectory (pThis->m_savepath+temp, NULL);
  185. pThis->MyCopyFile (filename, pThis->m_savepath+temp+filename.Right (filename.GetLength ()-filename.ReverseFind ('\\')), pThis->m_bOverWrite==0);
  186. temp2=filename.Right (filename.GetLength ()-filename.ReverseFind ('\\')-1);
  187. pos=temp2.Find (".");
  188. if(pos!=-1)
  189. {
  190. temp2=temp2.Left (pos);
  191. }
  192. pThis->m_progress.SetPos (i+1);
  193. }
  194. }
  195. }
  196. else if(pThis->m_pDesArray)
  197. {
  198. WriteTextLog("pThis->m_pDesArray");
  199. for(int i=0; i<pThis->m_pArray->GetSize (); i++)
  200. {
  201. filename=pThis->m_pArray->ElementAt (i);
  202. if(pThis->m_mode==2)
  203. {
  204. temp=filename.Right (filename.GetLength ()-filename.ReverseFind ('\\')-1);
  205. pos=temp.Find (".");
  206. bNeedGet=1;
  207. if(bNeedGet)// && (g_serverbak!="localserver"))
  208. filename2.Format("%s%03d.jpg",pThis->m_savepath, pThis->GetFileNo(pThis->m_calnopath) );
  209. else
  210. filename2.Format("%s%s.jpg",pThis->m_savepath, temp );
  211. pThis->MyCopyFile(filename, filename2, pThis->m_bOverWrite==0);
  212. }
  213. else
  214. pThis->MyCopyFile (filename, pThis->m_pDesArray->ElementAt (i), pThis->m_bOverWrite==0);
  215. pThis->m_progress.SetPos (i+1);
  216. }
  217. }
  218. else
  219. {
  220. WriteTextLog("!pThis->m_pDesArray");
  221. for(int i=0; i<pThis->m_pArray->GetSize (); i++)
  222. {
  223. filename=pThis->m_pArray->ElementAt (i);
  224. if(pThis->m_mode==2)
  225. {
  226. CString ext=filename.Right (filename.GetLength ()-filename.ReverseFind ('.')-1);
  227. if(0)//g_serverbak=="localserver")
  228. {
  229. temp=filename.Right (filename.GetLength ()-filename.ReverseFind ('\\')-1);
  230. filename2.Format("%s%s",pThis->m_savepath, temp);
  231. }
  232. else
  233. {
  234. fileno=pThis->GetFileNo(pThis->m_calnopath);
  235. filename2.Format("%s%03d.%s",pThis->m_savepath, fileno, ext);
  236. }
  237. pThis->MyCopyFile(filename, filename2, pThis->m_bOverWrite==0);
  238. }
  239. else
  240. {
  241. if(pThis->m_bBeautifySkinFrom)//修片导入
  242. {
  243. temp=pThis->m_savepath+filename.Right (filename.GetLength ()-filename.ReverseFind ('\\')-1);
  244. pos=temp.ReverseFind ('.');
  245. if(pos==-1)continue;
  246. temp=temp.Left (pos);
  247. pos=0;
  248. filename2.Format ("%s.jpg", temp);
  249. pos=2;
  250. while(::PathFileExists (filename2))
  251. {
  252. filename2.Format ("%s-%d.jpg", temp, pos);
  253. pos++;
  254. }
  255. pThis->MyCopyFile (filename, filename2, pThis->m_bOverWrite==0);
  256. }
  257. else
  258. {
  259. if(pThis->m_bOrigin)//原片导出
  260. {
  261. temp=filename.Right (filename.GetLength ()-filename.ReverseFind ('\\')-1);
  262. pos=temp.Find (".");
  263. if(pos==-1)continue;
  264. temp=temp.Left (pos);
  265. pThis->MyCopyFile (filename, pThis->m_savepath+filename.Right (filename.GetLength ()-filename.ReverseFind ('\\')-1), pThis->m_bOverWrite==0);
  266. }
  267. else
  268. pThis->MyCopyFile (filename, pThis->m_savepath+filename.Right (filename.GetLength ()-filename.ReverseFind ('\\')-1), pThis->m_bOverWrite==0);
  269. }
  270. }
  271. pThis->m_progress.SetPos (i+1);
  272. }
  273. }
  274. pThis->PostMessage (WM_CLOSE, 0, 0);
  275. return 1;
  276. }
  277. BOOL ImportPhoto::OnInitDialog()
  278. {
  279. CDialog::OnInitDialog();
  280. if(m_bCopyToLocal)
  281. SetDlgItemText(IDC_STATIC1, "客照缓存中, 请稍候...");
  282. else if(m_mode==1)
  283. SetDlgItemText(IDC_STATIC1, "正在导出客照, 请稍候...");
  284. if(beginno!=-1 && beginno!=0)
  285. {
  286. m_bautono=0;
  287. }
  288. /*
  289. #ifdef ENTERPRISE_VERSION
  290. if(m_bSaveUploadTask)
  291. {
  292. ZipTypeDlg dlg;
  293. dlg.DoModal ();
  294. m_sel=dlg.m_sel ;
  295. }
  296. #endif*/
  297. // m_fp.Open ("c:\\1.txt", CFile::modeCreate|CFile::modeWrite);
  298. // g_filecount=0;
  299. // TODO: Add extra initialization here
  300. AfxBeginThread((AFX_THREADPROC)ImportPhotoThread,(LPVOID)this );
  301. return TRUE; // return TRUE unless you set the focus to a control
  302. // EXCEPTION: OCX Property Pages should return FALSE
  303. }
  304. void SaveTaskPath(CString pathname)
  305. {
  306. return;
  307. CString path=g_path1+"\\taskpath.dat";
  308. CStringArray array;
  309. CFile fp;
  310. if(::PathFileExists (path))
  311. {
  312. try
  313. {
  314. int trycount=5;
  315. while(1)
  316. {
  317. if(fp.Open (path, CFile::modeRead|CFile::shareExclusive))break;
  318. fp.Close ();
  319. trycount--;
  320. if(trycount==0)break;
  321. ::Sleep (1000);
  322. }
  323. if(trycount==0)
  324. {
  325. if(::PathFileExists (path))return;
  326. }
  327. CArchive ar(&fp, CArchive::load);
  328. array.Serialize (ar);
  329. fp.Close ();
  330. }
  331. catch(...)
  332. {
  333. fp.Close ();
  334. // AfxMessageBox("读异常");
  335. }
  336. }
  337. array.Add (pathname);
  338. try
  339. {
  340. int trycount=5;
  341. while(1)
  342. {
  343. if(fp.Open (path, CFile::modeCreate|CFile::modeWrite|CFile::shareExclusive))break;
  344. fp.Close ();
  345. trycount--;
  346. if(trycount==0)break;
  347. ::Sleep (1000);
  348. }
  349. if(trycount==0)
  350. {
  351. // AfxMessageBox("打开失败2");
  352. return;
  353. }
  354. CArchive ar(&fp, CArchive::store);
  355. array.Serialize (ar);
  356. ar.Close();
  357. fp.Close ();
  358. }
  359. catch(...)
  360. {
  361. // AfxMessageBox("写异常");
  362. fp.Close ();
  363. }
  364. }
  365. void ImportPhoto::OnClose()
  366. {
  367. // TODO: Add your message handler code here and/or call default
  368. if(m_nphototype<0 || m_nphototype>3 )
  369. {
  370. CDialog::OnOK ();
  371. return;
  372. }
  373. if( m_uploadtaskarray.GetSize ()<=10)
  374. {
  375. CDialog::OnOK ();
  376. return;
  377. }
  378. #ifdef ENTERPRISE_VERSION
  379. if(m_bSaveUploadTask)
  380. {
  381. CString m_rule= g_cominfoarraylocal.ElementAt(0).ElementAt(116);
  382. CString m_header,m_left,m_right,m_currule;
  383. CStringArray rulearray;
  384. if(m_nphototype==0)
  385. {
  386. m_header="type0@:";
  387. }
  388. else if(m_nphototype==1)
  389. {
  390. m_header="type1@:";
  391. }
  392. else if(m_nphototype==2)
  393. {
  394. m_header="type2@:";
  395. }
  396. else if(m_nphototype==3)
  397. {
  398. m_header="type3@:";
  399. }
  400. int pos=m_rule.Find (m_header);
  401. if(pos!=-1)
  402. {
  403. m_left=m_rule.Left (pos);
  404. m_rule=m_rule.Right (m_rule.GetLength ()-pos);
  405. m_rule.Delete (0, m_header.GetLength ());
  406. pos=m_rule.Find ("@:");
  407. if(pos!=-1)
  408. {
  409. m_right=m_rule.Right (m_rule.GetLength ()-pos+5);
  410. m_rule=m_rule.Left (pos-5);
  411. }
  412. m_currule=m_rule;m_rule.Empty ();
  413. m_currule.TrimLeft ("%$");
  414. m_currule.TrimRight ("%$");
  415. if(m_currule.Find ("%$")!=-1)
  416. {
  417. pos=m_currule.Find ("%$");
  418. while(pos!=-1)
  419. {
  420. if(m_currule.Left (pos)!="")rulearray.Add(m_currule.Left (pos));
  421. m_currule=m_currule.Right (m_currule.GetLength ()-pos-2);
  422. pos=m_currule.Find ("%$");
  423. }
  424. }
  425. if(m_currule!="")rulearray.Add(m_currule);
  426. }
  427. for(int i=0; i<rulearray.GetSize (); i++)
  428. {
  429. m_currule=rulearray.ElementAt (i);
  430. pos=m_currule.Find ("->");
  431. if(pos==-1)continue;
  432. m_left=m_currule.Left (pos);
  433. m_right=m_currule.Right(m_currule.GetLength ()-pos-2);
  434. CString curdomain,curdomain2;
  435. if(m_branch!="")
  436. {
  437. curdomain=GetDomainFromBranch(m_branch);
  438. curdomain2=GetDomainFromBranch(g_brancharray.ElementAt (g_brancharray.GetSize ()-1).ElementAt (0));
  439. }
  440. else if(g_branchname!="")
  441. {
  442. curdomain=GetDomainFromBranch(g_branchname);
  443. curdomain2=GetDomainFromBranch(g_brancharray.ElementAt (g_brancharray.GetSize ()-1).ElementAt (0));
  444. }
  445. else
  446. {
  447. curdomain=GetDomainFromBranch(g_brancharray.ElementAt (g_brancharray.GetSize ()-1).ElementAt (0));
  448. curdomain2=curdomain;
  449. }
  450. CString domainleft=GetDomainFromBranch(m_left);
  451. if(curdomain!=domainleft)
  452. {
  453. continue;
  454. }
  455. CString domainright=GetDomainFromBranch(m_right);
  456. if(domainleft.Find(".ly.com")==-1 || domainright.Find(".ly.com")==-1)
  457. {
  458. continue;
  459. }
  460. if(curdomain2==domainright)
  461. {
  462. continue;
  463. }
  464. MyLock lock("uploadtaskaccess");
  465. m_uploadtaskarray.SetAt (1, domainright);//目的地
  466. m_uploadtaskarray.SetAt (2, domainleft);//文件夹加上域名
  467. m_uploadtaskarray.SetAt (3, m_sel);
  468. CFile fp;
  469. CString pathdir=m_savepath+"uploadtask";
  470. if(m_id!="")
  471. {
  472. int pos=pathdir.Find (m_id);
  473. pos+=m_id.GetLength ();
  474. int pos2=pathdir.ReverseFind ('\\');
  475. pathdir=pathdir.Left (pos)+pathdir.Right (pathdir.GetLength ()-pos2);
  476. }
  477. CString path;
  478. int taskpos=1;
  479. path.Format ("%s%d.dat", pathdir, taskpos);
  480. CString dir=path.Left (path.ReverseFind ('\\')+1);
  481. pathdir=g_path1+"\\上传任务\\";
  482. ::CreateDirectory(pathdir, NULL);
  483. path.Format ("%s%d.dat", pathdir, taskpos);
  484. while(::CheckFileExist (path))
  485. {
  486. taskpos++;
  487. path.Format ("%s%d.dat", pathdir, taskpos);
  488. }
  489. fp.Open (path, CFile::modeCreate|CFile::modeWrite);
  490. CArchive ar(&fp, CArchive::store);
  491. m_uploadtaskarray.SetAt(4, dir);
  492. m_uploadtaskarray.Serialize (ar);
  493. ar.Close();
  494. fp.Close ();
  495. // SaveTaskPath(path);
  496. }
  497. }
  498. #endif
  499. // CString ss;
  500. //ss.Format ("cc:%d", g_filecount);MessageBox(ss);m_fp.Close ();
  501. CDialog::OnOK();
  502. }
  503. // file1原文件;
  504. // file2目标文件;
  505. void ImportPhoto::MyCopyFile(CString file1, CString file2, BOOL bOverWrite)
  506. {
  507. WriteTextLog("MyCopyFile:run:%s->%s",file1, file2);
  508. if(::PathFileExists (file1)==0)
  509. {
  510. return;
  511. }
  512. if(m_bOfmat)
  513. {
  514. WriteTextLog("MyCopyFile:m_bOfmat");
  515. CString file1bak=file1;
  516. CString file2bak=file2;
  517. file1bak=file1bak.Left (file1bak.GetLength ()-3);
  518. file2bak=file2bak.Left (file2bak.GetLength ()-3);
  519. file1bak+="jpg";
  520. file2bak+="jpg";
  521. CString src=file1bak;
  522. CString des=file2bak;
  523. src.Replace(".jpg", ".raw");
  524. des.Replace(".jpg", ".raw");
  525. ::CopyFile (src, des, bOverWrite);
  526. src=file1bak;
  527. des=file2bak;
  528. src.Replace(".jpg", ".nef");
  529. des.Replace(".jpg", ".nef");
  530. ::CopyFile (src, des, bOverWrite);
  531. src=file1bak;
  532. des=file2bak;
  533. src.Replace(".jpg", ".cr2");
  534. des.Replace(".jpg", ".cr2");
  535. ::CopyFile (src, des, bOverWrite);
  536. }
  537. if(m_nphototype==0 ||m_nphototype==1 || m_nphototype==2 || m_nphototype==3)
  538. {
  539. CString str=file2;
  540. CString spath=str.Left (str.ReverseFind ('\\')+1);
  541. CString mpath=spath;
  542. spath+="s";
  543. spath+=str.Right (str.GetLength ()-str.ReverseFind ('\\')-1);
  544. mpath+="m";
  545. mpath+=str.Right (str.GetLength ()-str.ReverseFind ('\\')-1);
  546. ::DeleteFile (spath);
  547. ::DeleteFile (mpath);
  548. }
  549. if(m_nOutputSize)
  550. {
  551. WriteTextLog("MyCopyFile:m_nOutputSize");
  552. file1.MakeLower ();
  553. if(file1.Right (3)=="jpg")
  554. {
  555. Image *img=NULL;
  556. ::LoadImageFromBuf (&img, file1);
  557. if(img==NULL)
  558. {
  559. if(::CopyFile (file1, file2, bOverWrite)==0)
  560. {
  561. CString str;
  562. str=file1;
  563. int pos=str.ReverseFind ('\\');
  564. if(pos!=-1)
  565. str=str.Right (str.GetLength ()-pos-1);
  566. AfxMessageBox("拷贝失败"+str+"请重新导入此文件!");
  567. }
  568. }
  569. else if(img->GetWidth()==0)
  570. {
  571. if(::CopyFile (file1, file2, bOverWrite)==0)
  572. {
  573. CString str;
  574. str=file1;
  575. int pos=str.ReverseFind ('\\');
  576. if(pos!=-1)
  577. str=str.Right (str.GetLength ()-pos-1);
  578. AfxMessageBox("拷贝失败"+str+"请重新导入此文件!!");
  579. }
  580. }
  581. else
  582. {
  583. int newsize=m_nOutputSize;
  584. if(img->GetWidth()>newsize || img->GetHeight()>newsize)
  585. {
  586. CRect rc(0,0,newsize,newsize);
  587. RectFitDes(img->GetWidth(), img->GetHeight(), rc);
  588. Image *simg= img->GetThumbnailImage(rc.Width (), rc.Height (), NULL, NULL);
  589. Graphics graphic(simg);//防止GetThumbnailImage影响质量
  590. graphic.DrawImage(img, 0,0,simg->GetWidth(), simg->GetHeight() );
  591. delete img;
  592. ::SaveImageToFile(simg, file2);
  593. delete simg;
  594. }
  595. else
  596. {
  597. if(::CopyFile (file1, file2, bOverWrite)==0)
  598. {
  599. CString str;
  600. str=file1;
  601. int pos=str.ReverseFind ('\\');
  602. if(pos!=-1)
  603. str=str.Right (str.GetLength ()-pos-1);
  604. AfxMessageBox("拷贝失败"+str+"请重新导入此文件!!!");
  605. }
  606. }
  607. }
  608. }
  609. else
  610. {
  611. if(::CopyFile (file1, file2, bOverWrite)==0)
  612. {
  613. CString str;
  614. str=file1;
  615. int pos=str.ReverseFind ('\\');
  616. if(pos!=-1)
  617. str=str.Right (str.GetLength ()-pos-1);
  618. AfxMessageBox("拷贝失败"+str+"请重新导入此文件!!!!");
  619. }
  620. }
  621. }
  622. else
  623. {
  624. WriteTextLog("!MyCopyFile:m_nOutputSize");
  625. if(::CopyFile (file1, file2, bOverWrite)==0)
  626. {
  627. CString str;
  628. str=file1;
  629. int pos=str.ReverseFind ('\\');
  630. if(pos!=-1)
  631. str=str.Right (str.GetLength ()-pos-1);
  632. AfxMessageBox("拷贝失败"+str+"请重新导入此文件!!!!!");
  633. }
  634. //
  635. if(m_bCopyToLocal)//选片缓存
  636. {
  637. WriteTextLog("MyCopyFile:m_bCopyToLocal");
  638. CString path=file2;
  639. CString spath=path.Left (path.ReverseFind ('\\')+1);
  640. spath+="s";
  641. // CString temp=path.Right (path.GetLength ()-path.ReverseFind ('\\')-1);
  642. spath+=path.Right (path.GetLength ()-path.ReverseFind ('\\')-1);
  643. //if(!CheckFileExist (spath))
  644. {
  645. Image *pImg=NULL;
  646. ::LoadImageFromBuf(&pImg, path);
  647. if(pImg==NULL)return;
  648. if(pImg->GetWidth()==0)return;
  649. CRect rc(0,0,100,90);
  650. RectFitDes(pImg->GetWidth(), pImg->GetHeight(), rc);
  651. Image *simg=pImg->GetThumbnailImage(rc.Width (), rc.Height (), NULL, NULL);
  652. if(simg==NULL)return;
  653. Graphics graphic(simg);//防止GetThumbnailImage影响质量
  654. graphic.Clear(Color(255,255,255,255));
  655. graphic.DrawImage(pImg, 0,0,simg->GetWidth(), simg->GetHeight() );
  656. ///////////////////////////////
  657. UINT totalBufferSize;
  658. UINT numProperties;
  659. pImg->GetPropertySize(&totalBufferSize, &numProperties);
  660. // Allocate the buffer that will receive the property items.
  661. PropertyItem* pAllItems = (PropertyItem*)malloc(totalBufferSize);
  662. // Fill the buffer.
  663. pImg->GetAllPropertyItems(totalBufferSize, numProperties, pAllItems);
  664. // Print the id data member of each property item.
  665. for(UINT j = 0; j < numProperties; ++j)
  666. {
  667. if(PropertyTagOrientation==pAllItems[j].id)
  668. {
  669. short* ptrLong = (short*)(pAllItems[j].value);
  670. int ret=(int)*ptrLong;
  671. // CString str;
  672. // str.Format ("%d", ret);
  673. // AfxMessageBox(str);
  674. if(ret==8)
  675. {
  676. simg->RotateFlip( Rotate270FlipNone );
  677. }
  678. else if(ret==6)
  679. {
  680. simg->RotateFlip( Rotate90FlipNone );
  681. }
  682. break;
  683. }
  684. }
  685. free(pAllItems);
  686. ///////////////////////////////
  687. ::SaveImageToFile (simg, spath);
  688. delete simg;
  689. delete pImg;
  690. }
  691. }//选片缓存
  692. }
  693. file2.MakeLower ();
  694. if(m_mode!=1 && file2.Right (3)=="jpg")
  695. {
  696. CString path=file2.Left (file2.ReverseFind ('\\'));
  697. path.TrimRight ("\\");path+="\\";
  698. path+="modifytime";
  699. CStdioFile fp;
  700. if(::PathFileExists (path))
  701. {
  702. fp.Open (path,CFile::modeWrite);
  703. fp.WriteString (g_date);
  704. fp.Close ();
  705. }
  706. else
  707. {
  708. fp.Open (path,CFile::modeCreate|CFile::modeWrite);
  709. fp.WriteString (g_date);
  710. fp.Close ();
  711. }
  712. }
  713. #ifdef ENTERPRISE_VERSION
  714. if(m_bSaveUploadTask)
  715. {
  716. if(m_id!="")
  717. {
  718. if(file2.Right (3)=="jpg")
  719. {
  720. int pos=file2.Find (m_id);
  721. pos+=m_id.GetLength ();
  722. int pos2=file2.ReverseFind ('\\');
  723. CString jd;
  724. if(pos2>pos)
  725. {
  726. jd=file2.Mid(pos+1, pos2-pos-1);
  727. }
  728. CString task;
  729. if(jd!="")
  730. task=jd+"\\"+file2.Right (file2.GetLength ()-pos2-1);
  731. else
  732. task=file2.Right (file2.GetLength ()-pos2-1);
  733. m_uploadtaskarray.Add (task);
  734. m_uploadtaskarray.Add ("");
  735. }
  736. }
  737. else
  738. {
  739. if(file2.Right (3)=="jpg")
  740. {
  741. m_uploadtaskarray.Add (file2.Right (file2.GetLength ()-m_savepath.GetLength ()));
  742. m_uploadtaskarray.Add ("");
  743. }
  744. }
  745. }
  746. #endif
  747. }
  748. //*