/** * name: SvcExImINI_Export * desc: Exports a certain contact or all contacts to an ini file. * param: hContact - contact to export or -1 to export all contacts * pszFileName - ini-filename to write the contact to **/ int SvcExImINI_Export(lpExImParam ExImContact, LPCSTR pszFileName) { FILE* file; errno_t err; DB::CEnumList Modules; SYSTEMTIME now; MCONTACT hContact; if (!DlgExImModules_SelectModulesToExport(ExImContact, &Modules, NULL)) { if ((err = fopen_s(&file, pszFileName, "wt")) != NULL) { MsgErr(NULL, LPGENT("The ini-file \"%s\"\nfor saving contact information could not be opened."), pszFileName); return 1; } SetCursor(LoadCursor(NULL, IDC_WAIT)); // write header GetLocalTime(&now); fprintf(file, ";DATE = %04d-%02d-%02d %02d:%02d:%02d\n\n", now.wYear, now.wMonth, now.wDay, now.wHour, now.wMinute, now.wSecond ); if (Modules.getCount() == 0) { Modules.EnumModules(); } // hContact == -1 export entire db. if (ExImContact->Typ != EXIM_CONTACT) { // Owner ExportContact(NULL, &Modules, file); fprintf(file, "\n\n"); // Contacts for (hContact = db_find_first(); hContact != NULL; hContact = db_find_next(hContact)) { ExportContact(hContact, &Modules, file); fprintf(file, "\n\n"); } } // export only one contact else { ExportContact(ExImContact->hContact, &Modules, file); } if (file) fclose(file); SetCursor(LoadCursor(NULL, IDC_ARROW)); } return 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)); } }
INT_PTR CALLBACK DlgProcCopy(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_INITDIALOG: TranslateDialogDefault(hwnd); SetWindowLongPtr(hwnd, GWLP_USERDATA, ((PROPSHEETPAGE*)lParam)->lParam); return TRUE; case WM_COMMAND: SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0); switch (LOWORD(wParam)) { case IDC_EXPORT: ExportContact((MCONTACT)GetWindowLongPtr(hwnd, GWLP_USERDATA)); break; case IDC_DOIT: if (GetWindowTextLength(GetDlgItem(hwnd, IDC_STRING_REPLACE))) { char newString[MAX_REPLACES][512], oldString[MAX_REPLACES][512]; char dbVar1[2000], dbVar2[2000]; int i = 0, j = 0, k = 0; char *string = oldString[k]; MCONTACT hContact1 = (MCONTACT)GetWindowLongPtr(hwnd, GWLP_USERDATA); if (!db_get_static(hContact1, MODNAME, "Name", dbVar1, _countof(dbVar1))) { char *replace = (char*)malloc(GetWindowTextLength(GetDlgItem(hwnd, IDC_STRING_REPLACE)) + 1); GetDlgItemTextA(hwnd, IDC_STRING_REPLACE, replace, GetWindowTextLength(GetDlgItem(hwnd, IDC_STRING_REPLACE)) + 1); // get the list of replace strings while (replace[i] != '\0') { if (replace[i] == ',') { string = newString[k]; j = 0; } else if (!strncmp(replace + i, "\r\n", 2)) { if (string == newString[k]) k--; if (k == MAX_REPLACES) break; string = oldString[++k]; i += 2; continue; } else { string[j] = replace[i]; string[++j] = '\0'; } i++; } free(replace); MCONTACT hContact2 = (MCONTACT)CallService(MS_DB_CONTACT_ADD, 0, 0); Proto_AddToContact(hContact2, MODNAME); CallService(MS_IGNORE_IGNORE, (WPARAM)hContact2, IGNOREEVENT_USERONLINE); db_set_s(hContact2, MODNAME, "Nick", Translate("New Non-IM Contact")); // blank dbVar2 so the replaceing doesnt crash.. mir_strcpy(dbVar2, ""); // copy the name (dbVar1 is the name) for (i = 0; i < k; i++) copyReplaceString(dbVar1, dbVar2, oldString[i], newString[i]); db_set_s(hContact2, MODNAME, "Name", dbVar2); // copy the ProgramString if (!db_get_static(hContact1, MODNAME, "ProgramString", dbVar1, _countof(dbVar1))) { mir_strcpy(dbVar2, ""); for (i = 0; i <= k; i++) copyReplaceString(dbVar1, dbVar2, oldString[i], newString[i]); db_set_s(hContact2, MODNAME, "ProgramString", dbVar2); } // copy the ProgramParamString if (!db_get_static(hContact1, MODNAME, "ProgramParamString", dbVar1, _countof(dbVar1))) { mir_strcpy(dbVar2, ""); for (i = 0; i <= k; i++) copyReplaceString(dbVar1, dbVar2, oldString[i], newString[i]); db_set_s(hContact2, MODNAME, "ProgramParamString", dbVar2); } // copy the group if (!db_get_static(hContact1, "CList", "Group", dbVar1, _countof(dbVar1))) { mir_strcpy(dbVar2, ""); for (i = 0; i <= k; i++) copyReplaceString(dbVar1, dbVar2, oldString[i], newString[i]); db_set_s(hContact2, "CList", "Group", dbVar2); } // copy the ToolTip if (!db_get_static(hContact1, MODNAME, "ToolTip", dbVar1, _countof(dbVar1))) { mir_strcpy(dbVar2, ""); for (i = 0; i <= k; i++) copyReplaceString(dbVar1, dbVar2, oldString[i], newString[i]); db_set_s(hContact2, MODNAME, "ToolTip", dbVar2); } // timer db_set_b(hContact2, MODNAME, "UseTimer", (BYTE)db_get_b(hContact1, MODNAME, "UseTimer", 0)); db_set_b(hContact2, MODNAME, "Minutes", (BYTE)db_get_b(hContact1, MODNAME, "Minutes", 0)); db_set_w(hContact2, MODNAME, "Timer", (WORD)db_get_w(hContact1, MODNAME, "Timer", 0)); //icon db_set_w(hContact2, MODNAME, "Icon", (WORD)db_get_w(hContact1, MODNAME, "Icon", 40072)); replaceAllStrings(hContact2); } } else { char dbVar1[2000]; MCONTACT hContact1 = (MCONTACT)GetWindowLongPtr(hwnd, GWLP_USERDATA); if (!db_get_static(hContact1, MODNAME, "Name", dbVar1, _countof(dbVar1))) { MCONTACT hContact2 = (MCONTACT)CallService(MS_DB_CONTACT_ADD, 0, 0); if (!hContact2) { msg("contact did not get created", ""); return 0; } Proto_AddToContact(hContact2, MODNAME); CallService(MS_IGNORE_IGNORE, (WPARAM)hContact2, IGNOREEVENT_USERONLINE); db_set_s(hContact2, MODNAME, "Nick", Translate("New Non-IM Contact")); db_set_s(hContact2, MODNAME, "Name", dbVar1); if (!db_get_static(hContact1, MODNAME, "ProgramString", dbVar1, _countof(dbVar1))) db_set_s(hContact2, MODNAME, "ProgramString", dbVar1); // copy the ProgramParamString if (!db_get_static(hContact1, MODNAME, "ProgramParamString", dbVar1, _countof(dbVar1))) db_set_s(hContact2, MODNAME, "ProgramParamString", dbVar1); // copy the group if (!db_get_static(hContact1, "CList", "Group", dbVar1, _countof(dbVar1))) db_set_s(hContact2, "CList", "Group", dbVar1); // copy the ToolTip if (!db_get_static(hContact1, MODNAME, "ToolTip", dbVar1, _countof(dbVar1))) db_set_s(hContact2, MODNAME, "ToolTip", dbVar1); // timer db_set_b(hContact2, MODNAME, "UseTimer", (BYTE)db_get_b(hContact1, MODNAME, "UseTimer", 0)); db_set_b(hContact2, MODNAME, "Minutes", (BYTE)db_get_b(hContact1, MODNAME, "Minutes", 0)); db_set_w(hContact2, MODNAME, "Timer", (WORD)db_get_w(hContact1, MODNAME, "Timer", 0)); //icon db_set_w(hContact2, MODNAME, "Icon", (WORD)db_get_w(hContact1, MODNAME, "Icon", 40072)); replaceAllStrings(hContact2); } } } break; case WM_NOTIFY: switch (((LPNMHDR)lParam)->idFrom) { case 0: switch (((LPNMHDR)lParam)->code) { case PSN_APPLY: return TRUE; } } break; } return FALSE; }