OptionsGeneral.cpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. // OptionsGeneral.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "CP_Main.h"
  5. #include "OptionsGeneral.h"
  6. #include "InternetUpdate.h"
  7. #include <io.h>
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. /////////////////////////////////////////////////////////////////////////////
  14. // COptionsGeneral property page
  15. IMPLEMENT_DYNCREATE(COptionsGeneral, CPropertyPage)
  16. COptionsGeneral::COptionsGeneral() : CPropertyPage(COptionsGeneral::IDD)
  17. {
  18. //{{AFX_DATA_INIT(COptionsGeneral)
  19. //}}AFX_DATA_INIT
  20. }
  21. COptionsGeneral::~COptionsGeneral()
  22. {
  23. }
  24. void COptionsGeneral::DoDataExchange(CDataExchange* pDX)
  25. {
  26. CPropertyPage::DoDataExchange(pDX);
  27. //{{AFX_DATA_MAP(COptionsGeneral)
  28. DDX_Control(pDX, IDC_GET_PATH, m_btGetPath);
  29. DDX_Control(pDX, IDC_PATH, m_ePath);
  30. DDX_Control(pDX, IDC_SET_DB_PATH, m_btSetDatabasePath);
  31. DDX_Control(pDX, IDC_CHECK_UPDATES, m_btCheckForUpdates);
  32. DDX_Control(pDX, IDC_COMPACT_REPAIR, m_btCompactAndRepair);
  33. DDX_Control(pDX, IDC_EXPIRE_AFTER, m_eExpireAfter);
  34. DDX_Control(pDX, IDC_MAX_SAVED_COPIES, m_eMaxSavedCopies);
  35. DDX_Control(pDX, IDC_MAXIMUM, m_btMaximumCheck);
  36. DDX_Control(pDX, IDC_EXPIRE, m_btExpire);
  37. DDX_Control(pDX, IDC_DISPLAY_IN_SYSTEMTRAY, m_btShowIconInSysTray);
  38. DDX_Control(pDX, IDC_START_ON_STARTUP, m_btRunOnStartup);
  39. //}}AFX_DATA_MAP
  40. }
  41. BEGIN_MESSAGE_MAP(COptionsGeneral, CPropertyPage)
  42. //{{AFX_MSG_MAP(COptionsGeneral)
  43. ON_BN_CLICKED(IDC_BT_COMPACT_AND_REPAIR, OnBtCompactAndRepair)
  44. ON_BN_CLICKED(IDC_CHECK_FOR_UPDATES, OnCheckForUpdates)
  45. ON_BN_CLICKED(IDC_SET_DB_PATH, OnSetDbPath)
  46. ON_BN_CLICKED(IDC_GET_PATH, OnGetPath)
  47. //}}AFX_MSG_MAP
  48. END_MESSAGE_MAP()
  49. /////////////////////////////////////////////////////////////////////////////
  50. // COptionsGeneral message handlers
  51. BOOL COptionsGeneral::OnInitDialog()
  52. {
  53. CPropertyPage::OnInitDialog();
  54. m_pParent = (COptionsSheet *)GetParent();
  55. m_btRunOnStartup.SetCheck(CGetSetOptions::GetRunOnStartUp());
  56. m_btShowIconInSysTray.SetCheck(CGetSetOptions::GetShowIconInSysTray());
  57. m_btMaximumCheck.SetCheck(CGetSetOptions::GetCheckForMaxEntries());
  58. m_btExpire.SetCheck(CGetSetOptions::GetCheckForExpiredEntries());
  59. m_btCompactAndRepair.SetCheck(CGetSetOptions::GetCompactAndRepairOnExit());
  60. m_btCheckForUpdates.SetCheck(CGetSetOptions::GetCheckForUpdates());
  61. m_eExpireAfter.SetNumber(CGetSetOptions::GetExpiredEntries());
  62. m_eMaxSavedCopies.SetNumber(CGetSetOptions::GetMaxEntries());
  63. CString csPath = CGetSetOptions::GetDBPath(FALSE);
  64. if(csPath.IsEmpty())
  65. {
  66. m_ePath.EnableWindow(FALSE);
  67. m_btGetPath.EnableWindow(FALSE);
  68. csPath = CGetSetOptions::GetDBPath();
  69. m_ePath.SetWindowText(csPath);
  70. }
  71. else
  72. {
  73. m_btSetDatabasePath.SetCheck(BST_CHECKED);
  74. m_ePath.SetWindowText(csPath);
  75. }
  76. return TRUE;
  77. }
  78. BOOL COptionsGeneral::OnApply()
  79. {
  80. UpdateData();
  81. ::SendMessage(theApp.m_MainhWnd, WM_SHOW_TRAY_ICON, m_btShowIconInSysTray.GetCheck(), 0);
  82. CGetSetOptions::SetShowIconInSysTray(m_btShowIconInSysTray.GetCheck());
  83. CGetSetOptions::SetRunOnStartUp(m_btRunOnStartup.GetCheck());
  84. CGetSetOptions::SetCheckForMaxEntries(m_btMaximumCheck.GetCheck());
  85. CGetSetOptions::SetCheckForExpiredEntries(m_btExpire.GetCheck());
  86. CGetSetOptions::SetCompactAndRepairOnExit(m_btCompactAndRepair.GetCheck());
  87. CGetSetOptions::SetCheckForUpdates(m_btCheckForUpdates.GetCheck());
  88. CGetSetOptions::SetMaxEntries(m_eMaxSavedCopies.GetNumber());
  89. CGetSetOptions::SetExpiredEntries(m_eExpireAfter.GetNumber());
  90. if(m_btSetDatabasePath.GetCheck() == BST_CHECKED)
  91. {
  92. CString csPath;
  93. m_ePath.GetWindowText(csPath);
  94. bool bSetPath = true;
  95. if(csPath.IsEmpty() == FALSE)
  96. {
  97. if(_access(csPath, 0) == -1)
  98. {
  99. CString cs;
  100. cs.Format("The database %s does not exist.\n\nCreate a new database?", csPath);
  101. if(MessageBox(cs, "Ditto", MB_YESNO) == IDYES)
  102. {
  103. theApp.CloseDB();
  104. // -- create a new one
  105. if(CreateDB(csPath))
  106. {
  107. CGetSetOptions::SetDBPath(csPath);
  108. }
  109. else
  110. MessageBox("Error Creating Database");
  111. bSetPath = false;
  112. }
  113. else
  114. return FALSE;
  115. }
  116. else
  117. {
  118. if(ValidDB(csPath) == FALSE)
  119. {
  120. MessageBox("Invalid Database", "Ditto", MB_OK);
  121. m_ePath.SetFocus();
  122. return FALSE;
  123. }
  124. }
  125. }
  126. if((csPath != CGetSetOptions::GetDBPath(FALSE)) && (bSetPath))
  127. {
  128. CGetSetOptions::SetDBPath(csPath);
  129. theApp.CloseDB();
  130. }
  131. }
  132. return CPropertyPage::OnApply();
  133. }
  134. BOOL COptionsGeneral::OnSetActive()
  135. {
  136. return CPropertyPage::OnSetActive();
  137. }
  138. void COptionsGeneral::OnBtCompactAndRepair()
  139. {
  140. CompactDatabase();
  141. RepairDatabase();
  142. }
  143. void COptionsGeneral::OnCheckForUpdates()
  144. {
  145. CInternetUpdate update;
  146. if(update.CheckForUpdate(m_hWnd, FALSE, TRUE))
  147. {
  148. ::PostMessage(theApp.m_MainhWnd, WM_CLOSE_APP, 0, 0);
  149. m_pParent->EndDialog(-1);
  150. }
  151. }
  152. void COptionsGeneral::OnSetDbPath()
  153. {
  154. if(m_btSetDatabasePath.GetCheck() == BST_CHECKED)
  155. {
  156. m_ePath.EnableWindow(TRUE);
  157. m_btGetPath.EnableWindow(TRUE);
  158. }
  159. else
  160. {
  161. m_ePath.EnableWindow(FALSE);
  162. m_btGetPath.EnableWindow(FALSE);
  163. }
  164. }
  165. void COptionsGeneral::OnGetPath()
  166. {
  167. OPENFILENAME FileName;
  168. char szFileName[400];
  169. char szDir[400];
  170. memset(&FileName, 0, sizeof(FileName));
  171. memset(szFileName, 0, sizeof(szFileName));
  172. memset(&szDir, 0, sizeof(szDir));
  173. FileName.lStructSize = sizeof(FileName);
  174. FileName.lpstrTitle = "Open Database";
  175. FileName.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT|OFN_PATHMUSTEXIST;
  176. FileName.nMaxFile = 400;
  177. FileName.lpstrFile = szFileName;
  178. FileName.lpstrInitialDir = szDir;
  179. FileName.lpstrFilter = "Database Files (.MDB)\0*.mdb";
  180. FileName.lpstrDefExt = "mdb";
  181. if(GetOpenFileName(&FileName) == 0)
  182. return;
  183. CString csPath(FileName.lpstrFile);
  184. if(ValidDB(csPath) == FALSE)
  185. {
  186. MessageBox("Invalid Database", "Ditto", MB_OK);
  187. m_ePath.SetFocus();
  188. }
  189. else
  190. m_ePath.SetWindowText(csPath);
  191. }