mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-23 02:03:02 +01:00
improve duplicate file handling
This commit is contained in:
parent
704b787ec2
commit
7542247c48
20
src/chat.c
20
src/chat.c
@ -149,14 +149,20 @@ static void chat_onFileSendRequest(ToxWindow *self, Tox *m, int num, uint8_t fil
|
|||||||
|
|
||||||
/* Append current time to duplicate file names */
|
/* Append current time to duplicate file names */
|
||||||
FILE *filecheck = NULL;
|
FILE *filecheck = NULL;
|
||||||
|
int count = 1;
|
||||||
|
int len = strlen(filename);
|
||||||
|
|
||||||
if ((filecheck = fopen(filename, "r"))) {
|
while ((filecheck = fopen(filename, "r"))) {
|
||||||
struct tm *timeinfo = get_time();
|
filename[len] = '\0';
|
||||||
uint8_t cur_time[MAX_STR_SIZE];
|
char d[9];
|
||||||
snprintf(cur_time, sizeof(cur_time), ".%02d:%02d:%02d", timeinfo->tm_hour, timeinfo->tm_min,
|
sprintf(d,"(%d)", count++);
|
||||||
timeinfo->tm_sec);
|
strcat(filename, d);
|
||||||
strncat(filename, cur_time, MAX_STR_SIZE - strlen(filename));
|
filename[len + strlen(d)] = '\0';
|
||||||
fclose(filecheck);
|
|
||||||
|
if (count > 999999) {
|
||||||
|
wprintw(ctx->history, "Error saving file to disk.\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
wprintw(ctx->history, "Type '/savefile %d' to accept the file transfer.\n", filenum);
|
wprintw(ctx->history, "Type '/savefile %d' to accept the file transfer.\n", filenum);
|
||||||
|
Loading…
Reference in New Issue
Block a user