forked from KolibriOS/kolibrios
WebView Downloader: if file already exist, save the file with a new name
git-svn-id: svn://kolibrios.org@8697 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
99dce7afaf
commit
b930c6f5f7
@ -1,5 +1,5 @@
|
|||||||
#define MEMSIZE 1024 * 40
|
#define MEMSIZE 1024 * 40
|
||||||
//Copyright 2020 by Leency
|
//Copyright 2020 - 2021 by Leency
|
||||||
#include "../lib/gui.h"
|
#include "../lib/gui.h"
|
||||||
#include "../lib/random.h"
|
#include "../lib/random.h"
|
||||||
#include "../lib/obj/box_lib.h"
|
#include "../lib/obj/box_lib.h"
|
||||||
@ -181,22 +181,32 @@ void MonitorProgress()
|
|||||||
StartDownloading();
|
StartDownloading();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
SaveFile();
|
SaveFile(0);
|
||||||
if (exit_param) ExitProcess();
|
if (exit_param) ExitProcess();
|
||||||
StopDownloading();
|
StopDownloading();
|
||||||
DrawWindow();
|
DrawWindow();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SaveFile()
|
void SaveFile(int attempt)
|
||||||
{
|
{
|
||||||
int i;
|
int i, fi=0;
|
||||||
char notify_message[4296];
|
char notify_message[4296];
|
||||||
char file_name[URL_SIZE+96];
|
char file_name[URL_SIZE+96];
|
||||||
|
|
||||||
strcpy(#filepath, #save_dir);
|
strcpy(#filepath, #save_dir);
|
||||||
chrcat(#filepath, '/');
|
chrcat(#filepath, '/');
|
||||||
|
|
||||||
|
if (attempt > 9) {
|
||||||
|
notify("'Too many saving attempts' -E");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (attempt > 0) {
|
||||||
|
chrcat(#filepath, attempt+'0');
|
||||||
|
chrcat(#filepath, '_');
|
||||||
|
}
|
||||||
|
|
||||||
//Content-Disposition: attachment; filename="RealFootball_2018_Nokia_5800_EN_IGP_EU_TS_101.zip"
|
//Content-Disposition: attachment; filename="RealFootball_2018_Nokia_5800_EN_IGP_EU_TS_101.zip"
|
||||||
if (http.header_field("content-disposition", #file_name, sizeof(file_name))) {
|
if (http.header_field("content-disposition", #file_name, sizeof(file_name))) {
|
||||||
if (EDX = strstr(#file_name,"filename=\"")) {
|
if (EDX = strstr(#file_name,"filename=\"")) {
|
||||||
@ -214,6 +224,11 @@ void SaveFile()
|
|||||||
|
|
||||||
for (i=0; i<strlen(#filepath); i++) if(filepath[i]==':')||(filepath[i]=='?')filepath[i]='-';
|
for (i=0; i<strlen(#filepath); i++) if(filepath[i]==':')||(filepath[i]=='?')filepath[i]='-';
|
||||||
|
|
||||||
|
while (file_exists(#filepath)) {
|
||||||
|
SaveFile(attempt+1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (CreateFile(http.content_received, http.content_pointer, #filepath)==0) {
|
if (CreateFile(http.content_received, http.content_pointer, #filepath)==0) {
|
||||||
miniprintf(#notify_message, FILE_SAVED_AS, #filepath);
|
miniprintf(#notify_message, FILE_SAVED_AS, #filepath);
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user