2015-03-01 22:36:17 +01:00
|
|
|
|
#ifdef LANG_RUS
|
2015-03-16 15:20:32 +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> ᪠稢<E1AAA0><E7A8A2><EFBFBD><EFBFBD>"
|
|
|
|
|
#define SHOW_IN_FOLDER "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD>"
|
|
|
|
|
#define OPEN_FILE "<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 " <20><><EFBFBD><EFBFBD>祭<EFBFBD>"
|
2015-03-01 22:36:17 +01:00
|
|
|
|
#else
|
|
|
|
|
#define DL_WINDOW_HEADER "Download Manager"
|
|
|
|
|
#define START_DOWNLOADING "Start downloading"
|
|
|
|
|
#define STOP_DOWNLOADING "Stop downloading"
|
2015-03-16 15:20:32 +01:00
|
|
|
|
#define SHOW_IN_FOLDER "Show in folder"
|
|
|
|
|
#define OPEN_FILE "Open file"
|
2015-03-01 22:36:17 +01:00
|
|
|
|
#define FILE_SAVED_AS "'Download manager\nFile saved as "
|
2015-03-16 15:20:32 +01:00
|
|
|
|
#define KB_RECEIVED " received"
|
2015-03-01 22:36:17 +01:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
proc_info DL_Form;
|
|
|
|
|
char filepath[4096];
|
|
|
|
|
int mouse_twbi;
|
2015-08-05 17:30:25 +02:00
|
|
|
|
edit_box dl_edit = {250,20,20,0xffffff,0x94AECE,0xffffff,0xffffff,0,sizeof(DL_URL),#DL_URL,#mouse_twbi,2,19,19};
|
2015-03-16 15:20:32 +01:00
|
|
|
|
progress_bar DL_progress_bar = {0, 170, 51, 225, 12, 0, 0, 100, 0xFFFfff, 0x74DA00, 0x9F9F9F};
|
2015-03-01 22:36:17 +01:00
|
|
|
|
|
|
|
|
|
char save_to[4096] = "/tmp0/1/Downloads/";
|
2015-03-16 15:20:32 +01:00
|
|
|
|
byte cleft = 15;
|
|
|
|
|
|
|
|
|
|
byte downloader_opened;
|
|
|
|
|
|
2015-03-01 22:36:17 +01:00
|
|
|
|
|
|
|
|
|
void Downloader()
|
|
|
|
|
{
|
2015-08-05 17:30:25 +02:00
|
|
|
|
int key;
|
2015-03-01 22:36:17 +01:00
|
|
|
|
char notify_message[4296];
|
2015-08-05 17:30:25 +02:00
|
|
|
|
downloader_opened = 1;
|
|
|
|
|
SetEventMask(0x27);
|
2015-03-01 22:36:17 +01:00
|
|
|
|
|
2015-08-05 17:30:25 +02:00
|
|
|
|
if (DL_URL[0]) StartDownloading(); else strcpy(#DL_URL, "http://");
|
|
|
|
|
dl_edit.size = dl_edit.pos = dl_edit.shift = dl_edit.shift_old = strlen(#DL_URL);
|
2015-03-01 22:36:17 +01:00
|
|
|
|
|
2015-08-05 17:30:25 +02:00
|
|
|
|
Downloading_SetDefaults();
|
2015-03-01 22:36:17 +01:00
|
|
|
|
|
|
|
|
|
loop()
|
|
|
|
|
{
|
|
|
|
|
WaitEventTimeout(40);
|
|
|
|
|
switch(EAX & 0xFF)
|
|
|
|
|
{
|
|
|
|
|
CASE evMouse:
|
|
|
|
|
if (!CheckActiveProcess(DL_Form.ID)) break;
|
2015-08-05 17:30:25 +02:00
|
|
|
|
edit_box_mouse stdcall (#dl_edit);
|
2015-03-01 22:36:17 +01:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case evButton:
|
2015-08-05 17:30:25 +02:00
|
|
|
|
DL_Scan(GetButtonID());
|
2015-03-01 22:36:17 +01:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case evKey:
|
|
|
|
|
key = GetKey();
|
2015-08-05 13:00:04 +02:00
|
|
|
|
EAX=key<<8;
|
2015-08-05 17:30:25 +02:00
|
|
|
|
edit_box_key stdcall(#dl_edit);
|
2015-03-01 22:36:17 +01:00
|
|
|
|
if (key==13) DL_Scan(301);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case evReDraw:
|
2015-08-04 16:36:07 +02:00
|
|
|
|
system.color.get();
|
|
|
|
|
DefineAndDrawWindow(215, 100, 420, 120, 0x74, system.color.work, DL_WINDOW_HEADER, 0);
|
2015-03-01 22:36:17 +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:
|
2015-03-16 15:20:32 +01:00
|
|
|
|
if (DL_Form.width==0) || (DL_http_transfer <= 0) break;
|
2015-03-20 13:04:14 +01:00
|
|
|
|
http_receive stdcall (DL_http_transfer);
|
2015-03-16 15:20:32 +01:00
|
|
|
|
$push EAX
|
|
|
|
|
ESI = DL_http_transfer;
|
|
|
|
|
DL_progress_bar.max = ESI.http_msg.content_length;
|
|
|
|
|
if (DL_progress_bar.value != ESI.http_msg.content_received)
|
|
|
|
|
{
|
|
|
|
|
DL_progress_bar.value = ESI.http_msg.content_received;
|
|
|
|
|
progressbar_draw stdcall(#DL_progress_bar);
|
|
|
|
|
}
|
|
|
|
|
$pop EAX
|
2015-03-01 22:36:17 +01:00
|
|
|
|
if (EAX == 0) {
|
2015-08-05 17:30:25 +02:00
|
|
|
|
Downloading_Completed();
|
2015-03-01 22:36:17 +01:00
|
|
|
|
strcpy(#filepath, #save_to);
|
|
|
|
|
strcat(#filepath, #DL_URL+strrchr(#DL_URL, '/'));
|
|
|
|
|
if (WriteFile(DL_bufsize, DL_bufpointer, #filepath)==0)
|
|
|
|
|
{
|
2015-08-05 17:30:25 +02:00
|
|
|
|
sprintf(#notify_message, "%s%s%s",FILE_SAVED_AS,#filepath,"' -Dt");
|
2015-03-01 22:36:17 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-08-05 17:30:25 +02:00
|
|
|
|
sprintf(#notify_message, "%s%s%s","'Download manager\nError! Can\96t save file as ",#filepath,"' -Et");
|
2015-03-01 22:36:17 +01:00
|
|
|
|
}
|
|
|
|
|
notify(#notify_message);
|
2015-08-05 17:30:25 +02:00
|
|
|
|
dl_edit.blur_border_color = 0xFFFfff;
|
|
|
|
|
dl_edit.flags = 10b;
|
2015-03-01 22:36:17 +01:00
|
|
|
|
DL_Draw_Window();
|
2015-03-16 15:20:32 +01:00
|
|
|
|
break;
|
2015-03-01 22:36:17 +01:00
|
|
|
|
}
|
|
|
|
|
ESI = DL_http_transfer;
|
|
|
|
|
downloaded_size = ESI.http_msg.content_received;
|
|
|
|
|
full_size = ESI.http_msg.content_length;
|
|
|
|
|
DrawDownloading();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void DL_Draw_Window()
|
|
|
|
|
{
|
2015-08-04 16:36:07 +02:00
|
|
|
|
DrawBar(0,0, DL_Form.cwidth, DL_Form.cheight, system.color.work);
|
2015-03-16 15:20:32 +01:00
|
|
|
|
DeleteButton(305);
|
|
|
|
|
DeleteButton(306);
|
|
|
|
|
if (download_state == STATE_NOT_STARTED) || (download_state == STATE_COMPLETED)
|
2015-03-01 22:36:17 +01:00
|
|
|
|
{
|
2015-08-04 16:36:07 +02:00
|
|
|
|
DrawCaptButton(cleft, 50, 130, 27, 301, system.color.work_button, system.color.work_button_text, START_DOWNLOADING);
|
2015-03-01 22:36:17 +01:00
|
|
|
|
}
|
2015-03-16 15:20:32 +01:00
|
|
|
|
if (download_state == STATE_IN_PROGRESS)
|
2015-03-01 22:36:17 +01:00
|
|
|
|
{
|
2015-08-04 16:36:07 +02:00
|
|
|
|
DrawCaptButton(cleft, 50, 140, 27, 302, system.color.work_button, system.color.work_button_text, STOP_DOWNLOADING);
|
2015-03-16 15:20:32 +01:00
|
|
|
|
DrawDownloading();
|
2015-03-01 22:36:17 +01:00
|
|
|
|
}
|
2015-03-16 15:20:32 +01:00
|
|
|
|
if (download_state == STATE_COMPLETED)
|
2015-03-01 22:36:17 +01:00
|
|
|
|
{
|
2015-08-04 16:36:07 +02:00
|
|
|
|
DrawCaptButton(cleft+140, 50, 110, 27, 305, system.color.work_button, system.color.work_button_text, SHOW_IN_FOLDER);
|
|
|
|
|
DrawCaptButton(cleft+260, 50, 120, 27, 306, system.color.work_button, system.color.work_button_text, OPEN_FILE);
|
2015-03-01 22:36:17 +01:00
|
|
|
|
}
|
2015-08-05 17:30:25 +02:00
|
|
|
|
WriteText(cleft, dl_edit.top + 4, 0x80, system.color.work_text, "URL:");
|
|
|
|
|
dl_edit.left = strlen("URL:")*6 + 10 + cleft;
|
|
|
|
|
dl_edit.width = DL_Form.cwidth - dl_edit.left - cleft - 3;
|
|
|
|
|
dl_edit.offset=0;
|
|
|
|
|
edit_box_draw stdcall(#dl_edit);
|
|
|
|
|
DrawRectangle(dl_edit.left-1, dl_edit.top-1, dl_edit.width+2, 16, dl_edit.blur_border_color);
|
|
|
|
|
DrawRectangle(dl_edit.left-2, dl_edit.top-2, dl_edit.width+4, 18, border_color);
|
2015-03-16 15:20:32 +01:00
|
|
|
|
}
|
|
|
|
|
|
2015-03-01 22:36:17 +01:00
|
|
|
|
|
2015-03-16 15:20:32 +01:00
|
|
|
|
void DrawDownloading()
|
|
|
|
|
{
|
|
|
|
|
dword tmp;
|
|
|
|
|
char bytes_received[70];
|
|
|
|
|
|
|
|
|
|
tmp = ConvertSizeToKb(downloaded_size);
|
|
|
|
|
strcpy(#bytes_received, tmp);
|
|
|
|
|
strcat(#bytes_received, KB_RECEIVED);
|
2015-08-04 16:36:07 +02:00
|
|
|
|
DrawBar(DL_progress_bar.left, DL_progress_bar.top + 17, DL_Form.cwidth - DL_progress_bar.left, 9, system.color.work);
|
|
|
|
|
WriteText(DL_progress_bar.left, DL_progress_bar.top + 17, 0x80, system.color.work_text, #bytes_received);
|
2015-03-16 15:20:32 +01:00
|
|
|
|
progressbar_draw stdcall(#DL_progress_bar);
|
2015-03-01 22:36:17 +01:00
|
|
|
|
}
|
|
|
|
|
|
2015-03-16 15:20:32 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-03-01 22:36:17 +01:00
|
|
|
|
void DL_Scan(int id)
|
|
|
|
|
{
|
2015-03-16 15:20:32 +01:00
|
|
|
|
if (id==001) {
|
|
|
|
|
downloader_opened=0;
|
|
|
|
|
StopDownloading();
|
|
|
|
|
ExitProcess();
|
|
|
|
|
}
|
2015-03-01 22:36:17 +01:00
|
|
|
|
if (id==301) && (DL_http_transfer <= 0) StartDownloading();
|
|
|
|
|
if (id==302) StopDownloading();
|
|
|
|
|
if (id==305) RunProgram("/sys/File managers/Eolite", #save_to);
|
|
|
|
|
if (id==306) RunProgram("@open", #filepath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void StopDownloading()
|
|
|
|
|
{
|
2015-08-05 17:30:25 +02:00
|
|
|
|
Downloading_Stop();
|
|
|
|
|
dl_edit.blur_border_color = 0xFFFfff;
|
|
|
|
|
dl_edit.flags = 10b;
|
2015-03-01 22:36:17 +01:00
|
|
|
|
DL_Draw_Window();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StartDownloading()
|
|
|
|
|
{
|
|
|
|
|
StopDownloading();
|
|
|
|
|
if (strncmp(#DL_URL,"http:",5)==0)
|
|
|
|
|
{
|
2015-08-05 17:30:25 +02:00
|
|
|
|
Downloading_Start();
|
|
|
|
|
dl_edit.blur_border_color = 0xCACACA;
|
|
|
|
|
dl_edit.flags = 100000000000b;
|
2015-03-16 15:20:32 +01:00
|
|
|
|
DL_progress_bar.value = 0;
|
2015-03-01 22:36:17 +01:00
|
|
|
|
DL_Draw_Window();
|
|
|
|
|
if (DL_http_transfer == 0)
|
|
|
|
|
{
|
|
|
|
|
StopDownloading();
|
|
|
|
|
DL_bufsize = 0;
|
|
|
|
|
DL_bufpointer = mem_Free(DL_bufpointer);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
notify("File adress should starts from http://");
|
|
|
|
|
}
|
|
|
|
|
}
|