mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-16 04:03:02 +01:00
close file transfers on exit & fixes
This commit is contained in:
parent
8cf3043dd3
commit
04b394d6dd
@ -123,7 +123,7 @@ void cmd_savefile(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv
|
|||||||
|
|
||||||
void cmd_sendfile(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
void cmd_sendfile(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
||||||
{
|
{
|
||||||
if (num_file_senders >= MAX_FILES) {
|
if (max_file_senders_index >= (MAX_FILES-1)) {
|
||||||
wprintw(window,"Please wait for some of your outgoing file transfers to complete.\n");
|
wprintw(window,"Please wait for some of your outgoing file transfers to complete.\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -176,14 +176,14 @@ void cmd_sendfile(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv
|
|||||||
file_senders[i].file = file_to_send;
|
file_senders[i].file = file_to_send;
|
||||||
file_senders[i].filenum = (uint8_t) filenum;
|
file_senders[i].filenum = (uint8_t) filenum;
|
||||||
file_senders[i].friendnum = self->num;
|
file_senders[i].friendnum = self->num;
|
||||||
file_senders[i].timestamp = (uint64_t)time(NULL);
|
file_senders[i].timestamp = (uint64_t) time(NULL);
|
||||||
file_senders[i].piecelen = fread(file_senders[i].nextpiece, 1,
|
file_senders[i].piecelen = fread(file_senders[i].nextpiece, 1,
|
||||||
tox_filedata_size(m, self->num), file_to_send);
|
tox_filedata_size(m, self->num), file_to_send);
|
||||||
|
|
||||||
wprintw(window, "Sending file: '%s'\n", path);
|
wprintw(window, "Sending file: '%s'\n", path);
|
||||||
|
|
||||||
if (i == num_file_senders)
|
if (i == max_file_senders_index)
|
||||||
++num_file_senders;
|
++max_file_senders_index;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -239,10 +239,11 @@ static void groupchat_onKey(ToxWindow *self, Tox *m, wint_t key)
|
|||||||
} else
|
} else
|
||||||
/* Add printable chars to buffer and print on input space */
|
/* Add printable chars to buffer and print on input space */
|
||||||
#if HAVE_WIDECHAR
|
#if HAVE_WIDECHAR
|
||||||
if (iswprint(key)) {
|
if (iswprint(key))
|
||||||
#else
|
#else
|
||||||
if (isprint(key)) {
|
if (isprint(key))
|
||||||
#endif
|
#endif
|
||||||
|
{
|
||||||
if (ctx->pos < (MAX_STR_SIZE-1)) {
|
if (ctx->pos < (MAX_STR_SIZE-1)) {
|
||||||
mvwaddstr(self->window, y, x, wc_to_char(key));
|
mvwaddstr(self->window, y, x, wc_to_char(key));
|
||||||
ctx->line[ctx->pos++] = key;
|
ctx->line[ctx->pos++] = key;
|
||||||
|
20
src/main.c
20
src/main.c
@ -356,19 +356,19 @@ static void close_file_sender(int i)
|
|||||||
|
|
||||||
int j;
|
int j;
|
||||||
|
|
||||||
for (j = num_file_senders; j > 0; --j) {
|
for (j = max_file_senders_index; j > 0; --j) {
|
||||||
if (file_senders[j-1].active)
|
if (file_senders[j-1].active)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
num_file_senders = j;
|
max_file_senders_index = j;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void do_file_senders(Tox *m)
|
static void do_file_senders(Tox *m)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < num_file_senders; ++i) {
|
for (i = 0; i < max_file_senders_index; ++i) {
|
||||||
if (!file_senders[i].active)
|
if (!file_senders[i].active)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -419,9 +419,23 @@ static void do_file_senders(Tox *m)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* This should only be called on exit */
|
||||||
|
static void close_file_transfers(Tox *m)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i < max_file_senders_index; ++i) {
|
||||||
|
if (!file_senders[i].active)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
fclose(file_senders[i].file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void exit_toxic(Tox *m)
|
void exit_toxic(Tox *m)
|
||||||
{
|
{
|
||||||
store_data(m, DATA_FILE);
|
store_data(m, DATA_FILE);
|
||||||
|
close_file_transfers(m);
|
||||||
free(DATA_FILE);
|
free(DATA_FILE);
|
||||||
free(SRVLIST_FILE);
|
free(SRVLIST_FILE);
|
||||||
free(prompt->stb);
|
free(prompt->stb);
|
||||||
|
@ -122,7 +122,7 @@ typedef struct {
|
|||||||
} FileSender;
|
} FileSender;
|
||||||
|
|
||||||
FileSender file_senders[MAX_FILES];
|
FileSender file_senders[MAX_FILES];
|
||||||
uint8_t num_file_senders;
|
uint8_t max_file_senders_index;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint8_t filenames[MAX_FILES][MAX_STR_SIZE];
|
uint8_t filenames[MAX_FILES][MAX_STR_SIZE];
|
||||||
|
Loading…
Reference in New Issue
Block a user