CP_Main.cpp 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353
  1. #include "stdafx.h"
  2. #include "CP_Main.h"
  3. #include "MainFrm.h"
  4. #include "Misc.h"
  5. #include ".\cp_main.h"
  6. #include "server.h"
  7. #include "Client.h"
  8. #include "InternetUpdate.h"
  9. #include <io.h>
  10. #include "Path.h"
  11. #include "Clip_ImportExport.h"
  12. #include "HyperLink.h"
  13. #include "OptionsSheet.h"
  14. #include "DittoCopyBuffer.h"
  15. #include "SendKeys.h"
  16. #include "MainTableFunctions.h"
  17. #include "ShowTaskBarIcon.h"
  18. #include "NoDbFrameWnd.h"
  19. #include <clocale>
  20. #ifdef _DEBUG
  21. #define new DEBUG_NEW
  22. #undef THIS_FILE
  23. static char THIS_FILE[] = __FILE__;
  24. #endif
  25. class DittoCommandLineInfo : public CCommandLineInfo
  26. {
  27. public:
  28. DittoCommandLineInfo()
  29. {
  30. m_bDisconnect = FALSE;
  31. m_bConnect = FALSE;
  32. m_uacPID = 0;
  33. m_bOpenWindow = FALSE;
  34. m_bCloseWindow = FALSE;
  35. m_exit = FALSE;
  36. m_plainTextPaste = FALSE;
  37. m_pasteClip = FALSE;
  38. m_clipID = -1;
  39. m_editClip = FALSE;
  40. m_restartFromRestartManager = FALSE;
  41. }
  42. virtual void ParseParam(const TCHAR* pszParam, BOOL bFlag, BOOL bLast)
  43. {
  44. if(bFlag)
  45. {
  46. if(STRICMP(pszParam, _T("Connect")) == 0)
  47. {
  48. m_bConnect = TRUE;
  49. }
  50. else if(STRICMP(pszParam, _T("Disconnect")) == 0)
  51. {
  52. m_bDisconnect = TRUE;
  53. }
  54. else if(wcsncmp(pszParam, _T("uacpaste"), 8) == 0)
  55. {
  56. CString pidCommand(pszParam);
  57. long sep = pidCommand.ReverseFind(':');
  58. if(sep > -1)
  59. {
  60. CString pid = pidCommand.Right(pidCommand.GetLength() - sep - 1);
  61. m_uacPID = ATOI(pid);
  62. }
  63. }
  64. else if(STRICMP(pszParam, _T("open")) == 0)
  65. {
  66. m_bOpenWindow = TRUE;
  67. }
  68. else if(STRICMP(pszParam, _T("close")) == 0)
  69. {
  70. m_bCloseWindow = TRUE;
  71. }
  72. else if (STRICMP(pszParam, _T("exit")) == 0)
  73. {
  74. m_exit = TRUE;
  75. }
  76. else if (STRICMP(pszParam, _T("PlainTextPaste")) == 0)
  77. {
  78. m_plainTextPaste = TRUE;
  79. }
  80. else if (wcsnicmp(pszParam, _T("paste"), 5) == 0)
  81. {
  82. CString pidCommand(pszParam);
  83. long sep = pidCommand.ReverseFind(':');
  84. if (sep > -1)
  85. {
  86. CString id = pidCommand.Right(pidCommand.GetLength() - sep - 1);
  87. m_clipID = ATOI(id);
  88. m_pasteClip = TRUE;
  89. }
  90. }
  91. else if (wcsnicmp(pszParam, _T("edit"), 4) == 0)
  92. {
  93. CString pidCommand(pszParam);
  94. long sep = pidCommand.ReverseFind(':');
  95. if (sep > -1)
  96. {
  97. CString id = pidCommand.Right(pidCommand.GetLength() - sep - 1);
  98. m_clipID = ATOI(id);
  99. m_editClip = TRUE;
  100. }
  101. }
  102. else if (wcsnicmp(pszParam, _T("RestartByRestartManager"), 23) == 0)
  103. {
  104. m_restartFromRestartManager = true;
  105. }
  106. }
  107. CCommandLineInfo::ParseParam(pszParam, bFlag, bLast);
  108. }
  109. BOOL m_bDisconnect;
  110. BOOL m_bConnect;
  111. BOOL m_pasteClip;
  112. int m_uacPID;
  113. int m_clipID;
  114. BOOL m_bCloseWindow;
  115. BOOL m_exit;
  116. BOOL m_bOpenWindow;
  117. BOOL m_plainTextPaste;
  118. BOOL m_editClip;
  119. BOOL m_restartFromRestartManager;
  120. };
  121. CCP_MainApp theApp;
  122. BEGIN_MESSAGE_MAP(CCP_MainApp, CWinApp)
  123. //{{AFX_MSG_MAP(CCP_MainApp)
  124. // NOTE - the ClassWizard will add and remove mapping macros here.
  125. // DO NOT EDIT what you see in these blocks of generated code!
  126. //}}AFX_MSG_MAP
  127. END_MESSAGE_MAP()
  128. CCP_MainApp::CCP_MainApp()
  129. {
  130. m_copyReason = CopyReasonEnum::COPY_TO_UNKOWN;
  131. m_copyReasonStartTime = 0;
  132. m_activeGroupId = -1;
  133. m_activeGroupStartTime = 0;
  134. m_pUacPasteThread = NULL;
  135. m_bAppRunning = false;
  136. m_bAppExiting = false;
  137. m_connectOnStartup = -1;
  138. m_MainhWnd = NULL;
  139. m_pMainFrame = NULL;
  140. BOOL set = ::AllowSetForegroundWindow(ASFW_ANY);
  141. m_bShowingQuickPaste = false;
  142. m_GroupDefaultID = 0;
  143. m_GroupID = -1;
  144. m_GroupParentID = 0;
  145. m_GroupText = "History";
  146. m_FocusID = -1;
  147. ClearOldGroupState();
  148. m_bAsynchronousRefreshView = true;
  149. m_lClipsSent = 0;
  150. m_lClipsRecieved = 0;
  151. m_oldtStartUp = COleDateTime::GetCurrentTime();
  152. m_bExitServerThread = false;
  153. m_lLastGoodIndexForNextworkPassword = -2;
  154. m_RTFFormat = ::RegisterClipboardFormat(_T("Rich Text Format"));
  155. m_HTML_Format = ::RegisterClipboardFormat(_T("HTML Format"));
  156. m_PingFormat = ::RegisterClipboardFormat(_T("Ditto Ping Format"));
  157. m_cfIgnoreClipboard = ::RegisterClipboardFormat(_T("Clipboard Viewer Ignore"));
  158. m_cfDelaySavingData = ::RegisterClipboardFormat(_T("Ditto Delay Saving Data"));
  159. m_RemoteCF_HDROP = ::RegisterClipboardFormat(_T("Ditto Remote CF_HDROP"));
  160. m_DittoFileData = ::RegisterClipboardFormat(_T("Ditto File Data"));
  161. m_PNG_Format = GetFormatID(_T("PNG"));
  162. m_pNoDbMainFrame = NULL;
  163. m_databaseOnNetworkShare = false;
  164. m_dwRestartManagerSupportFlags = AFX_RESTART_MANAGER_SUPPORT_RESTART;
  165. }
  166. CCP_MainApp::~CCP_MainApp()
  167. {
  168. }
  169. BOOL CCP_MainApp::InitInstance()
  170. {
  171. INITCOMMONCONTROLSEX InitCtrls;
  172. InitCtrls.dwSize = sizeof(InitCtrls);
  173. // Set this to include all the common control classes you want to use
  174. // in your application.
  175. InitCtrls.dwICC = ICC_WIN95_CLASSES;
  176. InitCommonControlsEx(&InitCtrls);
  177. AfxEnableControlContainer();
  178. AfxOleInit();
  179. AfxInitRichEditEx();
  180. Gdiplus::GdiplusStartupInput gdiplusStartupInput;
  181. Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
  182. LoadLibrary(TEXT("MSFTEDIT.DLL"));
  183. setlocale(LC_TIME, ".OCP"); // defines the date/time formatting
  184. //MessageBox(NULL, _T("ditto starting"), _T("d"), MB_OK);
  185. DittoCommandLineInfo cmdInfo;
  186. ParseCommandLine(cmdInfo);
  187. g_Opt.LoadSettings();
  188. theApp.m_activeWnd.TrackActiveWnd(false);
  189. if(cmdInfo.m_uacPID > 0)
  190. {
  191. Log(StrF(_T("Startup up ditto as admin to paste to admin windows, parent process id: %d"), cmdInfo.m_uacPID));
  192. CString mutex;
  193. mutex.Format(_T("DittoAdminPaste_%d"), cmdInfo.m_uacPID);
  194. m_adminPasteMutex = CreateMutex(NULL, FALSE, mutex);
  195. m_pUacPasteThread = new CUAC_Thread(cmdInfo.m_uacPID);
  196. m_pUacPasteThread->Start();
  197. m_pUacPasteThread->WaitForThreadToExit(INT_MAX);
  198. return FALSE;
  199. }
  200. if (cmdInfo.m_restartFromRestartManager)
  201. {
  202. Log(StrF(_T("Ditto was restarted from restart manager")));
  203. }
  204. else if(cmdInfo.m_strFileName.IsEmpty() == FALSE)
  205. {
  206. try
  207. {
  208. g_Opt.m_bEnableDebugLogging = g_Opt.GetEnableDebugLogging();
  209. CClip_ImportExport Clip;
  210. CppSQLite3DB db;
  211. db.open(cmdInfo.m_strFileName);
  212. CClip_ImportExport clip;
  213. if(clip.ImportFromSqliteDB(db, false, true))
  214. {
  215. ShowCommandLineError("Ditto", theApp.m_Language.GetString("Importing_Good", "Clip placed on clipboard"));
  216. }
  217. else
  218. {
  219. ShowCommandLineError("Ditto", theApp.m_Language.GetString("Error_Importing", "Error importing exported clip"));
  220. }
  221. }
  222. catch (CppSQLite3Exception& e)
  223. {
  224. ASSERT(FALSE);
  225. CString csError;
  226. csError.Format(_T("%s - Exception - %d - %s"), theApp.m_Language.GetString("Error_Parsing", "Error parsing exported clip"), e.errorCode(), e.errorMessage());
  227. ShowCommandLineError("Ditto", csError);
  228. }
  229. return FALSE;
  230. }
  231. else if(cmdInfo.m_bConnect || cmdInfo.m_bDisconnect)
  232. {
  233. //First get the saved hwnd and send it a message
  234. //If ditto is running then this will return 1, meaning the running ditto process
  235. //handled this message
  236. //If it didn't handle the message(ditto is not running) then startup this processes of ditto
  237. //disconnected from the clipboard
  238. LRESULT ret = 0;
  239. HWND hWnd = (HWND)(LONG_PTR)CGetSetOptions::GetMainHWND();
  240. if(hWnd)
  241. {
  242. ret = ::SendMessage(hWnd, WM_SET_CONNECTED, cmdInfo.m_bConnect, cmdInfo.m_bDisconnect);
  243. }
  244. //passed off to the running instance of ditto, exit this instance
  245. if(ret == 1)
  246. {
  247. return FALSE;
  248. }
  249. if(cmdInfo.m_bConnect)
  250. {
  251. m_connectOnStartup = TRUE;
  252. }
  253. else if(cmdInfo.m_bDisconnect)
  254. {
  255. m_connectOnStartup = FALSE;
  256. }
  257. }
  258. else if(cmdInfo.m_bOpenWindow || cmdInfo.m_bCloseWindow)
  259. {
  260. //First get the saved hwnd and send it a message
  261. //If ditto is running then this will return 1, meaning the running ditto process
  262. //handled this message
  263. //If it didn't handle the message(ditto is not running) then startup this processes of ditto
  264. //disconnected from the clipboard
  265. LRESULT ret = 0;
  266. HWND hWnd = (HWND)(LONG_PTR)CGetSetOptions::GetMainHWND();
  267. if(hWnd)
  268. {
  269. ret = ::SendMessage(hWnd, WM_OPEN_CLOSE_WINDOW, cmdInfo.m_bOpenWindow, cmdInfo.m_bCloseWindow);
  270. }
  271. return FALSE;
  272. }
  273. else if (cmdInfo.m_exit)
  274. {
  275. //First get the saved hwnd and send it a message
  276. //If ditto is running then this will return 1, meaning the running ditto process
  277. //handled this message
  278. //If it didn't handle the message(ditto is not running) then startup this processes of ditto
  279. //disconnected from the clipboard
  280. LRESULT ret = 0;
  281. HWND hWnd = (HWND)(LONG_PTR)CGetSetOptions::GetMainHWND();
  282. if (hWnd)
  283. {
  284. ret = ::SendMessage(hWnd, WM_CLOSE, NULL, NULL);
  285. }
  286. return FALSE;
  287. }
  288. else if (cmdInfo.m_plainTextPaste)
  289. {
  290. LRESULT ret = 0;
  291. HWND hWnd = (HWND)(LONG_PTR)CGetSetOptions::GetMainHWND();
  292. if (hWnd)
  293. {
  294. ret = ::SendMessage(hWnd, WM_PLAIN_TEXT_PASTE, NULL, NULL);
  295. }
  296. return FALSE;
  297. }
  298. else if (cmdInfo.m_pasteClip)
  299. {
  300. LRESULT ret = 0;
  301. HWND hWnd = (HWND)(LONG_PTR)CGetSetOptions::GetMainHWND();
  302. if (hWnd)
  303. {
  304. ret = ::SendMessage(hWnd, WM_PASTE_CLIP, cmdInfo.m_clipID, NULL);
  305. }
  306. return FALSE;
  307. }
  308. else if (cmdInfo.m_editClip)
  309. {
  310. LRESULT ret = 0;
  311. HWND hWnd = (HWND)(LONG_PTR)CGetSetOptions::GetMainHWND();
  312. if (hWnd)
  313. {
  314. ret = ::SendMessage(hWnd, WM_EDIT_CLIP, cmdInfo.m_clipID, NULL);
  315. }
  316. return FALSE;
  317. }
  318. CInternetUpdate update;
  319. auto runningVersion = update.GetRunningVersion();
  320. CString cs = update.GetVersionString(runningVersion);
  321. cs.Insert(0, _T("InitInstance - Running Version - "));
  322. Log(cs);
  323. CString csMutex("Ditto Is Now Running");
  324. if(g_Opt.GetIsPortableDitto() || g_Opt.GetIsWindowsApp() || g_Opt.GetIsChocolateyApp())
  325. {
  326. csMutex += " ";
  327. csMutex += g_Opt.GetExeFileName();
  328. }
  329. CWinApp::RegisterWithRestartManager(false, csMutex);
  330. //create mutex doesn't like slashes, remove them, it always returns NULL with them in
  331. csMutex.Replace(_T("\\"), _T("_"));
  332. m_hMutex = CreateMutex(NULL, TRUE, csMutex);
  333. DWORD dwError = GetLastError();
  334. if(m_hMutex == NULL ||
  335. dwError == ERROR_ALREADY_EXISTS)
  336. {
  337. Log(StrF(_T("Ditto is already running, closing, mutex: %s"), csMutex));
  338. HWND hWnd = (HWND)(LONG_PTR)CGetSetOptions::GetMainHWND();
  339. if(hWnd)
  340. ::SendMessage(hWnd, WM_SHOW_TRAY_ICON, TRUE, TRUE);
  341. return TRUE;
  342. }
  343. Log(StrF(_T("Starting up ditto with mutex: %s"), csMutex));
  344. CString csFile = CGetSetOptions::GetLanguageFile();
  345. if(m_Language.LoadLanguageFile(csFile) == false)
  346. {
  347. CString cs;
  348. cs.Format(_T("Error loading language file - %s - \n\n%s"), csFile, m_Language.m_csLastError);
  349. Log(cs);
  350. m_Language.LoadLanguageFile(_T("English.xml"));
  351. }
  352. m_icuString.Load();
  353. int nRet = CheckDBExists(CGetSetOptions::GetDBPath());
  354. if(nRet == FALSE)
  355. {
  356. m_pNoDbMainFrame = new CNoDbFrameWnd();
  357. m_pMainWnd = m_pNoDbMainFrame;
  358. m_pNoDbMainFrame->LoadFrame(IDR_MAINFRAME, WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, NULL, NULL);
  359. m_pNoDbMainFrame->ShowWindow(SW_SHOW);
  360. m_pNoDbMainFrame->UpdateWindow();
  361. }
  362. else
  363. {
  364. //Sleep(1000);
  365. CreateMainWnd();
  366. }
  367. return TRUE;
  368. }
  369. void CCP_MainApp::CreateMainWnd()
  370. {
  371. CMainFrame* pFrame = new CMainFrame;
  372. m_pMainWnd = m_pMainFrame = pFrame;
  373. pFrame->LoadFrame(IDR_MAINFRAME, WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, NULL, NULL);
  374. //removed to keep ditto from taking focus on startup
  375. //pFrame->ShowWindow(SW_SHOW);
  376. //pFrame->UpdateWindow();
  377. }
  378. void CCP_MainApp::CloseNoDbWindow()
  379. {
  380. if (m_pNoDbMainFrame != NULL)
  381. {
  382. m_pNoDbMainFrame->CloseWindow();
  383. delete m_pNoDbMainFrame;
  384. m_pNoDbMainFrame = NULL;
  385. }
  386. }
  387. void CCP_MainApp::AfterMainCreate()
  388. {
  389. m_MainhWnd = m_pMainFrame->m_hWnd;
  390. ASSERT( ::IsWindow(m_MainhWnd) );
  391. g_Opt.SetMainHWND((long)(LONG_PTR)m_MainhWnd);
  392. g_HotKeys.Init(m_MainhWnd);
  393. // create hotkeys here. They are automatically deleted on exit
  394. m_pDittoHotKey = new CHotKey(CString("DittoHotKey"), 704); //704 is ctrl-tilda
  395. m_pDittoHotKey2 = new CHotKey(CString("DittoHotKey2"));
  396. m_pDittoHotKey3 = new CHotKey(CString("DittoHotKey3"));
  397. m_pPosOne = new CHotKey("Position1", 0, true);
  398. m_pPosTwo = new CHotKey("Position2", 0, true);
  399. m_pPosThree = new CHotKey("Position3", 0, true);
  400. m_pPosFour = new CHotKey("Position4", 0, true);
  401. m_pPosFive = new CHotKey("Position5", 0, true);
  402. m_pPosSix = new CHotKey("Position6", 0, true);
  403. m_pPosSeven = new CHotKey("Position7", 0, true);
  404. m_pPosEight = new CHotKey("Position8", 0, true);
  405. m_pPosNine = new CHotKey("Position9", 0, true);
  406. m_pPosTen = new CHotKey("Position10", 0, true);
  407. m_pCopyBuffer1 = new CHotKey("CopyBufferCopyHotKey_0", 0, true);
  408. m_pPasteBuffer1 = new CHotKey("CopyBufferPasteHotKey_0", 0, true);
  409. m_pCutBuffer1 = new CHotKey("CopyBufferCutHotKey_0", 0, true);
  410. m_pCopyBuffer2 = new CHotKey("CopyBufferCopyHotKey_1", 0, true);
  411. m_pPasteBuffer2 = new CHotKey("CopyBufferPasteHotKey_1", 0, true);
  412. m_pCutBuffer2 = new CHotKey("CopyBufferCutHotKey_1", 0, true);
  413. m_pCopyBuffer3 = new CHotKey("CopyBufferCopyHotKey_2", 0, true);
  414. m_pPasteBuffer3 = new CHotKey("CopyBufferPasteHotKey_2", 0, true);
  415. m_pCutBuffer3 = new CHotKey("CopyBufferCutHotKey_2", 0, true);
  416. m_pCopyBuffer4 = new CHotKey("CopyBufferCopyHotKey_3", 0, true);
  417. m_pPasteBuffer4 = new CHotKey("CopyBufferPasteHotKey_3", 0, true);
  418. m_pCutBuffer4 = new CHotKey("CopyBufferCutHotKey_3", 0, true);
  419. m_pCopyBuffer5 = new CHotKey("CopyBufferCopyHotKey_4", 0, true);
  420. m_pPasteBuffer5 = new CHotKey("CopyBufferPasteHotKey_4", 0, true);
  421. m_pCutBuffer5 = new CHotKey("CopyBufferCutHotKey_4", 0, true);
  422. m_pTextOnlyPaste = new CHotKey("TextOnlyPaste", 0, true);
  423. m_pSaveClipboard = new CHotKey("SaveClipboard", 0, false);
  424. m_pCopyAndSaveClipboard = new CHotKey("CopyAndSaveClipboard", 0, false);
  425. m_editThread.StartWatchingFolderForChanges();
  426. LoadGlobalClips();
  427. g_HotKeys.RegisterAll();
  428. StartCopyThread();
  429. StartStopServerThread();
  430. #ifdef UNICODE
  431. m_Addins.LoadAll();
  432. #endif
  433. m_bAppRunning = true;
  434. }
  435. void CCP_MainApp::LoadGlobalClips()
  436. {
  437. try
  438. {
  439. {
  440. CppSQLite3Query q = m_db.execQuery(_T("SELECT lID, lShortCut, mText FROM Main WHERE lShortCut > 0 AND globalShortCut = 1"));
  441. while(q.eof() == false)
  442. {
  443. int id = q.getIntField(_T("lID"));
  444. int shortcut = q.getIntField(_T("lShortCut"));
  445. CString desc = q.getStringField(_T("mText"));
  446. //Constructor will add to a global list and free
  447. CHotKey* globalHotKey = new CHotKey(StrF(_T("GlobalClip: %d"), id), shortcut, true, CHotKey::PASTE_OPEN_CLIP, desc);
  448. if(globalHotKey != NULL)
  449. {
  450. globalHotKey->m_clipId = id;
  451. }
  452. q.nextRow();
  453. }
  454. }
  455. {
  456. CppSQLite3Query q2 = m_db.execQuery(_T("SELECT lID, MoveToGroupShortCut, mText FROM Main WHERE MoveToGroupShortCut > 0 AND GlobalMoveToGroupShortCut = 1"));
  457. while(q2.eof() == false)
  458. {
  459. int id = q2.getIntField(_T("lID"));
  460. int shortcut = q2.getIntField(_T("MoveToGroupShortCut"));
  461. CString desc = q2.getStringField(_T("mText"));
  462. //Constructor will add to a global list and free
  463. CHotKey* globalHotKey = new CHotKey(StrF(_T("MoveToGroup: %d"), id), shortcut, true, CHotKey::MOVE_TO_GROUP, desc);
  464. if(globalHotKey != NULL)
  465. {
  466. globalHotKey->m_clipId = id;
  467. }
  468. q2.nextRow();
  469. }
  470. }
  471. }
  472. CATCH_SQLITE_EXCEPTION
  473. }
  474. void CCP_MainApp::StartStopServerThread()
  475. {
  476. if(CGetSetOptions::GetDisableRecieve() == FALSE && g_Opt.GetAllowFriends())
  477. {
  478. AfxBeginThread(MTServerThread, m_MainhWnd);
  479. }
  480. else
  481. {
  482. m_bExitServerThread = true;
  483. closesocket(theApp.m_sSocket);
  484. }
  485. }
  486. void CCP_MainApp::StopServerThread()
  487. {
  488. m_bExitServerThread = true;
  489. closesocket(theApp.m_sSocket);
  490. }
  491. void CCP_MainApp::BeforeMainClose()
  492. {
  493. ASSERT( m_bAppRunning && !m_bAppExiting );
  494. m_bAppRunning = false;
  495. m_bAppExiting = true;
  496. g_HotKeys.UnregisterAll();
  497. StopServerThread();
  498. StopCopyThread();
  499. }
  500. void CCP_MainApp::StartCopyThread()
  501. {
  502. ASSERT( m_MainhWnd );
  503. CClipTypes* pTypes = LoadTypesFromDB();
  504. // initialize to:
  505. // - m_MainhWnd = send WM_CLIPBOARD_COPIED messages to m_MainhWnd
  506. // - true = use Asynchronous communication (PostMessage)
  507. // - true = enable copying on clipboard changes
  508. // - pTypes = the supported types to use
  509. m_CopyThread.Init(CCopyConfig(m_MainhWnd, true, true, pTypes));
  510. if(m_connectOnStartup == FALSE || g_Opt.GetConnectedToClipboard() == FALSE)
  511. {
  512. m_CopyThread.m_connectOnStartup = false;
  513. Log(StrF(_T("Starting Ditto up disconnected from the clipboard, commandLine: %d, saved value: %d"), m_connectOnStartup, g_Opt.GetConnectedToClipboard()));
  514. SetConnectCV(false);
  515. }
  516. else if(m_connectOnStartup == TRUE)
  517. {
  518. SetConnectCV(true);
  519. Log(_T("Starting Ditto up connected from the clipboard, passed in true from command line to start connected"));
  520. }
  521. VERIFY(m_CopyThread.CreateThread(CREATE_SUSPENDED));
  522. m_CopyThread.ResumeThread();
  523. }
  524. void CCP_MainApp::StopCopyThread()
  525. {
  526. EnableCbCopy(false);
  527. m_CopyThread.Quit();
  528. }
  529. // returns the current Clipboard Viewer Connect state (though it might not yet
  530. // be actually connected -- check IsClipboardViewerConnected())
  531. bool CCP_MainApp::ToggleConnectCV()
  532. {
  533. bool bConnect = !GetConnectCV();
  534. SetConnectCV(bConnect);
  535. return bConnect;
  536. }
  537. // Sets a menu entry according to the current Clipboard Viewer Connection status
  538. // - the menu text indicates the available command (opposite the current state)
  539. // - a check mark appears in the rare cases that the menu text actually represents
  540. // the current state, e.g. if we are supposed to be connected, but we somehow
  541. // lose that connection, "Disconnect from Clipboard" will have a check next to it.
  542. void CCP_MainApp::UpdateMenuConnectCV(CMenu* pMenu, UINT nMenuID)
  543. {
  544. if(pMenu == NULL)
  545. return;
  546. bool bConnect = theApp.GetConnectCV();
  547. CString cs;
  548. if(bConnect)
  549. {
  550. cs = theApp.m_Language.GetString("Disconnect_Clipboard", "Disconnect from Clipboard.");
  551. pMenu->ModifyMenu(nMenuID, MF_BYCOMMAND, nMenuID, cs);
  552. }
  553. else
  554. {
  555. cs = theApp.m_Language.GetString("Connect_Clipboard", "Connect to Clipboard.");
  556. pMenu->ModifyMenu(nMenuID, MF_BYCOMMAND, nMenuID, cs);
  557. }
  558. }
  559. // Allocates a new CClipTypes
  560. CClipTypes* CCP_MainApp::LoadTypesFromDB()
  561. {
  562. CClipTypes* pTypes = new CClipTypes;
  563. try
  564. {
  565. CppSQLite3Query q = theApp.m_db.execQuery(_T("SELECT TypeText FROM Types"));
  566. while(q.eof() == false)
  567. {
  568. pTypes->Add(GetFormatID(q.getStringField(_T("TypeText"))));
  569. q.nextRow();
  570. }
  571. }
  572. CATCH_SQLITE_EXCEPTION
  573. if(pTypes->GetSize() <= 0)
  574. {
  575. pTypes->Add(CF_TEXT);
  576. pTypes->Add(RegisterClipboardFormat(CF_RTF));
  577. pTypes->Add(CF_UNICODETEXT);
  578. pTypes->Add(CF_HDROP);
  579. pTypes->Add(CF_DIB);
  580. pTypes->Add(GetFormatID(_T("HTML Format")));
  581. pTypes->Add(GetFormatID(_T("PNG")));
  582. }
  583. return pTypes;
  584. }
  585. void CCP_MainApp::ReloadTypes()
  586. {
  587. CClipTypes* pTypes = LoadTypesFromDB();
  588. if(pTypes)
  589. {
  590. m_CopyThread.SetSupportedTypes(pTypes);
  591. }
  592. }
  593. void CCP_MainApp::RefreshView(CopyReasonEnum::CopyReason copyReason)
  594. {
  595. CQPasteWnd *pWnd = QPasteWnd();
  596. if(pWnd)
  597. {
  598. if(m_bAsynchronousRefreshView)
  599. {
  600. pWnd->PostMessage(WM_REFRESH_VIEW, copyReason, 0);
  601. }
  602. else
  603. {
  604. pWnd->SendMessage(WM_REFRESH_VIEW, copyReason, 0);
  605. }
  606. }
  607. }
  608. void CCP_MainApp::RefreshClipInUI(int clipId, int updateFlags)
  609. {
  610. CQPasteWnd *pWnd = QPasteWnd();
  611. if(pWnd)
  612. {
  613. if(m_bAsynchronousRefreshView)
  614. {
  615. pWnd->PostMessage(WM_RELOAD_CLIP_IN_UI, clipId, updateFlags);
  616. }
  617. else
  618. {
  619. pWnd->SendMessage(WM_RELOAD_CLIP_IN_UI, clipId, updateFlags);
  620. }
  621. }
  622. }
  623. void CCP_MainApp::OnPasteCompleted()
  624. {
  625. }
  626. void CCP_MainApp::OnCopyCompleted(long lLastID, int count, CopyReasonEnum::CopyReason copyReason)
  627. {
  628. if(count <= 0)
  629. {
  630. return;
  631. }
  632. // update copy statistics
  633. CGetSetOptions::SetTripCopyCount(-count);
  634. CGetSetOptions::SetTotalCopyCount(-count);
  635. if(m_CopyBuffer.Active())
  636. {
  637. m_CopyBuffer.EndCopy(lLastID);
  638. }
  639. RefreshView(copyReason);
  640. }
  641. void CCP_MainApp::SaveCurrentGroupState()
  642. {
  643. m_oldGroupID = m_GroupID;
  644. m_oldGroupParentID = m_GroupParentID;
  645. m_oldGroupText = m_GroupText;
  646. }
  647. void CCP_MainApp::ClearOldGroupState()
  648. {
  649. m_oldGroupID = -2;
  650. m_oldGroupParentID = -2;
  651. m_oldGroupText = _T("");
  652. }
  653. BOOL CCP_MainApp::TryEnterOldGroupState()
  654. {
  655. BOOL enteredGroup = FALSE;
  656. if(m_oldGroupID > -2)
  657. {
  658. m_GroupID = m_oldGroupID;
  659. m_GroupParentID = m_oldGroupParentID;
  660. m_GroupText = m_oldGroupText;
  661. ClearOldGroupState();
  662. theApp.RefreshView();
  663. if(QPasteWnd())
  664. QPasteWnd()->UpdateStatus(true);
  665. enteredGroup = TRUE;
  666. }
  667. return enteredGroup;
  668. }
  669. BOOL CCP_MainApp::EnterGroupID(long lID, BOOL clearOldGroupState/* = TRUE*/, BOOL saveCurrentGroupState/* = FALSE*/)
  670. {
  671. BOOL bResult = FALSE;
  672. if(m_GroupID == lID)
  673. return TRUE;
  674. DWORD startTick = GetTickCount();
  675. if(clearOldGroupState)
  676. {
  677. ClearOldGroupState();
  678. }
  679. if(saveCurrentGroupState)
  680. {
  681. SaveCurrentGroupState();
  682. }
  683. // if we are switching to the parent, focus on the previous group
  684. if(m_GroupParentID == lID && m_GroupID > 0)
  685. m_FocusID = m_GroupID;
  686. switch(lID)
  687. {
  688. case -1:
  689. m_FocusID = -1;
  690. m_GroupID = -1;
  691. m_GroupParentID = -1;
  692. m_GroupText = "History";
  693. bResult = TRUE;
  694. break;
  695. default: // Normal Group
  696. try
  697. {
  698. CppSQLite3Query q = theApp.m_db.execQueryEx(_T("SELECT lParentID, mText, bIsGroup FROM Main WHERE lID = %d"), lID);
  699. if(q.eof() == false)
  700. {
  701. if(q.getIntField(_T("bIsGroup")) > 0)
  702. {
  703. m_GroupID = lID;
  704. m_GroupParentID = q.getIntField(_T("lParentID"));
  705. m_GroupText = q.getStringField(_T("mText"));
  706. bResult = TRUE;
  707. }
  708. }
  709. }
  710. CATCH_SQLITE_EXCEPTION
  711. break;
  712. }
  713. if(bResult)
  714. {
  715. theApp.RefreshView();
  716. if(QPasteWnd())
  717. QPasteWnd()->UpdateStatus(true);
  718. }
  719. DWORD endTick = GetTickCount();
  720. if((endTick-startTick) > 150)
  721. Log(StrF(_T("Paste Timing EnterParentId: %d"), endTick-startTick));
  722. return bResult;
  723. }
  724. // returns a usable group id (not negative)
  725. long CCP_MainApp::GetValidGroupID()
  726. {
  727. return m_GroupID;
  728. }
  729. // sets a valid id
  730. void CCP_MainApp::SetGroupDefaultID(long lID)
  731. {
  732. if(m_GroupDefaultID == lID)
  733. {
  734. return;
  735. }
  736. if(lID <= 0)
  737. {
  738. m_GroupDefaultID = 0;
  739. }
  740. else
  741. {
  742. m_GroupDefaultID = lID;
  743. }
  744. if(QPasteWnd())
  745. {
  746. QPasteWnd()->UpdateStatus();
  747. }
  748. }
  749. void CCP_MainApp::SetStatus(const TCHAR* status, bool bRepaintImmediately)
  750. {
  751. m_Status = status;
  752. if(QPasteWnd())
  753. {
  754. QPasteWnd()->UpdateStatus(bRepaintImmediately);
  755. }
  756. }
  757. void CCP_MainApp::ShowPersistent(bool bVal)
  758. {
  759. g_Opt.SetShowPersistent(bVal);
  760. // give some visual indication
  761. if(m_bShowingQuickPaste)
  762. {
  763. ASSERT(QPasteWnd());
  764. QPasteWnd()->SetCaptionColorActive(g_Opt.m_bShowPersistent, theApp.GetConnectCV());
  765. QPasteWnd()->RefreshNc();
  766. }
  767. }
  768. /////////////////////////////////////////////////////////////////////////////
  769. // CCP_MainApp message handlers
  770. int CCP_MainApp::ExitInstance()
  771. {
  772. Log(_T("ExitInstance"));
  773. DeleteDittoTempFiles(FALSE);
  774. m_db.close();
  775. if(m_pUacPasteThread != NULL)
  776. {
  777. if(m_pUacPasteThread->ThreadWasStarted() == false)
  778. {
  779. m_pUacPasteThread->FireExit();
  780. }
  781. delete m_pUacPasteThread;
  782. }
  783. Gdiplus::GdiplusShutdown(m_gdiplusToken);
  784. return CWinApp::ExitInstance();
  785. }
  786. // return TRUE if there is more idle processing to do
  787. BOOL CCP_MainApp::OnIdle(LONG lCount)
  788. {
  789. // let winapp handle its idle processing
  790. if(CWinApp::OnIdle(lCount))
  791. return TRUE;
  792. return FALSE;
  793. }
  794. void CCP_MainApp::SetConnectCV(bool bConnect)
  795. {
  796. m_CopyThread.SetConnectCV(bConnect);
  797. g_Opt.SetConnectedToClipboard(bConnect == true);
  798. if(bConnect)
  799. {
  800. m_pMainFrame->m_trayIcon.SetIcon(IDR_MAINFRAME);
  801. m_pMainFrame->m_trayIcon.SetTooltipText(_T("Ditto"));
  802. }
  803. else
  804. {
  805. m_pMainFrame->m_trayIcon.SetIcon(IDI_DITTO_NOCOPYCB);
  806. CString cs;
  807. cs = _T("Ditto ");
  808. cs += theApp.m_Language.GetString("disconnected", "[Disconnected]");
  809. m_pMainFrame->m_trayIcon.SetTooltipText(cs);
  810. }
  811. if(QPasteWnd())
  812. {
  813. QPasteWnd()->SetCaptionColorActive(g_Opt.m_bShowPersistent, theApp.GetConnectCV());
  814. QPasteWnd()->RefreshNc();
  815. }
  816. }
  817. void CCP_MainApp::OnDeleteID(long lID)
  818. {
  819. if(QPasteWnd())
  820. {
  821. QPasteWnd()->PostMessage(NM_ITEM_DELETED, lID, 0);
  822. }
  823. }
  824. bool CCP_MainApp::ImportClips(HWND hWnd)
  825. {
  826. OPENFILENAME FileName;
  827. TCHAR szFileName[400];
  828. TCHAR szDir[400];
  829. memset(&FileName, 0, sizeof(FileName));
  830. memset(szFileName, 0, sizeof(szFileName));
  831. memset(&szDir, 0, sizeof(szDir));
  832. CString csInitialDir = CGetSetOptions::GetLastImportDir();
  833. STRCPY(szDir, csInitialDir);
  834. FileName.lStructSize = sizeof(FileName);
  835. FileName.lpstrTitle = _T("Import Clips");
  836. FileName.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST | OFN_NOCHANGEDIR;
  837. FileName.nMaxFile = 400;
  838. FileName.lpstrFile = szFileName;
  839. FileName.lpstrInitialDir = szDir;
  840. FileName.lpstrFilter = _T("Exported Ditto Clips (.dto)\0*.dto\0\0");
  841. FileName.lpstrDefExt = _T("dto");
  842. if(GetOpenFileName(&FileName) == 0)
  843. {
  844. return false;
  845. }
  846. using namespace nsPath;
  847. CPath path(FileName.lpstrFile);
  848. CString csPath = path.GetPath();
  849. CGetSetOptions::SetLastImportDir(csPath);
  850. try
  851. {
  852. CppSQLite3DB db;
  853. db.open(FileName.lpstrFile);
  854. CClip_ImportExport clip;
  855. if(clip.ImportFromSqliteDB(db, true, false))
  856. {
  857. CShowTaskBarIcon show;
  858. CString cs;
  859. cs.Format(_T("%s %d "), theApp.m_Language.GetString("Import_Successfully", "Successfully imported"), clip.m_importCount);
  860. if(clip.m_importCount = 1)
  861. cs += theApp.m_Language.GetString("Clip", "clip");
  862. else
  863. cs += theApp.m_Language.GetString("Clips", "clips");
  864. MessageBox(hWnd, cs, _T("Ditto"), MB_OK);
  865. }
  866. else
  867. {
  868. CShowTaskBarIcon show;
  869. MessageBox(hWnd, theApp.m_Language.GetString("Error_Importing", "Error importing exported clip"), _T("Ditto"), MB_OK);
  870. }
  871. }
  872. catch (CppSQLite3Exception& e)
  873. {
  874. ASSERT(FALSE);
  875. CString csError;
  876. csError.Format(_T("%s - Exception - %d - %s"), theApp.m_Language.GetString("Error_Parsing", "Error parsing exported clip"), e.errorCode(), e.errorMessage());
  877. MessageBox(hWnd, csError, _T("Ditto"), MB_OK);
  878. }
  879. return true;
  880. }
  881. void CCP_MainApp::ShowCommandLineError(CString csTitle, CString csMessage)
  882. {
  883. Log(StrF(_T("ShowCommandLineError %s - %s"), csTitle, csMessage));
  884. CToolTipEx *pErrorWnd = new CToolTipEx;
  885. pErrorWnd->Create(NULL);
  886. pErrorWnd->SetToolTipText(csTitle + "\n\n" + csMessage);
  887. CPoint pt;
  888. CRect rcScreen = DefaultMonitorRect();
  889. pt = rcScreen.BottomRight();
  890. CRect cr = pErrorWnd->GetBoundsRect();
  891. pt.x -= max(cr.Width()+50, 150);
  892. pt.y -= max(cr.Height()+50, 150);
  893. pErrorWnd->Show(pt);
  894. PumpMessageEx(pErrorWnd->m_hWnd);
  895. Sleep(4000);
  896. pErrorWnd->DestroyWindow();
  897. }
  898. BOOL CCP_MainApp::GetClipData(long parentId, CClipFormat &Clip)
  899. {
  900. BOOL bRet = FALSE;
  901. try
  902. {
  903. CppSQLite3Query q = theApp.m_db.execQueryEx(_T("SELECT ooData FROM Data WHERE lParentID = %d AND strClipboardFormat = '%s'"), parentId, GetFormatName(Clip.m_cfType));
  904. if(q.eof() == false)
  905. {
  906. int nDataLen = 0;
  907. const unsigned char *cData = q.getBlobField(_T("ooData"), nDataLen);
  908. if(cData != NULL)
  909. {
  910. Clip.m_hgData = NewGlobal(nDataLen);
  911. ::CopyToGlobalHP(Clip.m_hgData, (LPVOID)cData, nDataLen);
  912. bRet = TRUE;
  913. }
  914. }
  915. }
  916. CATCH_SQLITE_EXCEPTION
  917. return bRet;
  918. }
  919. bool CCP_MainApp::EditItems(CClipIDs &Ids, bool bShowError, bool forceTextEdit)
  920. {
  921. bool ret = false;
  922. int lastFileCheckId = 1;
  923. for (int i = 0; i < min(Ids.GetCount(), 20); i++)
  924. {
  925. const int id = Ids[i];
  926. CClip clip;
  927. if (id >= 0 && clip.LoadFormats(id, true, true) == false)
  928. {
  929. Log(StrF(_T("Failed to load formats for clipId: %d"), id));
  930. continue;
  931. }
  932. bool unicodeFile = false;
  933. bool asciFile = false;
  934. bool rtfFile = false;
  935. CString exePath;
  936. CString extension;
  937. if (forceTextEdit == false && clip.ContainsClipFormat(theApp.m_RTFFormat))
  938. {
  939. extension = _T("rtf");
  940. rtfFile = true;
  941. exePath = CGetSetOptions::GetRTFEditorPath();
  942. }
  943. else if (clip.ContainsClipFormat(CF_UNICODETEXT))
  944. {
  945. extension = _T("txt");
  946. unicodeFile = true;
  947. exePath = CGetSetOptions::GetTextEditorPath();
  948. }
  949. else if (clip.ContainsClipFormat(CF_TEXT))
  950. {
  951. extension = _T("txt");
  952. asciFile = true;
  953. exePath = CGetSetOptions::GetTextEditorPath();
  954. }
  955. else if (id == -1)
  956. {
  957. extension = _T("txt");
  958. unicodeFile = true;
  959. exePath = CGetSetOptions::GetTextEditorPath();
  960. }
  961. else
  962. {
  963. continue;
  964. }
  965. CString startingFilePath = StrF(_T("%sEditClip_%d.%s"), CGetSetOptions::GetPath(PATH_EDIT_CLIPS), id, extension);
  966. if (id == -1)
  967. {
  968. startingFilePath = StrF(_T("%sNewClip_1.%s"), CGetSetOptions::GetPath(PATH_EDIT_CLIPS), extension);
  969. }
  970. CString savePath = startingFilePath;
  971. //for new files make a unique file name
  972. if (id < 0 &&
  973. FileExists(startingFilePath))
  974. {
  975. savePath = _T("");
  976. for (int y = lastFileCheckId; y < 1000000; y++)
  977. {
  978. CString testFilePath = StrF(_T("%sNewClip_%d.%s"), CGetSetOptions::GetPath(PATH_EDIT_CLIPS), y, extension);
  979. if (FileExists(testFilePath) == FALSE)
  980. {
  981. savePath = testFilePath;
  982. lastFileCheckId = y + 1;
  983. break;
  984. }
  985. }
  986. }
  987. m_editThread.WatchFile(savePath);
  988. clip.WriteTextToFile(savePath, unicodeFile, asciFile, rtfFile, (id == -1));
  989. SHELLEXECUTEINFO sei = { sizeof(sei) };
  990. sei.fMask = SEE_MASK_NOCLOSEPROCESS;
  991. sei.lpVerb = _T("open");
  992. if (exePath != _T(""))
  993. {
  994. sei.lpFile = exePath;
  995. sei.lpParameters = savePath;
  996. Log(StrF(_T("Launching editor path: %s, file: %s"), exePath, savePath));
  997. }
  998. else
  999. {
  1000. sei.lpFile = savePath;
  1001. Log(StrF(_T("Launching editor without specific exe path, file: %s"), savePath));
  1002. }
  1003. sei.nShow = SW_NORMAL;
  1004. if (ShellExecuteEx(&sei) == FALSE)
  1005. {
  1006. Log(StrF(_T("ShellExecuteEx failed, not editing clipid: %d"), id));
  1007. continue;
  1008. }
  1009. /*DWORD PID = GetProcessId(sei.hProcess);
  1010. HANDLE hProcess = sei.hProcess;
  1011. if (m_editThread.IsRunning() == false)
  1012. {
  1013. m_editThread.SubscribeToFileChanges();
  1014. m_editThread.Start();
  1015. }
  1016. m_editThread.WatchFileForChange(savePath, id, hProcess);*/
  1017. ret = true;
  1018. }
  1019. return true;
  1020. }
  1021. void CCP_MainApp::PumpMessageEx(HWND hWnd)
  1022. {
  1023. MSG KeyboardMsg;
  1024. while (::PeekMessage(&KeyboardMsg, hWnd, 0, 0, PM_REMOVE))
  1025. {
  1026. ::TranslateMessage(&KeyboardMsg);
  1027. ::DispatchMessage(&KeyboardMsg);
  1028. }
  1029. }
  1030. HWND CCP_MainApp::QPastehWnd()
  1031. {
  1032. if(m_pMainFrame != NULL)
  1033. {
  1034. if(m_pMainFrame->m_quickPaste.m_pwndPaste != NULL)
  1035. {
  1036. return m_pMainFrame->m_quickPaste.m_pwndPaste->GetSafeHwnd();
  1037. }
  1038. }
  1039. return NULL;
  1040. }
  1041. CQPasteWnd* CCP_MainApp::QPasteWnd()
  1042. {
  1043. if(m_pMainFrame != NULL)
  1044. {
  1045. return m_pMainFrame->m_quickPaste.m_pwndPaste;
  1046. }
  1047. return NULL;
  1048. }
  1049. bool CCP_MainApp::UACPaste()
  1050. {
  1051. if(m_pUacPasteThread == NULL)
  1052. {
  1053. m_pUacPasteThread = new CUAC_Thread(GetCurrentProcessId());
  1054. }
  1055. return m_pUacPasteThread->UACPaste();
  1056. }
  1057. bool CCP_MainApp::UACCopy()
  1058. {
  1059. if(m_pUacPasteThread == NULL)
  1060. {
  1061. m_pUacPasteThread = new CUAC_Thread(GetCurrentProcessId());
  1062. }
  1063. return m_pUacPasteThread->UACCopy();
  1064. }
  1065. bool CCP_MainApp::UACCut()
  1066. {
  1067. if(m_pUacPasteThread == NULL)
  1068. {
  1069. m_pUacPasteThread = new CUAC_Thread(GetCurrentProcessId());
  1070. }
  1071. return m_pUacPasteThread->UACCut();
  1072. }
  1073. bool CCP_MainApp::UACThreadRunning()
  1074. {
  1075. if(m_pUacPasteThread != NULL)
  1076. {
  1077. return m_pUacPasteThread->IsRunning();
  1078. }
  1079. return false;
  1080. }
  1081. void CCP_MainApp::RefreshShowInTaskBar()
  1082. {
  1083. if(m_pMainFrame != NULL)
  1084. {
  1085. m_pMainFrame->RefreshShowInTaskBar();
  1086. }
  1087. }
  1088. void CCP_MainApp::SetActiveGroupId(int groupId)
  1089. {
  1090. m_activeGroupId = groupId;
  1091. m_activeGroupStartTime = GetTickCount();
  1092. }
  1093. int CCP_MainApp::GetActiveGroupId()
  1094. {
  1095. int ret = -1;
  1096. DWORD maxDiff = CGetSetOptions::GetSaveToGroupTimeoutMS();
  1097. DWORD diff = GetTickCount() - m_activeGroupStartTime;
  1098. if(m_activeGroupId > -1 &&
  1099. diff < maxDiff)
  1100. {
  1101. ret = m_activeGroupId;
  1102. }
  1103. m_activeGroupId = -1;
  1104. m_activeGroupStartTime = 0;
  1105. return ret;
  1106. }
  1107. void CCP_MainApp::SetCopyReason(CopyReasonEnum::CopyReason copyReason)
  1108. {
  1109. m_copyReason = copyReason;
  1110. m_copyReasonStartTime = GetTickCount();
  1111. }
  1112. CopyReasonEnum::CopyReason CCP_MainApp::GetCopyReason()
  1113. {
  1114. CopyReasonEnum::CopyReason ret = CopyReasonEnum::COPY_TO_UNKOWN;
  1115. DWORD maxDiff = CGetSetOptions::GetCopyReasonTimeoutMS();
  1116. DWORD diff = GetTickCount() - m_copyReasonStartTime;
  1117. if(m_copyReason != CopyReasonEnum::COPY_TO_UNKOWN &&
  1118. diff < maxDiff)
  1119. {
  1120. ret = m_copyReason;
  1121. }
  1122. m_copyReason = CopyReasonEnum::COPY_TO_UNKOWN;
  1123. m_copyReasonStartTime = 0;
  1124. return ret;
  1125. }