From df77e258df8cec689a001ec92031538298661b1b Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 27 Jul 2012 15:33:58 +0000 Subject: merge of dbtool & database plugins git-svn-id: http://svn.miranda-ng.org/main/trunk@1213 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/DbChecker/src/dbchecker.h | 16 ------- plugins/DbChecker/src/selectdb.cpp | 3 +- plugins/DbChecker/src/worker.cpp | 85 +++++++++++++++++++++++++++++++++++--- 3 files changed, 81 insertions(+), 23 deletions(-) (limited to 'plugins/DbChecker/src') diff --git a/plugins/DbChecker/src/dbchecker.h b/plugins/DbChecker/src/dbchecker.h index d333f51b02..9554ff7134 100644 --- a/plugins/DbChecker/src/dbchecker.h +++ b/plugins/DbChecker/src/dbchecker.h @@ -84,23 +84,7 @@ void OpenDatabase(HWND hdlg, INT iNextPage); #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/selectdb.cpp b/plugins/DbChecker/src/selectdb.cpp index c1a6e75e90..a8b40af3d8 100644 --- a/plugins/DbChecker/src/selectdb.cpp +++ b/plugins/DbChecker/src/selectdb.cpp @@ -41,12 +41,13 @@ LBL_Error: } int error = 0; - opts.dbChecker = opts.dblink->CheckDB(opts.filename, &error); + opts.dbChecker = dblink->CheckDB(opts.filename, &error); if (opts.dbChecker == NULL) { opts.error = error; SendMessage(GetParent(hdlg), WZM_GOTOPAGE, IDD_OPENERROR, (LPARAM)OpenErrorDlgProc); return; } + opts.dblink = dblink; } if (iNextPage == IDD_FILEACCESS) diff --git a/plugins/DbChecker/src/worker.cpp b/plugins/DbChecker/src/worker.cpp index 9fa3e7aa2b..6847a47f13 100644 --- a/plugins/DbChecker/src/worker.cpp +++ b/plugins/DbChecker/src/worker.cpp @@ -28,6 +28,24 @@ void __cdecl WorkerThread(void *unused) AddToStatus(STATUS_MESSAGE, TranslateT("Database worker thread activated")); + _tcscpy(opts.workingFilename,opts.filename); + + if (opts.bCheckOnly) { + _tcscpy(opts.outputFilename, TranslateT("")); + opts.hOutFile = INVALID_HANDLE_VALUE; + } + else { + _tcscpy(opts.outputFilename,opts.filename); + *_tcsrchr(opts.outputFilename,'.') = 0; + _tcscat(opts.outputFilename,TranslateT(" (Output).dat")); + opts.hOutFile = CreateFile(opts.outputFilename,GENERIC_WRITE,FILE_SHARE_READ,NULL,CREATE_ALWAYS,FILE_FLAG_SEQUENTIAL_SCAN,NULL); + if (opts.hOutFile == INVALID_HANDLE_VALUE) { + AddToStatus(STATUS_FATAL,TranslateT("Can't create output file (%u)"),GetLastError()); + ProcessingDone(); + return; + } + } + DWORD sp = 0; firstTime = 0; @@ -36,6 +54,14 @@ void __cdecl WorkerThread(void *unused) callback.spaceUsed = 1; callback.spaceProcessed = 0; callback.pfnAddLogMessage = AddToStatus; + callback.hOutFile = opts.hOutFile; + callback.bCheckOnly = opts.bCheckOnly; + callback.bBackup = opts.bBackup; + callback.bAggressive = opts.bAggressive; + callback.bEraseHistory = opts.bEraseHistory; + callback.bMarkRead = opts.bMarkRead; + callback.bConvertUtf = opts.bConvertUtf; + opts.dbChecker->Start(&callback); for(task = 0;;) { if (callback.spaceProcessed/(callback.spaceUsed/1000+1) > sp) { @@ -48,9 +74,9 @@ void __cdecl WorkerThread(void *unused) break; } - int ret = opts.dbChecker->CheckDb(&callback, task, firstTime); + int ret = opts.dbChecker->CheckDb(task, firstTime); firstTime = 0; - if (ret == ERROR_NO_MORE_ITEMS) { + if (ret == ERROR_OUT_OF_PAPER) { 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); @@ -58,12 +84,59 @@ void __cdecl WorkerThread(void *unused) AddToStatus(STATUS_SUCCESS, TranslateT("All tasks completed successfully")); break; } + else if (ret == ERROR_NO_MORE_ITEMS) { + task++; + firstTime = 1; + } else if (ret != ERROR_SUCCESS) break; - - task++; - firstTime = 1; } - + + opts.dbChecker->Destroy(); + opts.dbChecker = NULL; + + if ( opts.hOutFile ) { + CloseHandle(opts.hOutFile); + opts.hOutFile = NULL; + } + + if (errorCount && !opts.bBackup && !opts.bCheckOnly) { + time_t dlg_ts = time(NULL); + if (IDYES == MessageBox(NULL, + TranslateT("Errors were encountered, however you selected not to backup the original database. It is strongly recommended that you do so in case important data was omitted. Do you wish to keep a backup of the original database?"), + TranslateT("Miranda Database Tool"), MB_YESNO)) + opts.bBackup = 1; + ts += time(NULL) - dlg_ts; + } + + if (opts.bBackup) { + TCHAR dbPath[MAX_PATH],dbFile[MAX_PATH]; + _tcscpy(dbPath, opts.filename); + TCHAR* str2 = _tcsrchr(dbPath, '\\'); + if (str2 != NULL) { + _tcscpy(dbFile, str2+1); + *str2 = 0; + } + else { + _tcscpy(dbFile, dbPath); + dbPath[0] = 0; + } + for (int i = 1;;i++) { + if (i == 1) wsprintf(opts.backupFilename,TranslateT("%s\\Backup of %s"),dbPath,dbFile); + else wsprintf(opts.backupFilename,TranslateT("%s\\Backup (%d) of %s"),dbPath,i,dbFile); + if (_taccess(opts.backupFilename,0) == -1) break; + } + + if ( !MoveFile(opts.filename,opts.backupFilename)) + AddToStatus(STATUS_WARNING,TranslateT("Unable to rename original file")); + } + else if (!opts.bCheckOnly) + if ( !DeleteFile(opts.filename)) + AddToStatus(STATUS_WARNING,TranslateT("Unable to delete original file")); + + if (!opts.bCheckOnly) + if ( !MoveFile(opts.outputFilename,opts.filename)) + AddToStatus(STATUS_WARNING,TranslateT("Unable to rename output file")); + ProcessingDone(); } -- cgit v1.2.3