DatabaseUtilities.cpp 17 KB

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