1
0

DatabaseUtilities.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713
  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. }
  272. CATCH_SQLITE_EXCEPTION_AND_RETURN(FALSE)
  273. return TRUE;
  274. }
  275. BOOL CreateDB(CString csFile)
  276. {
  277. try
  278. {
  279. CppSQLite3DB db;
  280. db.open(csFile);
  281. db.execDML(_T("PRAGMA auto_vacuum = 1"));
  282. db.execDML(_T("CREATE TABLE Main(")
  283. _T("lID INTEGER PRIMARY KEY AUTOINCREMENT, ")
  284. _T("lDate INTEGER, ")
  285. _T("mText TEXT, ")
  286. _T("lShortCut INTEGER, ")
  287. _T("lDontAutoDelete INTEGER, ")
  288. _T("CRC INTEGER, ")
  289. _T("bIsGroup INTEGER, ")
  290. _T("lParentID INTEGER, ")
  291. _T("QuickPasteText TEXT, ")
  292. _T("clipOrder REAL, ")
  293. _T("clipGroupOrder REAL);"));
  294. db.execDML(_T("CREATE TABLE Data(")
  295. _T("lID INTEGER PRIMARY KEY AUTOINCREMENT, ")
  296. _T("lParentID INTEGER, ")
  297. _T("strClipBoardFormat TEXT, ")
  298. _T("ooData BLOB);"));
  299. db.execDML(_T("CREATE TABLE Types(")
  300. _T("lID INTEGER PRIMARY KEY AUTOINCREMENT, ")
  301. _T("TypeText TEXT);"));
  302. db.execDML(_T("CREATE UNIQUE INDEX Main_ID on Main(lID ASC)"));
  303. db.execDML(_T("CREATE UNIQUE INDEX Data_ID on Data(lID ASC)"));
  304. db.execDML(_T("CREATE INDEX Main_ClipOrder on Main(clipOrder DESC)"));
  305. db.execDML(_T("CREATE INDEX Main_ClipGroupOrder on Main(clipGroupOrder DESC)"));
  306. db.execDML(_T("CREATE INDEX Main_ParentId on Main(lParentID DESC)"));
  307. db.execDML(_T("CREATE INDEX Main_IsGroup on Main(bIsGroup DESC)"));
  308. db.execDML(_T("CREATE INDEX Main_ShortCut on Main(lShortCut DESC)"));
  309. db.execDML(_T("CREATE TRIGGER delete_data_trigger BEFORE DELETE ON Main FOR EACH ROW\n")
  310. _T("BEGIN\n")
  311. _T("INSERT INTO MainDeletes VALUES(old.lID, datetime('now'));\n")
  312. _T("END\n"));
  313. db.execDML(_T("CREATE TABLE CopyBuffers(")
  314. _T("lID INTEGER PRIMARY KEY AUTOINCREMENT, ")
  315. _T("lClipID INTEGER, ")
  316. _T("lCopyBuffer INTEGER)"));
  317. db.execDML(_T("CREATE TABLE MainDeletes(")
  318. _T("clipID INTEGER,")
  319. _T("modifiedDate)"));
  320. db.execDML(_T("CREATE TRIGGER MainDeletes_delete_data_trigger BEFORE DELETE ON MainDeletes FOR EACH ROW\n")
  321. _T("BEGIN\n")
  322. _T("DELETE FROM CopyBuffers WHERE lClipID = old.clipID;\n")
  323. _T("DELETE FROM Data WHERE lParentID = old.clipID;\n")
  324. _T("END\n"));
  325. db.close();
  326. }
  327. CATCH_SQLITE_EXCEPTION_AND_RETURN(FALSE)
  328. return TRUE;
  329. }
  330. BOOL CompactDatabase()
  331. {
  332. // if(!theApp.CloseDB())
  333. // return FALSE;
  334. //
  335. // CString csDBName = GetDBName();
  336. // CString csTempDBName = csDBName;
  337. // csTempDBName.Replace(".mdb", "TempDBName.mdb");
  338. //
  339. // //Compact the database
  340. // try
  341. // {
  342. // CDaoWorkspace::CompactDatabase(csDBName, csTempDBName);//, dbLangGeneral, 0, "andrew");//DATABASE_PASSWORD);
  343. // }
  344. // catch(CDaoException* e)
  345. // {
  346. // AfxMessageBox(e->m_pErrorInfo->m_strDescription);
  347. // DeleteFile(csTempDBName);
  348. // e->Delete();
  349. // return FALSE;
  350. // }
  351. // catch(CMemoryException* e)
  352. // {
  353. // AfxMessageBox("Memory Exception");
  354. // DeleteFile(csTempDBName);
  355. // e->Delete();
  356. // return FALSE;
  357. // }
  358. //
  359. // //Since compacting the database creates a new db delete the old one and replace it
  360. // //with the compacted db
  361. // if(DeleteFile(csDBName))
  362. // {
  363. // try
  364. // {
  365. // CFile::Rename(csTempDBName, csDBName);
  366. // }
  367. // catch(CFileException *e)
  368. // {
  369. // e->ReportError();
  370. // e->Delete();
  371. // return FALSE;
  372. // }
  373. // }
  374. // else
  375. // AfxMessageBox("Error Compacting Database");
  376. return TRUE;
  377. }
  378. BOOL RepairDatabase()
  379. {
  380. // if(!theApp.CloseDB())
  381. // return FALSE;
  382. // try
  383. // {
  384. // CDaoWorkspace::RepairDatabase(GetDBName());
  385. // }
  386. // catch(CDaoException *e)
  387. // {
  388. // AfxMessageBox(e->m_pErrorInfo->m_strDescription);
  389. // e->Delete();
  390. // return FALSE;
  391. // }
  392. return TRUE;
  393. }
  394. BOOL RemoveOldEntries()
  395. {
  396. Log(StrF(_T("Beginning of RemoveOldEntries MaxEntries: %d - Keep days: %d"), CGetSetOptions::GetMaxEntries(), CGetSetOptions::GetExpiredEntries()));
  397. try
  398. {
  399. CppSQLite3DB db;
  400. CString csDbPath = CGetSetOptions::GetDBPath();
  401. db.open(csDbPath);
  402. if(CGetSetOptions::GetCheckForMaxEntries())
  403. {
  404. long lMax = CGetSetOptions::GetMaxEntries();
  405. if(lMax >= 0)
  406. {
  407. CClipIDs IDs;
  408. int clipId;
  409. CppSQLite3Query q = db.execQueryEx(_T("SELECT lID, lShortCut, lParentID, lDontAutoDelete FROM Main WHERE bIsGroup = 0 ORDER BY clipOrder DESC LIMIT -1 OFFSET %d"), lMax);
  410. while(q.eof() == false)
  411. {
  412. int shortcut = q.getIntField(_T("lShortCut"));
  413. int dontDelete = q.getIntField(_T("lDontAutoDelete"));
  414. int parentId = q.getIntField(_T("lParentID"));
  415. //Only delete entries that have no shortcut and don't have the flag set
  416. if(shortcut == 0 &&
  417. dontDelete == 0 &&
  418. parentId <= 0)
  419. {
  420. clipId = q.getIntField(_T("lID"));
  421. IDs.Add(clipId);
  422. Log(StrF(_T("From MaxEntries - Deleting Id: %d"), clipId));
  423. }
  424. q.nextRow();
  425. }
  426. if(IDs.GetCount() > 0)
  427. {
  428. IDs.DeleteIDs(false, db);
  429. }
  430. }
  431. }
  432. if(CGetSetOptions::GetCheckForExpiredEntries())
  433. {
  434. long lExpire = CGetSetOptions::GetExpiredEntries();
  435. if(lExpire)
  436. {
  437. CTime now = CTime::GetCurrentTime();
  438. now -= CTimeSpan(lExpire, 0, 0, 0);
  439. CClipIDs IDs;
  440. CppSQLite3Query q = db.execQueryEx(_T("SELECT lID FROM Main ")
  441. _T("WHERE lDate < %d AND ")
  442. _T("bIsGroup = 0 AND lShortCut = 0 AND lParentID <= 0 AND lDontAutoDelete = 0"), now.GetTime());
  443. while(q.eof() == false)
  444. {
  445. IDs.Add(q.getIntField(_T("lID")));
  446. Log(StrF(_T("From Clips Expire - Deleting Id: %d"), q.getIntField(_T("lID"))));
  447. q.nextRow();
  448. }
  449. if(IDs.GetCount() > 0)
  450. {
  451. IDs.DeleteIDs(false, db);
  452. }
  453. }
  454. }
  455. Log(_T("Before Deleting emptied out data"));
  456. //delete any data items sitting out there that the main table data was deleted
  457. //this was done to speed up deleted from the main table
  458. int deleteCount = db.execDML(_T("DELETE FROM MainDeletes"));
  459. Log(StrF(_T("After Deleting emptied out data rows, Count: %d"), deleteCount));
  460. }
  461. CATCH_SQLITE_EXCEPTION
  462. Log(_T("End of RemoveOldEntries"));
  463. return TRUE;
  464. }
  465. BOOL EnsureDirectory(CString csPath)
  466. {
  467. TCHAR drive[_MAX_DRIVE];
  468. TCHAR dir[_MAX_DIR];
  469. TCHAR fname[_MAX_FNAME];
  470. TCHAR ext[_MAX_EXT];
  471. SPLITPATH(csPath, drive, dir, fname, ext);
  472. CString csDir(drive);
  473. csDir += dir;
  474. if(FileExists(csDir) == FALSE)
  475. {
  476. if(CreateDirectory(csDir, NULL))
  477. return TRUE;
  478. }
  479. else
  480. return TRUE;
  481. return FALSE;
  482. }
  483. // BOOL RunZippApp(CString csCommandLine)
  484. // {
  485. // CString csLocalPath = GETENV(_T("U3_HOST_EXEC_PATH"));
  486. // FIX_CSTRING_PATH(csLocalPath);
  487. //
  488. // CString csZippApp = GETENV(_T("U3_DEVICE_EXEC_PATH"));
  489. // FIX_CSTRING_PATH(csZippApp);
  490. // csZippApp += "7za.exe";
  491. //
  492. // csZippApp += " ";
  493. // csZippApp += csCommandLine;
  494. //
  495. // Log(csZippApp);
  496. //
  497. // STARTUPINFO StartupInfo;
  498. // PROCESS_INFORMATION ProcessInformation;
  499. //
  500. // ZeroMemory(&StartupInfo, sizeof(StartupInfo));
  501. // StartupInfo.cb = sizeof(StartupInfo);
  502. // ZeroMemory(&ProcessInformation, sizeof(ProcessInformation));
  503. //
  504. // StartupInfo.dwFlags = STARTF_USESHOWWINDOW;
  505. // StartupInfo.wShowWindow = SW_HIDE;
  506. //
  507. // BOOL bRet = CreateProcess(NULL, csZippApp.GetBuffer(csZippApp.GetLength()), NULL, NULL, FALSE,
  508. // CREATE_DEFAULT_ERROR_MODE | NORMAL_PRIORITY_CLASS, NULL, csLocalPath,
  509. // &StartupInfo, &ProcessInformation);
  510. //
  511. // if(bRet)
  512. // {
  513. // WaitForSingleObject(ProcessInformation.hProcess, INFINITE);
  514. //
  515. // DWORD dwExitCode;
  516. // GetExitCodeProcess(ProcessInformation.hProcess, &dwExitCode);
  517. //
  518. // CString cs;
  519. // cs.Format(_T("Exit code from unzip = %d"), dwExitCode);
  520. // Log(cs);
  521. //
  522. // if(dwExitCode != 0)
  523. // {
  524. // bRet = FALSE;
  525. // }
  526. // }
  527. // else
  528. // {
  529. // bRet = FALSE;
  530. // Log(_T("Create Process Failed"));
  531. // }
  532. //
  533. // csZippApp.ReleaseBuffer();
  534. //
  535. // return bRet;
  536. // }
  537. // BOOL CopyDownDatabase()
  538. // {
  539. // BOOL bRet = FALSE;
  540. //
  541. // CString csZippedPath = GETENV(_T("U3_APP_DATA_PATH"));
  542. // FIX_CSTRING_PATH(csZippedPath);
  543. //
  544. // CString csUnZippedPath = csZippedPath;
  545. // csUnZippedPath += "Ditto.db";
  546. //
  547. // csZippedPath += "Ditto.7z";
  548. //
  549. // CString csLocalPath = GETENV(_T("U3_HOST_EXEC_PATH"));
  550. // FIX_CSTRING_PATH(csLocalPath);
  551. //
  552. // if(FileExists(csZippedPath))
  553. // {
  554. // CString csCommandLine;
  555. //
  556. // //e = extract
  557. // //surround command line arguments with quotes
  558. // //-aoa = overight files with extracted files
  559. //
  560. // csCommandLine += "e ";
  561. // csCommandLine += "\"";
  562. // csCommandLine += csZippedPath;
  563. // csCommandLine += "\"";
  564. // csCommandLine += " -o";
  565. // csCommandLine += "\"";
  566. // csCommandLine += csLocalPath;
  567. // csCommandLine += "\"";
  568. // csCommandLine += " -aoa";
  569. //
  570. // bRet = RunZippApp(csCommandLine);
  571. //
  572. // csLocalPath += "Ditto.db";
  573. // }
  574. // else if(FileExists(csUnZippedPath))
  575. // {
  576. // csLocalPath += "Ditto.db";
  577. // bRet = CopyFile(csUnZippedPath, csLocalPath, FALSE);
  578. // }
  579. //
  580. // if(FileExists(csLocalPath) == FALSE)
  581. // {
  582. // Log(_T("Failed to copy files from device zip file"));
  583. // }
  584. //
  585. // g_Opt.nLastDbWriteTime = GetLastWriteTime(csLocalPath);
  586. //
  587. // return bRet;
  588. // }
  589. //BOOL CopyUpDatabase()
  590. //{
  591. // CStringA csZippedPath = "C:\\";//getenv("U3_APP_DATA_PATH");
  592. // FIX_CSTRING_PATH(csZippedPath);
  593. // csZippedPath += "Ditto.zip";
  594. // CStringA csLocalPath = GetDBName();//getenv("U3_HOST_EXEC_PATH");
  595. // //FIX_CSTRING_PATH(csLocalPath);
  596. // //csLocalPath += "Ditto.db";
  597. //
  598. // CZipper Zip;
  599. //
  600. // if(Zip.OpenZip(csZippedPath))
  601. // {
  602. // Zip.AddFileToZip(csLocalPath);
  603. // }
  604. //
  605. // return TRUE;
  606. //}