static bool CheckBroken(const TCHAR *ptszFullPath) { DATABASELINK *dblink = FindDatabasePlugin(ptszFullPath); if (dblink == NULL || dblink->CheckDB == NULL) return true; return dblink->grokHeader(ptszFullPath) != EGROKPRF_NOERROR; }
int OpenDatabase(HWND hdlg, INT iNextPage) { TCHAR tszMsg[1024]; int error = 0; 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 false; } if (dblink->CheckDB == NULL) { mir_sntprintf(tszMsg, SIZEOF(tszMsg), TranslateT("Database driver '%s' doesn't support checking."), TranslateTS(dblink->szFullName)); goto LBL_Error; } opts.dbChecker = dblink->CheckDB(opts.filename, &error); if (opts.dbChecker == NULL) { if ((opts.error = GetLastError()) == 0) opts.error = error; PostMessage(GetParent(hdlg), WZM_GOTOPAGE, IDD_OPENERROR, (LPARAM)OpenErrorDlgProc); return true; } opts.dblink = dblink; } // force check if (error == EGROKPRF_OBSOLETE) { opts.bAggressive = opts.bBackup = true; PostMessage(GetParent(hdlg), WZM_GOTOPAGE, IDD_PROGRESS, (LPARAM)ProgressDlgProc); } else if (iNextPage == IDD_FILEACCESS) PostMessage(GetParent(hdlg), WZM_GOTOPAGE, IDD_FILEACCESS, (LPARAM)FileAccessDlgProc); else PostMessage(GetParent(hdlg), WZM_GOTOPAGE, IDD_PROGRESS, (LPARAM)ProgressDlgProc); return true; }
BOOL EnumProfilesForList(TCHAR *fullpath, TCHAR *profile, LPARAM lParam) { ProfileEnumData *ped = (ProfileEnumData*)lParam; HWND hwndList = GetDlgItem(ped->hwnd, IDC_PROFILELIST); TCHAR sizeBuf[64]; bool bFileExists = false, bFileLocked = true; TCHAR *p = _tcsrchr(profile, '.'); _tcscpy(sizeBuf, _T("0 KB")); if (p != NULL) *p = 0; LVITEM item = { 0 }; item.mask = LVIF_TEXT | LVIF_IMAGE; item.pszText = profile; item.iItem = 0; struct _stat statbuf; if (_tstat(fullpath, &statbuf) == 0) { if (statbuf.st_size > 1000000) { mir_sntprintf(sizeBuf, SIZEOF(sizeBuf), _T("%.3lf"), (double)statbuf.st_size / 1048576.0); _tcscpy(sizeBuf + 5, _T(" MB")); } else { mir_sntprintf(sizeBuf, SIZEOF(sizeBuf), _T("%.3lf"), (double)statbuf.st_size / 1024.0); _tcscpy(sizeBuf + 5, _T(" KB")); } bFileExists = TRUE; bFileLocked = !fileExist(fullpath); } item.iImage = bFileLocked; int iItem = SendMessage(hwndList, LVM_INSERTITEM, 0, (LPARAM)&item); if (lstrcmpi(ped->szProfile, fullpath) == 0) ListView_SetItemState(hwndList, iItem, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED); item.iItem = iItem; item.iSubItem = 2; item.pszText = sizeBuf; SendMessage(hwndList, LVM_SETITEMTEXT, iItem, (LPARAM)&item); if (bFileExists) { TCHAR szPath[MAX_PATH]; _tcscpy(szPath, fullpath); LVITEM item2; item2.mask = LVIF_TEXT; item2.iItem = iItem; DATABASELINK* dblink = FindDatabasePlugin(szPath); if (dblink != NULL) { if (bFileLocked) { // file locked item2.pszText = TranslateT("<In use>"); item2.iSubItem = 1; SendMessage(hwndList, LVM_SETITEMTEXT, iItem, (LPARAM)&item2); } else { item.pszText = TranslateTS(dblink->szFullName); item.iSubItem = 1; SendMessage(hwndList, LVM_SETITEMTEXT, iItem, (LPARAM)&item); } } } return TRUE; }
void MirandaImport(HWND hdlg) { DWORD dwTimer; char* pszModuleName = NULL; // Just to keep the macros happy hdlgProgress = hdlg; if ((dstDb = GetCurrentDatabase()) == NULL) { AddMessage(LPGENT("Error retrieving current profile, exiting.")); return; } DATABASELINK *dblink = FindDatabasePlugin(importFile); if (dblink == NULL) { AddMessage(LPGENT("There's no database driver to open the input file, exiting.")); return; } if ((srcDb = dblink->Load(importFile, TRUE)) == NULL) { AddMessage(LPGENT("Error loading source file, exiting.")); return; } // Reset statistics nSkippedEvents = 0; nDupes = 0; nContactsCount = 0; nMessagesCount = 0; nGroupsCount = 0; nSkippedContacts = 0; SetProgress(0); // Get number of contacts int nNumberOfContacts = srcDb->GetContactCount(); AddMessage(LPGENT("Number of contacts in database: %d"), nNumberOfContacts); AddMessage(_T("")); // Configure database for fast writing dstDb->SetCacheSafetyMode(FALSE); // Start benchmark timer dwTimer = time(NULL); // Import Groups if (nImportOption == IMPORT_ALL || (nCustomOptions & IOPT_GROUPS)) { AddMessage(LPGENT("Importing groups.")); nGroupsCount = ImportGroups(); if (nGroupsCount == -1) AddMessage(LPGENT("Group import failed.")); AddMessage(_T("")); } // End of Import Groups // Import Contacts if (nImportOption != IMPORT_CUSTOM || (nCustomOptions & IOPT_CONTACTS)) { AddMessage(LPGENT("Importing contacts.")); int i = 1; MCONTACT hContact = srcDb->FindFirstContact(); while (hContact != NULL) { if (ImportContact(hContact)) nContactsCount++; // Update progress bar SetProgress(100 * i / nNumberOfContacts); i++; // Process queued messages MSG msg; if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } // Get next contact in chain hContact = srcDb->FindNextContact(hContact); } } else AddMessage(LPGENT("Skipping new contacts import.")); AddMessage(_T("")); // End of Import Contacts // Import history if (nImportOption != IMPORT_CONTACTS) { // Import NULL contact message chain if (nImportOption == IMPORT_ALL || (nCustomOptions & IOPT_SYSTEM)) { AddMessage(LPGENT("Importing system history.")); int protoCount; PROTOACCOUNT **accs; CallService(MS_PROTO_ENUMACCOUNTS, (WPARAM)&protoCount, (LPARAM)&accs); if (protoCount > 0) ImportHistory(NULL, accs, protoCount); } else AddMessage(LPGENT("Skipping system history import.")); AddMessage(_T("")); // Import other contact messages if (nImportOption == IMPORT_ALL || (nCustomOptions & 2046)) { // 2 - 1024 types AddMessage(LPGENT("Importing history.")); MCONTACT hContact = srcDb->FindFirstContact(); for (int i = 1; hContact != NULL; i++) { ImportHistory(hContact, NULL, NULL); SetProgress(100 * i / nNumberOfContacts); hContact = srcDb->FindNextContact(hContact); } } else AddMessage(LPGENT("Skipping history import.")); AddMessage(_T("")); } // End of Import History // Restore database writing mode dstDb->SetCacheSafetyMode(TRUE); // Clean up before exit dblink->Unload(srcDb); // Stop timer dwTimer = time(NULL) - dwTimer; // Print statistics AddMessage(LPGENT("Import completed in %d seconds."), dwTimer); SetProgress(100); AddMessage((nImportOption == IMPORT_CONTACTS) ? LPGENT("Added %d contacts and %d groups.") : LPGENT("Added %d contacts, %d groups and %d events."), nContactsCount, nGroupsCount, nMessagesCount); if (nImportOption != IMPORT_CONTACTS) { if (nSkippedContacts) AddMessage(LPGENT("Skipped %d contacts."), nSkippedContacts); AddMessage((nImportOption == IMPORT_CUSTOM) ? LPGENT("Skipped %d duplicates and %d filtered events.") : LPGENT("Skipped %d duplicates."), nDupes, nSkippedEvents); } }