summaryrefslogtreecommitdiff
path: root/db3x_autobackups/backup.c
diff options
context:
space:
mode:
Diffstat (limited to 'db3x_autobackups/backup.c')
-rw-r--r--db3x_autobackups/backup.c26
1 files changed, 10 insertions, 16 deletions
diff --git a/db3x_autobackups/backup.c b/db3x_autobackups/backup.c
index 8eb26da..92560d0 100644
--- a/db3x_autobackups/backup.c
+++ b/db3x_autobackups/backup.c
@@ -22,7 +22,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "commonheaders.h"
-#include "database.h"
#include "options.h"
#define SHOW_PROGRESS_TIME 1000 // show progress window when backup time exceeds this many milliseconds
@@ -37,6 +36,8 @@ struct DBHeader dbHeader;
UINT timer_id = 0;
+void Map();
+void UnMap();
BOOL CALLBACK DlgProcProgress(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
@@ -153,34 +154,25 @@ int Backup() {
EnterCriticalSection(&csDbAccess);
+ UnMap();
+
file_size = GetFileSize(hDbFile, 0);
if(file_size == 0) {
+ Map();
LeaveCriticalSection(&csDbAccess);
CloseHandle(hBackupFile);
DestroyWindow(progress_dialog);
return 1;
}
- SetFilePointer(hDbFile, sizeof(dbHeader), 0, FILE_BEGIN);
-
- if(WriteFile(hBackupFile,&dbHeader,sizeof(dbHeader),&bytes_written,NULL) == TRUE) {
- total_bytes_copied += bytes_written;
- if(!options.disable_progress) {
- SendMessage(prog, PBM_SETPOS, (WPARAM)(int)(100.0 * total_bytes_copied / file_size), 0);
- UpdateWindow(progress_dialog);
- }
- } else {
- LeaveCriticalSection(&csDbAccess);
- CloseHandle(hBackupFile);
- DestroyWindow(progress_dialog);
- return 1;
- }
+ SetFilePointer(hDbFile, 0, 0, FILE_BEGIN);
while(ReadFile(hDbFile, buff, sizeof(buff), &bytes_read, 0) == TRUE && bytes_read > 0
&& GetWindowLong(progress_dialog, GWL_USERDATA) == 0)
{
if(!WriteFile(hBackupFile, buff, bytes_read, &bytes_written, 0)) {
+ Map();
LeaveCriticalSection(&csDbAccess);
CloseHandle(hBackupFile);
DestroyWindow(progress_dialog);
@@ -205,6 +197,7 @@ int Backup() {
UpdateWindow(progress_dialog);
}
}
+ Map();
LeaveCriticalSection(&csDbAccess);
CloseHandle(hBackupFile);
@@ -220,7 +213,8 @@ int Backup() {
return 0;
}
- DestroyWindow(progress_dialog);
+ if(!options.disable_progress)
+ DestroyWindow(progress_dialog);
return 1;
}