2015-12-22 19:14:35 +01:00
|
|
|
|
#ifdef LANG_RUS
|
2016-11-05 01:03:12 +01: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> "
|
2016-03-25 16:35:48 +01:00
|
|
|
|
#define KB_RECEIVED " <20><><EFBFBD><EFBFBD>祭<EFBFBD>"
|
2015-12-22 19:14:35 +01:00
|
|
|
|
#else
|
2016-03-25 16:35:48 +01: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 " received"
|
2015-12-22 19:14:35 +01:00
|
|
|
|
#endif
|
2016-03-23 12:13:28 +01:00
|
|
|
|
char save_to[4096] = "/tmp0/1/Downloads";
|
2016-03-25 16:35:48 +01:00
|
|
|
|
|
2015-12-22 19:14:35 +01:00
|
|
|
|
proc_info DL_Form;
|
|
|
|
|
char downloader_edit[10000];
|
|
|
|
|
char filepath[4096];
|
2016-03-25 16:35:48 +01:00
|
|
|
|
int mouse_twbi;
|
2016-11-05 11:13:29 +01:00
|
|
|
|
edit_box ed = {250,20,20,0xffffff,0x94AECE,0xffffff,0xffffff,0x10000000,sizeof(downloader_edit),#downloader_edit,#mouse_twbi,2,19,19};
|
2017-07-05 12:33:54 +02:00
|
|
|
|
progress_bar pb = {0, 200, 55, 225, 12, 0, 0, 100, 0xFFFfff, 0x74DA00, 0x9F9F9F};
|
2016-03-25 16:35:48 +01:00
|
|
|
|
|
2015-12-22 19:14:35 +01:00
|
|
|
|
byte downloader_opened;
|
2016-03-23 12:13:28 +01:00
|
|
|
|
char downloader_stak[4096];
|
2016-03-25 16:35:48 +01:00
|
|
|
|
char str[2048];
|
|
|
|
|
char aux[2048];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Downloader()
|
2015-12-22 19:14:35 +01:00
|
|
|
|
{
|
2016-11-05 01:03:12 +01:00
|
|
|
|
int key, i;
|
2016-03-25 16:35:48 +01:00
|
|
|
|
char notify_message[4296];
|
|
|
|
|
downloader_opened = 1;
|
|
|
|
|
SetEventMask(0x27);
|
|
|
|
|
|
2016-11-22 15:04:10 +01:00
|
|
|
|
filepath[0] = NULL;
|
|
|
|
|
|
2016-03-25 16:35:48 +01:00
|
|
|
|
downloader.Stop();
|
|
|
|
|
if (downloader_edit[0]) StartDownloading(); else strcpy(#downloader_edit, "http://");
|
|
|
|
|
ed.size = ed.pos = ed.shift = ed.shift_old = strlen(#downloader_edit);
|
|
|
|
|
|
|
|
|
|
loop()
|
|
|
|
|
{
|
|
|
|
|
WaitEventTimeout(30);
|
|
|
|
|
switch(EAX & 0xFF)
|
|
|
|
|
{
|
|
|
|
|
CASE evMouse:
|
|
|
|
|
if (!CheckActiveProcess(DL_Form.ID)) break;
|
|
|
|
|
edit_box_mouse stdcall (#ed);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case evButton:
|
|
|
|
|
Key_Scan(GetButtonID());
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case evKey:
|
|
|
|
|
GetKeys();
|
|
|
|
|
EAX = key_ascii << 8;
|
|
|
|
|
edit_box_key stdcall(#ed);
|
|
|
|
|
if (key_scancode==SCAN_CODE_ENTER) Key_Scan(301);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case evReDraw:
|
|
|
|
|
system.color.get();
|
2016-11-05 11:13:29 +01:00
|
|
|
|
DefineAndDrawWindow(215, 100, 580, 120, 0x74, system.color.work, DL_WINDOW_HEADER, 0);
|
2016-03-25 16:35:48 +01:00
|
|
|
|
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;
|
|
|
|
|
pb.max = downloader.data_full_size;
|
|
|
|
|
if (pb.value != downloader.data_downloaded_size)
|
|
|
|
|
{
|
|
|
|
|
pb.value = downloader.data_downloaded_size;
|
|
|
|
|
progressbar_draw stdcall(#pb);
|
|
|
|
|
DrawDownloading();
|
|
|
|
|
}
|
|
|
|
|
if (downloader.state == STATE_COMPLETED)
|
|
|
|
|
{
|
|
|
|
|
if (!dir_exists(#save_to)) CreateDir(#save_to);
|
|
|
|
|
strcpy(#filepath, #save_to);
|
|
|
|
|
chrcat(#filepath, '/');
|
|
|
|
|
// Clean all slashes at the end
|
|
|
|
|
strcpy(#aux, #downloader_edit);
|
|
|
|
|
while (aux[strlen(#aux)-1] == '/') {
|
|
|
|
|
aux[strlen(#aux)-1] = 0;
|
|
|
|
|
}
|
|
|
|
|
strcat(#filepath, #aux+strrchr(#aux, '/'));
|
2016-11-05 01:03:12 +01:00
|
|
|
|
|
|
|
|
|
for (i=0; i<strlen(#filepath); i++) if(filepath[i]==':')||(filepath[i]=='?')filepath[i]='-';
|
2016-03-25 16:35:48 +01:00
|
|
|
|
|
|
|
|
|
if (WriteFile(downloader.data_downloaded_size, downloader.bufpointer, #filepath)==0)
|
|
|
|
|
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);
|
|
|
|
|
StopDownloading();
|
|
|
|
|
DL_Draw_Window();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-12-22 19:14:35 +01:00
|
|
|
|
}
|
2016-03-25 16:35:48 +01:00
|
|
|
|
|
2015-12-22 19:14:35 +01:00
|
|
|
|
void Key_Scan(int id)
|
|
|
|
|
{
|
2016-03-25 16:35:48 +01:00
|
|
|
|
if (id==001) { downloader_opened=0; StopDownloading(); ExitProcess(); }
|
|
|
|
|
if (id==301) && (downloader.http_transfer <= 0) StartDownloading();
|
|
|
|
|
if (id==302) StopDownloading();
|
|
|
|
|
if (id==305) RunProgram("/sys/File managers/Eolite", #save_to);
|
2016-11-22 15:04:10 +01:00
|
|
|
|
if (id==306) RunProgram("/sys/@open", #filepath);
|
2015-12-22 19:14:35 +01:00
|
|
|
|
}
|
2016-03-25 16:35:48 +01:00
|
|
|
|
|
2015-12-22 19:14:35 +01:00
|
|
|
|
void DL_Draw_Window()
|
2016-03-25 16:35:48 +01:00
|
|
|
|
{
|
2016-11-05 11:13:29 +01:00
|
|
|
|
int cleft = 15;
|
|
|
|
|
int but_x;
|
2016-03-25 16:35:48 +01:00
|
|
|
|
DrawBar(0,0, DL_Form.cwidth, DL_Form.cheight, system.color.work);
|
|
|
|
|
DeleteButton(305);
|
|
|
|
|
DeleteButton(306);
|
|
|
|
|
if (downloader.state == STATE_NOT_STARTED) || (downloader.state == STATE_COMPLETED)
|
|
|
|
|
{
|
2016-11-05 11:13:29 +01:00
|
|
|
|
but_x = cleft + DrawStandartCaptButton(cleft, 55, 301, START_DOWNLOADING);
|
2016-03-25 16:35:48 +01:00
|
|
|
|
}
|
|
|
|
|
if (downloader.state == STATE_IN_PROGRESS)
|
|
|
|
|
{
|
2016-11-05 11:13:29 +01:00
|
|
|
|
DrawStandartCaptButton(cleft, 55, 302, STOP_DOWNLOADING);
|
2016-03-25 16:35:48 +01:00
|
|
|
|
DrawDownloading();
|
|
|
|
|
}
|
2016-11-05 11:13:29 +01:00
|
|
|
|
if (filepath[0])
|
2016-03-25 16:35:48 +01:00
|
|
|
|
{
|
2016-11-05 11:13:29 +01:00
|
|
|
|
but_x += DrawStandartCaptButton(but_x, 55, 305, SHOW_IN_FOLDER);
|
|
|
|
|
DrawStandartCaptButton(but_x, 55, 306, OPEN_FILE_TEXT);
|
2016-03-25 16:35:48 +01:00
|
|
|
|
}
|
2016-11-05 11:13:29 +01:00
|
|
|
|
WriteText(cleft, ed.top + 4, 0x90, system.color.work_text, "URL:");
|
|
|
|
|
ed.left = strlen("URL:")*8 + 10 + cleft;
|
2016-03-25 16:35:48 +01:00
|
|
|
|
ed.width = DL_Form.cwidth - ed.left - cleft - 3;
|
|
|
|
|
ed.offset=0;
|
|
|
|
|
DrawEditBox(#ed);
|
2015-12-22 19:14:35 +01:00
|
|
|
|
}
|
2016-03-25 16:35:48 +01:00
|
|
|
|
|
2015-12-22 19:14:35 +01:00
|
|
|
|
void StartDownloading()
|
|
|
|
|
{
|
2016-03-25 16:35:48 +01: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 19:14:35 +01:00
|
|
|
|
}
|
2016-03-25 16:35:48 +01:00
|
|
|
|
|
2015-12-22 19:14:35 +01:00
|
|
|
|
void DrawDownloading()
|
|
|
|
|
{
|
2016-03-25 16:35:48 +01:00
|
|
|
|
char bytes_received[70];
|
|
|
|
|
dword tmp = ConvertSizeToKb(downloader.data_downloaded_size);
|
|
|
|
|
sprintf(#bytes_received, "%s%s", tmp, KB_RECEIVED);
|
|
|
|
|
DrawBar(pb.left, pb.top + 17, DL_Form.cwidth - pb.left, 9, system.color.work);
|
|
|
|
|
WriteText(pb.left, pb.top + 17, 0x80, system.color.work_text, #bytes_received);
|
|
|
|
|
progressbar_draw stdcall(#pb);
|
2015-12-22 19:14:35 +01:00
|
|
|
|
}
|
2016-03-25 16:35:48 +01:00
|
|
|
|
|
2015-12-22 19:14:35 +01:00
|
|
|
|
void StopDownloading()
|
|
|
|
|
{
|
2016-03-25 16:35:48 +01:00
|
|
|
|
downloader.Stop();
|
|
|
|
|
ed.blur_border_color = 0xFFFfff;
|
|
|
|
|
ed.flags = 10b;
|
|
|
|
|
DL_Draw_Window();
|
|
|
|
|
}
|