1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-12-23 16:23: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 */
FILE *filecheck = NULL;
int count = 1;
int len = strlen(filename);
if ((filecheck = fopen(filename, "r"))) {
struct tm *timeinfo = get_time();
uint8_t cur_time[MAX_STR_SIZE];
snprintf(cur_time, sizeof(cur_time), ".%02d:%02d:%02d", timeinfo->tm_hour, timeinfo->tm_min,
timeinfo->tm_sec);
strncat(filename, cur_time, MAX_STR_SIZE - strlen(filename));
fclose(filecheck);
while ((filecheck = fopen(filename, "r"))) {
filename[len] = '\0';
char d[9];
sprintf(d,"(%d)", count++);
strcat(filename, d);
filename[len + strlen(d)] = '\0';
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);