DatabaseUtilities.cpp 17 KB

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