ImportPhoto.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897
  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::ImportPhoto(CWnd* pParent ): CDialog(ImportPhoto::IDD, pParent)
  15. {
  16. m_mode = 0;
  17. m_pArray2 = NULL;
  18. m_pDesArray = NULL;
  19. m_exitcode = 0;
  20. m_bOverWrite = 1;
  21. m_bBeautifySkinFrom = 0;
  22. m_bOrigin = 0;
  23. m_bSaveUploadTask = 0;
  24. m_bCopyToLocal = 0;
  25. m_nOutputSize = 0;
  26. m_bOfmat = 0;
  27. m_nphototype = -1;
  28. m_bAddname = 0;
  29. beginno = -1;
  30. m_bautono = 1;
  31. }
  32. void ImportPhoto::DoDataExchange(CDataExchange* pDX)
  33. {
  34. CDialog::DoDataExchange(pDX);
  35. DDX_Control(pDX, IDC_PROGRESS1, m_progress);
  36. }
  37. BEGIN_MESSAGE_MAP(ImportPhoto, CDialog)
  38. ON_WM_CLOSE()
  39. END_MESSAGE_MAP()
  40. /////////////////////////////////////////////////////////////////////////////
  41. void ImportPhoto::OnOK()
  42. {
  43. // TODO: Add extra validation here
  44. }
  45. void ImportPhoto::OnCancel()
  46. {
  47. // TODO: Add extra cleanup here
  48. }
  49. //----------------------------------------------------
  50. // remark by Jeff 2014.12.11 pm
  51. // 函数:GetFileNo
  52. // 描述:从订单文件夹中获取相片文件的最大编号值;
  53. // 参数:dir 订单文件夹;
  54. // 返回:返回订单文件夹中文件编号最大的值+1;
  55. //
  56. // 如果使用相片名来保存,就不需要这一步了;
  57. //----------------------------------------------------
  58. int ImportPhoto::GetFileNo(CString strOrderFolder)
  59. {
  60. if (m_bautono == 0)
  61. {
  62. int a = beginno;
  63. beginno++;
  64. return a;
  65. }
  66. CString path;
  67. CString path2;
  68. CString path3;
  69. CString path4;
  70. int begin = 1;
  71. CString temp;
  72. CStringArray array;
  73. // 1.查找订单文件夹下的所有文件夹,包括子文件夹下的文件夹;
  74. using namespace helper_coffs;
  75. ffsco o;
  76. o.dirs(1); // 子文件夹也查找;
  77. o.find(LPCSTR(strOrderFolder), 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. // 2.查找出订单文件夹下最大编号值的相片名;
  88. BOOL bFind = 1;
  89. while (bFind)
  90. {
  91. bFind = 0;
  92. for (int i = 0; i < array.GetSize(); i++)
  93. {
  94. strOrderFolder = array.ElementAt(i);
  95. path.Format("%s%03d.jpg", strOrderFolder, begin);
  96. path2.Format("%s%03d.raw", strOrderFolder, begin);
  97. path3.Format("%s%03d.cr2", strOrderFolder, begin);
  98. path4.Format("%s%03d.NEF", strOrderFolder, begin);
  99. //while (PathFileExists(path) || PathFileExists(path2) || PathFileExists(path3) || PathFileExists(path4))PathFileExists
  100. while (PathFileExists(path) || PathFileExists(path2) || PathFileExists(path3) || PathFileExists(path4))
  101. {
  102. begin++;
  103. path.Format("%s%03d.jpg", strOrderFolder, begin);
  104. path2.Format("%s%03d.raw", strOrderFolder, begin);
  105. path3.Format("%s%03d.cr2", strOrderFolder, begin);
  106. path4.Format("%s%03d.NEF", strOrderFolder, begin);
  107. bFind = 1;
  108. }
  109. }
  110. }
  111. // 3.返回找到的最大编号值+1;
  112. beginno = begin + 1;
  113. return begin;
  114. }
  115. void FilterFileName(CString &str)
  116. {
  117. //printf("Jeff:保存目录old:%s\n\n",str);
  118. ///\:*?"<>|
  119. str.Replace("/", "");
  120. str.Replace("\\", "");
  121. str.Replace(":", "");
  122. str.Replace("*", "");
  123. str.Replace("?", "");
  124. str.Replace("\"", "");
  125. str.Replace("<", "");
  126. str.Replace(">", "");
  127. str.Replace("|", "");
  128. //printf("Jeff:保存目录last:%s\n\n",str);
  129. }
  130. UINT ImportPhotoThread(LPVOID lpParameter)
  131. {
  132. ImportPhoto *pThis = (ImportPhoto*)lpParameter;
  133. pThis->m_progress.SetRange(0, pThis->m_pArray->GetSize());
  134. CString filename, filename2;
  135. CString temp;
  136. int pos;
  137. BOOL bNeedGet;
  138. CString temp2;
  139. int fileno;
  140. if (pThis->m_pArray2) // m_pArray2:产品名;
  141. {
  142. if (pThis->m_bAddname) // 相片名包含产品名:不生成产品文件夹;
  143. {
  144. for (int i = 0; i < pThis->m_pArray->GetSize(); i++)
  145. {
  146. filename = pThis->m_pArray->ElementAt(i);
  147. temp = filename.Right(filename.GetLength() - filename.ReverseFind('\\') - 1);
  148. pos = temp.Find(".");
  149. temp = temp.Left(pos);
  150. temp += "(" + pThis->m_name + ",";
  151. temp2 = pThis->m_pArray2->ElementAt(i) + ").jpg";
  152. FilterFileName(temp2);
  153. // Jeff.add:拷贝文件失败,未做处理,最起码要日志记录失败原因;
  154. ::CopyFile(filename, pThis->m_savepath + temp + temp2, pThis->m_bOverWrite == 0);
  155. pThis->m_progress.SetPos(i + 1);
  156. }
  157. }
  158. else // 相片名不包含产品,另外生成产品文件夹。
  159. {
  160. for (int i = 0; i < pThis->m_pArray->GetSize(); i++)
  161. {
  162. filename = pThis->m_pArray->ElementAt(i);
  163. filename2 = pThis->m_pArray2->ElementAt(i);
  164. pos = filename2.Find(";");
  165. while (pos != -1)
  166. {
  167. temp = filename2.Left(pos);
  168. FilterFileName(temp);
  169. filename2 = filename2.Right(filename2.GetLength() - pos - 1);
  170. pos = filename2.Find(";");
  171. // Jeff:生成产品文件夹,然后将与之关联的所有相片都复制一份.
  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. for (int i = 0; i < pThis->m_pArray->GetSize(); i++)
  199. {
  200. filename = pThis->m_pArray->ElementAt(i);
  201. if (pThis->m_mode == 2)
  202. {
  203. temp = filename.Right(filename.GetLength() - filename.ReverseFind('\\') - 1);
  204. pos = temp.Find(".");
  205. bNeedGet = 1;
  206. if (bNeedGet)// && (g_serverbak!="localserver"))
  207. filename2.Format("%s%03d.jpg", pThis->m_savepath, pThis->GetFileNo(pThis->m_calnopath));
  208. else
  209. filename2.Format("%s%s.jpg", pThis->m_savepath, temp);
  210. pThis->MyCopyFile(filename, filename2, pThis->m_bOverWrite == 0);
  211. }
  212. else
  213. pThis->MyCopyFile(filename, pThis->m_pDesArray->ElementAt(i), pThis->m_bOverWrite == 0);
  214. pThis->m_progress.SetPos(i + 1);
  215. }
  216. }
  217. //-----------------------------------------------------------------
  218. //-----------------------------------------------------------------
  219. // 1.拍照导入原片;
  220. // 2.初修导出原片;
  221. // 3.初修导入修好的修片;
  222. // 4.初修导出修好的片;
  223. // 5.选片缓存到本机;
  224. else
  225. {
  226. for (int i = 0; i < pThis->m_pArray->GetSize(); i++)
  227. {
  228. // filename源文件的文件名;
  229. filename = pThis->m_pArray->ElementAt(i);
  230. // 在导入原片时,该值m_mode=2;
  231. // 在初修导出原片时,该值m_mode=1;
  232. // 选片缓存到梧桐时,m_mode=1;
  233. if (pThis->m_mode == 2)
  234. {
  235. // 得到相片的后缀名ext;
  236. CString ext = filename.Right(filename.GetLength() - filename.ReverseFind('.') - 1);
  237. if (0)//g_serverbak=="localserver")
  238. {
  239. temp = filename.Right(filename.GetLength() - filename.ReverseFind('\\') - 1);
  240. filename2.Format("%s%s", pThis->m_savepath, temp);
  241. }
  242. else
  243. {
  244. // 在导入原片时,m_calnopath其实就是订单文件夹;
  245. // 从订单文件夹里获取最大的相片名编号值+1;
  246. // 这一步过于蛋痛!
  247. fileno = pThis->GetFileNo(pThis->m_calnopath);
  248. // 用最大编号+1重新命名新导入的相片名;
  249. filename2.Format("%s%03d.%s", pThis->m_savepath, fileno, ext);
  250. }
  251. // 新文件名:filename2,原文件名filename;boverwrite==0表示新文件名存在就覆盖;
  252. pThis->MyCopyFile(filename, filename2, pThis->m_bOverWrite == 0);
  253. }
  254. else
  255. {
  256. if (pThis->m_bBeautifySkinFrom)//修片导入
  257. {
  258. temp = pThis->m_savepath + filename.Right(filename.GetLength() - filename.ReverseFind('\\') - 1);
  259. pos = temp.ReverseFind('.');
  260. if (pos == -1)continue;
  261. temp = temp.Left(pos);
  262. pos = 0;
  263. filename2.Format("%s.jpg", temp);
  264. pos = 2;
  265. while (::PathFileExists(filename2))
  266. {
  267. filename2.Format("%s-%d.jpg", temp, pos);
  268. pos++;
  269. }
  270. pThis->MyCopyFile(filename, filename2, pThis->m_bOverWrite == 0);
  271. }
  272. else
  273. {
  274. if (pThis->m_bOrigin)//原片导出
  275. {
  276. temp = filename.Right(filename.GetLength() - filename.ReverseFind('\\') - 1);
  277. pos = temp.Find(".");
  278. if (pos == -1)continue;
  279. temp = temp.Left(pos);
  280. pThis->MyCopyFile(filename, pThis->m_savepath + filename.Right(filename.GetLength() - filename.ReverseFind('\\') - 1), pThis->m_bOverWrite == 0);
  281. }
  282. else
  283. pThis->MyCopyFile(filename, pThis->m_savepath + filename.Right(filename.GetLength() - filename.ReverseFind('\\') - 1), pThis->m_bOverWrite == 0);
  284. }
  285. }
  286. pThis->m_progress.SetPos(i + 1);
  287. }
  288. }
  289. pThis->PostMessage(WM_CLOSE, 0, 0);
  290. return 1;
  291. }
  292. BOOL ImportPhoto::OnInitDialog()
  293. {
  294. CDialog::OnInitDialog();
  295. #if JEFF_TEST_OFF
  296. // Jeff:判断目标路径是否合法;
  297. if ( IsDirectoryLegitimate(m_name) == FALSE)
  298. {
  299. AfxMessageBox("目标路径包含创建目录时的非法目录字符'/ \\ : * ? \" < > |',请修改后重新操作!");
  300. return FALSE;
  301. }
  302. #endif
  303. if (m_bCopyToLocal)
  304. SetDlgItemText(IDC_STATIC1, "客照缓存中, 请稍候...");
  305. else if (m_mode == 1)
  306. SetDlgItemText(IDC_STATIC1, "正在导出客照, 请稍候...");
  307. #if JEFF_TEST_OFF
  308. HANDLE hThread = (HANDLE)_beginthreadex(NULL, 0, ImprotOrExportImageThread, (LPVOID)this, 0, NULL);
  309. CloseHandle(hThread);
  310. #endif
  311. if (beginno != -1 && beginno != 0)
  312. {
  313. m_bautono = 0;
  314. }
  315. AfxBeginThread((AFX_THREADPROC)ImportPhotoThread, (LPVOID)this);
  316. return TRUE;
  317. }
  318. void SaveTaskPath(CString pathname)
  319. {
  320. return;
  321. CString path = g_path1 + "\\taskpath.dat";
  322. CStringArray array;
  323. CFile fp;
  324. if (::PathFileExists(path))
  325. {
  326. try
  327. {
  328. int trycount = 5;
  329. while (1)
  330. {
  331. if (fp.Open(path, CFile::modeRead | CFile::shareExclusive))break;
  332. fp.Close();
  333. trycount--;
  334. if (trycount == 0)break;
  335. ::Sleep(1000);
  336. }
  337. if (trycount == 0)
  338. {
  339. if (::PathFileExists(path))return;
  340. }
  341. CArchive ar(&fp, CArchive::load);
  342. array.Serialize(ar);
  343. fp.Close();
  344. }
  345. catch (...)
  346. {
  347. fp.Close();
  348. // AfxMessageBox("读异常");
  349. }
  350. }
  351. array.Add(pathname);
  352. try
  353. {
  354. int trycount = 5;
  355. while (1)
  356. {
  357. if (fp.Open(path, CFile::modeCreate | CFile::modeWrite | CFile::shareExclusive))break;
  358. fp.Close();
  359. trycount--;
  360. if (trycount == 0)break;
  361. ::Sleep(1000);
  362. }
  363. if (trycount == 0)
  364. {
  365. // AfxMessageBox("打开失败2");
  366. return;
  367. }
  368. CArchive ar(&fp, CArchive::store);
  369. array.Serialize(ar);
  370. ar.Close();
  371. fp.Close();
  372. }
  373. catch (...)
  374. {
  375. // AfxMessageBox("写异常");
  376. fp.Close();
  377. }
  378. }
  379. void ImportPhoto::OnClose()
  380. {
  381. // TODO: Add your message handler code here and/or call default
  382. if (m_nphototype < 0 || m_nphototype>3)
  383. {
  384. CDialog::OnOK();
  385. return;
  386. }
  387. if (m_uploadtaskarray.GetSize() <= 10)
  388. {
  389. CDialog::OnOK();
  390. return;
  391. }
  392. #ifdef ENTERPRISE_VERSION
  393. if (m_bSaveUploadTask)
  394. {
  395. CString m_rule = g_cominfoarraylocal.ElementAt(0).ElementAt(116);
  396. //printf("Jeff:m_rule: %s\n", m_rule);
  397. CString m_header, m_left, m_right, m_currule;
  398. CStringArray rulearray;
  399. if (m_nphototype == 0)
  400. {
  401. m_header = "type0@:";
  402. }
  403. else if (m_nphototype == 1)
  404. {
  405. m_header = "type1@:";
  406. }
  407. else if (m_nphototype == 2)
  408. {
  409. m_header = "type2@:";
  410. }
  411. else if (m_nphototype == 3)
  412. {
  413. m_header = "type3@:";
  414. }
  415. //printf("Jeff:m_header: %s\n", m_header);
  416. int pos = m_rule.Find(m_header);
  417. if (pos != -1)
  418. {
  419. m_left = m_rule.Left(pos);
  420. //printf("Jeff:m_left: %s\n", m_left);
  421. m_rule = m_rule.Right(m_rule.GetLength() - pos);
  422. m_rule.Delete(0, m_header.GetLength());
  423. //printf("Jeff:m_rule: %s\n", m_rule);
  424. pos = m_rule.Find("@:");
  425. if (pos != -1)
  426. {
  427. m_right = m_rule.Right(m_rule.GetLength() - pos + 5);
  428. m_rule = m_rule.Left(pos - 5);
  429. //printf("Jeff:m_right: %s # m_rule : %s\n", m_right, m_rule);
  430. }
  431. m_currule = m_rule;
  432. m_rule.Empty();
  433. m_currule.TrimLeft("%$");
  434. m_currule.TrimRight("%$");
  435. //printf("Jeff:m_currule: %s # m_rule : %s\n", m_currule, m_rule);
  436. if (m_currule.Find("%$") != -1)
  437. {
  438. pos = m_currule.Find("%$");
  439. while (pos != -1)
  440. {
  441. if (m_currule.Left(pos) != "")rulearray.Add(m_currule.Left(pos));
  442. m_currule = m_currule.Right(m_currule.GetLength() - pos - 2);
  443. pos = m_currule.Find("%$");
  444. //printf("Jeff:m_currule: %s\n", m_currule);
  445. }
  446. }
  447. if (m_currule != "")rulearray.Add(m_currule);
  448. }
  449. for (int i = 0; i < rulearray.GetSize(); i++)
  450. {
  451. m_currule = rulearray.ElementAt(i);
  452. pos = m_currule.Find("->");
  453. if (pos == -1)continue;
  454. m_left = m_currule.Left(pos);
  455. m_right = m_currule.Right(m_currule.GetLength() - pos - 2);
  456. CString curdomain, curdomain2;
  457. //printf("Jeff:m_branch: %s\n", m_branch);
  458. if (m_branch != "")
  459. {
  460. curdomain = GetDomainFromBranch(m_branch);
  461. curdomain2 = GetDomainFromBranch(g_brancharray.ElementAt(g_brancharray.GetSize() - 1).ElementAt(0));
  462. }
  463. else if (g_branchname != "")
  464. {
  465. curdomain = GetDomainFromBranch(g_branchname);
  466. curdomain2 = GetDomainFromBranch(g_brancharray.ElementAt(g_brancharray.GetSize() - 1).ElementAt(0));
  467. }
  468. else
  469. {
  470. curdomain = GetDomainFromBranch(g_brancharray.ElementAt(g_brancharray.GetSize() - 1).ElementAt(0));
  471. curdomain2 = curdomain;
  472. }
  473. //printf("Jeff:curdomain: %s # curdomain2 : %s\n", curdomain, curdomain2);
  474. CString domainleft = GetDomainFromBranch(m_left);
  475. if (curdomain != domainleft)
  476. {
  477. continue;
  478. }
  479. CString domainright = GetDomainFromBranch(m_right);
  480. //printf("Jeff:domainright: %s\n", domainright);
  481. if (domainleft.Find(".ly.com") == -1 || domainright.Find(".ly.com") == -1)
  482. {
  483. continue;
  484. }
  485. if (curdomain2 == domainright)
  486. {
  487. continue;
  488. }
  489. MyLock lock("uploadtaskaccess");
  490. //printf("Jeff:domainright: %s # domainleft : %s # m_sel : %s\n", domainright, domainleft, m_sel);
  491. m_uploadtaskarray.SetAt(1, domainright);//目的地
  492. m_uploadtaskarray.SetAt(2, domainleft);//文件夹加上域名
  493. m_uploadtaskarray.SetAt(3, m_sel);
  494. CFile fp;
  495. CString pathdir = m_savepath + "uploadtask";
  496. //printf("Jeff:pathdir: %s\n", pathdir);
  497. if (m_id != "")
  498. {
  499. int pos = pathdir.Find(m_id);
  500. pos += m_id.GetLength();
  501. int pos2 = pathdir.ReverseFind('\\');
  502. pathdir = pathdir.Left(pos) + pathdir.Right(pathdir.GetLength() - pos2);
  503. }
  504. CString path;
  505. int taskpos = 1;
  506. path.Format("%s%d.dat", pathdir, taskpos);
  507. CString dir = path.Left(path.ReverseFind('\\') + 1);
  508. pathdir = g_path1 + "\\上传任务\\";
  509. //printf("Jeff:pathdir: %s\n", pathdir);
  510. ::CreateDirectory(pathdir, NULL);
  511. path.Format("%s%d.dat", pathdir, taskpos);
  512. while (PathFileExists(path))
  513. {
  514. taskpos++;
  515. path.Format("%s%d.dat", pathdir, taskpos);
  516. printf("Jeff:path: %s\n", path);
  517. }
  518. fp.Open(path, CFile::modeCreate | CFile::modeWrite);
  519. CArchive ar(&fp, CArchive::store);
  520. //printf("Jeff:dir: %s\n", dir);
  521. m_uploadtaskarray.SetAt(4, dir);
  522. m_uploadtaskarray.Serialize(ar);
  523. ar.Close();
  524. fp.Close();
  525. // SaveTaskPath(path);
  526. }
  527. }
  528. #endif
  529. // CString ss;
  530. //ss.Format ("cc:%d", g_filecount);MessageBox(ss);m_fp.Close ();
  531. CDialog::OnOK();
  532. }
  533. extern void SaveImageToFile(Image *img, CString path);
  534. void ImportPhoto::MyCopyFile(CString file1, CString file2, BOOL bOverWrite)
  535. {
  536. if (::PathFileExists(file1) == 0)
  537. {
  538. return;
  539. }
  540. if (m_bOfmat)
  541. {
  542. CString file1bak = file1;
  543. CString file2bak = file2;
  544. file1bak = file1bak.Left(file1bak.GetLength() - 3);
  545. file2bak = file2bak.Left(file2bak.GetLength() - 3);
  546. file1bak += "jpg";
  547. file2bak += "jpg";
  548. CString src = file1bak;
  549. CString des = file2bak;
  550. src.Replace(".jpg", ".raw");
  551. des.Replace(".jpg", ".raw");
  552. ::CopyFile(src, des, bOverWrite);
  553. src = file1bak;
  554. des = file2bak;
  555. src.Replace(".jpg", ".nef");
  556. des.Replace(".jpg", ".nef");
  557. ::CopyFile(src, des, bOverWrite);
  558. src = file1bak;
  559. des = file2bak;
  560. src.Replace(".jpg", ".cr2");
  561. des.Replace(".jpg", ".cr2");
  562. ::CopyFile(src, des, bOverWrite);
  563. }
  564. if (m_nphototype == 0 || m_nphototype == 1 || m_nphototype == 2 || m_nphototype == 3)
  565. {
  566. CString str = file2;
  567. CString spath = str.Left(str.ReverseFind('\\') + 1);
  568. CString mpath = spath;
  569. spath += "s";
  570. spath += str.Right(str.GetLength() - str.ReverseFind('\\') - 1);
  571. mpath += "m";
  572. mpath += str.Right(str.GetLength() - str.ReverseFind('\\') - 1);
  573. ::DeleteFile(spath); // 删除s小图;
  574. ::DeleteFile(mpath); // 删除m小图;
  575. }
  576. if (m_nOutputSize)
  577. {
  578. file1.MakeLower();
  579. if (file1.Right(3) == "jpg")
  580. {
  581. Image *img = NULL;
  582. ::LoadImageFromBuf(&img, file1);
  583. if (img == NULL)
  584. {
  585. if (::CopyFile(file1, file2, bOverWrite) == 0)
  586. {
  587. CString str;
  588. str = file1;
  589. int pos = str.ReverseFind('\\');
  590. if (pos != -1)
  591. str = str.Right(str.GetLength() - pos - 1);
  592. AfxMessageBox("拷贝失败" + str + "请重新导入此文件!");
  593. }
  594. }
  595. else if (img->GetWidth() == 0)
  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. else
  608. {
  609. int newsize = m_nOutputSize;
  610. if (img->GetWidth() > newsize || img->GetHeight() > newsize)
  611. {
  612. CRect rc(0, 0, newsize, newsize);
  613. RectFitDes(img->GetWidth(), img->GetHeight(), rc);
  614. Image *simg = img->GetThumbnailImage(rc.Width(), rc.Height(), NULL, NULL);
  615. Graphics graphic(simg);//防止GetThumbnailImage影响质量
  616. graphic.DrawImage(img, 0, 0, simg->GetWidth(), simg->GetHeight());
  617. delete img;
  618. ::SaveImageToFile(simg, file2);
  619. delete simg;
  620. }
  621. else
  622. {
  623. if (::CopyFile(file1, file2, bOverWrite) == 0)
  624. {
  625. CString str;
  626. str = file1;
  627. int pos = str.ReverseFind('\\');
  628. if (pos != -1)
  629. str = str.Right(str.GetLength() - pos - 1);
  630. AfxMessageBox("拷贝失败" + str + "请重新导入此文件!!!");
  631. }
  632. }
  633. }
  634. }
  635. else
  636. {
  637. if (::CopyFile(file1, file2, bOverWrite) == 0)
  638. {
  639. CString str;
  640. str = file1;
  641. int pos = str.ReverseFind('\\');
  642. if (pos != -1)
  643. str = str.Right(str.GetLength() - pos - 1);
  644. AfxMessageBox("拷贝失败" + str + "请重新导入此文件!!!!");
  645. }
  646. }
  647. }
  648. else
  649. {
  650. if (::CopyFile(file1, file2, bOverWrite) == 0)
  651. {
  652. CString str;
  653. str = file1;
  654. int pos = str.ReverseFind('\\');
  655. if (pos != -1)
  656. str = str.Right(str.GetLength() - pos - 1);
  657. AfxMessageBox("拷贝失败" + str + "请重新导入此文件!!!!!");
  658. }
  659. //
  660. if (m_bCopyToLocal)//选片缓存
  661. {
  662. CString path = file2;
  663. CString spath = path.Left(path.ReverseFind('\\') + 1);
  664. spath += "s";
  665. // CString temp=path.Right (path.GetLength ()-path.ReverseFind ('\\')-1);
  666. spath += path.Right(path.GetLength() - path.ReverseFind('\\') - 1);
  667. //if(!PathFileExists (spath))
  668. {
  669. Image *pImg = NULL;
  670. ::LoadImageFromBuf(&pImg, path);
  671. if (pImg == NULL)return;
  672. if (pImg->GetWidth() == 0)return;
  673. CRect rc(0, 0, 100, 90);
  674. RectFitDes(pImg->GetWidth(), pImg->GetHeight(), rc);
  675. Image *simg = pImg->GetThumbnailImage(rc.Width(), rc.Height(), NULL, NULL);
  676. if (simg == NULL)return;
  677. Graphics graphic(simg);//防止GetThumbnailImage影响质量
  678. graphic.Clear(Color(255, 255, 255, 255));
  679. graphic.DrawImage(pImg, 0, 0, simg->GetWidth(), simg->GetHeight());
  680. ///////////////////////////////
  681. UINT totalBufferSize;
  682. UINT numProperties;
  683. pImg->GetPropertySize(&totalBufferSize, &numProperties);
  684. // Allocate the buffer that will receive the property items.
  685. PropertyItem* pAllItems = (PropertyItem*)malloc(totalBufferSize);
  686. // Fill the buffer.
  687. pImg->GetAllPropertyItems(totalBufferSize, numProperties, pAllItems);
  688. // Print the id data member of each property item.
  689. for (UINT j = 0; j < numProperties; ++j)
  690. {
  691. if (PropertyTagOrientation == pAllItems[j].id)
  692. {
  693. short* ptrLong = (short*)(pAllItems[j].value);
  694. int ret = (int)*ptrLong;
  695. // CString str;
  696. // str.Format ("%d", ret);
  697. // AfxMessageBox(str);
  698. if (ret == 8)
  699. {
  700. simg->RotateFlip(Rotate270FlipNone);
  701. }
  702. else if (ret == 6)
  703. {
  704. simg->RotateFlip(Rotate90FlipNone);
  705. }
  706. break;
  707. }
  708. }
  709. free(pAllItems);
  710. ///////////////////////////////
  711. ::SaveImageToFile(simg, spath);
  712. delete simg;
  713. delete pImg;
  714. }
  715. }//选片缓存
  716. }
  717. file2.MakeLower();
  718. if (m_mode != 1 && file2.Right(3) == "jpg")
  719. {
  720. CString path = file2.Left(file2.ReverseFind('\\'));
  721. path.TrimRight("\\"); path += "\\";
  722. path += "modifytime";
  723. CStdioFile fp;
  724. if (::PathFileExists(path))
  725. {
  726. fp.Open(path, CFile::modeWrite);
  727. fp.WriteString(g_date);
  728. fp.Close();
  729. }
  730. else
  731. {
  732. fp.Open(path, CFile::modeCreate | CFile::modeWrite);
  733. fp.WriteString(g_date);
  734. fp.Close();
  735. }
  736. }
  737. #ifdef ENTERPRISE_VERSION
  738. if (m_bSaveUploadTask)
  739. {
  740. if (m_id != "")
  741. {
  742. if (file2.Right(3) == "jpg")
  743. {
  744. int pos = file2.Find(m_id);
  745. pos += m_id.GetLength();
  746. int pos2 = file2.ReverseFind('\\');
  747. // Jeff:获取景点;
  748. CString jd;
  749. if (pos2 > pos)
  750. {
  751. jd = file2.Mid(pos + 1, pos2 - pos - 1);
  752. }
  753. CString task;
  754. if (jd != "")
  755. task = jd + "\\" + file2.Right(file2.GetLength() - pos2 - 1);
  756. else
  757. task = file2.Right(file2.GetLength() - pos2 - 1);
  758. m_uploadtaskarray.Add(task);
  759. m_uploadtaskarray.Add("");
  760. }
  761. }
  762. else
  763. {
  764. if (file2.Right(3) == "jpg")
  765. {
  766. m_uploadtaskarray.Add(file2.Right(file2.GetLength() - m_savepath.GetLength()));
  767. m_uploadtaskarray.Add("");
  768. }
  769. }
  770. }
  771. #endif
  772. }
  773. //*
  774. unsigned int WINAPI ImportPhoto::ImprotOrExportImageThread(LPVOID lp)
  775. {
  776. ImportPhoto *pThis = (ImportPhoto*)lp;
  777. if ( pThis->m_bImportImage )
  778. {
  779. // 初始化工作,并将导入标识写入数据库中;
  780. switch ( pThis->m_ImportOfImageType )
  781. {
  782. case ImageType_Original:
  783. break;
  784. case ImageType_Early:
  785. break;
  786. case ImageType_Further:
  787. break;
  788. case ImageType_Design:
  789. break;
  790. default:
  791. break;
  792. }
  793. // 实参校验;
  794. if ( pThis->m_pArray->GetSize() > 0 && lyfzCreateDirectory(pThis->m_savepath))
  795. lyfzImportImage(pThis->m_savepath, *(pThis->m_pArray));
  796. }
  797. else
  798. {
  799. // 初始化工作;
  800. switch (pThis->m_ExportOfImageType)
  801. {
  802. case ImageType_Original:
  803. break;
  804. case ImageType_Early:
  805. break;
  806. case ImageType_Further:
  807. break;
  808. case ImageType_Design:
  809. default:
  810. break;
  811. }
  812. }
  813. return 0;
  814. }