2018-05-20 17:03:53 +03:00
|
|
|
|
DOWNLOADER downloader;
|
|
|
|
|
|
2015-12-22 21:14:35 +03:00
|
|
|
|
#ifdef LANG_RUS
|
2018-05-18 23:18:10 +03:00
|
|
|
|
#define DL_WINDOW_HEADER "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>㧮<EFBFBD>"
|
|
|
|
|
#define START_DOWNLOADING "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"
|
|
|
|
|
#define STOP_DOWNLOADING "<22><>⠭<EFBFBD><E2A0AD><EFBFBD><EFBFBD><EFBFBD>"
|
|
|
|
|
#define SHOW_IN_FOLDER "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD>"
|
|
|
|
|
#define OPEN_FILE_TEXT "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 䠩<>"
|
|
|
|
|
#define FILE_SAVED_AS "'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>㧮<EFBFBD>\n<><6E><EFBFBD><EFBFBD> <20><><EFBFBD>࠭<EFBFBD><E0A0AD> <20><><EFBFBD> "
|
|
|
|
|
#define KB_RECEIVED "<22><><EFBFBD><EFBFBD> ᪠稢<E1AAA0><E7A8A2><EFBFBD><EFBFBD>... %s <20><><EFBFBD><EFBFBD>祭<EFBFBD>"
|
2015-12-22 21:14:35 +03:00
|
|
|
|
#else
|
2018-05-18 23:18:10 +03:00
|
|
|
|
#define DL_WINDOW_HEADER "Download Manager"
|
|
|
|
|
#define START_DOWNLOADING "Start downloading"
|
|
|
|
|
#define STOP_DOWNLOADING "Stop downloading"
|
|
|
|
|
#define SHOW_IN_FOLDER "Show in folder"
|
|
|
|
|
#define OPEN_FILE_TEXT "Open file"
|
|
|
|
|
#define FILE_SAVED_AS "'Download manager\nFile saved as "
|
|
|
|
|
#define KB_RECEIVED "Downloading... %s received"
|
2015-12-22 21:14:35 +03:00
|
|
|
|
#endif
|
2016-03-23 14:13:28 +03:00
|
|
|
|
char save_to[4096] = "/tmp0/1/Downloads";
|
2016-03-25 18:35:48 +03:00
|
|
|
|
|
2018-11-02 00:48:33 +03:00
|
|
|
|
#define CONX 15
|
|
|
|
|
|
2015-12-22 21:14:35 +03:00
|
|
|
|
proc_info DL_Form;
|
|
|
|
|
char downloader_edit[10000];
|
|
|
|
|
char filepath[4096];
|
2018-10-29 14:39:31 +03:00
|
|
|
|
edit_box ed = {NULL,57,20,0xffffff,0x94AECE,0xffffff,0xffffff,0x10000000,sizeof(downloader_edit)-2,#downloader_edit,0,2,19,19};
|
2018-11-02 00:48:33 +03:00
|
|
|
|
progress_bar pb = {0, CONX, 58, 350, 17, 0, 0, 100, 0xFFFfff, 0x74DA00, 0x9F9F9F};
|
2017-09-10 08:38:29 +03:00
|
|
|
|
//progress_bar pb = {0, 180, 55, 225, 12, 0, 0, 100, 0xFFFfff, 0x74DA00, 0x9F9F9F};
|
|
|
|
|
//progress_bar: value, left, top, width, height, style, min, max, back_color, progress_color, frame_color;
|
2018-11-02 00:48:33 +03:00
|
|
|
|
|
2018-05-18 23:18:10 +03:00
|
|
|
|
|
2016-03-25 18:35:48 +03:00
|
|
|
|
|
2018-05-18 23:18:10 +03:00
|
|
|
|
bool downloader_opened;
|
2016-03-23 14:13:28 +03:00
|
|
|
|
char downloader_stak[4096];
|
2016-03-25 18:35:48 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Downloader()
|
2015-12-22 21:14:35 +03:00
|
|
|
|
{
|
2018-05-18 23:18:10 +03:00
|
|
|
|
if (!dir_exists(#save_to)) CreateDir(#save_to);
|
|
|
|
|
downloader_opened = true;
|
|
|
|
|
SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER + EVM_STACK);
|
2017-09-10 08:38:29 +03:00
|
|
|
|
|
2018-05-18 23:18:10 +03:00
|
|
|
|
system.color.get();
|
|
|
|
|
pb.frame_color = system.color.work_dark;
|
2016-03-25 18:35:48 +03:00
|
|
|
|
|
2018-05-18 23:18:10 +03:00
|
|
|
|
filepath[0] = NULL;
|
|
|
|
|
|
|
|
|
|
downloader.Stop();
|
|
|
|
|
if (downloader_edit[0]) StartDownloading(); else strcpy(#downloader_edit, "http://");
|
|
|
|
|
ed.size = ed.pos = ed.shift = ed.shift_old = strlen(#downloader_edit);
|
2016-03-25 18:35:48 +03:00
|
|
|
|
|
2018-05-18 23:18:10 +03:00
|
|
|
|
loop() switch(WaitEvent())
|
|
|
|
|
{
|
|
|
|
|
case evMouse:
|
|
|
|
|
edit_box_mouse stdcall (#ed);
|
|
|
|
|
break;
|
2017-09-17 04:32:09 +03:00
|
|
|
|
|
2018-05-18 23:18:10 +03:00
|
|
|
|
case evButton:
|
|
|
|
|
Key_Scan(GetButtonID());
|
|
|
|
|
break;
|
2017-09-17 04:32:09 +03:00
|
|
|
|
|
2018-05-18 23:18:10 +03:00
|
|
|
|
case evKey:
|
|
|
|
|
GetKeys();
|
|
|
|
|
edit_box_key stdcall(#ed);
|
|
|
|
|
if (key_scancode==SCAN_CODE_ENTER) Key_Scan(301);
|
|
|
|
|
break;
|
2017-09-17 04:32:09 +03:00
|
|
|
|
|
2018-05-18 23:18:10 +03:00
|
|
|
|
case evReDraw:
|
|
|
|
|
DefineAndDrawWindow(215, 100, 580, 130, 0x74, system.color.work, DL_WINDOW_HEADER, 0);
|
|
|
|
|
GetProcessInfo(#DL_Form, SelfInfo);
|
|
|
|
|
if (DL_Form.status_window>2) break;
|
|
|
|
|
if (DL_Form.height<120) MoveSize(OLD,OLD,OLD,120);
|
|
|
|
|
if (DL_Form.width<280) MoveSize(OLD,OLD,280,OLD);
|
|
|
|
|
DL_Draw_Window();
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
if (!downloader.MonitorProgress()) break;
|
2018-11-04 03:20:00 +03:00
|
|
|
|
pb.max = downloader.httpd.content_length / 100;
|
|
|
|
|
EDI = downloader.httpd.content_received/100;
|
|
|
|
|
if (pb.value != EDI)
|
2018-05-18 23:18:10 +03:00
|
|
|
|
{
|
2018-11-04 03:20:00 +03:00
|
|
|
|
pb.value = EDI;
|
2018-05-18 23:18:10 +03:00
|
|
|
|
progressbar_draw stdcall(#pb);
|
|
|
|
|
DrawDownloading();
|
|
|
|
|
}
|
|
|
|
|
if (downloader.state == STATE_COMPLETED)
|
|
|
|
|
{
|
|
|
|
|
SaveDownloadedFile();
|
|
|
|
|
StopDownloading();
|
|
|
|
|
DL_Draw_Window();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-12-22 21:14:35 +03:00
|
|
|
|
}
|
2016-03-25 18:35:48 +03:00
|
|
|
|
|
2015-12-22 21:14:35 +03:00
|
|
|
|
void Key_Scan(int id)
|
|
|
|
|
{
|
2018-05-18 23:18:10 +03:00
|
|
|
|
if (id==001) { downloader_opened=false; StopDownloading(); ExitProcess(); }
|
|
|
|
|
if (id==301) && (downloader.httpd.transfer <= 0) StartDownloading();
|
|
|
|
|
if (id==302) StopDownloading();
|
|
|
|
|
if (id==305) RunProgram("/sys/File managers/Eolite", #save_to);
|
|
|
|
|
if (id==306) {
|
|
|
|
|
SetCurDir(#save_to);
|
|
|
|
|
RunProgram("/sys/@open", #filepath);
|
|
|
|
|
}
|
2015-12-22 21:14:35 +03:00
|
|
|
|
}
|
2016-03-25 18:35:48 +03:00
|
|
|
|
|
2015-12-22 21:14:35 +03:00
|
|
|
|
void DL_Draw_Window()
|
2016-03-25 18:35:48 +03:00
|
|
|
|
{
|
2018-05-18 23:18:10 +03:00
|
|
|
|
int but_x = 0;
|
|
|
|
|
int but_y = 58;
|
|
|
|
|
DrawBar(0,0, DL_Form.cwidth, DL_Form.cheight, system.color.work);
|
|
|
|
|
DeleteButton(301);
|
|
|
|
|
DeleteButton(302);
|
|
|
|
|
DeleteButton(305);
|
|
|
|
|
DeleteButton(306);
|
|
|
|
|
if (downloader.state == STATE_NOT_STARTED) || (downloader.state == STATE_COMPLETED)
|
|
|
|
|
{
|
2018-11-02 00:48:33 +03:00
|
|
|
|
but_x = CONX + DrawStandartCaptButton(CONX, but_y, 301, START_DOWNLOADING);
|
2018-05-18 23:18:10 +03:00
|
|
|
|
if (filepath[0])
|
|
|
|
|
{
|
|
|
|
|
but_x += DrawStandartCaptButton(but_x, but_y, 305, SHOW_IN_FOLDER);
|
|
|
|
|
DrawStandartCaptButton(but_x, but_y, 306, OPEN_FILE_TEXT);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (downloader.state == STATE_IN_PROGRESS)
|
|
|
|
|
{
|
|
|
|
|
DrawStandartCaptButton(DL_Form.width - 190, but_y, 302, STOP_DOWNLOADING);
|
|
|
|
|
DrawDownloading();
|
|
|
|
|
}
|
2018-11-02 00:48:33 +03:00
|
|
|
|
WriteText(CONX, ed.top + 4, 0x90, system.color.work_text, "URL:");
|
|
|
|
|
ed.width = DL_Form.cwidth - ed.left - CONX - 3;
|
2018-05-18 23:18:10 +03:00
|
|
|
|
ed.offset=0;
|
|
|
|
|
DrawEditBox(#ed);
|
2015-12-22 21:14:35 +03:00
|
|
|
|
}
|
2016-03-25 18:35:48 +03:00
|
|
|
|
|
2015-12-22 21:14:35 +03:00
|
|
|
|
void StartDownloading()
|
|
|
|
|
{
|
2018-05-18 23:18:10 +03:00
|
|
|
|
StopDownloading();
|
|
|
|
|
if (strncmp(#downloader_edit,"http://",7)!=0) {
|
|
|
|
|
notify("'File address should start from http://' -E");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!downloader.Start(#downloader_edit)) {
|
|
|
|
|
notify("'Error while starting download process.\nPlease, check entered path and internet connection.' -E");
|
|
|
|
|
StopDownloading();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
ed.blur_border_color = 0xCACACA;
|
|
|
|
|
ed.flags = 100000000000b;
|
|
|
|
|
pb.value = 0;
|
|
|
|
|
DL_Draw_Window();
|
2015-12-22 21:14:35 +03:00
|
|
|
|
}
|
2018-11-02 00:48:33 +03:00
|
|
|
|
|
2018-11-04 03:20:00 +03:00
|
|
|
|
/*
|
2018-11-02 00:48:33 +03:00
|
|
|
|
struct TIME
|
|
|
|
|
{
|
|
|
|
|
dword old;
|
|
|
|
|
dword cur;
|
|
|
|
|
dword gone;
|
|
|
|
|
} time = {0,0,0};
|
|
|
|
|
|
|
|
|
|
dword netdata_received;
|
|
|
|
|
dword speed;
|
|
|
|
|
|
|
|
|
|
void CalculateSpeed()
|
|
|
|
|
{
|
|
|
|
|
time.cur = GetStartTime();
|
|
|
|
|
|
|
|
|
|
if (time.old) {
|
|
|
|
|
time.gone = time.cur - time.old;
|
|
|
|
|
if (time.gone > 200) {
|
|
|
|
|
speed = downloader.httpd.content_received - netdata_received / time.gone * 100;
|
|
|
|
|
debugval("speed", speed);
|
|
|
|
|
debugln(ConvertSizeToKb(speed) );
|
|
|
|
|
time.old = time.cur;
|
|
|
|
|
netdata_received = downloader.httpd.content_received;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else time.old = time.cur;
|
|
|
|
|
}
|
2018-11-04 03:20:00 +03:00
|
|
|
|
*/
|
2016-03-25 18:35:48 +03:00
|
|
|
|
|
2015-12-22 21:14:35 +03:00
|
|
|
|
void DrawDownloading()
|
|
|
|
|
{
|
2018-05-18 23:18:10 +03:00
|
|
|
|
char bytes_received[70];
|
2018-05-20 16:40:58 +03:00
|
|
|
|
sprintf(#bytes_received, KB_RECEIVED, ConvertSizeToKb(downloader.httpd.content_received) );
|
2018-11-02 00:48:33 +03:00
|
|
|
|
DrawBar(CONX, pb.top + 22, pb.width, 16, system.color.work);
|
|
|
|
|
WriteText(CONX, pb.top + 22, 0x90, system.color.work_text, #bytes_received);
|
|
|
|
|
//CalculateSpeed();
|
2018-05-18 23:18:10 +03:00
|
|
|
|
progressbar_draw stdcall(#pb);
|
2015-12-22 21:14:35 +03:00
|
|
|
|
}
|
2016-03-25 18:35:48 +03:00
|
|
|
|
|
2015-12-22 21:14:35 +03:00
|
|
|
|
void StopDownloading()
|
|
|
|
|
{
|
2018-05-18 23:18:10 +03:00
|
|
|
|
downloader.Stop();
|
|
|
|
|
ed.blur_border_color = 0xFFFfff;
|
|
|
|
|
ed.flags = 10b;
|
|
|
|
|
DL_Draw_Window();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SaveDownloadedFile()
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
char aux[2048];
|
|
|
|
|
char notify_message[4296];
|
|
|
|
|
|
|
|
|
|
// Clean all slashes at the end
|
|
|
|
|
strcpy(#aux, #downloader_edit);
|
|
|
|
|
while (aux[strlen(#aux)-1] == '/') {
|
|
|
|
|
aux[strlen(#aux)-1] = 0;
|
|
|
|
|
}
|
|
|
|
|
sprintf(#filepath, "%s/%s", #save_to, #aux+strrchr(#aux, '/'));
|
|
|
|
|
|
|
|
|
|
for (i=0; i<strlen(#filepath); i++) if(filepath[i]==':')||(filepath[i]=='?')filepath[i]='-';
|
|
|
|
|
|
2018-05-20 16:40:58 +03:00
|
|
|
|
if (CreateFile(downloader.httpd.content_received, downloader.bufpointer, #filepath)==0)
|
2018-05-18 23:18:10 +03:00
|
|
|
|
sprintf(#notify_message, "%s%s%s",FILE_SAVED_AS,#filepath,"' -Dt");
|
|
|
|
|
else
|
|
|
|
|
sprintf(#notify_message, "%s%s%s","'Download manager\nError! Can\96t save file as ",#filepath,"' -Et");
|
|
|
|
|
|
|
|
|
|
notify(#notify_message);
|
2016-03-25 18:35:48 +03:00
|
|
|
|
}
|