HANDLE CSametimeProto::AcceptFileTransfer(MCONTACT hContact, HANDLE hFt, char* save_path) { mwFileTransfer* ft = (mwFileTransfer*)hFt; CSametimeProto* proto = getProtoFromMwFileTransfer(ft); debugLog(_T("CSametimeProto::AcceptFileTransfer() start")); FileTransferClientData* ftcd = new FileTransferClientData; memset((void*)ftcd, 0, sizeof(FileTransferClientData)); ftcd->ft = ft; ftcd->sending = false; ftcd->hFt = hFt; if (save_path) // save path ftcd->save_path = _strdup(save_path); else ftcd->save_path = 0; mwFileTransfer_setClientData(ft, (gpointer)ftcd, 0); char fp[MAX_PATH]; char* fn = strrchr((char*)mwFileTransfer_getFileName(ft), '\\'); if (fn) fn++; if (ftcd->save_path) mir_strcpy(fp, ftcd->save_path); else fp[0] = 0; if (fn) mir_strcat(fp, fn); else mir_strcat(fp, mwFileTransfer_getFileName(ft)); ftcd->hFile = CreateFileA(fp, GENERIC_WRITE, FILE_SHARE_READ, 0, OPEN_ALWAYS, 0, 0); if (ftcd->hFile == INVALID_HANDLE_VALUE) { debugLog(_T("CSametimeProto::AcceptFileTransfer() INVALID_HANDLE_VALUE")); mwFileTransfer_close(ft, mwFileTransfer_ERROR); return 0; } ftcd->hContact = hContact; mwFileTransfer_setClientData(ft, (gpointer)ftcd, 0); mwFileTransfer_accept(ft); return hFt; }
HANDLE CSametimeProto::SendFilesToUser(MCONTACT hContact, TCHAR** files, const TCHAR* ptszDesc) { debugLog(_T("CSametimeProto::SendFilesToUser() start")); mwAwareIdBlock id_block; if (GetAwareIdFromContact(hContact, &id_block)) { mwIdBlock idb; idb.user = id_block.user; idb.community = id_block.community; FileTransferClientData *ftcd, *prev_ftcd = 0, *first_ftcd = 0; mwFileTransfer *ft, *first_ft = 0; for (int i = 0; files[i]; i++) { HANDLE hFile = CreateFile(files[i], GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0); if (hFile != INVALID_HANDLE_VALUE) { DWORD filesize = GetFileSize(hFile, 0); TCHAR *fn = _tcsrchr(files[i], '\\'); if (fn) fn++; else fn = files[i]; ft = mwFileTransfer_new(service_files, &idb, T2Utf(ptszDesc), T2Utf(fn), filesize); ftcd = new FileTransferClientData; memset(ftcd, 0, sizeof(FileTransferClientData)); ftcd->ft = ft; ftcd->hContact = hContact; ftcd->next = 0; if (prev_ftcd) { prev_ftcd->next = ftcd; // link into list // each node contains a pointer to the first - it will contain infor linke the count etc ftcd->first = prev_ftcd->first; } else ftcd->first = ftcd; if (!first_ft) first_ft = ft; ftcd->sending = true; ftcd->hFile = hFile; ftcd->hFt = (HANDLE)first_ft; ftcd->save_path = 0; ftcd->buffer = new char[FILE_BUFF_SIZE]; ftcd->ft_number = ftcd->first->ft_count; ftcd->first->ft_count++; ftcd->sizeToHere = ftcd->first->totalSize; ftcd->first->totalSize += filesize; mwFileTransfer_setClientData(ft, (gpointer)ftcd, 0); prev_ftcd = ftcd; } } free(id_block.user); if (first_ft) { mwFileTransfer_offer(first_ft); return (HANDLE)first_ft; } } return 0; }