Beispiel #1
0
// enumerate all plugins that had valid DatabasePluginInfo()
int tryOpenDatabase(const TCHAR *tszProfile)
{
	bool bWasOpened = false;

	for (int i=arDbPlugins.getCount()-1; i >= 0; i--) {
		DATABASELINK *p = arDbPlugins[i];

		// liked the profile?
		int err = p->grokHeader(tszProfile);
		if (err != ERROR_SUCCESS) { // smth went wrong
			switch (err) {
			case EGROKPRF_CANTREAD:
			case EGROKPRF_UNKHEADER:
				// just not supported.
				continue;
			}
			return err;
		}

		bWasOpened = true;

		// try to load database
		MIDatabase *pDb = p->Load(tszProfile);
		if (pDb) {
			fillProfileName(tszProfile);
			currDblink = p;
			db_setCurrent(currDb = pDb);
			return 0;
		}
	}

	return (bWasOpened) ? -1 : EGROKPRF_CANTREAD;
}
Beispiel #2
0
static bool CheckBroken(const TCHAR *ptszFullPath)
{
	DATABASELINK *dblink = FindDatabasePlugin(ptszFullPath);
	if (dblink == NULL || dblink->CheckDB == NULL)
		return true;

	return dblink->grokHeader(ptszFullPath) != EGROKPRF_NOERROR;
}
Beispiel #3
0
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;
}
Beispiel #4
0
// enumerate all plugins that had valid DatabasePluginInfo()
static int tryCreateDatabase(const TCHAR* ptszProfile)
{
	TCHAR* tszProfile = NEWTSTR_ALLOCA(ptszProfile);
	CreatePathToFileT(tszProfile);

	for (int i=0; i < arDbPlugins.getCount(); i++) {
		DATABASELINK* p = arDbPlugins[i];

		int err = p->makeDatabase(tszProfile);
		if (err == ERROR_SUCCESS) {
			g_bDbCreated = true;
			MIDatabase *pDb = p->Load(tszProfile);
			if (pDb != NULL) {
				fillProfileName(tszProfile);
				currDblink = p;
				db_setCurrent(currDb = pDb);
				return 0;
			}
			return 1;
		}
	}
	return 1;
}
Beispiel #5
0
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);
    }
}