mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
feat(core): Add error parsing for Tox_Err_File_Get
This commit is contained in:
parent
aff5663351
commit
040beae56a
|
@ -122,8 +122,12 @@ void CoreFile::sendAvatarFile(uint32_t friendId, const QByteArray& data)
|
||||||
file.fileKind = TOX_FILE_KIND_AVATAR;
|
file.fileKind = TOX_FILE_KIND_AVATAR;
|
||||||
file.avatarData = data;
|
file.avatarData = data;
|
||||||
file.resumeFileId.resize(TOX_FILE_ID_LENGTH);
|
file.resumeFileId.resize(TOX_FILE_ID_LENGTH);
|
||||||
|
Tox_Err_File_Get fileGetErr;
|
||||||
tox_file_get_file_id(tox, friendId, fileNum, reinterpret_cast<uint8_t*>(file.resumeFileId.data()),
|
tox_file_get_file_id(tox, friendId, fileNum, reinterpret_cast<uint8_t*>(file.resumeFileId.data()),
|
||||||
nullptr);
|
&fileGetErr);
|
||||||
|
if (!PARSE_ERR(fileGetErr)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
addFile(friendId, fileNum, file);
|
addFile(friendId, fileNum, file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,8 +149,12 @@ void CoreFile::sendFile(uint32_t friendId, QString filename, QString filePath,
|
||||||
|
|
||||||
ToxFile file{fileNum, friendId, fileName.getQString(), filePath, static_cast<uint64_t>(filesize), ToxFile::SENDING};
|
ToxFile file{fileNum, friendId, fileName.getQString(), filePath, static_cast<uint64_t>(filesize), ToxFile::SENDING};
|
||||||
file.resumeFileId.resize(TOX_FILE_ID_LENGTH);
|
file.resumeFileId.resize(TOX_FILE_ID_LENGTH);
|
||||||
|
Tox_Err_File_Get fileGetErr;
|
||||||
tox_file_get_file_id(tox, friendId, fileNum, reinterpret_cast<uint8_t*>(file.resumeFileId.data()),
|
tox_file_get_file_id(tox, friendId, fileNum, reinterpret_cast<uint8_t*>(file.resumeFileId.data()),
|
||||||
nullptr);
|
&fileGetErr);
|
||||||
|
if (!PARSE_ERR(fileGetErr)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (!file.open(false)) {
|
if (!file.open(false)) {
|
||||||
qWarning() << QString("sendFile: Can't open file, error: %1").arg(file.file->errorString());
|
qWarning() << QString("sendFile: Can't open file, error: %1").arg(file.file->errorString());
|
||||||
}
|
}
|
||||||
|
@ -327,7 +335,11 @@ void CoreFile::onFileReceiveCallback(Tox* tox, uint32_t friendId, uint32_t fileI
|
||||||
static_assert(TOX_HASH_LENGTH <= TOX_FILE_ID_LENGTH,
|
static_assert(TOX_HASH_LENGTH <= TOX_FILE_ID_LENGTH,
|
||||||
"TOX_HASH_LENGTH > TOX_FILE_ID_LENGTH!");
|
"TOX_HASH_LENGTH > TOX_FILE_ID_LENGTH!");
|
||||||
uint8_t avatarHash[TOX_FILE_ID_LENGTH];
|
uint8_t avatarHash[TOX_FILE_ID_LENGTH];
|
||||||
tox_file_get_file_id(tox, friendId, fileId, avatarHash, nullptr);
|
Tox_Err_File_Get fileGetErr;
|
||||||
|
tox_file_get_file_id(tox, friendId, fileId, avatarHash, &fileGetErr);
|
||||||
|
if (!PARSE_ERR(fileGetErr)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
QByteArray avatarBytes{static_cast<const char*>(static_cast<const void*>(avatarHash)),
|
QByteArray avatarBytes{static_cast<const char*>(static_cast<const void*>(avatarHash)),
|
||||||
TOX_HASH_LENGTH};
|
TOX_HASH_LENGTH};
|
||||||
emit core->fileAvatarOfferReceived(friendId, fileId, avatarBytes, filesize);
|
emit core->fileAvatarOfferReceived(friendId, fileId, avatarBytes, filesize);
|
||||||
|
@ -348,8 +360,12 @@ void CoreFile::onFileReceiveCallback(Tox* tox, uint32_t friendId, uint32_t fileI
|
||||||
ToxFile file{fileId, friendId, filename.getBytes(), "", filesize, ToxFile::RECEIVING};
|
ToxFile file{fileId, friendId, filename.getBytes(), "", filesize, ToxFile::RECEIVING};
|
||||||
file.fileKind = kind;
|
file.fileKind = kind;
|
||||||
file.resumeFileId.resize(TOX_FILE_ID_LENGTH);
|
file.resumeFileId.resize(TOX_FILE_ID_LENGTH);
|
||||||
|
Tox_Err_File_Get fileGetErr;
|
||||||
tox_file_get_file_id(tox, friendId, fileId, reinterpret_cast<uint8_t*>(file.resumeFileId.data()),
|
tox_file_get_file_id(tox, friendId, fileId, reinterpret_cast<uint8_t*>(file.resumeFileId.data()),
|
||||||
nullptr);
|
&fileGetErr);
|
||||||
|
if (!PARSE_ERR(fileGetErr)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
coreFile->addFile(friendId, fileId, file);
|
coreFile->addFile(friendId, fileId, file);
|
||||||
if (kind != TOX_FILE_KIND_AVATAR) {
|
if (kind != TOX_FILE_KIND_AVATAR) {
|
||||||
emit coreFile->fileReceiveRequested(file);
|
emit coreFile->fileReceiveRequested(file);
|
||||||
|
@ -377,8 +393,12 @@ void CoreFile::handleAvatarOffer(uint32_t friendId, uint32_t fileId, bool accept
|
||||||
ToxFile file{fileId, friendId, "<avatar>", "", filesize, ToxFile::RECEIVING};
|
ToxFile file{fileId, friendId, "<avatar>", "", filesize, ToxFile::RECEIVING};
|
||||||
file.fileKind = TOX_FILE_KIND_AVATAR;
|
file.fileKind = TOX_FILE_KIND_AVATAR;
|
||||||
file.resumeFileId.resize(TOX_FILE_ID_LENGTH);
|
file.resumeFileId.resize(TOX_FILE_ID_LENGTH);
|
||||||
|
Tox_Err_File_Get getErr;
|
||||||
tox_file_get_file_id(tox, friendId, fileId, reinterpret_cast<uint8_t*>(file.resumeFileId.data()),
|
tox_file_get_file_id(tox, friendId, fileId, reinterpret_cast<uint8_t*>(file.resumeFileId.data()),
|
||||||
nullptr);
|
&getErr);
|
||||||
|
if (!PARSE_ERR(getErr)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
addFile(friendId, fileId, file);
|
addFile(friendId, fileId, file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,6 +50,6 @@ namespace ToxcoreErrorParser {
|
||||||
bool parseErr(Tox_Err_Set_Typing error, int line);
|
bool parseErr(Tox_Err_Set_Typing error, int line);
|
||||||
bool parseErr(Tox_Err_Conference_Delete error, int line);
|
bool parseErr(Tox_Err_Conference_Delete error, int line);
|
||||||
bool parseErr(Tox_Err_Get_Port error, int line);
|
bool parseErr(Tox_Err_Get_Port error, int line);
|
||||||
|
bool parseErr(Tox_Err_File_Get error, int line);
|
||||||
bool parseErr(Tox_Err_File_Send error, int line);
|
bool parseErr(Tox_Err_File_Send error, int line);
|
||||||
|
|
||||||
} // namespace ToxcoreErrorParser
|
} // namespace ToxcoreErrorParser
|
||||||
|
|
|
@ -413,6 +413,28 @@ bool ToxcoreErrorParser::parseErr(Tox_Err_Get_Port error, int line)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ToxcoreErrorParser::parseErr(Tox_Err_File_Get error, int line)
|
||||||
|
{
|
||||||
|
switch (error) {
|
||||||
|
case TOX_ERR_FILE_GET_OK:
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case TOX_ERR_FILE_GET_NULL:
|
||||||
|
qCritical() << line << ": One of the arguments to the function was NULL when it was not expected.";
|
||||||
|
return false;
|
||||||
|
|
||||||
|
case TOX_ERR_FILE_GET_FRIEND_NOT_FOUND:
|
||||||
|
qCritical() << line << ": The friend_number passed did not designate a valid friend.";
|
||||||
|
return false;
|
||||||
|
|
||||||
|
case TOX_ERR_FILE_GET_NOT_FOUND:
|
||||||
|
qCritical() << line << ": The friend_number passed did not designate a valid friend.";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
qCritical() << line << ": Unknown Tox_Err_Conference_Title error code:" << error;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool ToxcoreErrorParser::parseErr(Tox_Err_File_Send error, int line)
|
bool ToxcoreErrorParser::parseErr(Tox_Err_File_Send error, int line)
|
||||||
{
|
{
|
||||||
switch (error) {
|
switch (error) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user