ImportPhoto.cpp 19 KB

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