summaryrefslogtreecommitdiff
path: root/plugins/DbChecker/src
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2012-07-26 14:56:53 +0000
committerGeorge Hazan <george.hazan@gmail.com>2012-07-26 14:56:53 +0000
commitd5d6965af7e69367babf40b7fb1d7fca8617cabe (patch)
tree614f57382fcf26c3895d4166f67657c3b0e23e3e /plugins/DbChecker/src
parent78eb36ffcbd1b71eee1b912a927522fd3f19b347 (diff)
dbtool is divided into two parts: DbChecker & appendix for db3x_mmap plugin
git-svn-id: http://svn.miranda-ng.org/main/trunk@1195 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/DbChecker/src')
-rw-r--r--plugins/DbChecker/src/cleaning.cpp67
-rw-r--r--plugins/DbChecker/src/dbchecker.h105
-rw-r--r--plugins/DbChecker/src/fileaccess.cpp73
-rw-r--r--plugins/DbChecker/src/finished.cpp86
-rw-r--r--plugins/DbChecker/src/main.cpp26
-rw-r--r--plugins/DbChecker/src/openerror.cpp58
-rw-r--r--plugins/DbChecker/src/progress.cpp224
-rw-r--r--plugins/DbChecker/src/resource.h54
-rw-r--r--plugins/DbChecker/src/selectdb.cpp296
-rw-r--r--plugins/DbChecker/src/utf.cpp69
-rw-r--r--plugins/DbChecker/src/version.h5
-rw-r--r--plugins/DbChecker/src/welcome.cpp70
-rw-r--r--plugins/DbChecker/src/wizard.cpp141
-rw-r--r--plugins/DbChecker/src/worker.cpp79
14 files changed, 1353 insertions, 0 deletions
diff --git a/plugins/DbChecker/src/cleaning.cpp b/plugins/DbChecker/src/cleaning.cpp
new file mode 100644
index 0000000000..4ecd2772fb
--- /dev/null
+++ b/plugins/DbChecker/src/cleaning.cpp
@@ -0,0 +1,67 @@
+/*
+Miranda Database Tool
+Copyright (C) 2001-2005 Richard Hughes
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+#include "dbchecker.h"
+
+INT_PTR CALLBACK CleaningDlgProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam)
+{
+ INT_PTR bReturn;
+ if (DoMyControlProcessing(hdlg, message, wParam, lParam, &bReturn))
+ return bReturn;
+
+ switch(message) {
+ case WM_INITDIALOG:
+ CheckDlgButton(hdlg, IDC_ERASEHISTORY, opts.bEraseHistory);
+ EnableWindow(GetDlgItem(hdlg, IDC_ERASEHISTORY), !opts.bAggressive);
+ CheckDlgButton(hdlg, IDC_MARKREAD, opts.bMarkRead);
+ CheckDlgButton(hdlg, IDC_CONVERTUTF, opts.bConvertUtf);
+ TranslateDialogDefault(hdlg);
+ return TRUE;
+
+ case WZN_PAGECHANGING:
+ opts.bEraseHistory = IsDlgButtonChecked(hdlg, IDC_ERASEHISTORY)&&!opts.bAggressive;
+ opts.bMarkRead = IsDlgButtonChecked(hdlg, IDC_MARKREAD);
+ opts.bConvertUtf = IsDlgButtonChecked(hdlg, IDC_CONVERTUTF);
+ break;
+
+ case WM_COMMAND:
+ switch(LOWORD(wParam)) {
+ case IDC_BACK:
+ if (opts.bCheckOnly)
+ SendMessage(GetParent(hdlg), WZM_GOTOPAGE, IDD_SELECTDB, (LPARAM)SelectDbDlgProc);
+ else
+ SendMessage(GetParent(hdlg), WZM_GOTOPAGE, IDD_FILEACCESS, (LPARAM)FileAccessDlgProc);
+ 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);
+ break;
+ }
+ break;
+ }
+ return FALSE;
+}
diff --git a/plugins/DbChecker/src/dbchecker.h b/plugins/DbChecker/src/dbchecker.h
new file mode 100644
index 0000000000..39d64cb089
--- /dev/null
+++ b/plugins/DbChecker/src/dbchecker.h
@@ -0,0 +1,105 @@
+/*
+Miranda Database Tool
+Copyright 2000-2011 Miranda ICQ/IM project,
+all portions of this codebase are copyrighted to the people
+listed in contributors.txt.
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+
+#include <tchar.h>
+
+#include <windows.h>
+#include <stdio.h>
+#include <stddef.h>
+#include <io.h>
+#include <stdarg.h>
+#include <process.h>
+#include <direct.h>
+#include <malloc.h>
+#include <commctrl.h>
+#include <time.h>
+
+#include <m_database.h>
+#include <m_db_int.h>
+
+#include "resource.h"
+
+#define WinVerMajor() LOBYTE(LOWORD(GetVersion()))
+#define IsWinVerXPPlus() (WinVerMajor()>=5 && LOWORD(GetVersion())!=5)
+
+#define WZM_GOTOPAGE (WM_USER+1)
+#define WZN_PAGECHANGING (WM_USER+1221)
+#define WZN_CANCELCLICKED (WM_USER+1222)
+
+struct DbToolOptions {
+ TCHAR filename[MAX_PATH];
+ TCHAR workingFilename[MAX_PATH];
+ TCHAR outputFilename[MAX_PATH];
+ TCHAR backupFilename[MAX_PATH];
+ HANDLE hFile;
+ HANDLE hOutFile;
+ HANDLE hMap;
+ BYTE *pFile;
+ DWORD error;
+ int bCheckOnly, bBackup, bAggressive;
+ int bEraseHistory, bMarkRead, bConvertUtf;
+};
+
+extern HINSTANCE hInst;
+extern DbToolOptions opts;
+extern HANDLE hEventRun, hEventAbort;
+extern int errorCount;
+
+int DoMyControlProcessing(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam, INT_PTR *bReturn);
+
+INT_PTR CALLBACK SelectDbDlgProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam);
+INT_PTR CALLBACK CleaningDlgProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam);
+INT_PTR CALLBACK ProgressDlgProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam);
+INT_PTR CALLBACK FileAccessDlgProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam);
+INT_PTR CALLBACK WizardDlgProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam);
+INT_PTR CALLBACK FinishedDlgProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM 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};
+
+#define SIZEOF(X) (sizeof(X)/sizeof(X[0]))
+
+#define STATUS_MESSAGE 0
+#define STATUS_WARNING 1
+#define STATUS_ERROR 2
+#define STATUS_FATAL 3
+#define STATUS_SUCCESS 4
+#define STATUS_CLASSMASK 0x0f
+void AddToStatus(int flags, const TCHAR* fmt, ...);
+void SetProgressBar(int perThou);
+
+int PeekSegment(DWORD ofs, PVOID buf, int cbBytes);
+int ReadSegment(DWORD ofs, PVOID buf, int cbBytes);
+#define WSOFS_END 0xFFFFFFFF
+#define WS_ERROR 0xFFFFFFFF
+DWORD WriteSegment(DWORD ofs, PVOID buf, int cbBytes);
+int ReadWrittenSegment(DWORD ofs, PVOID buf, int cbBytes);
+int SignatureValid(DWORD ofs, DWORD signature);
+DWORD ConvertModuleNameOfs(DWORD ofsOld);
+void FreeModuleChain();
+
+bool is_utf8_string(const char* str);
diff --git a/plugins/DbChecker/src/fileaccess.cpp b/plugins/DbChecker/src/fileaccess.cpp
new file mode 100644
index 0000000000..f9b6e2d656
--- /dev/null
+++ b/plugins/DbChecker/src/fileaccess.cpp
@@ -0,0 +1,73 @@
+/*
+Miranda Database Tool
+Copyright (C) 2001-2005 Richard Hughes
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+#include "dbchecker.h"
+
+INT_PTR CALLBACK FileAccessDlgProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam)
+{
+ INT_PTR bReturn;
+ if (DoMyControlProcessing(hdlg, message, wParam, lParam, &bReturn))
+ return bReturn;
+
+ switch(message) {
+ case WM_INITDIALOG:
+ CheckDlgButton(hdlg, IDC_CHECKONLY, opts.bCheckOnly);
+ CheckDlgButton(hdlg, IDC_BACKUP, opts.bBackup);
+ CheckDlgButton(hdlg, IDC_AGGRESSIVE, opts.bAggressive);
+ SendMessage(hdlg, WM_COMMAND, MAKEWPARAM(IDC_CHECKONLY, BN_CLICKED), 0);
+ TranslateDialogDefault(hdlg);
+ return TRUE;
+
+ case WZN_PAGECHANGING:
+ opts.bCheckOnly = IsDlgButtonChecked(hdlg, IDC_CHECKONLY);
+ opts.bAggressive = IsDlgButtonChecked(hdlg, IDC_AGGRESSIVE);
+ if (opts.bCheckOnly) opts.bBackup = 0;
+ else opts.bBackup = IsDlgButtonChecked(hdlg, IDC_BACKUP);
+ break;
+
+ case WM_COMMAND:
+ switch(LOWORD(wParam)) {
+ case IDC_BACK:
+ SendMessage(GetParent(hdlg), WZM_GOTOPAGE, IDD_SELECTDB, (LPARAM)SelectDbDlgProc);
+ 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);
+ break;
+
+ case IDC_CHECKONLY:
+ EnableWindow(GetDlgItem(hdlg, IDC_BACKUP), !IsDlgButtonChecked(hdlg, IDC_CHECKONLY));
+ EnableWindow(GetDlgItem(hdlg, IDC_STBACKUP), !IsDlgButtonChecked(hdlg, IDC_CHECKONLY));
+ break;
+ }
+ break;
+ }
+ return FALSE;
+}
diff --git a/plugins/DbChecker/src/finished.cpp b/plugins/DbChecker/src/finished.cpp
new file mode 100644
index 0000000000..96da1a0917
--- /dev/null
+++ b/plugins/DbChecker/src/finished.cpp
@@ -0,0 +1,86 @@
+/*
+Miranda Database Tool
+Copyright (C) 2001-2005 Richard Hughes
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+#include "dbchecker.h"
+
+#define WM_LAUNCHMIRANDA (WM_USER+1)
+INT_PTR CALLBACK FinishedDlgProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam)
+{
+ INT_PTR bReturn;
+ if ( DoMyControlProcessing(hdlg, message, wParam, lParam, &bReturn))
+ return bReturn;
+
+ switch(message) {
+ case WM_INITDIALOG:
+ EnableWindow(GetDlgItem(GetParent(hdlg), IDC_BACK), FALSE);
+ SetDlgItemText(GetParent(hdlg), IDCANCEL, TranslateT("&Finish"));
+ SetWindowLongPtr(GetDlgItem(hdlg, IDC_DBFILE), GWL_STYLE, GetWindowLongPtr(GetDlgItem(hdlg, IDC_DBFILE), GWL_STYLE)|SS_PATHELLIPSIS);
+ SetDlgItemText(hdlg, IDC_DBFILE, opts.filename);
+ if (opts.bBackup) {
+ ShowWindow(GetDlgItem(hdlg, IDC_STBACKUP), TRUE);
+ SetWindowLongPtr(GetDlgItem(hdlg, IDC_BACKUPFILE), GWL_STYLE, GetWindowLongPtr(GetDlgItem(hdlg, IDC_BACKUPFILE), GWL_STYLE)|SS_PATHELLIPSIS);
+ SetDlgItemText(hdlg, IDC_BACKUPFILE, opts.backupFilename);
+ }
+ else ShowWindow(GetDlgItem(hdlg, IDC_STBACKUP), FALSE);
+ TranslateDialogDefault(hdlg);
+ return TRUE;
+
+ case WM_LAUNCHMIRANDA:
+ if (IsDlgButtonChecked(hdlg, IDC_LAUNCHMIRANDA)) {
+ TCHAR dbFile[MAX_PATH], dbPath[MAX_PATH], *str2;
+ _tcscpy(dbPath, opts.filename);
+ str2 = _tcsrchr(dbPath, '\\');
+ if (str2 == NULL) {
+ _tcscpy(dbFile, dbPath);
+ dbPath[ 0 ] = 0;
+ }
+ else {
+ _tcscpy(dbFile, str2+1);
+ *str2 = 0;
+ }
+ str2 = _tcsrchr(dbFile, '.');
+ if (str2 != NULL)
+ *str2 = 0;
+ _tcscat(dbPath, _T("\\miranda32.exe"));
+ if (GetFileAttributes(dbPath) == INVALID_FILE_ATTRIBUTES) {
+ GetModuleFileName(NULL, dbPath, SIZEOF(dbPath));
+ if ((str2 = _tcsrchr(dbPath, '\\')) != NULL)
+ *str2 = 0;
+ else
+ dbPath[0] = 0;
+ _tcscat(dbPath, _T("\\miranda32.exe"));
+ }
+ ShellExecute(hdlg, NULL, dbPath, dbFile, _T(""), 0);
+ }
+ break;
+
+ case WZN_CANCELCLICKED:
+ SendMessage(hdlg, WM_LAUNCHMIRANDA, 0, 0);
+ break;
+
+ case WM_COMMAND:
+ switch(LOWORD(wParam)) {
+ case IDOK:
+ SendMessage(hdlg, WM_LAUNCHMIRANDA, 0, 0);
+ SendMessage(GetParent(hdlg), WZM_GOTOPAGE, IDD_SELECTDB, (LPARAM)SelectDbDlgProc);
+ break;
+ }
+ break;
+ }
+ return FALSE;
+}
diff --git a/plugins/DbChecker/src/main.cpp b/plugins/DbChecker/src/main.cpp
new file mode 100644
index 0000000000..f59f66a13a
--- /dev/null
+++ b/plugins/DbChecker/src/main.cpp
@@ -0,0 +1,26 @@
+/*
+Miranda Database Tool
+Copyright (C) 2001-2005 Richard Hughes
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+#include "dbchecker.h"
+
+HINSTANCE hInst;
+int hLangpack = 0;
+
+DbToolOptions opts = {0};
+
diff --git a/plugins/DbChecker/src/openerror.cpp b/plugins/DbChecker/src/openerror.cpp
new file mode 100644
index 0000000000..f86ba163cb
--- /dev/null
+++ b/plugins/DbChecker/src/openerror.cpp
@@ -0,0 +1,58 @@
+/*
+Miranda Database Tool
+Copyright (C) 2001-2005 Richard Hughes
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+#include "dbchecker.h"
+
+INT_PTR CALLBACK OpenErrorDlgProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam)
+{
+ INT_PTR bReturn;
+
+ if (DoMyControlProcessing(hdlg, message, wParam, lParam, &bReturn)) return bReturn;
+ switch(message) {
+ case WM_INITDIALOG:
+ {
+ TCHAR szError[256];
+ FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, opts.error, 0, szError, SIZEOF(szError), NULL);
+ SetDlgItemText(hdlg, IDC_ERRORTEXT, szError);
+ }
+ if (opts.error == ERROR_SHARING_VIOLATION) ShowWindow(GetDlgItem(hdlg, IDC_INUSE), SW_SHOW);
+ SetWindowLongPtr(GetDlgItem(hdlg, IDC_FILE), GWL_STYLE, GetWindowLongPtr(GetDlgItem(hdlg, IDC_FILE), GWL_STYLE) | SS_PATHELLIPSIS);
+ TranslateDialogDefault(hdlg);
+ SetDlgItemText(hdlg, IDC_FILE, opts.filename);
+ return TRUE;
+
+ case WM_COMMAND:
+ switch(LOWORD(wParam)) {
+ case IDC_BACK:
+ SendMessage(GetParent(hdlg), WZM_GOTOPAGE, IDD_SELECTDB, (LPARAM)SelectDbDlgProc);
+ 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);
+ break;
+ }
+ break;
+ }
+ return FALSE;
+}
diff --git a/plugins/DbChecker/src/progress.cpp b/plugins/DbChecker/src/progress.cpp
new file mode 100644
index 0000000000..5465fee8fa
--- /dev/null
+++ b/plugins/DbChecker/src/progress.cpp
@@ -0,0 +1,224 @@
+/*
+Miranda Database Tool
+Copyright (C) 2001-2005 Richard Hughes
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+#include "dbchecker.h"
+
+#define WM_PROCESSINGDONE (WM_USER+1)
+
+void __cdecl WorkerThread(void *unused);
+static HWND hwndStatus, hdlgProgress, hwndBar;
+HANDLE hEventRun = NULL, hEventAbort = NULL;
+int errorCount;
+
+void AddToStatus(int flags, const TCHAR* fmt, ...)
+{
+ va_list vararg;
+ va_start(vararg, fmt);
+
+ TCHAR str[256];
+ _vsntprintf(str, SIZEOF(str), fmt, vararg);
+ va_end(vararg);
+
+ int i = SendMessage(hwndStatus, LB_ADDSTRING, 0, (LPARAM)str);
+ SendMessage(hwndStatus, LB_SETITEMDATA, i, flags);
+ InvalidateRect(hwndStatus, NULL, FALSE);
+ SendMessage(hwndStatus, LB_SETTOPINDEX, i, 0);
+
+ #ifdef _DEBUG
+ OutputDebugString(str);
+ OutputDebugStringA("\n");
+ #endif
+
+ if ((flags & STATUS_CLASSMASK) == STATUS_ERROR)
+ errorCount++;
+}
+
+void SetProgressBar(int perThou)
+{
+ SendMessage(hwndBar, PBM_SETPOS, perThou, 0);
+}
+
+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);
+}
+
+INT_PTR CALLBACK ProgressDlgProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam)
+{
+ static int fontHeight, listWidth;
+ static int manualAbort;
+ static HFONT hBoldFont = NULL;
+
+ INT_PTR bReturn;
+ if (DoMyControlProcessing(hdlg, message, wParam, lParam, &bReturn))
+ return bReturn;
+
+ switch(message) {
+ case WM_INITDIALOG:
+ EnableWindow(GetDlgItem(GetParent(hdlg), IDOK), FALSE);
+ hdlgProgress = hdlg;
+ hwndStatus = GetDlgItem(hdlg, IDC_STATUS);
+ errorCount = 0;
+ hwndBar = GetDlgItem(hdlg, IDC_PROGRESS);
+ SendMessage(hwndBar, PBM_SETRANGE, 0, MAKELPARAM(0, 1000));
+ {
+ HDC hdc;
+ HFONT hFont, hoFont;
+ SIZE s;
+ hdc = GetDC(NULL);
+ hFont = (HFONT)SendMessage(hdlg, WM_GETFONT, 0, 0);
+ hoFont = (HFONT)SelectObject(hdc, hFont);
+ GetTextExtentPoint32(hdc, _T("x"), 1, &s);
+ SelectObject(hdc, hoFont);
+ ReleaseDC(NULL, hdc);
+ fontHeight = s.cy;
+
+ RECT rc;
+ GetClientRect(GetDlgItem(hdlg, IDC_STATUS), &rc);
+ listWidth = rc.right;
+
+ LOGFONT lf;
+ GetObject((HFONT)SendDlgItemMessage(hdlg, IDC_STATUS, WM_GETFONT, 0, 0), sizeof(lf), &lf);
+ lf.lfWeight = FW_BOLD;
+ hBoldFont = CreateFontIndirect(&lf);
+ }
+ manualAbort = 0;
+ hEventRun = CreateEvent(NULL, TRUE, TRUE, NULL);
+ hEventAbort = CreateEvent(NULL, TRUE, FALSE, NULL);
+ TranslateDialogDefault(hdlg);
+ _beginthread(WorkerThread, 0, NULL);
+ return TRUE;
+
+ case WM_MEASUREITEM:
+ {
+ LPMEASUREITEMSTRUCT mis = (LPMEASUREITEMSTRUCT)lParam;
+ mis->itemWidth = listWidth;
+ mis->itemHeight = fontHeight;
+ }
+ return TRUE;
+
+ case WM_DRAWITEM:
+ {
+ LPDRAWITEMSTRUCT dis = (LPDRAWITEMSTRUCT)lParam;
+ TCHAR str[256];
+ int bold = 0;
+ HFONT hoFont;
+ if ((int)dis->itemID == -1) break;
+ SendMessage(dis->hwndItem, LB_GETTEXT, dis->itemID, (LPARAM)str);
+ switch(dis->itemData&STATUS_CLASSMASK) {
+ case STATUS_MESSAGE:
+ SetTextColor(dis->hDC, RGB(0, 0, 0));
+ break;
+ case STATUS_WARNING:
+ SetTextColor(dis->hDC, RGB(192, 128, 0));
+ break;
+ case STATUS_ERROR:
+ SetTextColor(dis->hDC, RGB(192, 0, 0));
+ break;
+ case STATUS_FATAL:
+ bold = 1;
+ SetTextColor(dis->hDC, RGB(192, 0, 0));
+ break;
+ case STATUS_SUCCESS:
+ bold = 1;
+ SetTextColor(dis->hDC, RGB(0, 192, 0));
+ break;
+ }
+ if (bold) hoFont = (HFONT)SelectObject(dis->hDC, hBoldFont);
+ ExtTextOut(dis->hDC, dis->rcItem.left, dis->rcItem.top, ETO_CLIPPED|ETO_OPAQUE, &dis->rcItem, str, (UINT)_tcslen(str), NULL);
+ if (bold) SelectObject(dis->hDC, hoFont);
+ }
+ return TRUE;
+
+ case WM_PROCESSINGDONE:
+ SetProgressBar(1000);
+ EnableWindow(GetDlgItem(GetParent(hdlg), IDOK), TRUE);
+ if (manualAbort == 1)
+ EndDialog(GetParent(hdlg), 0);
+ else if (manualAbort == 2) {
+ if (opts.bCheckOnly)
+ SendMessage(GetParent(hdlg), WZM_GOTOPAGE, IDD_FILEACCESS, (LPARAM)FileAccessDlgProc);
+ else {
+ SendMessage(GetParent(hdlg), WZM_GOTOPAGE, IDD_CLEANING, (LPARAM)CleaningDlgProc);
+ CloseHandle(opts.hOutFile);
+ opts.hOutFile = NULL;
+ }
+ break;
+ }
+ AddToStatus(STATUS_SUCCESS, TranslateT("Click Next to continue"));
+ break;
+
+ case WZN_CANCELCLICKED:
+ ResetEvent(hEventRun);
+ if (IsWindowEnabled(GetDlgItem(GetParent(hdlg), IDOK))) break;
+ if (MessageBox(hdlg, TranslateT("Processing has not yet completed, if you cancel now then the changes that have currently been made will be rolled back and the original database will be restored. Do you still want to cancel?"), TranslateT("Miranda Database Tool"), MB_YESNO) == IDYES) {
+ manualAbort = 1;
+ SetEvent(hEventAbort);
+ }
+ SetEvent(hEventRun);
+ SetWindowLongPtr(hdlg, DWLP_MSGRESULT, TRUE);
+ return TRUE;
+
+ case WM_COMMAND:
+ switch(LOWORD(wParam)) {
+ case IDC_BACK:
+ ResetEvent(hEventRun);
+ if (!IsWindowEnabled(GetDlgItem(GetParent(hdlg), IDOK))) {
+ if (MessageBox(hdlg, TranslateT("Processing has not yet completed, if you go back now then the changes that have currently been made will be rolled back and the original database will be restored. Do you still want to go back?"), TranslateT("Miranda Database Tool"), MB_YESNO) == IDYES) {
+ manualAbort = 2;
+ SetEvent(hEventAbort);
+ }
+ SetEvent(hEventRun);
+ break;
+ }
+ SetEvent(hEventRun);
+ if (opts.bCheckOnly)
+ SendMessage(GetParent(hdlg), WZM_GOTOPAGE, IDD_FILEACCESS, (LPARAM)FileAccessDlgProc);
+ else
+ SendMessage(GetParent(hdlg), WZM_GOTOPAGE, IDD_CLEANING, (LPARAM)CleaningDlgProc);
+ break;
+ case IDOK:
+ SendMessage(GetParent(hdlg), WZM_GOTOPAGE, IDD_FINISHED, (LPARAM)FinishedDlgProc);
+ break;
+ }
+ break;
+ case WM_DESTROY:
+ if (hEventAbort) {
+ CloseHandle(hEventAbort);
+ hEventAbort = NULL;
+ }
+ if (hEventRun) {
+ CloseHandle(hEventRun);
+ hEventRun = NULL;
+ }
+ if (hBoldFont) {
+ DeleteObject(hBoldFont);
+ hBoldFont = NULL;
+ }
+ break;
+ }
+ return FALSE;
+}
diff --git a/plugins/DbChecker/src/resource.h b/plugins/DbChecker/src/resource.h
new file mode 100644
index 0000000000..a76f82ee1c
--- /dev/null
+++ b/plugins/DbChecker/src/resource.h
@@ -0,0 +1,54 @@
+//{{NO_DEPENDENCIES}}
+// Microsoft Visual C++ generated include file.
+// Used by resource.rc
+//
+#define IDC_BACK 3
+#define IDD_WIZARD 101
+#define IDE_WATERMARK 102
+#define IDI_DBTOOL 102
+#define IDE_HDRLOGO 103
+#define IDI_PROFILEGREEN 104
+#define IDR_DEFAULT1 104
+#define IDI_PROFILEYELLOW 105
+#define IDD_WELCOME 106
+#define IDI_PROFILERED 106
+#define IDD_SELECTDB 107
+#define IDD_OPENERROR 108
+#define IDD_FILEACCESS 109
+#define IDD_CLEANING 110
+#define IDD_PROGRESS 111
+#define IDD_FINISHED 112
+#define IDI_BAD 113
+#define IDC_WATERMARK 1000
+#define IDC_TITLE 1001
+#define IDC_HDRLOGO 1002
+#define IDC_DBLIST 1003
+#define IDC_FILE 1004
+#define IDC_OTHER 1005
+#define IDC_ERRORTEXT 1006
+#define IDC_INUSE 1007
+#define IDC_BACKUP 1008
+#define IDC_AGGRESSIVE 1009
+#define IDC_ERASEHISTORY 1010
+#define IDC_CHECKONLY 1010
+#define IDC_MARKREAD 1011
+#define IDC_PROGRESS 1011
+#define IDC_STATUS 1012
+#define IDC_STBACKUP 1013
+#define IDC_LAUNCHMIRANDA 1015
+#define IDC_DBFILE 1016
+#define IDC_BACKUPFILE 1017
+#define IDC_CHECK1 1018
+#define IDC_CONVERTUTF 1018
+#define IDC_STATIC -1
+
+// Next default values for new objects
+//
+#ifdef APSTUDIO_INVOKED
+#ifndef APSTUDIO_READONLY_SYMBOLS
+#define _APS_NEXT_RESOURCE_VALUE 105
+#define _APS_NEXT_COMMAND_VALUE 40001
+#define _APS_NEXT_CONTROL_VALUE 1019
+#define _APS_NEXT_SYMED_VALUE 101
+#endif
+#endif
diff --git a/plugins/DbChecker/src/selectdb.cpp b/plugins/DbChecker/src/selectdb.cpp
new file mode 100644
index 0000000000..0b61d5c5b6
--- /dev/null
+++ b/plugins/DbChecker/src/selectdb.cpp
@@ -0,0 +1,296 @@
+/*
+Miranda Database Tool
+Copyright (C) 2001-2005 Richard Hughes
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+#include "dbchecker.h"
+
+void GetProfileDirectory(TCHAR* szMirandaDir, TCHAR* szPath, int cbPath)
+{
+ TCHAR szProfileDir[MAX_PATH], szExpandedProfileDir[MAX_PATH], szMirandaBootIni[MAX_PATH];
+
+ lstrcpy(szMirandaBootIni, szMirandaDir);
+ lstrcat(szMirandaBootIni, _T("\\mirandaboot.ini"));
+ GetPrivateProfileString( _T("Database"), _T("ProfileDir"), _T("./Profiles"), szProfileDir, SIZEOF(szProfileDir), szMirandaBootIni);
+ ExpandEnvironmentStrings(szProfileDir, szExpandedProfileDir, SIZEOF(szExpandedProfileDir));
+ _tchdir(szMirandaDir);
+ if ( !_tfullpath(szPath, szExpandedProfileDir, cbPath))
+ lstrcpyn(szPath, szMirandaDir, cbPath);
+ if (szPath[lstrlen(szPath)-1] == '\\')
+ szPath[lstrlen(szPath)-1] = 0;
+}
+
+static int AddDatabaseToList(HWND hwndList, const TCHAR* filename, TCHAR* dir)
+{
+ LV_ITEM lvi;
+ lvi.mask = LVIF_PARAM;
+ lvi.iSubItem = 0;
+ for(lvi.iItem = ListView_GetItemCount(hwndList)-1;lvi.iItem >= 0;lvi.iItem--) {
+ ListView_GetItem(hwndList, &lvi);
+ if (!_tcsicmp((TCHAR*)lvi.lParam, filename))
+ return lvi.iItem;
+ }
+
+ _stat st;
+ if ( _tstat(filename, &st) == -1)
+ return -1;
+
+ int broken = 0;
+ DWORD totalSize = st.st_size;
+ DWORD wasted = 0;
+
+ const TCHAR *pName = _tcsrchr(filename, '\\');
+ if (pName == NULL)
+ pName = (LPTSTR)filename;
+ else
+ pName++;
+
+ TCHAR szName[MAX_PATH];
+ mir_sntprintf(szName, MAX_PATH, _T("%s%s"), dir, pName);
+
+ TCHAR *pDot = _tcsrchr(szName, '.');
+ if (pDot != NULL && !_tcsicmp(pDot, _T(".dat")))
+ *pDot = 0;
+
+ lvi.iItem = 0;
+ lvi.mask = LVIF_TEXT | LVIF_PARAM | LVIF_IMAGE;
+ lvi.iSubItem = 0;
+ lvi.lParam = (LPARAM)_tcsdup(filename);
+ lvi.pszText = szName;
+ if (broken)
+ lvi.iImage = 3;
+ else if (wasted < 1024*128)
+ lvi.iImage = 0;
+ else if (wasted < 1024*256 + (DWORD)(totalSize > 2*1024*1024) ? 256 * 1024 : 0)
+ lvi.iImage = 1;
+ else
+ lvi.iImage = 2;
+
+ int iNewItem = ListView_InsertItem(hwndList, &lvi);
+ TCHAR szSize[20];
+ _stprintf(szSize, _T("%.2lf MB"), totalSize/1048576.0);
+ ListView_SetItemText(hwndList, iNewItem, 1, szSize);
+ if (!broken) {
+ _stprintf(szSize, _T("%.2lf MB"), wasted/1048576.0);
+ ListView_SetItemText(hwndList, iNewItem, 2, szSize);
+ }
+ return iNewItem;
+}
+
+void FindAdd(HWND hdlg, TCHAR *szProfileDir, TCHAR *szPrefix)
+{
+ HANDLE hFind;
+ WIN32_FIND_DATA fd;
+ TCHAR szSearchPath[MAX_PATH], szFilename[MAX_PATH];
+
+ lstrcpy(szSearchPath, szProfileDir);
+ lstrcat(szSearchPath, _T("\\*.*"));
+
+ hFind = FindFirstFile(szSearchPath, &fd);
+ if (hFind != INVALID_HANDLE_VALUE) {
+ do {
+ if ( !(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) || !_tcscmp(fd.cFileName, _T(".")) || !_tcscmp(fd.cFileName, _T("..")))
+ continue;
+
+ wsprintf(szFilename, _T("%s\\%s\\%s.dat"), szProfileDir, fd.cFileName, fd.cFileName);
+ if ( _taccess(szFilename, 0) == 0)
+ AddDatabaseToList(GetDlgItem(hdlg, IDC_DBLIST), szFilename, szPrefix);
+ }
+ while(FindNextFile(hFind, &fd));
+ FindClose(hFind);
+ }
+}
+
+TCHAR *addstring(TCHAR *str, TCHAR *add)
+{
+ _tcscpy(str, add);
+ return str + _tcslen(add) + 1;
+}
+
+INT_PTR CALLBACK SelectDbDlgProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam)
+{
+ INT_PTR bReturn;
+ if (DoMyControlProcessing(hdlg, message, wParam, lParam, &bReturn))
+ return bReturn;
+
+ switch (message) {
+ case WM_INITDIALOG:
+ TranslateDialogDefault(hdlg);
+ {
+ HIMAGELIST hIml = ImageList_Create(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON),
+ (IsWinVerXPPlus() ? ILC_COLOR32 : ILC_COLOR16) | ILC_MASK, 3, 3);
+ ImageList_AddIcon(hIml, LoadIcon(hInst, MAKEINTRESOURCE(IDI_PROFILEGREEN)));
+ ImageList_AddIcon(hIml, LoadIcon(hInst, MAKEINTRESOURCE(IDI_PROFILEYELLOW)));
+ ImageList_AddIcon(hIml, LoadIcon(hInst, MAKEINTRESOURCE(IDI_PROFILERED)));
+ ImageList_AddIcon(hIml, LoadIcon(hInst, MAKEINTRESOURCE(IDI_BAD)));
+ ListView_SetImageList(GetDlgItem(hdlg, IDC_DBLIST), hIml, LVSIL_SMALL);
+ }
+ ListView_SetExtendedListViewStyleEx(GetDlgItem(hdlg, IDC_DBLIST), LVS_EX_FULLROWSELECT, LVS_EX_FULLROWSELECT);
+ {
+ LV_COLUMN lvc;
+ lvc.mask = LVCF_WIDTH | LVCF_FMT | LVCF_TEXT;
+ lvc.cx = 205;
+ lvc.fmt = LVCFMT_LEFT;
+ lvc.pszText = TranslateT("Database");
+ ListView_InsertColumn(GetDlgItem(hdlg, IDC_DBLIST), 0, &lvc);
+ lvc.cx = 68;
+ lvc.fmt = LVCFMT_RIGHT;
+ lvc.pszText = TranslateT("Total size");
+ ListView_InsertColumn(GetDlgItem(hdlg, IDC_DBLIST), 1, &lvc);
+ lvc.pszText = TranslateT("Wasted");
+ ListView_InsertColumn(GetDlgItem(hdlg, IDC_DBLIST), 2, &lvc);
+
+ TCHAR szMirandaPath[MAX_PATH];
+ GetModuleFileName(NULL, szMirandaPath, SIZEOF(szMirandaPath));
+ TCHAR *str2 = _tcsrchr(szMirandaPath, '\\');
+ if (str2 != NULL)
+ *str2 = 0;
+
+ int i = 0;
+ HKEY hKey;
+ TCHAR szProfileDir[MAX_PATH];
+ TCHAR szMirandaProfiles[MAX_PATH];
+ DWORD cbData = SIZEOF(szMirandaPath);
+
+ _tcscpy(szMirandaProfiles, szMirandaPath);
+ _tcscat(szMirandaProfiles, _T("\\Profiles"));
+ GetProfileDirectory(szMirandaPath, szProfileDir, SIZEOF(szProfileDir));
+
+ // search in profile dir (using ini file)
+ if (lstrcmpi(szProfileDir, szMirandaProfiles))
+ FindAdd(hdlg, szProfileDir, _T("[ini]\\"));
+
+ FindAdd(hdlg, szMirandaProfiles, _T("[prf]\\"));
+ // search in current dir (as DBTOOL)
+ 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) {
+ if (RegQueryValueEx(hKey, _T("Path"), NULL, NULL, (PBYTE)szMirandaPath, &cbData) == ERROR_SUCCESS) {
+ if (lstrcmp(szProfileDir, szMirandaPath)) {
+ GetProfileDirectory(szMirandaPath, szProfileDir, SIZEOF(szProfileDir));
+ FindAdd(hdlg, szProfileDir, _T("[reg]\\"));
+ }
+ }
+ RegCloseKey(hKey);
+ }
+ // select
+ if (opts.filename[0])
+ i = AddDatabaseToList(GetDlgItem(hdlg, IDC_DBLIST), opts.filename, _T(""));
+ if (i == -1)
+ 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;
+ }
+ return TRUE;
+
+ case WZN_PAGECHANGING:
+ GetDlgItemText(hdlg, IDC_FILE, opts.filename, SIZEOF(opts.filename));
+ break;
+
+ case WM_COMMAND:
+ switch(LOWORD(wParam)) {
+ case IDC_FILE:
+ if (HIWORD(wParam) == EN_CHANGE)
+ EnableWindow(GetDlgItem(GetParent(hdlg), IDOK), GetWindowTextLength(GetDlgItem(hdlg, IDC_FILE)));
+ break;
+
+ case IDC_OTHER:
+ {
+ OPENFILENAME ofn = {0};
+ TCHAR str[MAX_PATH];
+
+ // _T("Miranda Databases (*.dat)\0*.DAT\0All Files (*)\0*\0");
+ TCHAR *filter, *tmp, *tmp1, *tmp2;
+ tmp1 = TranslateT("Miranda Databases (*.dat)");
+ tmp2 = TranslateT("All Files");
+ filter = tmp = (TCHAR*)_alloca((_tcslen(tmp1)+_tcslen(tmp2)+11)*sizeof(TCHAR));
+ tmp = addstring(tmp, tmp1);
+ tmp = addstring(tmp, _T("*.DAT"));
+ tmp = addstring(tmp, tmp2);
+ tmp = addstring(tmp, _T("*"));
+ *tmp = 0;
+
+ GetDlgItemText(hdlg, IDC_FILE, str, SIZEOF(str));
+ ofn.lStructSize = sizeof(ofn);
+ ofn.hwndOwner = hdlg;
+ ofn.hInstance = NULL;
+ ofn.lpstrFilter = filter;
+ ofn.lpstrDefExt = _T("dat");
+ ofn.lpstrFile = str;
+ ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
+ ofn.nMaxFile = SIZEOF(str);
+ ofn.nMaxFileTitle = MAX_PATH;
+ if (GetOpenFileName(&ofn)) {
+ int i = AddDatabaseToList(GetDlgItem(hdlg, IDC_DBLIST), str, _T(""));
+ if (i == -1)
+ i = 0;
+ ListView_SetItemState(GetDlgItem(hdlg, IDC_DBLIST), i, LVIS_SELECTED, LVIS_SELECTED);
+ }
+ }
+ break;
+
+ case IDC_BACK:
+ SendMessage(GetParent(hdlg), WZM_GOTOPAGE, IDD_WELCOME, (LPARAM)WelcomeDlgProc);
+ 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);
+ break;
+ }
+ break;
+ case WM_NOTIFY:
+ switch(((LPNMHDR)lParam)->idFrom) {
+ case IDC_DBLIST:
+ switch(((LPNMLISTVIEW)lParam)->hdr.code) {
+ case LVN_ITEMCHANGED:
+ {
+ LV_ITEM lvi;
+ lvi.iItem = ListView_GetNextItem(GetDlgItem(hdlg, IDC_DBLIST), -1, LVNI_SELECTED);
+ if (lvi.iItem == -1) break;
+ lvi.mask = LVIF_PARAM;
+ ListView_GetItem(GetDlgItem(hdlg, IDC_DBLIST), &lvi);
+ SetDlgItemText(hdlg, IDC_FILE, (TCHAR*)lvi.lParam);
+ SendMessage(hdlg, WM_COMMAND, MAKEWPARAM(IDC_FILE, EN_CHANGE), (LPARAM)GetDlgItem(hdlg, IDC_FILE));
+ }
+ break;
+ }
+ break;
+ }
+ break;
+
+ case WM_DESTROY:
+ {
+ LV_ITEM lvi;
+ lvi.mask = LVIF_PARAM;
+ for(lvi.iItem = ListView_GetItemCount(GetDlgItem(hdlg, IDC_DBLIST))-1;lvi.iItem >= 0;lvi.iItem--) {
+ ListView_GetItem(GetDlgItem(hdlg, IDC_DBLIST), &lvi);
+ free((char*)lvi.lParam);
+ }
+ }
+ break;
+ }
+ return FALSE;
+}
diff --git a/plugins/DbChecker/src/utf.cpp b/plugins/DbChecker/src/utf.cpp
new file mode 100644
index 0000000000..ffb73d3280
--- /dev/null
+++ b/plugins/DbChecker/src/utf.cpp
@@ -0,0 +1,69 @@
+/*
+
+Miranda IM: the free IM client for Microsoft* Windows*
+
+Copyright 2000-2009 Miranda ICQ/IM project,
+all portions of this codebase are copyrighted to the people
+listed in contributors.txt.
+
+ Copyright 2000 Alexandre Julliard of Wine project
+ (UTF-8 conversion routines)
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+#include "dbchecker.h"
+
+bool is_utf8_string(const char* str)
+{
+ int expect_bytes = 0, utf_found = 0;
+
+ if (!str) return 0;
+
+ while (*str) {
+ if ((*str & 0x80) == 0) {
+ /* Looks like an ASCII character */
+ if (expect_bytes)
+ /* byte of UTF-8 character expected */
+ return 0;
+ }
+ else {
+ /* Looks like byte of an UTF-8 character */
+ if (expect_bytes) {
+ /* expect_bytes already set: first byte of UTF-8 char already seen */
+ if ((*str & 0xC0) != 0x80) {
+ /* again first byte ?!?! */
+ return 0;
+ }
+ }
+ else {
+ /* First byte of the UTF-8 character */
+ /* count initial one bits and set expect_bytes to 1 less */
+ char ch = *str;
+ while (ch & 0x80) {
+ expect_bytes++;
+ ch = (ch & 0x7f) << 1;
+ }
+ }
+ /* OK, next byte of UTF-8 character */
+ /* Decrement number of expected bytes */
+ if (--expect_bytes == 0)
+ utf_found = 1;
+ }
+ str++;
+ }
+
+ return (utf_found && expect_bytes == 0);
+}
diff --git a/plugins/DbChecker/src/version.h b/plugins/DbChecker/src/version.h
new file mode 100644
index 0000000000..58f9cf348c
--- /dev/null
+++ b/plugins/DbChecker/src/version.h
@@ -0,0 +1,5 @@
+#include <m_version.h>
+
+#define __FILEVERSION_STRING MIRANDA_VERSION_FILEVERSION
+#define __VERSION_STRING MIRANDA_VERSION_STRING
+#define __VERSION_DWORD MIRANDA_VERSION_DWORD
diff --git a/plugins/DbChecker/src/welcome.cpp b/plugins/DbChecker/src/welcome.cpp
new file mode 100644
index 0000000000..99d7a3091a
--- /dev/null
+++ b/plugins/DbChecker/src/welcome.cpp
@@ -0,0 +1,70 @@
+/*
+Miranda Database Tool
+Copyright (C) 2001-2005 Richard Hughes
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+#include "dbchecker.h"
+
+INT_PTR CALLBACK WelcomeDlgProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam)
+{
+ static HENHMETAFILE hEmfWatermark;
+ static HFONT hTitleFont;
+
+ INT_PTR bReturn;
+ if ( DoMyControlProcessing(hdlg, message, wParam, lParam, &bReturn))
+ return bReturn;
+
+ switch(message) {
+ case WM_INITDIALOG:
+ {
+ HRSRC hRsrcWatermark = FindResourceA(hInst, MAKEINTRESOURCEA(IDE_WATERMARK), "EMF");
+ HGLOBAL hGlobWatermark = LoadResource(hInst, hRsrcWatermark);
+ hEmfWatermark = SetEnhMetaFileBits(SizeofResource(hInst, hRsrcWatermark), (PBYTE)LockResource(hGlobWatermark));
+ }
+ SendDlgItemMessage(hdlg, IDC_WATERMARK, STM_SETIMAGE, IMAGE_ENHMETAFILE, (LPARAM)hEmfWatermark);
+ {
+ NONCLIENTMETRICS ncm = {0};
+ ncm.cbSize = sizeof(ncm);
+ SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &ncm, 0);
+ LOGFONT TitleLogFont = ncm.lfMessageFont;
+ TitleLogFont.lfWeight = FW_BOLD;
+ lstrcpy(TitleLogFont.lfFaceName, TEXT("Verdana Bold"));
+
+ HDC hdc = GetDC(NULL);
+ INT FontSize = 12;
+ TitleLogFont.lfHeight = 0 - GetDeviceCaps(hdc, LOGPIXELSY) * FontSize / 72;
+ hTitleFont = CreateFontIndirect(&TitleLogFont);
+ ReleaseDC(NULL, hdc);
+ }
+ SendDlgItemMessage(hdlg, IDC_TITLE, WM_SETFONT, (WPARAM)hTitleFont, 0);
+ EnableWindow(GetDlgItem(GetParent(hdlg), IDC_BACK), FALSE);
+ return FALSE;
+
+ case WM_COMMAND:
+ switch(LOWORD(wParam)) {
+ case IDOK:
+ SendMessage(GetParent(hdlg), WZM_GOTOPAGE, IDD_SELECTDB, (LPARAM)SelectDbDlgProc);
+ break;
+ }
+ break;
+
+ case WM_DESTROY:
+ DeleteEnhMetaFile(hEmfWatermark);
+ DeleteObject(hTitleFont);
+ break;
+ }
+ return FALSE;
+}
diff --git a/plugins/DbChecker/src/wizard.cpp b/plugins/DbChecker/src/wizard.cpp
new file mode 100644
index 0000000000..dd10b614ac
--- /dev/null
+++ b/plugins/DbChecker/src/wizard.cpp
@@ -0,0 +1,141 @@
+/*
+Miranda Database Tool
+Copyright 2000-2011 Miranda ICQ/IM project,
+all portions of this codebase are copyrighted to the people
+listed in contributors.txt.
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+#include "dbchecker.h"
+
+static HFONT hBoldFont = NULL;
+static HENHMETAFILE hEmfHeaderLogo = NULL;
+
+static BOOL CALLBACK MyControlsEnumChildren(HWND hwnd, LPARAM lParam)
+{
+ DWORD style = GetWindowLongPtr(hwnd, GWL_STYLE);
+ DWORD exstyle = GetWindowLongPtr(hwnd, GWL_EXSTYLE);
+ char szClass[64];
+ int makeBold = 0;
+
+ GetClassNameA(hwnd, szClass, sizeof(szClass));
+ if (!strcmp(szClass, "Static")) {
+ if (((style & SS_TYPEMASK) == SS_LEFT || (style & SS_TYPEMASK) == SS_CENTER || (style & SS_TYPEMASK) == SS_RIGHT) && exstyle & WS_EX_CLIENTEDGE)
+ makeBold = 1;
+ }
+ else if (!strcmp(szClass, "Button")) {
+ if (exstyle&WS_EX_CLIENTEDGE)
+ makeBold = 1;
+ }
+ if (makeBold) {
+ if (hBoldFont == NULL) {
+ LOGFONT lf;
+ hBoldFont = (HFONT)SendMessage(hwnd, WM_GETFONT, 0, 0);
+ GetObject(hBoldFont, sizeof(lf), &lf);
+ lf.lfWeight = FW_BOLD;
+ hBoldFont = CreateFontIndirect(&lf);
+ }
+ SendMessage(hwnd, WM_SETFONT, (WPARAM)hBoldFont, 0);
+ SetWindowLongPtr(hwnd, GWL_EXSTYLE, exstyle&~WS_EX_CLIENTEDGE);
+ SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_FRAMECHANGED);
+ }
+ return TRUE;
+}
+
+int DoMyControlProcessing(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam, INT_PTR *bReturn)
+{
+ switch(message) {
+ case WM_INITDIALOG:
+ EnumChildWindows(hdlg, MyControlsEnumChildren, 0);
+ if (hEmfHeaderLogo == NULL) {
+ HRSRC hRsrc = FindResourceA(hInst, MAKEINTRESOURCEA(IDE_HDRLOGO), "EMF");
+ HGLOBAL hGlob = LoadResource(hInst, hRsrc);
+ hEmfHeaderLogo = SetEnhMetaFileBits(SizeofResource(hInst, hRsrc), (PBYTE)LockResource(hGlob));
+ }
+ SendDlgItemMessage(hdlg, IDC_HDRLOGO, STM_SETIMAGE, IMAGE_ENHMETAFILE, (LPARAM)hEmfHeaderLogo);
+ break;
+
+ case WM_CTLCOLORSTATIC:
+ if ((GetWindowLongPtr((HWND)lParam, GWL_STYLE)&0xFFFF) == 0) {
+ char szText[256];
+ GetWindowTextA((HWND)lParam, szText, sizeof(szText));
+ if (!strcmp(szText, "whiterect")) {
+ SetTextColor((HDC)wParam, RGB(255, 255, 255));
+ SetBkColor((HDC)wParam, RGB(255, 255, 255));
+ SetBkMode((HDC)wParam, OPAQUE);
+ *bReturn = (INT_PTR)GetStockObject(WHITE_BRUSH);
+ return TRUE;
+ }
+ else {
+ SetBkMode((HDC)wParam, TRANSPARENT);
+ *bReturn = (INT_PTR)GetStockObject(NULL_BRUSH);
+ return TRUE;
+ }
+ }
+ break;
+ }
+ return FALSE;
+}
+
+INT_PTR CALLBACK WizardDlgProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam)
+{
+ static HWND hdlgPage;
+
+ switch(message) {
+ case WM_INITDIALOG:
+ SendMessage(hdlg, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(hInst, MAKEINTRESOURCE(IDI_DBTOOL)));
+ hdlgPage = NULL;
+ SendMessage(hdlg, WZM_GOTOPAGE, IDD_WELCOME, (LPARAM)WelcomeDlgProc);
+ TranslateDialogDefault(hdlg);
+ return TRUE;
+
+ case WZM_GOTOPAGE:
+ if (hdlgPage != NULL) DestroyWindow(hdlgPage);
+ EnableWindow(GetDlgItem(hdlg, IDC_BACK), TRUE);
+ EnableWindow(GetDlgItem(hdlg, IDOK), TRUE);
+ EnableWindow(GetDlgItem(hdlg, IDCANCEL), TRUE);
+ SetDlgItemText(hdlg, IDCANCEL, TranslateT("Cancel"));
+ hdlgPage = CreateDialog(hInst, MAKEINTRESOURCE(wParam), hdlg, (DLGPROC)lParam);
+ TranslateDialogDefault(hdlgPage);
+ SetWindowPos(hdlgPage, 0, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOSIZE);
+ ShowWindow(hdlgPage, SW_SHOW);
+ break;
+
+ case WM_COMMAND:
+ switch(LOWORD(wParam)) {
+ case IDC_BACK:
+ case IDOK:
+ SendMessage(hdlgPage, WZN_PAGECHANGING, wParam, 0);
+ SendMessage(hdlgPage, message, wParam, lParam);
+ break;
+ case IDCANCEL:
+ if (SendMessage(hdlgPage, WZN_CANCELCLICKED, 0, 0)) break;
+ EndDialog(hdlg, 0);
+ break;
+ }
+ break;
+
+ case WM_DESTROY:
+ if (opts.hFile)
+ CloseHandle(opts.hFile);
+ if (opts.hOutFile)
+ CloseHandle(opts.hOutFile);
+ DestroyWindow(hdlgPage);
+ if (hBoldFont != NULL) DeleteObject(hBoldFont);
+ if (hEmfHeaderLogo != NULL) DeleteEnhMetaFile(hEmfHeaderLogo);
+ break;
+ }
+ return FALSE;
+}
diff --git a/plugins/DbChecker/src/worker.cpp b/plugins/DbChecker/src/worker.cpp
new file mode 100644
index 0000000000..834a40f308
--- /dev/null
+++ b/plugins/DbChecker/src/worker.cpp
@@ -0,0 +1,79 @@
+/*
+Miranda Database Tool
+Copyright (C) 2001-2005 Richard Hughes
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+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)
+{
+ int task, firstTime;
+ 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;
+
+ for(task = 0;;) {
+ if (callback.spaceProcessed/(callback.spaceUsed/1000+1) > sp) {
+ sp = callback.spaceProcessed/(callback.spaceUsed/1000+1);
+ SetProgressBar(sp);
+ }
+ WaitForSingleObject(hEventRun, INFINITE);
+ if (WaitForSingleObject(hEventAbort, 0) == WAIT_OBJECT_0) {
+ AddToStatus(STATUS_FATAL, TranslateT("Processing aborted by user"));
+ break;
+ }
+
+ int ret = dblink->CheckDb(&callback, task, firstTime);
+ firstTime = 0;
+ if (ret == ERROR_NO_MORE_ITEMS) {
+ AddToStatus(STATUS_MESSAGE, TranslateT("Elapsed time: %d sec"), time(NULL)-ts);
+ if (errorCount)
+ AddToStatus(STATUS_SUCCESS, TranslateT("All tasks completed but with errors (%d)"), errorCount);
+ else
+ AddToStatus(STATUS_SUCCESS, TranslateT("All tasks completed successfully"));
+ break;
+ }
+ else if (ret != ERROR_SUCCESS)
+ break;
+
+ task++;
+ firstTime = 1;
+ }
+
+ ProcessingDone();
+}