1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-26 15:03:27 +01:00

error checking for file senders, fixes

This commit is contained in:
Jfreegman 2014-08-17 15:16:04 -04:00
parent eca4882ce2
commit affc88d0a8
2 changed files with 22 additions and 11 deletions

View File

@ -477,15 +477,12 @@ static void chat_onFileControl(ToxWindow *self, Tox *m, int32_t num, uint8_t rec
snprintf(msg, sizeof(msg), "File transfer for '%s' complete.", filename); snprintf(msg, sizeof(msg), "File transfer for '%s' complete.", filename);
chat_close_file_receiver(m, filenum, num, TOX_FILECONTROL_FINISHED); chat_close_file_receiver(m, filenum, num, TOX_FILECONTROL_FINISHED);
} else { } else {
char msg[MAX_STR_SIZE];
snprintf(msg, sizeof(msg), "File '%s' successfuly sent.", filename); snprintf(msg, sizeof(msg), "File '%s' successfuly sent.", filename);
close_file_sender(self, m, i, msg, TOX_FILECONTROL_FINISHED, filenum, num); close_file_sender(self, m, i, NULL, TOX_FILECONTROL_FINISHED, filenum, num);
return;
} }
if (self->active_box != -1) if (self->active_box != -1)
box_notify2(self, transfer_completed, NT_NOFOCUS | NT_WNDALERT_2, box_notify2(self, transfer_completed, NT_NOFOCUS | NT_WNDALERT_2, self->active_box, "%s", msg);
self->active_box, "%s", msg);
else else
box_notify(self, transfer_completed, NT_NOFOCUS | NT_WNDALERT_2, &self->active_box, box_notify(self, transfer_completed, NT_NOFOCUS | NT_WNDALERT_2, &self->active_box,
self->name, "%s", msg); self->name, "%s", msg);

View File

@ -218,11 +218,25 @@ static void send_file_data(ToxWindow *self, Tox *m, int i, int32_t friendnum, in
file_senders[i].piecelen = fread(file_senders[i].nextpiece, 1, file_senders[i].piecelen = fread(file_senders[i].nextpiece, 1,
tox_file_data_size(m, friendnum), fp); tox_file_data_size(m, friendnum), fp);
/* file sender is closed in chat_onFileControl callback after receiving reply */ /* note: file sender is closed in chat_onFileControl callback after receiving reply */
if (file_senders[i].piecelen == 0 && !file_senders[i].finished) { if (file_senders[i].piecelen == 0) {
print_progress_bar(self, i, -1, 100.0); if (feof(fp) != 0) { /* make sure we're really at eof */
tox_file_send_control(m, friendnum, 0, filenum, TOX_FILECONTROL_FINISHED, 0, 0); print_progress_bar(self, i, -1, 100.0);
file_senders[i].finished = true; tox_file_send_control(m, friendnum, 0, filenum, TOX_FILECONTROL_FINISHED, 0, 0);
file_senders[i].finished = true;
} else {
char msg[MAX_STR_SIZE];
snprintf(msg, sizeof(msg), "File transfer for '%s' failed: Read error.", file_senders[i].filename);
close_file_sender(self, m, i, msg, TOX_FILECONTROL_KILL, filenum, friendnum);
sound_notify(self, error, NT_NOFOCUS | NT_WNDALERT_2, NULL);
if (self->active_box != -1)
box_notify2(self, error, NT_NOFOCUS | NT_WNDALERT_2, self->active_box, "%s", msg);
else
box_notify(self, error, NT_NOFOCUS | NT_WNDALERT_2, &self->active_box, self->name, "%s", msg);
}
return;
} }
} }
} }
@ -265,7 +279,7 @@ void do_file_senders(Tox *m)
continue; continue;
} }
if (file_senders[i].noconnection == false) if (!file_senders[i].noconnection && !file_senders[i].finished)
send_file_data(self, m, i, friendnum, filenum, filename); send_file_data(self, m, i, friendnum, filenum, filename);
file_senders[i].queue_pos = num_active_file_senders - 1; file_senders[i].queue_pos = num_active_file_senders - 1;