Skip to content

Commit

Permalink
Warn the user when multiple database versions are found
Browse files Browse the repository at this point in the history
  • Loading branch information
smowton committed Apr 13, 2019
1 parent 9a8cc43 commit a5588b7
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 17 deletions.
45 changes: 39 additions & 6 deletions Source/incredimail_convert.c
Original file line number Diff line number Diff line change
Expand Up @@ -534,8 +534,12 @@ enum INCREDIMAIL_VERSIONS FindIncredimailVersion(const char *file_or_directory)
hFind = FindFirstFile(temp_path, &FindFileData);
FindClose(hFind);

const char *found_files[3];
size_t n_tests_succeeded = 0;

if (hFind != INVALID_HANDLE_VALUE) {
ret = INCREDIMAIL_XE;
found_files[n_tests_succeeded++] = "* At least one .imh file, as used by Incredimail XE\n";
}

// is there an Incredimail 2 database, i.e. containers.db
Expand All @@ -544,13 +548,42 @@ enum INCREDIMAIL_VERSIONS FindIncredimailVersion(const char *file_or_directory)

if (testimdb(temp_path)) {
ret = INCREDIMAIL_2;
found_files[n_tests_succeeded++] = "* A containers.db file, as used by earlier versions of Incredimail 2\n";
}
else {
// Is there a messageStore.db, indicating maildir format?
strcpy(temp_path, file_or_directory);
strcat(temp_path, "\\messageStore.db");
if (testimdb(temp_path))
ret = INCREDIMAIL_2_MAILDIR;

// Is there a messageStore.db, indicating maildir format?
strcpy(temp_path, file_or_directory);
strcat(temp_path, "\\messageStore.db");
if (testimdb(temp_path)) {
ret = INCREDIMAIL_2_MAILDIR;
found_files[n_tests_succeeded++] = "* A MessageStore.db file, as used by newer versions of Incredimail 2\n";
}

if (n_tests_succeeded > 1) {
const char *msgHeader = "Multiple Incredimail database types were found:\n";
const char *msgFooter = "The last one (as the newest format) has been selected for now, but you might want to try selecting an individual database to convert";
size_t msgLength = strlen(msgHeader) + strlen(msgFooter);
for (size_t i = 0; i < n_tests_succeeded; ++i) {
msgLength += strlen(found_files[i]);
}
msgLength++; // For final null terminator

char *msg = (char *)malloc(msgLength);
msg[0] = '\0';
if (!msg) {
MessageBox(global_hwnd, msg, "Failed to allocate memory in FindIncredimailVersion", MB_OK);
exit(1);
}

strcat_s(msg, msgLength, msgHeader);
for (size_t i = 0; i < n_tests_succeeded; ++i) {
strcat_s(msg, msgLength, found_files[i]);
}
strcat_s(msg, msgLength, msgFooter);

MessageBox(global_hwnd, msg, "Warning", MB_OK);

free(msg);
}

return ret;
Expand Down
22 changes: 11 additions & 11 deletions Source/winmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -735,19 +735,19 @@ enum INCREDIMAIL_VERSIONS incredimail_version;
}
} else {

// This looks for *.imm, for the IncrediMail XE or non-maildir case.
total_count = FindDatabaseFiles( im_database_filename, temp_file_listing );
if (total_count < 0) {
// See if we can find an IncrediMail 2 Maildir store instead:
std::string storename = std::string(im_database_filename) + "\\MessageStore.db";
struct _stat buf;
if (!_stat(storename.c_str(), &buf))
process_emails2(storename.c_str(), im_attachments_directory);
else {
MessageBox(global_hwnd, "No .imm files and no MessageStore.db found within given directory", "Error!", MB_OK);
}
incredimail_version = FindIncredimailVersion(im_database_filename);

if (incredimail_version == INCREDIMAIL_2_MAILDIR) {
std::string messagestore_path = std::string(im_database_filename) + "\\MessageStore.db";
process_emails2(messagestore_path.c_str(), im_attachments_directory);
return;
}
else if (incredimail_version == INCREDIMAIL_VERSION_UNKNOWN) {
MessageBox(global_hwnd, "No .imm files and no MessageStore.db found within given directory", "Error!", MB_OK);
exit(1);
}

total_count = FindDatabaseFiles(im_database_filename, temp_file_listing);

// set the progress bar 2
SendDlgItemMessage( global_hwnd, IDC_PROGRESS2, PBM_SETRANGE, 0, (LPARAM) MAKELPARAM (0, total_count));
Expand Down

0 comments on commit a5588b7

Please sign in to comment.