Browse Source

added message window when backing up db and running script updates

git-svn-id: svn://svn.code.sf.net/p/ditto-cp/code/trunk@773 595ec19a-5cb4-439b-94a8-42fb3063c22c
sabrogden 10 years ago
parent
commit
d35218c398
8 changed files with 160 additions and 15 deletions
  1. 2 0
      CP_Main.vcxproj
  2. 5 0
      CP_Main.vcxproj.filters
  3. 33 11
      DatabaseUtilities.cpp
  4. 3 1
      DatabaseUtilities.h
  5. 89 0
      DittoPopupWindow.cpp
  6. 24 0
      DittoPopupWindow.h
  7. 2 1
      QPasteWnd.h
  8. 2 2
      WndEx.cpp

+ 2 - 0
CP_Main.vcxproj

@@ -564,6 +564,7 @@
     </ClCompile>
     <ClCompile Include="CreateQRCodeImage.cpp" />
     <ClCompile Include="DeleteClipData.cpp" />
+    <ClCompile Include="DittoPopupWindow.cpp" />
     <ClCompile Include="DPI.cpp" />
     <ClCompile Include="DrawHTML.C">
       <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
@@ -1834,6 +1835,7 @@
     <ClInclude Include="ClipFormatQListCtrl.h" />
     <ClInclude Include="CreateQRCodeImage.h" />
     <ClInclude Include="DeleteClipData.h" />
+    <ClInclude Include="DittoPopupWindow.h" />
     <ClInclude Include="DPI.h" />
     <ClInclude Include="DrawHTML.h" />
     <ClInclude Include="EditWithButton.h" />

+ 5 - 0
CP_Main.vcxproj.filters

@@ -388,12 +388,16 @@
     <ClCompile Include="DrawHTML.C">
       <Filter>source</Filter>
     </ClCompile>
+<<<<<<< .mine
+    <ClCompile Include="DittoPopupWindow.cpp" />
+=======
     <ClCompile Include="TrayWnd.cpp">
       <Filter>source</Filter>
     </ClCompile>
     <ClCompile Include="SpecialPasteOptions.cpp">
       <Filter>source</Filter>
     </ClCompile>
+>>>>>>> .r772
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="sqlite\CppSQLite3.h">
@@ -834,6 +838,7 @@
     <ClInclude Include="DrawHTML.h">
       <Filter>header</Filter>
     </ClInclude>
+    <ClInclude Include="DittoPopupWindow.h" />
     <ClInclude Include="SpecialPasteOptions.h">
       <Filter>header</Filter>
     </ClInclude>

+ 33 - 11
DatabaseUtilities.cpp

