summaryrefslogtreecommitdiff
path: root/plugins/DbChecker/src
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2012-07-27 07:04:06 +0000
committerGeorge Hazan <george.hazan@gmail.com>2012-07-27 07:04:06 +0000
commitadc5442e0cbaec78f5c81fa672e3e14e4c928f59 (patch)
tree2090ab5a08c2c060b1db52c231b9d6ed608cf654 /plugins/DbChecker/src
parent1718ecd06e6bb305385e5dea79c5649af6e9470a (diff)
dbchecker - initial version
git-svn-id: http://svn.miranda-ng.org/main/trunk@1208 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/DbChecker/src')
-rw-r--r--plugins/DbChecker/src/cleaning.cpp11
-rw-r--r--plugins/DbChecker/src/dbchecker.h19
-rw-r--r--plugins/DbChecker/src/fileaccess.cpp17
-rw-r--r--plugins/DbChecker/src/main.cpp65
-rw-r--r--plugins/DbChecker/src/openerror.cpp8
-rw-r--r--plugins/DbChecker/src/progress.cpp8
-rw-r--r--plugins/DbChecker/src/selectdb.cpp55
-rw-r--r--plugins/DbChecker/src/version.h9
-rw-r--r--plugins/DbChecker/src/wizard.cpp10
-rw-r--r--plugins/DbChecker/src/worker.cpp12
10 files changed, 143 insertions, 71 deletions
diff --git a/plugins/DbChecker/src/cleaning.cpp b/plugins/DbChecker/src/cleaning.cpp
index 4ecd2772fb..bd8f296afb 100644
--- a/plugins/DbChecker/src/cleaning.cpp
+++ b/plugins/DbChecker/src/cleaning.cpp
@@ -49,16 +49,7 @@ INT_PTR CALLBACK CleaningDlgProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM
break;
case IDOK:
- if (!opts.hFile) {
- opts.hFile = CreateFile(opts.filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
- if (opts.hFile == INVALID_HANDLE_VALUE) {
- opts.hFile = NULL;
- opts.error = GetLastError();
- SendMessage(GetParent(hdlg), WZM_GOTOPAGE, IDD_OPENERROR, (LPARAM)OpenErrorDlgProc);
- break;
- }
- }
- SendMessage(GetParent(hdlg), WZM_GOTOPAGE, IDD_PROGRESS, (LPARAM)ProgressDlgProc);
+ OpenDatabase(hdlg, IDD_PROGRESS);
break;
}
break;
diff --git a/plugins/DbChecker/src/dbchecker.h b/plugins/DbChecker/src/dbchecker.h
index 39d64cb089..d333f51b02 100644
--- a/plugins/DbChecker/src/dbchecker.h
+++ b/plugins/DbChecker/src/dbchecker.h
@@ -33,8 +33,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <commctrl.h>
#include <time.h>
+#include <m_system.h>
+#include <m_system_cpp.h>
+#include <newpluginapi.h>
#include <m_database.h>
#include <m_db_int.h>
+#include <m_langpack.h>
#include "resource.h"
@@ -45,15 +49,15 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define WZN_PAGECHANGING (WM_USER+1221)
#define WZN_CANCELCLICKED (WM_USER+1222)
-struct DbToolOptions {
+struct DbToolOptions
+{
TCHAR filename[MAX_PATH];
TCHAR workingFilename[MAX_PATH];
TCHAR outputFilename[MAX_PATH];
TCHAR backupFilename[MAX_PATH];
- HANDLE hFile;
+ DATABASELINK *dblink;
+ MIDatabaseChecker* dbChecker;
HANDLE hOutFile;
- HANDLE hMap;
- BYTE *pFile;
DWORD error;
int bCheckOnly, bBackup, bAggressive;
int bEraseHistory, bMarkRead, bConvertUtf;
@@ -63,6 +67,7 @@ extern HINSTANCE hInst;
extern DbToolOptions opts;
extern HANDLE hEventRun, hEventAbort;
extern int errorCount;
+extern bool bServiceMode;
int DoMyControlProcessing(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam, INT_PTR *bReturn);
@@ -75,11 +80,7 @@ INT_PTR CALLBACK FinishedDlgProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM
INT_PTR CALLBACK WelcomeDlgProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam);
INT_PTR CALLBACK OpenErrorDlgProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam);
-struct DBSignature {
- char name[15];
- BYTE eof;
-};
-static struct DBSignature dbSignature = {"Miranda ICQ DB", 0x1A};
+void OpenDatabase(HWND hdlg, INT iNextPage);
#define SIZEOF(X) (sizeof(X)/sizeof(X[0]))
diff --git a/plugins/DbChecker/src/fileaccess.cpp b/plugins/DbChecker/src/fileaccess.cpp
index f9b6e2d656..ef19a1244f 100644
--- a/plugins/DbChecker/src/fileaccess.cpp
+++ b/plugins/DbChecker/src/fileaccess.cpp
@@ -47,19 +47,10 @@ INT_PTR CALLBACK FileAccessDlgProc(HWND hdlg, UINT message, WPARAM wParam, LPARA
break;
case IDOK:
- if (opts.bCheckOnly) {
- if (!opts.hFile) {
- opts.hFile = CreateFile(opts.filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
- if (opts.hFile == INVALID_HANDLE_VALUE) {
- opts.hFile = NULL;
- opts.error = GetLastError();
- SendMessage(GetParent(hdlg), WZM_GOTOPAGE, IDD_OPENERROR, (LPARAM)OpenErrorDlgProc);
- break;
- }
- }
- SendMessage(GetParent(hdlg), WZM_GOTOPAGE, IDD_PROGRESS, (LPARAM)ProgressDlgProc);
- }
- else SendMessage(GetParent(hdlg), WZM_GOTOPAGE, IDD_CLEANING, (LPARAM)CleaningDlgProc);
+ if (opts.bCheckOnly)
+ OpenDatabase(hdlg, IDD_PROGRESS);
+ else
+ SendMessage(GetParent(hdlg), WZM_GOTOPAGE, IDD_CLEANING, (LPARAM)CleaningDlgProc);
break;
case IDC_CHECKONLY:
diff --git a/plugins/DbChecker/src/main.cpp b/plugins/DbChecker/src/main.cpp
index f59f66a13a..209bef8a70 100644
--- a/plugins/DbChecker/src/main.cpp
+++ b/plugins/DbChecker/src/main.cpp
@@ -18,9 +18,74 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "dbchecker.h"
+#include "version.h"
HINSTANCE hInst;
int hLangpack = 0;
+bool bServiceMode = false;
+
+static HANDLE hLaunchFunc;
DbToolOptions opts = {0};
+PLUGININFOEX pluginInfoEx =
+{
+ sizeof(pluginInfoEx),
+ __PLUGIN_NAME,
+ __VERSION_DWORD,
+ __DESCRIPTION,
+ __AUTHOR,
+ __AUTHOREMAIL,
+ __COPYRIGHT,
+ __AUTHORWEB,
+ UNICODE_AWARE,
+ // {A0138FC6-4C52-4501-AF93-7D3E20BCAE5B}
+ { 0xa0138fc6, 0x4c52, 0x4501, { 0xaf, 0x93, 0x7d, 0x3e, 0x20, 0xbc, 0xae, 0x5b}}
+};
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
+BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved)
+{
+ hInst=hinstDLL;
+ return TRUE;
+}
+
+extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD mirandaVersion)
+{
+ return &pluginInfoEx;
+}
+
+// we implement service mode interface
+extern "C" __declspec(dllexport) const MUUID MirandaInterfaces[] = {MIID_SERVICEMODE, MIID_LAST};
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
+static INT_PTR ServiceMode(WPARAM, LPARAM)
+{
+ bServiceMode = true;
+ return SERVICE_MONOPOLY; // unload db and open a wizard
+}
+
+static int OnModulesLoaded(WPARAM, LPARAM)
+{
+ if (bServiceMode)
+ DialogBox(hInst, MAKEINTRESOURCE(IDD_WIZARD), NULL, WizardDlgProc);
+ return 0;
+}
+
+extern "C" __declspec(dllexport) int Load(void)
+{
+ mir_getLP(&pluginInfoEx);
+
+ HookEvent(ME_SYSTEM_MODULESLOADED, OnModulesLoaded);
+
+ hLaunchFunc = CreateServiceFunction(MS_SERVICEMODE_LAUNCH, ServiceMode);
+ return 0;
+}
+
+extern "C" __declspec(dllexport) int Unload(void)
+{
+ DestroyServiceFunction(hLaunchFunc);
+ return 0;
+}
diff --git a/plugins/DbChecker/src/openerror.cpp b/plugins/DbChecker/src/openerror.cpp
index f86ba163cb..0ae07ed2c4 100644
--- a/plugins/DbChecker/src/openerror.cpp
+++ b/plugins/DbChecker/src/openerror.cpp
@@ -43,13 +43,7 @@ INT_PTR CALLBACK OpenErrorDlgProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM
break;
case IDOK:
- opts.hFile = CreateFile(opts.filename, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
- if (opts.hFile == INVALID_HANDLE_VALUE) {
- opts.hFile = NULL;
- opts.error = GetLastError();
- SendMessage(GetParent(hdlg), WZM_GOTOPAGE, IDD_OPENERROR, (LPARAM)OpenErrorDlgProc);
- }
- else SendMessage(GetParent(hdlg), WZM_GOTOPAGE, IDD_FILEACCESS, (LPARAM)FileAccessDlgProc);
+ OpenDatabase(hdlg, IDD_FILEACCESS);
break;
}
break;
diff --git a/plugins/DbChecker/src/progress.cpp b/plugins/DbChecker/src/progress.cpp
index 5465fee8fa..4fe976f61f 100644
--- a/plugins/DbChecker/src/progress.cpp
+++ b/plugins/DbChecker/src/progress.cpp
@@ -55,14 +55,6 @@ void SetProgressBar(int perThou)
void ProcessingDone(void)
{
- if (opts.pFile) {
- UnmapViewOfFile(opts.pFile);
- opts.pFile = NULL;
- }
- if (opts.hMap) {
- CloseHandle(opts.hMap);
- opts.hMap = NULL;
- }
SendMessage(hdlgProgress, WM_PROCESSINGDONE, 0, 0);
}
diff --git a/plugins/DbChecker/src/selectdb.cpp b/plugins/DbChecker/src/selectdb.cpp
index 0b61d5c5b6..c1a6e75e90 100644
--- a/plugins/DbChecker/src/selectdb.cpp
+++ b/plugins/DbChecker/src/selectdb.cpp
@@ -18,6 +18,43 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "dbchecker.h"
+void OpenDatabase(HWND hdlg, INT iNextPage)
+{
+ TCHAR tszMsg[1024];
+
+ if (opts.dbChecker == NULL) {
+ DATABASELINK* dblink = FindDatabasePlugin(opts.filename);
+ if (dblink == NULL) {
+ mir_sntprintf(tszMsg, SIZEOF(tszMsg),
+ TranslateT("Database Checker cannot find a suitable database plugin to open '%s'."),
+ opts.filename);
+LBL_Error:
+ MessageBox(hdlg, tszMsg, TranslateT("Error"), MB_OK | MB_ICONERROR);
+ return;
+ }
+
+ if (dblink->CheckDB == NULL) {
+ mir_sntprintf(tszMsg, SIZEOF(tszMsg),
+ TranslateT("Database driver '%s' doesn't support checking."),
+ TranslateTS(dblink->szFullName));
+ goto LBL_Error;
+ }
+
+ int error = 0;
+ opts.dbChecker = opts.dblink->CheckDB(opts.filename, &error);
+ if (opts.dbChecker == NULL) {
+ opts.error = error;
+ SendMessage(GetParent(hdlg), WZM_GOTOPAGE, IDD_OPENERROR, (LPARAM)OpenErrorDlgProc);
+ return;
+ }
+ }
+
+ if (iNextPage == IDD_FILEACCESS)
+ SendMessage(GetParent(hdlg), WZM_GOTOPAGE, IDD_FILEACCESS, (LPARAM)FileAccessDlgProc);
+ else
+ SendMessage(GetParent(hdlg), WZM_GOTOPAGE, IDD_PROGRESS, (LPARAM)ProgressDlgProc);
+}
+
void GetProfileDirectory(TCHAR* szMirandaDir, TCHAR* szPath, int cbPath)
{
TCHAR szProfileDir[MAX_PATH], szExpandedProfileDir[MAX_PATH], szMirandaBootIni[MAX_PATH];
@@ -175,7 +212,7 @@ INT_PTR CALLBACK SelectDbDlgProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM
FindAdd(hdlg, szMirandaProfiles, _T("[prf]\\"));
// search in current dir (as DBTOOL)
- FindAdd(hdlg, szMirandaPath, _T("[ . ]\\"));
+ FindAdd(hdlg, szMirandaPath, _T("[.]\\"));
// search in profile dir (using registry path + ini file)
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\miranda32.exe"), 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS) {
@@ -194,9 +231,10 @@ INT_PTR CALLBACK SelectDbDlgProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM
i = 0;
ListView_SetItemState(GetDlgItem(hdlg, IDC_DBLIST), i, LVIS_SELECTED, LVIS_SELECTED);
}
- if (opts.hFile != NULL && opts.hFile != INVALID_HANDLE_VALUE) {
- CloseHandle(opts.hFile);
- opts.hFile = NULL;
+
+ if (opts.dbChecker != NULL) {
+ opts.dbChecker->Destroy();
+ opts.dbChecker = NULL;
}
return TRUE;
@@ -251,16 +289,11 @@ INT_PTR CALLBACK SelectDbDlgProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM
break;
case IDOK:
- opts.hFile = CreateFile(opts.filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
- if (opts.hFile == INVALID_HANDLE_VALUE) {
- opts.hFile = NULL;
- opts.error = GetLastError();
- SendMessage(GetParent(hdlg), WZM_GOTOPAGE, IDD_OPENERROR, (LPARAM)OpenErrorDlgProc);
- }
- else SendMessage(GetParent(hdlg), WZM_GOTOPAGE, IDD_FILEACCESS, (LPARAM)FileAccessDlgProc);
+ OpenDatabase(hdlg, IDD_FILEACCESS);
break;
}
break;
+
case WM_NOTIFY:
switch(((LPNMHDR)lParam)->idFrom) {
case IDC_DBLIST:
diff --git a/plugins/DbChecker/src/version.h b/plugins/DbChecker/src/version.h
index 58f9cf348c..690140005a 100644
--- a/plugins/DbChecker/src/version.h
+++ b/plugins/DbChecker/src/version.h
@@ -3,3 +3,12 @@
#define __FILEVERSION_STRING MIRANDA_VERSION_FILEVERSION
#define __VERSION_STRING MIRANDA_VERSION_STRING
#define __VERSION_DWORD MIRANDA_VERSION_DWORD
+
+#define __PLUGIN_NAME "Database Checker"
+#define __INTERNAL_NAME "dbchecker"
+#define __FILENAME "dbchecker.dll"
+#define __DESCRIPTION "Miranda NG Database Checker"
+#define __AUTHOR "George Hazan"
+#define __AUTHOREMAIL "ghazan@miranda-ng.org"
+#define __AUTHORWEB "http://www.miranda-ng.org/"
+#define __COPYRIGHT "© 2012, George Hazan"
diff --git a/plugins/DbChecker/src/wizard.cpp b/plugins/DbChecker/src/wizard.cpp
index dd10b614ac..835bb9d563 100644
--- a/plugins/DbChecker/src/wizard.cpp
+++ b/plugins/DbChecker/src/wizard.cpp
@@ -128,13 +128,19 @@ INT_PTR CALLBACK WizardDlgProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lP
break;
case WM_DESTROY:
- if (opts.hFile)
- CloseHandle(opts.hFile);
+ if (opts.dbChecker) {
+ opts.dbChecker->Destroy();
+ opts.dbChecker = NULL;
+ }
+
if (opts.hOutFile)
CloseHandle(opts.hOutFile);
+
DestroyWindow(hdlgPage);
if (hBoldFont != NULL) DeleteObject(hBoldFont);
if (hEmfHeaderLogo != NULL) DeleteEnhMetaFile(hEmfHeaderLogo);
+ if (bServiceMode)
+ PostQuitMessage(0);
break;
}
return FALSE;
diff --git a/plugins/DbChecker/src/worker.cpp b/plugins/DbChecker/src/worker.cpp
index 834a40f308..9fa3e7aa2b 100644
--- a/plugins/DbChecker/src/worker.cpp
+++ b/plugins/DbChecker/src/worker.cpp
@@ -20,14 +20,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "dbchecker.h"
void ProcessingDone(void);
-int WorkInitialChecks(int firstTime);
-int WorkModuleChain(int firstTime);
-int WorkUser(int firstTime);
-int WorkContactChain(int firstTime);
-int WorkAggressive(int firstTime);
-int WorkFinalTasks(int firstTime);
-
-DATABASELINK* dblink;
void __cdecl WorkerThread(void *unused)
{
@@ -35,14 +27,12 @@ void __cdecl WorkerThread(void *unused)
time_t ts = time(NULL);
AddToStatus(STATUS_MESSAGE, TranslateT("Database worker thread activated"));
- SetFilePointer(opts.hFile, 0, NULL, FILE_BEGIN);
DWORD sp = 0;
firstTime = 0;
DBCHeckCallback callback;
callback.cbSize = sizeof(callback);
- callback.db = NULL;
callback.spaceUsed = 1;
callback.spaceProcessed = 0;
callback.pfnAddLogMessage = AddToStatus;
@@ -58,7 +48,7 @@ void __cdecl WorkerThread(void *unused)
break;
}
- int ret = dblink->CheckDb(&callback, task, firstTime);
+ int ret = opts.dbChecker->CheckDb(&callback, task, firstTime);
firstTime = 0;
if (ret == ERROR_NO_MORE_ITEMS) {
AddToStatus(STATUS_MESSAGE, TranslateT("Elapsed time: %d sec"), time(NULL)-ts);