Ejemplo n.º 1
0
//-----------------------------------------------------------------------------
// Function:    PrintMenu
// Purpose:     Prints a menu, retrieves the user selection, calls the handler, loops.
//              Returns when "Quit" is selected from the menu
// Parameters:  None
//
void RunMenu()
{
    HRESULT hr;
    WCHAR wzBuff[INPUT_BUFSIZE];
    int nInput;

    // Continuously show the menu to user and respond to their request
    //
    while (TRUE)
    {
        PrintMenu();

        fflush(stdin);
        hr = StringCbGets(wzBuff, sizeof(wzBuff));

        if (FAILED(hr))
        {
            wprintf (L"Invalid input, expected a number between 1 and 25 or Q to quit.\n");
            continue;
        }

        if  ((wcsncmp(wzBuff, L"Q", INPUT_BUFSIZE) == 0) || (wcsncmp(wzBuff, L"q", INPUT_BUFSIZE) == 0))
        {
            // break out of while loop.
            //
            break;
        }

        // since wtoi can't distinguish between 0 and an error, note that valid values start at 1, not 0    
        nInput = _wtoi(wzBuff);
        if (nInput < 1  || nInput > 25)
        {
            printf ("Invalid input, expected a number between 1 and 25 or Q to quit.\n");
            continue;
        }

        switch (nInput)
        {
            case 1:
                SignIn();
                break;

            case 2:
                SignOut();
                break;

            case 3:
                SignInOptions();
                break;

            case 4:
                SetEndpointName();
                break;

            case 5:
                GetEndpointName();
                break;

            case 6:
                DisplayEndpointInformation();
                break;

            case 7:
                EnumeratePeopleNearMe();
                break;

            case 8:
                AddEndpointAsContact();
                break;

            case 9:
                ExportContact();
                break;

            case 10:
                ParseContact();
                break;
            
            case 11:
                ImportContact();
                break;
            
            case 12:
                DeleteContact();
                break;

            case 13:
                EnumContacts();
                break;
            
            case 14:
                SetWatching();
                break;

            case 15:
                SetWatchPermissions();
                break;

            case 16:
                GetPresenceInformation();
                break;
                    
            case 17:
                SetPresenceInformation();
                break;

            case 18:
                SubscribeEndpointData();
                break;

            case 19:
                UnsubscribeEndpointData();
                break;

            case 20:
                PublishEndpointObject();
                break;

            case 21:
                DeleteEndpointObject();
                break;
                                    
            case 22:
                RegisterApplication();
                break;

            case 23:
                UnregisterApplication();
                break;

            case 24:
                DisplayApplicationRegistrations();
                break;

            case 25:
                SendInvite();
                break;

            default:
                wprintf(L"Invalid selection.\n");
                break;

        }

        //Pause so that our output doesn't scroll
        //off the screen before the user gets a change to
        //read it.
         wprintf(L"\n\nPress <ENTER> to continue.\n");
        fflush(stdin);
        (void)StringCbGets(wzBuff, sizeof(wzBuff));
    }
}
Ejemplo n.º 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);
    }
}