@@ -223,6 +223,8 @@ BOOL OpenDatabase(CString csDB)
 
 BOOL ValidDB(CString csPath, BOOL bUpgrade)
 {
+	CDittoPopupWindow *popUpMsg = NULL;
+
 	try
 	{
 		BOOL didBackup = FALSE;
@@ -268,7 +270,7 @@ BOOL ValidDB(CString csPath, BOOL bUpgrade)
 		catch(CppSQLite3Exception& e)
 		{
 			if(didBackup == FALSE)
-				didBackup = BackupDB(csPath, backupFilePrefix);
+				didBackup = BackupDB(csPath, backupFilePrefix, &popUpMsg);
 
  			e.errorCode();
  		}
@@ -281,7 +283,7 @@ BOOL ValidDB(CString csPath, BOOL bUpgrade)
 		catch(CppSQLite3Exception& e)
 		{
 			if(didBackup == FALSE)
-				didBackup = BackupDB(csPath, backupFilePrefix);
+				didBackup = BackupDB(csPath, backupFilePrefix, &popUpMsg);
 
 			e.errorCode();
 
@@ -299,7 +301,7 @@ BOOL ValidDB(CString csPath, BOOL bUpgrade)
 		catch(CppSQLite3Exception& e)
 		{
 			if(didBackup == FALSE)
-				didBackup = BackupDB(csPath, backupFilePrefix);
+				didBackup = BackupDB(csPath, backupFilePrefix, &popUpMsg);
 
 			e.errorCode();
 
@@ -332,7 +334,7 @@ BOOL ValidDB(CString csPath, BOOL bUpgrade)
 		catch(CppSQLite3Exception& e)
 		{
 			if(didBackup == FALSE)
-				didBackup = BackupDB(csPath, backupFilePrefix);
+				didBackup = BackupDB(csPath, backupFilePrefix, &popUpMsg);
 
 			db.execDML(_T("ALTER TABLE Main ADD clipOrder REAL"));
 			db.execDML(_T("ALTER TABLE Main ADD clipGroupOrder REAL"));
@@ -354,7 +356,8 @@ BOOL ValidDB(CString csPath, BOOL bUpgrade)
 		catch(CppSQLite3Exception& e)
 		{
 			if(didBackup == FALSE)
-				didBackup = BackupDB(csPath, backupFilePrefix);
+				didBackup = BackupDB(csPath, backupFilePrefix, &popUpMsg);
+
 
 			db.execDML(_T("ALTER TABLE Main ADD globalShortCut INTEGER"));
 
@@ -368,7 +371,7 @@ BOOL ValidDB(CString csPath, BOOL bUpgrade)
 		catch(CppSQLite3Exception& e)
 		{
 			if(didBackup == FALSE)
-				didBackup = BackupDB(csPath, backupFilePrefix);
+				didBackup = BackupDB(csPath, backupFilePrefix, &popUpMsg);
 
 			db.execDML(_T("ALTER TABLE Main ADD lastPasteDate INTEGER"));
 			db.execDML(_T("Update Main set lastPasteDate = lDate"));
@@ -384,7 +387,7 @@ BOOL ValidDB(CString csPath, BOOL bUpgrade)
 		catch (CppSQLite3Exception& e)
 		{
 			if (didBackup == FALSE)
-				didBackup = BackupDB(csPath, backupFilePrefix);
+				didBackup = BackupDB(csPath, backupFilePrefix, &popUpMsg);
 
 			db.execDML(_T("ALTER TABLE Main ADD stickyClipOrder REAL"));
 			db.execDML(_T("ALTER TABLE Main ADD stickyClipGroupOrder REAL"));
@@ -405,7 +408,7 @@ BOOL ValidDB(CString csPath, BOOL bUpgrade)
 			if(count == 0)
 			{
 				if (didBackup == FALSE)
-					didBackup = BackupDB(csPath, backupFilePrefix);				
+					didBackup = BackupDB(csPath, backupFilePrefix, &popUpMsg);
 
 				db.execDML(_T("Update Main set stickyClipOrder = -(2147483647) where stickyClipOrder IS NULL;"));
 				db.execDML(_T("Update Main set stickyClipGroupOrder = -(2147483647) where stickyClipGroupOrder IS NULL;"));
@@ -420,19 +423,33 @@ BOOL ValidDB(CString csPath, BOOL bUpgrade)
 		catch (CppSQLite3Exception& e)
 		{
 			if (didBackup == FALSE)
-				didBackup = BackupDB(csPath, backupFilePrefix);
-
+				didBackup = BackupDB(csPath, backupFilePrefix, &popUpMsg);
 
 			e.errorCode();
 		}
 	}
 	CATCH_SQLITE_EXCEPTION_AND_RETURN(FALSE)
 
+	if(popUpMsg != NULL)
+	{
+		popUpMsg->CloseWindow();
+		popUpMsg = NULL;
+	}
 	return TRUE;                                                     
 }
 
-BOOL BackupDB(CString dbPath, CString prefix)
+BOOL BackupDB(CString dbPath, CString prefix, CDittoPopupWindow **popUpMsg)
 {
+	if ((*popUpMsg) == NULL)
+	{
+		CRect r;
+		GetMonitorRect(0, r);
+		*popUpMsg = new CDittoPopupWindow();
+		(*popUpMsg)->Create(CRect(r.right - 400, r.bottom - 100, r.right - 10, r.bottom - 10), NULL);
+		(*popUpMsg)->UpdateText(_T("Backing up Ditto's Database"));
+		::SetWindowPos((*popUpMsg)->m_hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_SHOWWINDOW);
+		(*popUpMsg)->ShowWindow(SW_SHOW);
+	}
 	CString backup = GetFilePath(dbPath);
 
 	CInternetUpdate update;
@@ -459,6 +476,11 @@ BOOL BackupDB(CString dbPath, CString prefix)
 
 	BOOL ret = CopyFile(dbPath, backup, TRUE);
 
+	if ((*popUpMsg) != NULL)
+	{
+		(*popUpMsg)->UpdateText(_T("Running Ditto database scripts"));
+	}
+
 	return ret;
 }
 

+ 3 - 1
DatabaseUtilities.h

@@ -9,6 +9,8 @@
 #pragma once
 #endif // _MSC_VER > 1000
 
+#include "DittoPopupWindow.h"
+
 #define DEFAULT_DB_NAME "Ditto.db"
 #define ERROR_OPENING_DATABASE	2
 
@@ -27,7 +29,7 @@ BOOL RemoveOldEntries(bool checkIdleTime);
 
 BOOL EnsureDirectory(CString csPath);
 
-BOOL BackupDB(CString dbPath, CString prefix);
+BOOL BackupDB(CString dbPath, CString prefix, CDittoPopupWindow **popUpMsg);
 
 //BOOL CopyDownDatabase();
 //BOOL CopyUpDatabase();

+ 89 - 0
DittoPopupWindow.cpp

@@ -0,0 +1,89 @@
+#include "stdafx.h"
+#include "CP_Main.h"
+#include "DittoPopupWindow.h"
+
+
+CDittoPopupWindow::CDittoPopupWindow()
+{
+}
+
+
+CDittoPopupWindow::~CDittoPopupWindow()
+{
+}
+
+BEGIN_MESSAGE_MAP(CDittoPopupWindow, CWndEx)
+	ON_WM_CREATE()
+	ON_WM_SIZE()
+	ON_WM_CTLCOLOR()
+END_MESSAGE_MAP()
+
+int CDittoPopupWindow::OnCreate(LPCREATESTRUCT lpCreateStruct)
+{
+	if (CWndEx::OnCreate(lpCreateStruct) == -1)
+	{
+		return -1;
+	}
+
+	CWndEx::SetCaptionOn(CAPTION_TOP);
+
+	m_font.CreateFont(-theApp.m_metrics.PointsToPixels(12), 0, 0, 0, 400, 0, 0, 0, DEFAULT_CHARSET, 3, 2, 1, 34, _T("MS Sans Serif"));
+	m_textLabel.Create(_T("test"), WS_CHILD | WS_VISIBLE | SS_CENTERIMAGE, CRect(0, 0, 0, 0), this);
+	m_textLabel.SetFont(&m_font);
+
+	SetWindowText(_T("Running Ditto Updates"));
+
+	//m_textLabel.SetWindowText(_T("test"));
+
+	return 0;
+}
+
+void CDittoPopupWindow::UpdateText(CString text)
+{
+	m_textLabel.SetWindowText(text);
+
+	CRect rect;
+	m_textLabel.GetWindowRect(&rect);
+	ScreenToClient(&rect);
+	InvalidateRect(&rect);
+	UpdateWindow();
+
+	PumpMessages();
+}
+
+void CDittoPopupWindow::OnSize(UINT nType, int cx, int cy)
+{
+	CWndEx::OnSize(nType, cx, cy);
+
+	if(m_textLabel.m_hWnd != NULL)
+	{
+		m_textLabel.MoveWindow(0, 0, cx, cy);
+	}
+	
+}
+
+HBRUSH CDittoPopupWindow::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
+{
+	if (pWnd->GetDlgCtrlID() == 0xffff)
+	{
+		pDC->SetBkMode(TRANSPARENT);
+		return reinterpret_cast<HBRUSH>(::GetStockObject(NULL_BRUSH));
+	}
+	else
+		return CWndEx::OnCtlColor(pDC, pWnd, nCtlColor);
+}
+
+void CDittoPopupWindow::PumpMessages()
+{
+	int nLoops = 0;
+	MSG msg;
+	while (::PeekMessage(&msg, m_hWnd, 0, 0, PM_REMOVE))
+	{
+		TranslateMessage(&msg);
+		DispatchMessage(&msg);
+
+		nLoops++;
+		if (nLoops > 100)
+			break;
+	}
+}

+ 24 - 0
DittoPopupWindow.h

@@ -0,0 +1,24 @@
+#pragma once
+#include "WndEx.h"
+
+class CDittoPopupWindow : public CWndEx
+{
+public:
+	CDittoPopupWindow();
+	~CDittoPopupWindow();
+
+	void UpdateText(CString text);
+	
+protected:
+	DECLARE_MESSAGE_MAP()
+	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
+	afx_msg void OnSize(UINT nType, int cx, int cy);
+	afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
+
+
+	CStatic m_textLabel;
+	CFont m_font;
+
+	void PumpMessages();
+};
+

+ 2 - 1
QPasteWnd.h

@@ -247,7 +247,8 @@ public:
     // Generated message map functions
 protected:
     //{{AFX_MSG(CQPasteWnd)
-    DECLARE_MESSAGE_MAP()afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
+    DECLARE_MESSAGE_MAP()
+	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
     afx_msg void OnSize(UINT nType, int cx, int cy);
     afx_msg void OnSetFocus(CWnd *pOldWnd);
     afx_msg void OnActivate(UINT nState, CWnd *pWndOther, BOOL bMinimized);

+ 2 - 2
WndEx.cpp

@@ -22,7 +22,7 @@ static char THIS_FILE[] = __FILE__;
 
 CWndEx::CWndEx()
 {	
-	SetCaptionColorActive(false, theApp.GetConnectCV());
+	SetCaptionColorActive(false, TRUE);
 	m_crFullSizeWindow.SetRectEmpty();
 	m_lDelayMaxSeconds = 2;
 }
@@ -99,7 +99,7 @@ int CWndEx::OnCreate(LPCREATESTRUCT lpCreateStruct)
 	m_DittoWindow.m_bDrawMinimize = false;
 	m_DittoWindow.m_bDrawMaximize = false;
 
-	SetCaptionColorActive(false, theApp.GetConnectCV());
+	SetCaptionColorActive(false, TRUE);
 	m_DittoWindow.SetCaptionOn(this, CGetSetOptions::GetCaptionPos(), true);
 	SetAutoMaxDelay(CGetSetOptions::GetAutoMaxDelay());