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

improve duplicate file handling

This commit is contained in:
Jfreegman 2013-11-12 02:18:43 -05:00
parent 704b787ec2
commit 7542247c48

View File

@ -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);