Kaynağa Gözat

prompt to download installation if dao is not installed

git-svn-id: svn://svn.code.sf.net/p/ditto-cp/code/trunk@88 595ec19a-5cb4-439b-94a8-42fb3063c22c
sabrogden 21 yıl önce
ebeveyn
işleme
6a48ead4c7
3 değiştirilmiş dosya ile 66 ekleme ve 25 silme
  1. 14 22
      CP_Main.cpp
  2. 51 3
      DatabaseUtilities.cpp
  3. 1 0
      DatabaseUtilities.h

+ 14 - 22
CP_Main.cpp

@@ -97,35 +97,27 @@ BOOL CCP_MainApp::InitInstance()
 		return TRUE;
 	}
 	
+	AfxOleInit();
+
 	m_cfIgnoreClipboard = ::RegisterClipboardFormat("Clipboard Viewer Ignore");
 
-	if(CheckDBExists(CGetSetOptions::GetDBPath()) == FALSE)
+	int nRet = CheckDBExists(CGetSetOptions::GetDBPath());
+	if(nRet == FALSE)
 	{
 		AfxMessageBox("Error Opening Database.");
 		return TRUE;
 	}
+	else if(nRet == ERROR_OPENING_DATABASE)
+	{
+		CString cs;
+		cs.Format("Unable to initialize DAO/Jet db engine.\nSelect YES to download DAO from http://ditto-cp.sourceforge.net/dao_setup.exe\n\nRestart Ditto after installation of DAO.");
+		if(MessageBox(NULL, cs, "Ditto", MB_YESNO) == IDYES)
+		{
+			ShellExecute(NULL, "open", "http://ditto-cp.sourceforge.net/dao_setup.exe", "", "", SW_SHOW);
+		}
 
-	AfxOleInit();
-
-//	if(g_Opt.m_bUseHookDllForFocus)
-//	{
-//		m_hHookDll = LoadLibrary("focus.dll");
-//		if(m_hHookDll)
-//		{
-//			m_MonitorFocusChanges = (DWORD(*)(HWND,UINT))GetProcAddress(m_hHookDll, "_MonitorFocusChanges@8");
-//			m_StopMonitoringFocusChanges = (DWORD(*)())GetProcAddress(m_hHookDll, "_StopMonitoringFocusChanges@0");
-//			m_GetCurrentFocus = (HWND(*)())GetProcAddress(m_hHookDll, "_GetCurrentFocus@0");
-//		}
-//
-//		if(	m_hHookDll == NULL || m_MonitorFocusChanges == NULL || 
-//			m_StopMonitoringFocusChanges == NULL || m_GetCurrentFocus == NULL)
-//		{
-//			g_Opt.m_bUseHookDllForFocus = FALSE;
-//		}
-//	}
-
-//	if(DoCleanups() == FALSE)
-//		return TRUE;
+		return TRUE;
+	}
 
 	CMainFrame* pFrame = new CMainFrame;
 	m_pMainWnd = m_pMainFrame = pFrame;

+ 51 - 3
DatabaseUtilities.cpp

@@ -78,8 +78,10 @@ BOOL CheckDBExists(CString csDBPath)
 	}
 	
 	BOOL bRet = FALSE;
+
+	int nRet = ValidDB(csDBPath);
 	
-	if(ValidDB(csDBPath) == FALSE)
+	if(nRet == FALSE)
 	{
 		theApp.CloseDB();
 		
@@ -106,6 +108,8 @@ BOOL CheckDBExists(CString csDBPath)
 		
 		bRet = CreateDB(csPath);
 	}
+	else if(nRet == ERROR_OPENING_DATABASE)
+		bRet = ERROR_OPENING_DATABASE;
 	else
 		bRet = TRUE;
 	
@@ -136,7 +140,28 @@ BOOL ValidDB(CString csPath, BOOL bUpgrade)
 	try
 	{
 		CDaoDatabase db;
-		db.Open(csPath);
+
+		try
+		{
+			db.Open(csPath);
+		}
+		catch(CDaoException* e)
+		{
+			TCHAR   szErrorMessage[512];
+			UINT    nHelpContext;
+
+			if(e->GetErrorMessage(szErrorMessage, 512, &nHelpContext))
+			{
+				if(strcmp(szErrorMessage, "Unable to initialize DAO/Jet db engine.") == 0)
+				{
+					e->Delete();
+					return ERROR_OPENING_DATABASE;				
+				}
+			}
+			e->ReportError();
+			e->Delete();
+		}
+		
 		
 		CDaoTableDef table(&db);
 		CDaoFieldInfo info;
@@ -187,7 +212,30 @@ BOOL CreateDB(CString csPath)
 	{
 		CDaoDatabase db;
 		EnsureDirectory(csPath);
-		db.Create(csPath);
+
+		try
+		{
+			db.Create(csPath);
+		}
+		catch(CDaoException* e)
+		{
+			TCHAR   szErrorMessage[512];
+			UINT    nHelpContext;
+
+			if(e->GetErrorMessage(szErrorMessage, 512, &nHelpContext))
+			{
+				if(strcmp(szErrorMessage, "Unable to initialize DAO/Jet db engine.") == 0)
+				{
+					e->Delete();
+					return ERROR_OPENING_DATABASE;	
+				}
+			}
+
+			e->ReportError();
+			e->Delete();
+
+			return FALSE;
+		}
 		
 		CDaoTableDefEx table(&db);
 		//Create the Main table

+ 1 - 0
DatabaseUtilities.h

@@ -10,6 +10,7 @@
 #endif // _MSC_VER > 1000
 
 #define DEFAULT_DB_NAME "DittoDB.mdb"
+#define ERROR_OPENING_DATABASE	2
 
 #define CATCHDAO \
 	catch(CDaoException* e) \