Clip.cpp 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350
  1. // ProcessCopy.cpp: implementation of the CProcessCopy class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "CP_Main.h"
  6. #include "Clip.h"
  7. #include "DatabaseUtilities.h"
  8. #include "Crc32Dynamic.h"
  9. #include "sqlite\CppSQLite3.h"
  10. #include "shared/TextConvert.h"
  11. #include "zlib/zlib.h"
  12. #include "Misc.h"
  13. #include <Mmsystem.h>
  14. #include "Path.h"
  15. #ifdef _DEBUG
  16. #undef THIS_FILE
  17. static char THIS_FILE[]=__FILE__;
  18. #define new DEBUG_NEW
  19. #endif
  20. /*----------------------------------------------------------------------------*\
  21. COleDataObjectEx
  22. \*----------------------------------------------------------------------------*/
  23. HGLOBAL COleDataObjectEx::GetGlobalData(CLIPFORMAT cfFormat, LPFORMATETC lpFormatEtc)
  24. {
  25. HGLOBAL hGlobal = COleDataObject::GetGlobalData(cfFormat, lpFormatEtc);
  26. if(hGlobal)
  27. {
  28. if(!::IsValid(hGlobal))
  29. {
  30. Log( StrF(
  31. _T("COleDataObjectEx::GetGlobalData(\"%s\"): ERROR: Invalid (NULL) data returned."),
  32. GetFormatName(cfFormat) ) );
  33. ::GlobalFree( hGlobal );
  34. hGlobal = NULL;
  35. }
  36. return hGlobal;
  37. }
  38. // The data isn't in global memory, so try getting an IStream interface to it.
  39. STGMEDIUM stg;
  40. if(!GetData(cfFormat, &stg))
  41. {
  42. return 0;
  43. }
  44. switch(stg.tymed)
  45. {
  46. case TYMED_HGLOBAL:
  47. hGlobal = stg.hGlobal;
  48. break;
  49. case TYMED_ISTREAM:
  50. {
  51. UINT uDataSize;
  52. LARGE_INTEGER li;
  53. ULARGE_INTEGER uli;
  54. li.HighPart = li.LowPart = 0;
  55. if ( SUCCEEDED( stg.pstm->Seek ( li, STREAM_SEEK_END, &uli )))
  56. {
  57. hGlobal = GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE, uli.LowPart );
  58. void* pv = GlobalLock(hGlobal);
  59. stg.pstm->Seek(li, STREAM_SEEK_SET, NULL);
  60. HRESULT result = stg.pstm->Read(pv, uli.LowPart, (PULONG)&uDataSize);
  61. GlobalUnlock(hGlobal);
  62. if( FAILED(result) )
  63. hGlobal = GlobalFree(hGlobal);
  64. }
  65. break; // case TYMED_ISTREAM
  66. }
  67. } // end switch
  68. ReleaseStgMedium(&stg);
  69. if(hGlobal && !::IsValid(hGlobal))
  70. {
  71. Log( StrF(
  72. _T("COleDataObjectEx::GetGlobalData(\"%s\"): ERROR: Invalid (NULL) data returned."),
  73. GetFormatName(cfFormat)));
  74. ::GlobalFree(hGlobal);
  75. hGlobal = NULL;
  76. }
  77. return hGlobal;
  78. }
  79. /*----------------------------------------------------------------------------*\
  80. CClipFormat - holds the data of one clip format.
  81. \*----------------------------------------------------------------------------*/
  82. CClipFormat::CClipFormat(CLIPFORMAT cfType, HGLOBAL hgData, int parentId)
  83. {
  84. m_cfType = cfType;
  85. m_hgData = hgData;
  86. m_autoDeleteData = true;
  87. m_parentId = parentId;
  88. }
  89. CClipFormat::~CClipFormat()
  90. {
  91. Free();
  92. }
  93. void CClipFormat::Clear()
  94. {
  95. m_cfType = 0;
  96. m_hgData = 0;
  97. m_dataId = -1;
  98. m_parentId = -1;
  99. }
  100. void CClipFormat::Free()
  101. {
  102. if(m_autoDeleteData)
  103. {
  104. if(m_hgData)
  105. {
  106. m_hgData = ::GlobalFree( m_hgData );
  107. m_hgData = NULL;
  108. }
  109. }
  110. }
  111. /*----------------------------------------------------------------------------*\
  112. CClipFormats - holds an array of CClipFormat
  113. \*----------------------------------------------------------------------------*/
  114. // returns a pointer to the CClipFormat in this array which matches the given type
  115. // or NULL if that type doesn't exist in this array.
  116. CClipFormat* CClipFormats::FindFormat(UINT cfType)
  117. {
  118. CClipFormat* pCF;
  119. INT_PTR count = GetSize();
  120. for(int i=0; i < count; i++)
  121. {
  122. pCF = &ElementAt(i);
  123. if(pCF->m_cfType == cfType)
  124. return pCF;
  125. }
  126. return NULL;
  127. }
  128. /*----------------------------------------------------------------------------*\
  129. CClip - holds multiple CClipFormats and CopyClipboard() statistics
  130. \*----------------------------------------------------------------------------*/
  131. DWORD CClip::m_LastAddedCRC = 0;
  132. int CClip::m_lastAddedID = -1;
  133. CClip::CClip() :
  134. m_id(0),
  135. m_CRC(0),
  136. m_parentId(-1),
  137. m_dontAutoDelete(FALSE),
  138. m_shortCut(0),
  139. m_bIsGroup(FALSE),
  140. m_param1(0),
  141. m_clipOrder(0),
  142. m_stickyClipOrder(INVALID_STICKY),
  143. m_stickyClipGroupOrder(INVALID_STICKY),
  144. m_clipGroupOrder(0),
  145. m_globalShortCut(FALSE),
  146. m_moveToGroupShortCut(0),
  147. m_globalMoveToGroupShortCut(FALSE)
  148. {
  149. m_copyReason = CopyReasonEnum::COPY_TO_UNKOWN;
  150. }
  151. CClip::~CClip()
  152. {
  153. EmptyFormats();
  154. }
  155. void CClip::Clear()
  156. {
  157. m_id = -1;
  158. m_Time = 0;
  159. m_Desc = "";
  160. m_CRC = 0;
  161. m_parentId = -1;
  162. m_dontAutoDelete = FALSE;
  163. m_shortCut = 0;
  164. m_bIsGroup = FALSE;
  165. m_csQuickPaste = "";
  166. m_param1 = 0;
  167. m_globalShortCut = FALSE;
  168. m_moveToGroupShortCut = 0;
  169. m_globalMoveToGroupShortCut = 0;
  170. EmptyFormats();
  171. }
  172. const CClip& CClip::operator=(const CClip &clip)
  173. {
  174. const CClipFormat* pCF;
  175. m_id = clip.m_id;
  176. m_Time = clip.m_Time;
  177. m_lastPasteDate = clip.m_lastPasteDate;
  178. m_CRC = clip.m_CRC;
  179. m_parentId = clip.m_parentId;
  180. m_dontAutoDelete = clip.m_dontAutoDelete;
  181. m_shortCut = clip.m_shortCut;
  182. m_bIsGroup = clip.m_bIsGroup;
  183. m_csQuickPaste = clip.m_csQuickPaste;
  184. m_moveToGroupShortCut = clip.m_moveToGroupShortCut;
  185. m_globalMoveToGroupShortCut = clip.m_globalMoveToGroupShortCut;
  186. INT_PTR nCount = clip.m_Formats.GetSize();
  187. for(int i = 0; i < nCount; i++)
  188. {
  189. pCF = &clip.m_Formats.GetData()[i];
  190. LPVOID pvData = GlobalLock(pCF->m_hgData);
  191. if(pvData)
  192. {
  193. AddFormat(pCF->m_cfType, pvData, (UINT)GlobalSize(pCF->m_hgData));
  194. }
  195. GlobalUnlock(pCF->m_hgData);
  196. }
  197. //Set this after since in could get the wrong description in AddFormat
  198. m_Desc = clip.m_Desc;
  199. return *this;
  200. }
  201. void CClip::EmptyFormats()
  202. {
  203. // free global memory in m_Formats
  204. for(INT_PTR i = m_Formats.GetSize()-1; i >= 0; i--)
  205. {
  206. m_Formats[i].Free();
  207. m_Formats.RemoveAt(i);
  208. }
  209. }
  210. // Adds a new Format to this Clip by copying the given data.
  211. bool CClip::AddFormat(CLIPFORMAT cfType, void* pData, UINT nLen)
  212. {
  213. ASSERT(pData && nLen);
  214. HGLOBAL hGlobal = ::NewGlobalP(pData, nLen);
  215. ASSERT(hGlobal);
  216. // update the Clip statistics
  217. m_Time = m_Time.GetCurrentTime();
  218. if(!SetDescFromText(hGlobal, true))
  219. SetDescFromType();
  220. CClipFormat format(cfType,hGlobal);
  221. CClipFormat *pFormat;
  222. pFormat = m_Formats.FindFormat(cfType);
  223. // if the format type already exists as part of this clip, replace the data
  224. if(pFormat)
  225. {
  226. pFormat->Free();
  227. pFormat->m_hgData = format.m_hgData;
  228. }
  229. else
  230. {
  231. m_Formats.Add(format);
  232. }
  233. format.m_hgData = 0; // now owned by m_Formats
  234. return true;
  235. }
  236. // Fills this CClip with the contents of the clipboard.
  237. bool CClip::LoadFromClipboard(CClipTypes* pClipTypes, bool checkClipboardIgnore)
  238. {
  239. COleDataObjectEx oleData;
  240. CClipTypes defaultTypes;
  241. CClipTypes* pTypes = pClipTypes;
  242. // m_Formats should be empty when this is called.
  243. ASSERT(m_Formats.GetSize() == 0);
  244. // If the data is supposed to be private, then return
  245. if(::IsClipboardFormatAvailable(theApp.m_cfIgnoreClipboard))
  246. {
  247. Log(_T("Clipboard ignore type is on the clipboard, skipping this clipboard change"));
  248. return false;
  249. }
  250. //If we are saving a multi paste then delay us connecting to the clipboard
  251. //to allow the ctrl-v to do a paste
  252. if(::IsClipboardFormatAvailable(theApp.m_cfDelaySavingData))
  253. {
  254. Log(_T("Delay clipboard type is on the clipboard, delaying 1500 ms to allow ctrl-v to work"));
  255. Sleep(1500);
  256. }
  257. //Attach to the clipboard
  258. if(!oleData.AttachClipboard())
  259. {
  260. Log(_T("failed to attache to clipboard, skipping this clipboard change"));
  261. ASSERT(0); // does this ever happen?
  262. return false;
  263. }
  264. oleData.EnsureClipboardObject();
  265. // if no types were given, get only the first (most important) type.
  266. // (subsequent types could be synthetic due to automatic type conversions)
  267. if(pTypes == NULL || pTypes->GetSize() == 0)
  268. {
  269. ASSERT(0); // this feature is not currently used... it is an error if it is.
  270. FORMATETC formatEtc;
  271. oleData.BeginEnumFormats();
  272. oleData.GetNextFormat(&formatEtc);
  273. defaultTypes.Add(formatEtc.cfFormat);
  274. pTypes = &defaultTypes;
  275. }
  276. m_Desc = "[Ditto Error] BAD DESCRIPTION";
  277. // Get Description String
  278. // NOTE: We make sure that the description always corresponds to the
  279. // data saved by using the exact same globalmem instance as the source
  280. // for both... i.e. we only fetch the description format type once.
  281. CClipFormat cfDesc;
  282. bool bIsDescSet = false;
  283. cfDesc.m_cfType = CF_UNICODETEXT;
  284. if(oleData.IsDataAvailable(cfDesc.m_cfType))
  285. {
  286. cfDesc.m_hgData = oleData.GetGlobalData(cfDesc.m_cfType);
  287. bIsDescSet = SetDescFromText(cfDesc.m_hgData, true);
  288. Log(StrF(_T("Tried to set description from cf_unicode text, Set: %d, Desc: [%s]"), bIsDescSet, m_Desc.Left(30)));
  289. }
  290. if(bIsDescSet == false)
  291. {
  292. cfDesc.m_cfType = CF_TEXT;
  293. if(oleData.IsDataAvailable(cfDesc.m_cfType))
  294. {
  295. cfDesc.m_hgData = oleData.GetGlobalData(cfDesc.m_cfType);
  296. bIsDescSet = SetDescFromText(cfDesc.m_hgData, false);
  297. Log(StrF(_T("Tried to set description from cf_text text, Set: %d, Desc: [%s]"), bIsDescSet, m_Desc.Left(30)));
  298. }
  299. }
  300. INT_PTR nSize;
  301. CClipFormat cf;
  302. INT_PTR numTypes = pTypes->GetSize();
  303. Log(StrF(_T("Begin enumerating over supported types, Count: %d"), numTypes));
  304. for(int i = 0; i < numTypes; i++)
  305. {
  306. cf.m_cfType = pTypes->ElementAt(i);
  307. BOOL bSuccess = false;
  308. Log(StrF(_T("Begin try and load type %s"), GetFormatName(cf.m_cfType)));
  309. // is this the description we already fetched?
  310. if(cf.m_cfType == cfDesc.m_cfType)
  311. {
  312. cf = cfDesc;
  313. cfDesc.m_hgData = 0; // cf owns it now (to go into m_Formats)
  314. }
  315. else if(!oleData.IsDataAvailable(cf.m_cfType))
  316. {
  317. Log(StrF(_T("End of load - Data is not available for type %s"), GetFormatName(cf.m_cfType)));
  318. continue;
  319. }
  320. else
  321. {
  322. cf.m_hgData = oleData.GetGlobalData(cf.m_cfType);
  323. }
  324. if(cf.m_hgData)
  325. {
  326. nSize = GlobalSize(cf.m_hgData);
  327. if(nSize > 0)
  328. {
  329. if(g_Opt.m_lMaxClipSizeInBytes > 0 && (int)nSize > g_Opt.m_lMaxClipSizeInBytes)
  330. {
  331. CString cs;
  332. cs.Format(_T("Maximum clip size reached max size = %d, clip size = %d"), g_Opt.m_lMaxClipSizeInBytes, nSize);
  333. Log(cs);
  334. oleData.Release();
  335. return false;
  336. }
  337. ASSERT(::IsValid(cf.m_hgData));
  338. m_Formats.Add(cf);
  339. bSuccess = true;
  340. }
  341. else
  342. {
  343. ASSERT(FALSE); // a valid GlobalMem with 0 size is strange
  344. cf.Free();
  345. Log(StrF(_T("Data length is 0 for type %s"), GetFormatName(cf.m_cfType)));
  346. }
  347. cf.m_hgData = 0; // m_Formats owns it now
  348. }
  349. Log(StrF(_T("End of load - type %s, Success: %d"), GetFormatName(cf.m_cfType), bSuccess));
  350. }
  351. Log(StrF(_T("End enumerating over supported types, Count: %d"), numTypes));
  352. m_Time = CTime::GetCurrentTime();
  353. if(!bIsDescSet)
  354. {
  355. SetDescFromType();
  356. Log(StrF(_T("Setting description from type, Desc: [%s]"), m_Desc.Left(30)));
  357. }
  358. // if the description was in a type that is not supported,
  359. //we have to free it since it wasn't added to m_Formats
  360. if(cfDesc.m_hgData)
  361. {
  362. cfDesc.Free();
  363. }
  364. oleData.Release();
  365. if(m_Formats.GetSize() == 0)
  366. {
  367. Log(_T("No clip types were in supported types array"));
  368. return false;
  369. }
  370. return true;
  371. }
  372. bool CClip::SetDescFromText(HGLOBAL hgData, bool unicode)
  373. {
  374. if(hgData == 0)
  375. return false;
  376. bool bRet = false;
  377. INT_PTR bufLen = 0;
  378. if(unicode)
  379. {
  380. TCHAR* text = (TCHAR *) GlobalLock(hgData);
  381. bufLen = GlobalSize(hgData);
  382. m_Desc = text;
  383. bRet = true;
  384. }
  385. else
  386. {
  387. char* text = (char *) GlobalLock(hgData);
  388. bufLen = GlobalSize(hgData);
  389. m_Desc = text;
  390. bRet = true;
  391. }
  392. if(bufLen > g_Opt.m_bDescTextSize)
  393. {
  394. m_Desc = m_Desc.Left(g_Opt.m_bDescTextSize);
  395. }
  396. //Unlock the data
  397. GlobalUnlock(hgData);
  398. return bRet;
  399. }
  400. bool CClip::SetDescFromType()
  401. {
  402. INT_PTR size = m_Formats.GetSize();
  403. if(size <= 0)
  404. {
  405. return false;
  406. }
  407. int nCF_HDROPIndex = -1;
  408. for(int i = 0; i < size; i++)
  409. {
  410. if(m_Formats[i].m_cfType == CF_HDROP)
  411. {
  412. nCF_HDROPIndex = i;
  413. }
  414. }
  415. if(nCF_HDROPIndex >= 0)
  416. {
  417. using namespace nsPath;
  418. HDROP drop = (HDROP)GlobalLock(m_Formats[nCF_HDROPIndex].m_hgData);
  419. int nNumFiles = min(5, DragQueryFile(drop, -1, NULL, 0));
  420. if(nNumFiles > 1)
  421. m_Desc = "Copied Files - ";
  422. else
  423. m_Desc = "Copied File - ";
  424. TCHAR file[MAX_PATH];
  425. for(int nFile = 0; nFile < nNumFiles; nFile++)
  426. {
  427. if(DragQueryFile(drop, nFile, file, sizeof(file)) > 0)
  428. {
  429. CPath path(file);
  430. m_Desc += path.GetName();
  431. m_Desc += " - ";
  432. m_Desc += file;
  433. m_Desc += "\n";
  434. }
  435. }
  436. GlobalUnlock(m_Formats[nCF_HDROPIndex].m_hgData);
  437. }
  438. else
  439. {
  440. m_Desc = GetFormatName(m_Formats[0].m_cfType);
  441. }
  442. return m_Desc.GetLength() > 0;
  443. }
  444. bool CClip::AddToDB(bool bCheckForDuplicates)
  445. {
  446. bool bResult;
  447. try
  448. {
  449. m_CRC = GenerateCRC();
  450. if(bCheckForDuplicates &&
  451. m_parentId < 0)
  452. {
  453. int nID = FindDuplicate();
  454. if(nID >= 0)
  455. {
  456. MakeLatestOrder();
  457. MakeLatestGroupOrder();
  458. CString sql;
  459. sql.Format(_T("UPDATE Main SET clipOrder = %f, lastPasteDate = %d where lID = %d;"),
  460. m_clipOrder, (int)CTime::GetCurrentTime().GetTime(), nID);
  461. int ret = theApp.m_db.execDML(sql);
  462. int groupRet = -1;
  463. if(m_parentId > -1)
  464. {
  465. sql.Format(_T("UPDATE Main SET clipGroupOrder = %f where lID = %d;"),
  466. m_clipGroupOrder, nID);
  467. groupRet = theApp.m_db.execDML(sql);
  468. }
  469. m_id = nID;
  470. Log(StrF(_T("Found duplicate clip in db, Id: %d, ParentId: %d crc: %d, NewOrder: %f, GroupOrder %f, Ret: %d, GroupRet: %d, SQL: %s"),
  471. nID, m_parentId, m_CRC, m_clipOrder, m_clipGroupOrder, ret, groupRet, sql));
  472. return true;
  473. }
  474. }
  475. }
  476. CATCH_SQLITE_EXCEPTION_AND_RETURN(false)
  477. bResult = false;
  478. if(AddToMainTable())
  479. {
  480. bResult = AddToDataTable();
  481. }
  482. if(bResult)
  483. {
  484. if(g_Opt.m_csPlaySoundOnCopy.IsEmpty() == FALSE)
  485. PlaySound(g_Opt.m_csPlaySoundOnCopy, NULL, SND_FILENAME|SND_ASYNC);
  486. }
  487. // should be emptied by AddToDataTable
  488. //ASSERT(m_Formats.GetSize() == 0);
  489. return bResult;
  490. }
  491. // if a duplicate exists, set recset to the duplicate and return true
  492. int CClip::FindDuplicate()
  493. {
  494. try
  495. {
  496. //If they are allowing duplicates still check
  497. //the last copied item
  498. if(g_Opt.m_bAllowDuplicates)
  499. {
  500. if(m_CRC == m_LastAddedCRC)
  501. return m_lastAddedID;
  502. }
  503. else
  504. {
  505. CppSQLite3Query q = theApp.m_db.execQueryEx(_T("SELECT lID FROM Main WHERE CRC = %d"), m_CRC);
  506. if(q.eof() == false)
  507. {
  508. return q.getIntField(_T("lID"));
  509. }
  510. }
  511. }
  512. CATCH_SQLITE_EXCEPTION
  513. return -1;
  514. }
  515. DWORD CClip::GenerateCRC()
  516. {
  517. CClipFormat* pCF;
  518. DWORD dwCRC = 0xFFFFFFFF;
  519. CCrc32Dynamic *pCrc32 = new CCrc32Dynamic;
  520. if(pCrc32)
  521. {
  522. //Generate a CRC value for all copied data
  523. INT_PTR size = m_Formats.GetSize();
  524. for(int i = 0; i < size ; i++)
  525. {
  526. pCF = & m_Formats.ElementAt(i);
  527. const unsigned char *Data = (const unsigned char *)GlobalLock(pCF->m_hgData);
  528. if(Data)
  529. {
  530. pCrc32->GenerateCrc32((const LPBYTE)Data, (DWORD)GlobalSize(pCF->m_hgData), dwCRC);
  531. }
  532. GlobalUnlock(pCF->m_hgData);
  533. }
  534. dwCRC = ~dwCRC;
  535. delete pCrc32;
  536. }
  537. return dwCRC;
  538. }
  539. // assigns m_ID
  540. bool CClip::AddToMainTable()
  541. {
  542. try
  543. {
  544. m_Desc.Replace(_T("'"), _T("''"));
  545. m_csQuickPaste.Replace(_T("'"), _T("''"));
  546. CString cs;
  547. cs.Format(_T("INSERT into Main (lDate, mText, lShortCut, lDontAutoDelete, CRC, bIsGroup, lParentID, QuickPasteText, clipOrder, clipGroupOrder, globalShortCut, lastPasteDate, stickyClipOrder, stickyClipGroupOrder, MoveToGroupShortCut, GlobalMoveToGroupShortCut) ")
  548. _T("values(%d, '%s', %d, %d, %d, %d, %d, '%s', %f, %f, %d, %d, %f, %f, %d, %d);"),
  549. (int)m_Time.GetTime(),
  550. m_Desc,
  551. m_shortCut,
  552. m_dontAutoDelete,
  553. m_CRC,
  554. m_bIsGroup,
  555. m_parentId,
  556. m_csQuickPaste,
  557. m_clipOrder,
  558. m_clipGroupOrder,
  559. m_globalShortCut,
  560. (int)CTime::GetCurrentTime().GetTime(),
  561. m_stickyClipOrder,
  562. m_stickyClipGroupOrder,
  563. m_moveToGroupShortCut,
  564. m_globalMoveToGroupShortCut);
  565. theApp.m_db.execDML(cs);
  566. m_id = (long)theApp.m_db.lastRowId();
  567. Log(StrF(_T("Added clip to main table, Id: %d, ParentId: %d Desc: %s, Order: %f, GroupOrder: %f"), m_id, m_parentId, m_Desc, m_clipOrder, m_clipGroupOrder));
  568. m_LastAddedCRC = m_CRC;
  569. m_lastAddedID = m_id;
  570. }
  571. CATCH_SQLITE_EXCEPTION_AND_RETURN(false)
  572. return true;
  573. }
  574. bool CClip::ModifyMainTable()
  575. {
  576. bool bRet = false;
  577. try
  578. {
  579. m_Desc.Replace(_T("'"), _T("''"));
  580. m_csQuickPaste.Replace(_T("'"), _T("''"));
  581. theApp.m_db.execDMLEx(_T("UPDATE Main SET lShortCut = %d, ")
  582. _T("mText = '%s', ")
  583. _T("lParentID = %d, ")
  584. _T("lDontAutoDelete = %d, ")
  585. _T("QuickPasteText = '%s', ")
  586. _T("clipOrder = %f, ")
  587. _T("clipGroupOrder = %f, ")
  588. _T("globalShortCut = %d, ")
  589. _T("stickyClipOrder = %f, ")
  590. _T("stickyClipGroupOrder = %f, ")
  591. _T("MoveToGroupShortCut = %d, ")
  592. _T("GlobalMoveToGroupShortCut = %d ")
  593. _T("WHERE lID = %d;"),
  594. m_shortCut,
  595. m_Desc,
  596. m_parentId,
  597. m_dontAutoDelete,
  598. m_csQuickPaste,
  599. m_clipOrder,
  600. m_clipGroupOrder,
  601. m_globalShortCut,
  602. m_stickyClipOrder,
  603. m_stickyClipGroupOrder,
  604. m_moveToGroupShortCut,
  605. m_globalMoveToGroupShortCut,
  606. m_id);
  607. bRet = true;
  608. }
  609. CATCH_SQLITE_EXCEPTION_AND_RETURN(false)
  610. return bRet;
  611. }
  612. // Empties m_Formats as it saves them to the Data Table.
  613. bool CClip::AddToDataTable()
  614. {
  615. CClipFormat* pCF;
  616. try
  617. {
  618. CppSQLite3Statement stmt = theApp.m_db.compileStatement(_T("insert into Data values (NULL, ?, ?, ?);"));
  619. for(INT_PTR i = m_Formats.GetSize()-1; i >= 0 ; i--)
  620. {
  621. pCF = &m_Formats.ElementAt(i);
  622. CString formatName = GetFormatName(pCF->m_cfType);
  623. int clipSize = 0;
  624. stmt.bind(1, m_id);
  625. stmt.bind(2, formatName);
  626. const unsigned char *Data = (const unsigned char *)GlobalLock(pCF->m_hgData);
  627. if(Data)
  628. {
  629. clipSize = (int)GlobalSize(pCF->m_hgData);
  630. stmt.bind(3, Data, clipSize);
  631. }
  632. GlobalUnlock(pCF->m_hgData);
  633. stmt.execDML();
  634. stmt.reset();
  635. pCF->m_dataId = (long)theApp.m_db.lastRowId();
  636. Log(StrF(_T("Added ClipData to DB, Id: %d, ParentId: %d Type: %s, size: %d"), pCF->m_dataId, m_id, formatName, clipSize));
  637. }
  638. }
  639. CATCH_SQLITE_EXCEPTION_AND_RETURN(false)
  640. return true;
  641. }
  642. void CClip::MoveUp()
  643. {
  644. if (m_stickyClipOrder == INVALID_STICKY)
  645. {
  646. CppSQLite3Query q = theApp.m_db.execQueryEx(_T("SELECT lID, clipOrder FROM Main Where clipOrder > %f ORDER BY clipOrder ASC LIMIT 1"), m_clipOrder);
  647. if (q.eof() == false)
  648. {
  649. int idAbove = q.getIntField(_T("lID"));
  650. double orderAbove = q.getFloatField(_T("clipOrder"));
  651. CppSQLite3Query q2 = theApp.m_db.execQueryEx(_T("SELECT lID, clipOrder FROM Main Where clipOrder > %f ORDER BY clipOrder ASC LIMIT 1"), orderAbove);
  652. if (q2.eof() == false)
  653. {
  654. int idTwoAbove = q2.getIntField(_T("lID"));
  655. double orderTwoAbove = q2.getFloatField(_T("clipOrder"));
  656. m_clipOrder = orderAbove + (orderTwoAbove - orderAbove) / 2.0;
  657. }
  658. else
  659. {
  660. m_clipOrder = orderAbove + 1;
  661. }
  662. }
  663. }
  664. else
  665. {
  666. CppSQLite3Query q = theApp.m_db.execQueryEx(_T("SELECT lID, stickyClipOrder FROM Main Where stickyClipOrder > %f ORDER BY clipOrder ASC LIMIT 1"), m_stickyClipOrder);
  667. if (q.eof() == false)
  668. {
  669. int idAbove = q.getIntField(_T("lID"));
  670. double orderAbove = q.getFloatField(_T("stickyClipOrder"));
  671. CppSQLite3Query q2 = theApp.m_db.execQueryEx(_T("SELECT lID, stickyClipOrder FROM Main Where stickyClipOrder > %f ORDER BY clipOrder ASC LIMIT 1"), orderAbove);
  672. if (q2.eof() == false)
  673. {
  674. int idTwoAbove = q2.getIntField(_T("lID"));
  675. double orderTwoAbove = q2.getFloatField(_T("stickyClipOrder"));
  676. m_stickyClipOrder = orderAbove + (orderTwoAbove - orderAbove) / 2.0;
  677. }
  678. else
  679. {
  680. m_stickyClipOrder = orderAbove + 1;
  681. }
  682. }
  683. }
  684. }
  685. void CClip::MakeStickyTop(int parentId)
  686. {
  687. if (parentId < 0)
  688. {
  689. m_stickyClipOrder = GetNewTopSticky(parentId, m_id);
  690. }
  691. else
  692. {
  693. m_stickyClipGroupOrder = GetNewTopSticky(parentId, m_id);
  694. }
  695. }
  696. void CClip::MakeStickyLast(int parentId)
  697. {
  698. if (parentId < 0)
  699. {
  700. m_stickyClipOrder = GetNewLastSticky(parentId, m_id);
  701. }
  702. else
  703. {
  704. m_stickyClipGroupOrder = GetNewLastSticky(parentId, m_id);
  705. }
  706. }
  707. void CClip::RemoveStickySetting(int parentId)
  708. {
  709. if (parentId < 0)
  710. {
  711. m_stickyClipOrder = INVALID_STICKY;
  712. }
  713. else
  714. {
  715. m_stickyClipGroupOrder = INVALID_STICKY;
  716. }
  717. }
  718. double CClip::GetNewTopSticky(int parentId, int clipId)
  719. {
  720. double newOrder = 1;
  721. double existingMaxOrder = 0;
  722. CString existingDesc = _T("");
  723. try
  724. {
  725. if (parentId < 0)
  726. {
  727. CppSQLite3Query q = theApp.m_db.execQuery(_T("SELECT stickyClipOrder, mText FROM Main ORDER BY stickyClipOrder DESC LIMIT 1"));
  728. if (q.eof() == false)
  729. {
  730. existingMaxOrder = q.getFloatField(_T("stickyClipOrder"));
  731. existingDesc = q.getStringField(_T("mText"));
  732. newOrder = existingMaxOrder + 1;
  733. }
  734. }
  735. else
  736. {
  737. CppSQLite3Query q = theApp.m_db.execQueryEx(_T("SELECT stickyClipGroupOrder, mText FROM Main WHERE lParentID = %d ORDER BY stickyClipGroupOrder DESC LIMIT 1"), parentId);
  738. if (q.eof() == false)
  739. {
  740. existingMaxOrder = q.getFloatField(_T("stickyClipGroupOrder"));
  741. newOrder = existingMaxOrder + 1;
  742. }
  743. }
  744. if (newOrder == 0.0)
  745. newOrder += 1;
  746. Log(StrF(_T("GetNewTopSticky, Id: %d, parentId: %d, CurrentMax: %f, CurrentDesc: %s, NewMax: %f"), clipId, parentId, existingMaxOrder, existingDesc, newOrder));
  747. }
  748. CATCH_SQLITE_EXCEPTION
  749. return newOrder;
  750. }
  751. double CClip::GetNewLastSticky(int parentId, int clipId)
  752. {
  753. double newOrder = 1;
  754. double existingMaxOrder = 0;
  755. CString existingDesc = _T("");
  756. try
  757. {
  758. if (parentId < 0)
  759. {
  760. CppSQLite3Query q = theApp.m_db.execQuery(_T("SELECT stickyClipOrder, mText FROM Main WHERE stickyClipOrder <> -10000000 ORDER BY stickyClipOrder LIMIT 1"));
  761. if (q.eof() == false)
  762. {
  763. existingMaxOrder = q.getFloatField(_T("stickyClipOrder"));
  764. existingDesc = q.getStringField(_T("mText"));
  765. newOrder = existingMaxOrder - 1;
  766. }
  767. }
  768. else
  769. {
  770. CppSQLite3Query q = theApp.m_db.execQueryEx(_T("SELECT stickyClipGroupOrder, mText FROM Main WHERE lParentID = %d ORDER BY stickyClipGroupOrder LIMIT 1"), parentId);
  771. if (q.eof() == false)
  772. {
  773. existingMaxOrder = q.getFloatField(_T("stickyClipGroupOrder"));
  774. newOrder = existingMaxOrder - 1;
  775. }
  776. }
  777. if (newOrder == 0.0)
  778. newOrder -= 1;
  779. Log(StrF(_T("GetNewLastSticky, Id: %d, parentId: %d, CurrentMax: %f, CurrentDesc: %s, NewMax: %f"), clipId, parentId, existingMaxOrder, existingDesc, newOrder));
  780. }
  781. CATCH_SQLITE_EXCEPTION
  782. return newOrder;
  783. }
  784. void CClip::MakeLatestOrder()
  785. {
  786. m_clipOrder = GetNewOrder(-1, m_id);
  787. }
  788. void CClip::MakeLatestGroupOrder()
  789. {
  790. if(m_parentId > -1)
  791. {
  792. m_clipGroupOrder = GetNewOrder(m_parentId, m_id);
  793. }
  794. }
  795. double CClip::GetNewOrder(int parentId, int clipId)
  796. {
  797. double newOrder = 0;
  798. double existingMaxOrder = 0;
  799. CString existingDesc = _T("");
  800. try
  801. {
  802. if(parentId < 0)
  803. {
  804. CppSQLite3Query q = theApp.m_db.execQuery(_T("SELECT clipOrder, mText FROM Main ORDER BY clipOrder DESC LIMIT 1"));
  805. if(q.eof() == false)
  806. {
  807. existingMaxOrder = q.getFloatField(_T("clipOrder"));
  808. existingDesc = q.getStringField(_T("mText"));
  809. newOrder = existingMaxOrder + 1;
  810. }
  811. }
  812. else
  813. {
  814. CppSQLite3Query q = theApp.m_db.execQueryEx(_T("SELECT clipGroupOrder, mText FROM Main WHERE lParentID = %d ORDER BY clipGroupOrder DESC LIMIT 1"), parentId);
  815. if(q.eof() == false)
  816. {
  817. existingMaxOrder = q.getFloatField(_T("clipGroupOrder"));
  818. newOrder = existingMaxOrder + 1;
  819. }
  820. }
  821. Log(StrF(_T("GetNewOrder, Id: %d, parentId: %d, CurrentMax: %f, CurrentDesc: %s, NewMax: %f"), clipId, parentId, existingMaxOrder, existingDesc, newOrder));
  822. }
  823. CATCH_SQLITE_EXCEPTION
  824. return newOrder;
  825. }
  826. BOOL CClip::LoadMainTable(int id)
  827. {
  828. bool bRet = false;
  829. try
  830. {
  831. CppSQLite3Query q = theApp.m_db.execQueryEx(_T("SELECT * FROM Main WHERE lID = %d"), id);
  832. if(q.eof() == false)
  833. {
  834. m_Time = q.getIntField(_T("lDate"));
  835. m_Desc = q.getStringField(_T("mText"));
  836. m_CRC = q.getIntField(_T("CRC"));
  837. m_parentId = q.getIntField(_T("lParentID"));
  838. m_dontAutoDelete = q.getIntField(_T("lDontAutoDelete"));
  839. m_shortCut = q.getIntField(_T("lShortCut"));
  840. m_bIsGroup = q.getIntField(_T("bIsGroup"));
  841. m_csQuickPaste = q.getStringField(_T("QuickPasteText"));
  842. m_clipOrder = q.getFloatField(_T("clipOrder"));
  843. m_clipGroupOrder = q.getFloatField(_T("clipGroupOrder"));
  844. m_globalShortCut = q.getIntField(_T("globalShortCut"));
  845. m_lastPasteDate = q.getIntField(_T("lastPasteDate"));
  846. m_stickyClipOrder = q.getFloatField(_T("stickyClipOrder"));
  847. m_stickyClipGroupOrder = q.getFloatField(_T("stickyClipGroupOrder"));
  848. m_moveToGroupShortCut = q.getIntField(_T("MoveToGroupShortCut"));
  849. m_globalMoveToGroupShortCut = q.getIntField(_T("GlobalMoveToGroupShortCut"));
  850. m_id = id;
  851. bRet = true;
  852. }
  853. }
  854. CATCH_SQLITE_EXCEPTION_AND_RETURN(FALSE)
  855. return bRet;
  856. }
  857. // STATICS
  858. // Allocates a Global containing the requested Clip Format Data
  859. HGLOBAL CClip::LoadFormat(int id, UINT cfType)
  860. {
  861. HGLOBAL hGlobal = 0;
  862. try
  863. {
  864. CString csSQL;
  865. csSQL.Format(
  866. _T("SELECT Data.ooData FROM Data ")
  867. _T("INNER JOIN Main ON Main.lID = Data.lParentID ")
  868. _T("WHERE Main.lID = %d ")
  869. _T("AND Data.strClipBoardFormat = \'%s\'"),
  870. id,
  871. GetFormatName(cfType));
  872. CppSQLite3Query q = theApp.m_db.execQuery(csSQL);
  873. if(q.eof() == false)
  874. {
  875. int nDataLen = 0;
  876. const unsigned char *cData = q.getBlobField(0, nDataLen);
  877. if(cData == NULL)
  878. {
  879. return false;
  880. }
  881. hGlobal = NewGlobalP((LPVOID)cData, nDataLen);
  882. }
  883. }
  884. CATCH_SQLITE_EXCEPTION
  885. return hGlobal;
  886. }
  887. bool CClip::LoadFormats(int id, bool bOnlyLoad_CF_TEXT)
  888. {
  889. DWORD startTick = GetTickCount();
  890. CClipFormat cf;
  891. HGLOBAL hGlobal = 0;
  892. m_Formats.RemoveAll();
  893. try
  894. {
  895. //Open the data table for all that have the parent id
  896. //Order by Data.lID so that when generating CRC it's always in the same order as the first time
  897. //we generated it
  898. CString csSQL;
  899. CString textFilter = _T("");
  900. if(bOnlyLoad_CF_TEXT)
  901. {
  902. textFilter = _T("(strClipBoardFormat = 'CF_TEXT' OR strClipBoardFormat = 'CF_UNICODETEXT' OR strClipBoardFormat = 'CF_HDROP') AND ");
  903. }
  904. csSQL.Format(
  905. _T("SELECT lID, lParentID, strClipBoardFormat, ooData FROM Data ")
  906. _T("WHERE %s lParentID = %d ORDER BY Data.lID desc"), textFilter, id);
  907. CppSQLite3Query q = theApp.m_db.execQuery(csSQL);
  908. while(q.eof() == false)
  909. {
  910. cf.m_dataId = q.getIntField(_T("lID"));
  911. cf.m_parentId = q.getIntField(_T("lParentID"));
  912. cf.m_cfType = GetFormatID(q.getStringField(_T("strClipBoardFormat")));
  913. if(bOnlyLoad_CF_TEXT)
  914. {
  915. if(cf.m_cfType != CF_TEXT &&
  916. cf.m_cfType != CF_UNICODETEXT &&
  917. cf.m_cfType != CF_HDROP)
  918. {
  919. q.nextRow();
  920. continue;
  921. }
  922. }
  923. int nDataLen = 0;
  924. const unsigned char *cData = q.getBlobField(_T("ooData"), nDataLen);
  925. if(cData != NULL)
  926. {
  927. hGlobal = NewGlobalP((LPVOID)cData, nDataLen);
  928. }
  929. cf.m_hgData = hGlobal;
  930. m_Formats.Add(cf);
  931. q.nextRow();
  932. }
  933. // formats owns all the data
  934. cf.m_hgData = 0;
  935. }
  936. CATCH_SQLITE_EXCEPTION_AND_RETURN(false)
  937. DWORD endTick = GetTickCount();
  938. if((endTick-startTick) > 150)
  939. Log(StrF(_T("Paste Timing LoadFormats: %d, ClipId: %d"), endTick-startTick, id));
  940. return m_Formats.GetSize() > 0;
  941. }
  942. void CClip::LoadTypes(int id, CClipTypes& types)
  943. {
  944. types.RemoveAll();
  945. try
  946. {
  947. CString csSQL;
  948. // get formats for Clip "lID" (Main.lID) using the corresponding Main.lDataID
  949. //Order by Data.lID so that when generating CRC it's always in the same order as the first time
  950. //we generated it
  951. csSQL.Format(
  952. _T("SELECT strClipBoardFormat FROM Data ")
  953. _T("INNER JOIN Main ON Main.lID = Data.lParentID ")
  954. _T("WHERE Main.lID = %d ORDER BY Data.lID desc"), id);
  955. CppSQLite3Query q = theApp.m_db.execQuery(csSQL);
  956. while(q.eof() == false)
  957. {
  958. types.Add(GetFormatID(q.getStringField(0)));
  959. q.nextRow();
  960. }
  961. }
  962. CATCH_SQLITE_EXCEPTION
  963. }
  964. bool CClip::SaveFromEditWnd(BOOL bUpdateDesc)
  965. {
  966. bool bRet = false;
  967. try
  968. {
  969. theApp.m_db.execDMLEx(_T("DELETE FROM Data WHERE lParentID = %d;"), m_id);
  970. DWORD CRC = GenerateCRC();
  971. AddToDataTable();
  972. theApp.m_db.execDMLEx(_T("UPDATE Main SET CRC = %d WHERE lID = %d"), CRC, m_id);
  973. if(bUpdateDesc)
  974. {
  975. m_Desc.Replace(_T("'"), _T("''"));
  976. theApp.m_db.execDMLEx(_T("UPDATE Main SET mText = '%s' WHERE lID = %d"), m_Desc, m_id);
  977. }
  978. bRet = true;
  979. }
  980. CATCH_SQLITE_EXCEPTION
  981. return bRet;
  982. }
  983. CStringW CClip::GetUnicodeTextFormat()
  984. {
  985. IClipFormat *pFormat = this->Clips()->FindFormatEx(CF_UNICODETEXT);
  986. if(pFormat != NULL)
  987. {
  988. wchar_t *stringData = (wchar_t *)GlobalLock(pFormat->Data());
  989. if(stringData != NULL)
  990. {
  991. CStringW string(stringData);
  992. GlobalUnlock(pFormat->Data());
  993. return string;
  994. }
  995. }
  996. return _T("");
  997. }
  998. CStringA CClip::GetCFTextTextFormat()
  999. {
  1000. IClipFormat *pFormat = this->Clips()->FindFormatEx(CF_TEXT);
  1001. if(pFormat != NULL)
  1002. {
  1003. char *stringData = (char *)GlobalLock(pFormat->Data());
  1004. if(stringData != NULL)
  1005. {
  1006. CStringA string(stringData);
  1007. GlobalUnlock(pFormat->Data());
  1008. return string;
  1009. }
  1010. }
  1011. return _T("");
  1012. }
  1013. BOOL CClip::WriteTextToFile(CString path, BOOL unicode, BOOL asci, BOOL utf8)
  1014. {
  1015. BOOL ret = false;
  1016. CFile f;
  1017. if(f.Open(path, CFile::modeWrite|CFile::modeCreate))
  1018. {
  1019. CStringW w = GetUnicodeTextFormat();
  1020. CStringA a = GetCFTextTextFormat();
  1021. if(utf8 && w != _T(""))
  1022. {
  1023. CStringA convToUtf8;
  1024. CTextConvert::ConvertToUTF8(w, convToUtf8);
  1025. byte header[2];
  1026. header[0] = 0xEF;
  1027. header[1] = 0xBB;
  1028. f.Write(&header, 2);
  1029. f.Write(convToUtf8.GetBuffer(), convToUtf8.GetLength());
  1030. ret = true;
  1031. }
  1032. else if(unicode && w != _T(""))
  1033. {
  1034. byte header[2];
  1035. header[0] = 0xFF;
  1036. header[1] = 0xFE;
  1037. f.Write(&header, 2);
  1038. f.Write(w.GetBuffer(), w.GetLength() * sizeof(wchar_t));
  1039. ret = true;
  1040. }
  1041. else if(asci && a != _T(""))
  1042. {
  1043. f.Write(a.GetBuffer(), a.GetLength());
  1044. ret = true;
  1045. }
  1046. f.Close();
  1047. }
  1048. return ret;
  1049. }
  1050. /*----------------------------------------------------------------------------*\
  1051. CClipList
  1052. \*----------------------------------------------------------------------------*/
  1053. CClipList::~CClipList()
  1054. {
  1055. CClip* pClip;
  1056. while(GetCount())
  1057. {
  1058. pClip = RemoveHead();
  1059. delete pClip;
  1060. }
  1061. }
  1062. // returns the number of clips actually saved
  1063. // while this does empty the Format Data, it does not delete the Clips.
  1064. int CClipList::AddToDB(bool bLatestOrder)
  1065. {
  1066. Log(_T("AddToDB - Start"));
  1067. int savedCount = 0;
  1068. CClip* pClip;
  1069. POSITION pos;
  1070. bool bResult;
  1071. INT_PTR remaining = GetCount();
  1072. pos = GetHeadPosition();
  1073. while(pos)
  1074. {
  1075. Log(StrF(_T("AddToDB - while(pos), Start Remaining %d"), remaining));
  1076. remaining--;
  1077. pClip = GetNext(pos);
  1078. ASSERT(pClip);
  1079. if(bLatestOrder)
  1080. {
  1081. pClip->MakeLatestOrder();
  1082. pClip->MakeLatestGroupOrder();
  1083. }
  1084. pClip->m_Time = CTime::GetCurrentTime().GetTime();
  1085. bResult = pClip->AddToDB();
  1086. if(bResult)
  1087. {
  1088. savedCount++;
  1089. }
  1090. Log(StrF(_T("AddToDB - while(pos), End Remaining %d, save count: %d"), remaining, savedCount));
  1091. }
  1092. Log(StrF(_T("AddToDB - Start, count: %d"), savedCount));
  1093. return savedCount;
  1094. }
  1095. const CClipList& CClipList::operator=(const CClipList &cliplist)
  1096. {
  1097. POSITION pos;
  1098. CClip* pClip;
  1099. pos = cliplist.GetHeadPosition();
  1100. while(pos)
  1101. {
  1102. pClip = cliplist.GetNext(pos);
  1103. ASSERT(pClip);
  1104. CClip *pNewClip = new CClip;
  1105. if(pNewClip)
  1106. {
  1107. *pNewClip = *pClip;
  1108. AddTail(pNewClip);
  1109. }
  1110. }
  1111. return *this;
  1112. }