Example #1
0
extern "C" __declspec(dllexport) int Load(void)
{
	mir_getLP(&pluginInfoEx);

	hwnd2mainWindow = hwnd2watchedVarsWindow = hwnd2importWindow = 0;
	hRestore = NULL;
	g_db = GetCurrentDatabase();

	hSettingsChangedHook = HookEvent(ME_DB_CONTACT_SETTINGCHANGED, DBSettingChanged);
	hOptInitHook = HookEvent(ME_OPT_INITIALISE, OptInit);
	hPreShutdownHook = HookEvent(ME_SYSTEM_PRESHUTDOWN, PreShutdown);
	hModulesLoadedHook = HookEvent(ME_SYSTEM_MODULESLOADED, ModulesLoaded);

	sMenuCommand = CreateServiceFunction("DBEditorpp/MenuCommand", DBEditorppMenuCommand);
	sImport = CreateServiceFunction("DBEditorpp/Import", ImportFromFile);

	sServicemodeLaunch = CreateServiceFunction(MS_SERVICEMODE_LAUNCH, ServiceMode);

	// Ensure that the common control DLL is loaded.
	INITCOMMONCONTROLSEX icex;
	icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
	icex.dwICC = ICC_LISTVIEW_CLASSES;
	InitCommonControlsEx(&icex);

	ZeroMemory(&WatchListArray, sizeof(WatchListArray));
	return 0;
}
Example #2
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);
    }
}