DatabaseUtilities.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739
  1. // DatabaseUtilites.cpp: implementation of the CDatabaseUtilites class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "CP_Main.h"
  6. #include "DatabaseUtilities.h"
  7. #include "ProcessPaste.h"
  8. #include <io.h>
  9. #include "AccessToSqlite.h"
  10. #include "Path.h"
  11. //////////////////////////////////////////////////////////////////////
  12. // Construction/Destruction
  13. //////////////////////////////////////////////////////////////////////
  14. BOOL CreateBackup(CString csPath)
  15. {
  16. CString csOriginal;
  17. int count = 0;
  18. // create a backup of the existing database
  19. do
  20. {
  21. count++;
  22. csOriginal = csPath + StrF(_T(".%03d"), count);
  23. // in case of some weird infinite loop
  24. if( count > 50 )
  25. {
  26. ASSERT(0);
  27. return FALSE;
  28. }
  29. } while( !::CopyFile(csPath, csOriginal, TRUE));
  30. return TRUE;
  31. }
  32. CString GetDBName()
  33. {
  34. return CGetSetOptions::GetDBPath();
  35. }
  36. CString GetOLDDefaultDBName()
  37. {
  38. CString csDefaultPath;
  39. LPMALLOC pMalloc;
  40. if(SUCCEEDED(::SHGetMalloc(&pMalloc)))
  41. {
  42. LPITEMIDLIST pidlPrograms;
  43. SHGetSpecialFolderLocation(NULL, CSIDL_APPDATA, &pidlPrograms);
  44. TCHAR string[MAX_PATH];
  45. SHGetPathFromIDList(pidlPrograms, string);
  46. pMalloc->Free(pidlPrograms);
  47. pMalloc->Release();
  48. csDefaultPath = string;
  49. csDefaultPath += "\\Ditto\\";
  50. csDefaultPath += "DittoDB.mdb";
  51. }
  52. return csDefaultPath;
  53. }
  54. CString GetDefaultDBName()
  55. {
  56. CString csDefaultPath = _T("c:\\program files\\Ditto\\");
  57. if(g_Opt.m_bU3)
  58. {
  59. csDefaultPath = CGetSetOptions::GetPath(PATH_DATABASE);
  60. }
  61. else
  62. {
  63. //If portable then default to the running path
  64. if(CGetSetOptions::GetIsPortableDitto())
  65. {
  66. csDefaultPath.Empty();
  67. }
  68. else
  69. {
  70. LPMALLOC pMalloc;
  71. if(SUCCEEDED(::SHGetMalloc(&pMalloc)))
  72. {
  73. LPITEMIDLIST pidlPrograms;
  74. SHGetSpecialFolderLocation(NULL, CSIDL_APPDATA, &pidlPrograms);
  75. TCHAR string[MAX_PATH];
  76. SHGetPathFromIDList(pidlPrograms, string);
  77. pMalloc->Free(pidlPrograms);
  78. pMalloc->Release();
  79. csDefaultPath = string;
  80. }
  81. FIX_CSTRING_PATH(csDefaultPath);
  82. csDefaultPath += "Ditto\\";
  83. }
  84. }
  85. CString csTempName = csDefaultPath + "Ditto.db";
  86. int i = 1;
  87. while(FileExists(csTempName))
  88. {
  89. csTempName.Format(_T("%sDitto_%d.db"), csDefaultPath, i);
  90. i++;
  91. }
  92. csDefaultPath = csTempName;
  93. return csDefaultPath;
  94. }
  95. BOOL CheckDBExists(CString csDBPath)
  96. {
  97. //If this is the first time running this version then convert the old database to the new db
  98. if(csDBPath.IsEmpty() && g_Opt.m_bU3 == false)
  99. {
  100. csDBPath = GetDefaultDBName();
  101. if(FileExists(csDBPath) == FALSE && CGetSetOptions::GetIsPortableDitto() == FALSE)
  102. {
  103. CString csOldDB = CGetSetOptions::GetDBPathOld();
  104. if(csOldDB.IsEmpty())
  105. {
  106. csOldDB = GetOLDDefaultDBName();
  107. }
  108. if(FileExists(csOldDB))
  109. {
  110. //create the new sqlite db
  111. CreateDB(csDBPath);
  112. CAccessToSqlite Convert;
  113. Convert.ConvertDatabase(csDBPath, csOldDB);
  114. }
  115. }
  116. }
  117. BOOL bRet = FALSE;
  118. if(FileExists(csDBPath) == FALSE)
  119. {
  120. csDBPath = GetDefaultDBName();
  121. nsPath::CPath FullPath(csDBPath);
  122. CString csPath = FullPath.GetPath().GetStr();
  123. if(csPath.IsEmpty() == false && FileExists(csDBPath) == FALSE)
  124. {
  125. CreateDirectory(csPath, NULL);
  126. }
  127. // -- create a new one
  128. bRet = CreateDB(csDBPath);
  129. }
  130. else
  131. {
  132. if(ValidDB(csDBPath) == FALSE)
  133. {
  134. //Db existed but was bad
  135. CString csMarkAsBad;
  136. csMarkAsBad = csDBPath;
  137. csMarkAsBad.Replace(_T("."), _T("_BAD."));
  138. CString csPath = GetDefaultDBName();
  139. CString cs;
  140. cs.Format(_T("%s \"%s\",\n")
  141. _T("%s \"%s\",\n")
  142. _T("%s,\n")
  143. _T("\"%s\""),
  144. theApp.m_Language.GetString("Database_Format", "Unrecognized Database Format"),
  145. csDBPath,
  146. theApp.m_Language.GetString("File_Renamed", "the file will be renamed"),
  147. csMarkAsBad,
  148. theApp.m_Language.GetString("New_Database", "and a new database will be created"),
  149. csPath);
  150. AfxMessageBox(cs);
  151. CFile::Rename(csDBPath, csMarkAsBad);
  152. csDBPath = csPath;
  153. bRet = CreateDB(csDBPath);
  154. }
  155. else
  156. {
  157. bRet = TRUE;
  158. }
  159. }
  160. if(bRet)
  161. {
  162. bRet = OpenDatabase(csDBPath);
  163. }
  164. return bRet;
  165. }
  166. BOOL OpenDatabase(CString csDB)
  167. {
  168. try
  169. {
  170. theApp.m_db.close();
  171. theApp.m_db.open(csDB);
  172. CGetSetOptions::SetDBPath(csDB);
  173. return TRUE;
  174. }
  175. CATCH_SQLITE_EXCEPTION
  176. return FALSE;
  177. }
  178. BOOL ValidDB(CString csPath, BOOL bUpgrade)
  179. {
  180. try
  181. {
  182. CppSQLite3DB db;
  183. db.open(csPath);
  184. db.execQuery(_T("SELECT lID, lDate, mText, lShortCut, lDontAutoDelete, ")
  185. _T("CRC, bIsGroup, lParentID, QuickPasteText ")
  186. _T("FROM Main"));
  187. db.execQuery(_T("SELECT lID, lParentID, strClipBoardFormat, ooData FROM Data"));
  188. db.execQuery(_T("SELECT lID, TypeText FROM Types"));
  189. try
  190. {
  191. db.execDML(_T("DROP TRIGGER delete_data_trigger"));
  192. }
  193. catch(CppSQLite3Exception& e)
  194. {
  195. e.errorCode();
  196. }
  197. try
  198. {
  199. db.execDML(_T("DROP TRIGGER delete_copy_buffer_trigger"));
  200. }
  201. catch(CppSQLite3Exception& e)
  202. {
  203. e.errorCode();
  204. }
  205. //This was added later so try to add each time and catch the exception here
  206. try
  207. {
  208. db.execDML(_T("CREATE TRIGGER delete_data_trigger BEFORE DELETE ON Main FOR EACH ROW\n")
  209. _T("BEGIN\n")
  210. _T("INSERT INTO MainDeletes VALUES(old.lID, datetime('now'));\n")
  211. _T("END\n"));
  212. }
  213. catch(CppSQLite3Exception& e)
  214. {
  215. e.errorCode();
  216. }
  217. //This was added later so try to add each time and catch the exception here
  218. try
  219. {
  220. db.execQuery(_T("SELECT lID, lClipID, lCopyBuffer FROM CopyBuffers"));
  221. }
  222. catch(CppSQLite3Exception& e)
  223. {
  224. e.errorCode();
  225. db.execDML(_T("CREATE TABLE CopyBuffers(")
  226. _T("lID INTEGER PRIMARY KEY AUTOINCREMENT, ")
  227. _T("lClipID INTEGER,")
  228. _T("lCopyBuffer INTEGER)"));
  229. }
  230. //This was added later so try to add each time and catch the exception here
  231. try
  232. {
  233. db.execQuery(_T("SELECT clipId FROM MainDeletes"));
  234. }
  235. catch(CppSQLite3Exception& e)
  236. {
  237. e.errorCode();
  238. db.execDML(_T("CREATE TABLE MainDeletes(")
  239. _T("clipID INTEGER,")
  240. _T("modifiedDate)"));
  241. db.execDML(_T("CREATE TRIGGER MainDeletes_delete_data_trigger BEFORE DELETE ON MainDeletes FOR EACH ROW\n")
  242. _T("BEGIN\n")
  243. _T("DELETE FROM CopyBuffers WHERE lClipID = old.clipID;\n")
  244. _T("DELETE FROM Data WHERE lParentID = old.clipID;\n")
  245. _T("END\n"));
  246. }
  247. try
  248. {
  249. db.execDML(_T("CREATE INDEX Main_ParentId on Main(lParentID DESC)"));
  250. db.execDML(_T("CREATE INDEX Main_IsGroup on Main(bIsGroup DESC)"));
  251. db.execDML(_T("CREATE INDEX Main_ShortCut on Main(lShortCut DESC)"));
  252. }
  253. catch(CppSQLite3Exception& e)
  254. {
  255. e.errorCode();
  256. }
  257. try
  258. {
  259. db.execQuery(_T("SELECT clipOrder, clipGroupOrder FROM Main"));
  260. }
  261. catch(CppSQLite3Exception& e)
  262. {
  263. db.execDML(_T("ALTER TABLE Main ADD clipOrder REAL"));
  264. db.execDML(_T("ALTER TABLE Main ADD clipGroupOrder REAL"));
  265. db.execDML(_T("Update Main set clipOrder = lDate, clipGroupOrder = lDate"));
  266. db.execDML(_T("CREATE INDEX Main_ClipOrder on Main(clipOrder DESC)"));
  267. db.execDML(_T("CREATE INDEX Main_ClipGroupOrder on Main(clipGroupOrder DESC)"));
  268. db.execDML(_T("DROP INDEX Main_Date"));
  269. e.errorCode();
  270. }
  271. try
  272. {
  273. db.execQuery(_T("SELECT globalShortCut FROM Main"));
  274. }
  275. catch(CppSQLite3Exception& e)
  276. {
  277. db.execDML(_T("ALTER TABLE Main ADD globalShortCut INTEGER"));
  278. e.errorCode();
  279. }
  280. try
  281. {
  282. db.execQuery(_T("SELECT lastPasteDate FROM Main"));
  283. }
  284. catch(CppSQLite3Exception& e)
  285. {
  286. db.execDML(_T("ALTER TABLE Main ADD lastPasteDate INTEGER"));
  287. db.execDML(_T("Update Main set lastPasteDate = lDate"));
  288. db.execDMLEx(_T("Update Main set lastPasteDate = %d where lastPasteDate <= 0"), CTime::GetCurrentTime().GetTime());
  289. e.errorCode();
  290. }
  291. }
  292. CATCH_SQLITE_EXCEPTION_AND_RETURN(FALSE)
  293. return TRUE;
  294. }
  295. BOOL CreateDB(CString csFile)
  296. {
  297. try
  298. {
  299. CppSQLite3DB db;
  300. db.open(csFile);
  301. db.execDML(_T("PRAGMA auto_vacuum = 1"));
  302. db.execDML(_T("CREATE TABLE Main(")
  303. _T("lID INTEGER PRIMARY KEY AUTOINCREMENT, ")
  304. _T("lDate INTEGER, ")
  305. _T("mText TEXT, ")
  306. _T("lShortCut INTEGER, ")
  307. _T("lDontAutoDelete INTEGER, ")
  308. _T("CRC INTEGER, ")
  309. _T("bIsGroup INTEGER, ")
  310. _T("lParentID INTEGER, ")
  311. _T("QuickPasteText TEXT, ")
  312. _T("clipOrder REAL, ")
  313. _T("clipGroupOrder REAL, ")
  314. _T("globalShortCut INTEGER, ")
  315. _T("lastPasteDate INTEGER);"));
  316. db.execDML(_T("CREATE TABLE Data(")
  317. _T("lID INTEGER PRIMARY KEY AUTOINCREMENT, ")
  318. _T("lParentID INTEGER, ")
  319. _T("strClipBoardFormat TEXT, ")
  320. _T("ooData BLOB);"));
  321. db.execDML(_T("CREATE TABLE Types(")
  322. _T("lID INTEGER PRIMARY KEY AUTOINCREMENT, ")
  323. _T("TypeText TEXT);"));
  324. db.execDML(_T("CREATE UNIQUE INDEX Main_ID on Main(lID ASC)"));
  325. db.execDML(_T("CREATE UNIQUE INDEX Data_ID on Data(lID ASC)"));
  326. db.execDML(_T("CREATE INDEX Main_ClipOrder on Main(clipOrder DESC)"));
  327. db.execDML(_T("CREATE INDEX Main_ClipGroupOrder on Main(clipGroupOrder DESC)"));
  328. db.execDML(_T("CREATE INDEX Main_ParentId on Main(lParentID DESC)"));
  329. db.execDML(_T("CREATE INDEX Main_IsGroup on Main(bIsGroup DESC)"));
  330. db.execDML(_T("CREATE INDEX Main_ShortCut on Main(lShortCut DESC)"));
  331. db.execDML(_T("CREATE TRIGGER delete_data_trigger BEFORE DELETE ON Main FOR EACH ROW\n")
  332. _T("BEGIN\n")
  333. _T("INSERT INTO MainDeletes VALUES(old.lID, datetime('now'));\n")
  334. _T("END\n"));
  335. db.execDML(_T("CREATE TABLE CopyBuffers(")
  336. _T("lID INTEGER PRIMARY KEY AUTOINCREMENT, ")
  337. _T("lClipID INTEGER, ")
  338. _T("lCopyBuffer INTEGER)"));
  339. db.execDML(_T("CREATE TABLE MainDeletes(")
  340. _T("clipID INTEGER,")
  341. _T("modifiedDate)"));
  342. db.execDML(_T("CREATE TRIGGER MainDeletes_delete_data_trigger BEFORE DELETE ON MainDeletes FOR EACH ROW\n")
  343. _T("BEGIN\n")
  344. _T("DELETE FROM CopyBuffers WHERE lClipID = old.clipID;\n")
  345. _T("DELETE FROM Data WHERE lParentID = old.clipID;\n")
  346. _T("END\n"));
  347. db.close();
  348. }
  349. CATCH_SQLITE_EXCEPTION_AND_RETURN(FALSE)
  350. return TRUE;
  351. }
  352. BOOL CompactDatabase()
  353. {
  354. // if(!theApp.CloseDB())
  355. // return FALSE;
  356. //
  357. // CString csDBName = GetDBName();
  358. // CString csTempDBName = csDBName;
  359. // csTempDBName.Replace(".mdb", "TempDBName.mdb");
  360. //
  361. // //Compact the database
  362. // try
  363. // {
  364. // CDaoWorkspace::CompactDatabase(csDBName, csTempDBName);//, dbLangGeneral, 0, "andrew");//DATABASE_PASSWORD);
  365. // }
  366. // catch(CDaoException* e)
  367. // {
  368. // AfxMessageBox(e->m_pErrorInfo->m_strDescription);
  369. // DeleteFile(csTempDBName);
  370. // e->Delete();
  371. // return FALSE;
  372. // }
  373. // catch(CMemoryException* e)
  374. // {
  375. // AfxMessageBox("Memory Exception");
  376. // DeleteFile(csTempDBName);
  377. // e->Delete();
  378. // return FALSE;
  379. // }
  380. //
  381. // //Since compacting the database creates a new db delete the old one and replace it
  382. // //with the compacted db
  383. // if(DeleteFile(csDBName))
  384. // {
  385. // try
  386. // {
  387. // CFile::Rename(csTempDBName, csDBName);
  388. // }
  389. // catch(CFileException *e)
  390. // {
  391. // e->ReportError();
  392. // e->Delete();
  393. // return FALSE;
  394. // }
  395. // }
  396. // else
  397. // AfxMessageBox("Error Compacting Database");
  398. return TRUE;
  399. }
  400. BOOL RepairDatabase()
  401. {
  402. // if(!theApp.CloseDB())
  403. // return FALSE;
  404. // try
  405. // {
  406. // CDaoWorkspace::RepairDatabase(GetDBName());
  407. // }
  408. // catch(CDaoException *e)
  409. // {
  410. // AfxMessageBox(e->m_pErrorInfo->m_strDescription);
  411. // e->Delete();
  412. // return FALSE;
  413. // }
  414. return TRUE;
  415. }
  416. BOOL RemoveOldEntries()
  417. {
  418. Log(StrF(_T("Beginning of RemoveOldEntries MaxEntries: %d - Keep days: %d"), CGetSetOptions::GetMaxEntries(), CGetSetOptions::GetExpiredEntries()));
  419. try
  420. {
  421. CppSQLite3DB db;
  422. CString csDbPath = CGetSetOptions::GetDBPath();
  423. db.open(csDbPath);
  424. if(CGetSetOptions::GetCheckForMaxEntries())
  425. {
  426. long lMax = CGetSetOptions::GetMaxEntries();
  427. if(lMax >= 0)
  428. {
  429. CClipIDs IDs;
  430. int clipId;
  431. CppSQLite3Query q = db.execQueryEx(_T("SELECT lID, lShortCut, lParentID, lDontAutoDelete FROM Main WHERE bIsGroup = 0 ORDER BY clipOrder DESC LIMIT -1 OFFSET %d"), lMax);
  432. while(q.eof() == false)
  433. {
  434. int shortcut = q.getIntField(_T("lShortCut"));
  435. int dontDelete = q.getIntField(_T("lDontAutoDelete"));
  436. int parentId = q.getIntField(_T("lParentID"));
  437. //Only delete entries that have no shortcut and don't have the flag set
  438. if(shortcut == 0 &&
  439. dontDelete == 0 &&
  440. parentId <= 0)
  441. {
  442. clipId = q.getIntField(_T("lID"));
  443. IDs.Add(clipId);
  444. Log(StrF(_T("From MaxEntries - Deleting Id: %d"), clipId));
  445. }
  446. q.nextRow();
  447. }
  448. if(IDs.GetCount() > 0)
  449. {
  450. IDs.DeleteIDs(false, db);
  451. }
  452. }
  453. }
  454. if(CGetSetOptions::GetCheckForExpiredEntries())
  455. {
  456. long lExpire = CGetSetOptions::GetExpiredEntries();
  457. if(lExpire)
  458. {
  459. CTime now = CTime::GetCurrentTime();
  460. now -= CTimeSpan(lExpire, 0, 0, 0);
  461. CClipIDs IDs;
  462. CppSQLite3Query q = db.execQueryEx(_T("SELECT lID FROM Main ")
  463. _T("WHERE lastPasteDate < %d AND ")
  464. _T("bIsGroup = 0 AND lShortCut = 0 AND lParentID <= 0 AND lDontAutoDelete = 0"), now.GetTime());
  465. while(q.eof() == false)
  466. {
  467. IDs.Add(q.getIntField(_T("lID")));
  468. Log(StrF(_T("From Clips Expire - Deleting Id: %d"), q.getIntField(_T("lID"))));
  469. q.nextRow();
  470. }
  471. if(IDs.GetCount() > 0)
  472. {
  473. IDs.DeleteIDs(false, db);
  474. }
  475. }
  476. }
  477. Log(_T("Before Deleting emptied out data"));
  478. //delete any data items sitting out there that the main table data was deleted
  479. //this was done to speed up deleted from the main table
  480. int deleteCount = db.execDML(_T("DELETE FROM MainDeletes"));
  481. Log(StrF(_T("After Deleting emptied out data rows, Count: %d"), deleteCount));
  482. }
  483. CATCH_SQLITE_EXCEPTION
  484. Log(_T("End of RemoveOldEntries"));
  485. return TRUE;
  486. }
  487. BOOL EnsureDirectory(CString csPath)
  488. {
  489. TCHAR drive[_MAX_DRIVE];
  490. TCHAR dir[_MAX_DIR];
  491. TCHAR fname[_MAX_FNAME];
  492. TCHAR ext[_MAX_EXT];
  493. SPLITPATH(csPath, drive, dir, fname, ext);
  494. CString csDir(drive);
  495. csDir += dir;
  496. if(FileExists(csDir) == FALSE)
  497. {
  498. if(CreateDirectory(csDir, NULL))
  499. return TRUE;
  500. }
  501. else
  502. return TRUE;
  503. return FALSE;
  504. }
  505. // BOOL RunZippApp(CString csCommandLine)
  506. // {
  507. // CString csLocalPath = GETENV(_T("U3_HOST_EXEC_PATH"));
  508. // FIX_CSTRING_PATH(csLocalPath);
  509. //
  510. // CString csZippApp = GETENV(_T("U3_DEVICE_EXEC_PATH"));
  511. // FIX_CSTRING_PATH(csZippApp);
  512. // csZippApp += "7za.exe";
  513. //
  514. // csZippApp += " ";
  515. // csZippApp += csCommandLine;
  516. //
  517. // Log(csZippApp);
  518. //
  519. // STARTUPINFO StartupInfo;
  520. // PROCESS_INFORMATION ProcessInformation;
  521. //
  522. // ZeroMemory(&StartupInfo, sizeof(StartupInfo));
  523. // StartupInfo.cb = sizeof(StartupInfo);
  524. // ZeroMemory(&ProcessInformation, sizeof(ProcessInformation));
  525. //
  526. // StartupInfo.dwFlags = STARTF_USESHOWWINDOW;
  527. // StartupInfo.wShowWindow = SW_HIDE;
  528. //
  529. // BOOL bRet = CreateProcess(NULL, csZippApp.GetBuffer(csZippApp.GetLength()), NULL, NULL, FALSE,
  530. // CREATE_DEFAULT_ERROR_MODE | NORMAL_PRIORITY_CLASS, NULL, csLocalPath,
  531. // &StartupInfo, &ProcessInformation);
  532. //
  533. // if(bRet)
  534. // {
  535. // WaitForSingleObject(ProcessInformation.hProcess, INFINITE);
  536. //
  537. // DWORD dwExitCode;
  538. // GetExitCodeProcess(ProcessInformation.hProcess, &dwExitCode);
  539. //
  540. // CString cs;
  541. // cs.Format(_T("Exit code from unzip = %d"), dwExitCode);
  542. // Log(cs);
  543. //
  544. // if(dwExitCode != 0)
  545. // {
  546. // bRet = FALSE;
  547. // }
  548. // }
  549. // else
  550. // {
  551. // bRet = FALSE;
  552. // Log(_T("Create Process Failed"));
  553. // }
  554. //
  555. // csZippApp.ReleaseBuffer();
  556. //
  557. // return bRet;
  558. // }
  559. // BOOL CopyDownDatabase()
  560. // {
  561. // BOOL bRet = FALSE;
  562. //
  563. // CString csZippedPath = GETENV(_T("U3_APP_DATA_PATH"));
  564. // FIX_CSTRING_PATH(csZippedPath);
  565. //
  566. // CString csUnZippedPath = csZippedPath;
  567. // csUnZippedPath += "Ditto.db";
  568. //
  569. // csZippedPath += "Ditto.7z";
  570. //
  571. // CString csLocalPath = GETENV(_T("U3_HOST_EXEC_PATH"));
  572. // FIX_CSTRING_PATH(csLocalPath);
  573. //
  574. // if(FileExists(csZippedPath))
  575. // {
  576. // CString csCommandLine;
  577. //
  578. // //e = extract
  579. // //surround command line arguments with quotes
  580. // //-aoa = overight files with extracted files
  581. //
  582. // csCommandLine += "e ";
  583. // csCommandLine += "\"";
  584. // csCommandLine += csZippedPath;
  585. // csCommandLine += "\"";
  586. // csCommandLine += " -o";
  587. // csCommandLine += "\"";
  588. // csCommandLine += csLocalPath;
  589. // csCommandLine += "\"";
  590. // csCommandLine += " -aoa";
  591. //
  592. // bRet = RunZippApp(csCommandLine);
  593. //
  594. // csLocalPath += "Ditto.db";
  595. // }
  596. // else if(FileExists(csUnZippedPath))
  597. // {
  598. // csLocalPath += "Ditto.db";
  599. // bRet = CopyFile(csUnZippedPath, csLocalPath, FALSE);
  600. // }
  601. //
  602. // if(FileExists(csLocalPath) == FALSE)
  603. // {
  604. // Log(_T("Failed to copy files from device zip file"));
  605. // }
  606. //
  607. // g_Opt.nLastDbWriteTime = GetLastWriteTime(csLocalPath);
  608. //
  609. // return bRet;
  610. // }
  611. //BOOL CopyUpDatabase()
  612. //{
  613. // CStringA csZippedPath = "C:\\";//getenv("U3_APP_DATA_PATH");
  614. // FIX_CSTRING_PATH(csZippedPath);
  615. // csZippedPath += "Ditto.zip";
  616. // CStringA csLocalPath = GetDBName();//getenv("U3_HOST_EXEC_PATH");
  617. // //FIX_CSTRING_PATH(csLocalPath);
  618. // //csLocalPath += "Ditto.db";
  619. //
  620. // CZipper Zip;
  621. //
  622. // if(Zip.OpenZip(csZippedPath))
  623. // {
  624. // Zip.AddFileToZip(csLocalPath);
  625. // }
  626. //
  627. // return TRUE;
  628. //}