mirror of
https://github.com/Tha14/toxic.git
synced 2024-12-23 19:43:26 +01:00
send name instead of full path with file send request
This commit is contained in:
parent
1f06606c5b
commit
16b8f85d95
18
src/chat.c
18
src/chat.c
@ -136,23 +136,7 @@ static void chat_onFileSendRequest(ToxWindow *self, Tox *m, int num, uint8_t fil
|
||||
|
||||
ChatContext *ctx = self->chatwin;
|
||||
|
||||
int idx = strlen(pathname) - 1;
|
||||
while (idx >= 0 && pathname[idx] == '/') {
|
||||
pathname[idx--] = 0;
|
||||
}
|
||||
|
||||
/* try to get file name from path */
|
||||
uint8_t *filename = strrchr(pathname, '/'); // Try unix style paths
|
||||
|
||||
if (filename != NULL) {
|
||||
if (!strlen(++filename))
|
||||
filename = pathname;
|
||||
} else {
|
||||
filename = strrchr(pathname, '\\'); // Try windows style paths
|
||||
|
||||
if (filename == NULL)
|
||||
filename = pathname;
|
||||
}
|
||||
uint8_t *filename = get_file_name(pathname);
|
||||
|
||||
wprintw(ctx->history, "File transfer request for '%s' (%llu bytes).\n", filename,
|
||||
(long long unsigned int)filesize);
|
||||
|
@ -164,7 +164,8 @@ void cmd_sendfile(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv
|
||||
uint64_t filesize = ftell(file_to_send);
|
||||
fseek(file_to_send, 0, SEEK_SET);
|
||||
|
||||
int filenum = tox_new_file_sender(m, self->num, filesize, path, path_len + 1);
|
||||
uint8_t *filename = get_file_name(path);
|
||||
int filenum = tox_new_file_sender(m, self->num, filesize, filename, strlen(filename) + 1);
|
||||
|
||||
if (filenum == -1) {
|
||||
wprintw(window, "Error sending file.\n");
|
||||
|
@ -216,11 +216,9 @@ static void groupchat_onGroupNamelistChange(ToxWindow *self, Tox *m, int groupnu
|
||||
/* get old peer name before updating name list */
|
||||
uint8_t oldpeername[TOX_MAX_NAME_LENGTH] = {0};
|
||||
|
||||
if (change != TOX_CHAT_CHANGE_PEER_ADD) {
|
||||
if (change != TOX_CHAT_CHANGE_PEER_ADD)
|
||||
memcpy(oldpeername, &groupchats[groupnum].oldpeer_names[peernum*TOX_MAX_NAME_LENGTH],
|
||||
sizeof(oldpeername));
|
||||
oldpeername[TOXIC_MAX_NAME_LENGTH] = '\0';
|
||||
}
|
||||
|
||||
/* Update name lists */
|
||||
uint8_t tmp_peerlist[num_peers][TOX_MAX_NAME_LENGTH];
|
||||
|
@ -193,3 +193,26 @@ void mv_curs_end(WINDOW *w, size_t len, int max_y, int max_x)
|
||||
int end_x = len % max_x;
|
||||
wmove(w, end_y, end_x);
|
||||
}
|
||||
|
||||
/* Returns base file name from path or original file name if no path is supplied */
|
||||
uint8_t *get_file_name(uint8_t *pathname)
|
||||
{
|
||||
int idx = strlen(pathname) - 1;
|
||||
|
||||
while (idx >= 0 && pathname[idx] == '/')
|
||||
pathname[idx--] = '\0';
|
||||
|
||||
uint8_t *filename = strrchr(pathname, '/'); // Try unix style paths
|
||||
|
||||
if (filename != NULL) {
|
||||
if (!strlen(++filename))
|
||||
filename = pathname;
|
||||
} else {
|
||||
filename = strrchr(pathname, '\\'); // Try windows style paths
|
||||
|
||||
if (filename == NULL)
|
||||
filename = pathname;
|
||||
}
|
||||
|
||||
return filename;
|
||||
}
|
||||
|
@ -47,3 +47,6 @@ bool valid_nick(uint8_t *nick);
|
||||
|
||||
/* Moves the cursor to the end of the line in given window */
|
||||
void mv_curs_end(WINDOW *w, size_t len, int max_y, int max_x);
|
||||
|
||||
/* Returns base file name from path or original file name if no path is supplied */
|
||||
uint8_t *get_file_name(uint8_t *pathname);
|
||||
|
Loading…
Reference in New Issue
Block a user