2015-03-02 00:36:17 +03:00
|
|
|
|
#ifdef LANG_RUS
|
2015-03-16 17:20:32 +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> ᪠稢<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-02 00:36:17 +03:00
|
|
|
|
#else
|
|
|
|
|
#define DL_WINDOW_HEADER "Download Manager"
|
|
|
|
|
#define START_DOWNLOADING "Start downloading"
|
|
|
|
|
#define STOP_DOWNLOADING "Stop downloading"
|
2015-03-16 17:20:32 +03:00
|
|
|
|
#define SHOW_IN_FOLDER "Show in folder"
|
|
|
|
|
#define OPEN_FILE "Open file"
|
2015-03-02 00:36:17 +03:00
|
|
|
|
#define FILE_SAVED_AS "'Download manager\nFile saved as "
|
2015-03-16 17:20:32 +03:00
|
|
|
|
#define KB_RECEIVED " received"
|
2015-03-02 00:36:17 +03:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
proc_info DL_Form;
|
|
|
|
|
system_colors sc;
|
|
|
|
|
char DL_URL[10000];
|
2015-03-16 17:20:32 +03:00
|
|
|
|
dword DL_bufpointer, DL_bufsize, DL_http_transfer, DL_http_buffer;
|
2015-03-02 00:36:17 +03:00
|
|
|
|
char filepath[4096];
|
|
|
|
|
int downloaded_size, full_size;
|
|
|
|
|
int mouse_twbi;
|
|
|
|
|
edit_box DL_address_box = {250,20,20,0xffffff,0x94AECE,0xffffff,0xffffff,0,sizeof(DL_URL),#DL_URL,#mouse_twbi,2,19,19};
|
2015-03-16 17:20:32 +03:00
|
|
|
|
progress_bar DL_progress_bar = {0, 170, 51, 225, 12, 0, 0, 100, 0xFFFfff, 0x74DA00, 0x9F9F9F};
|
2015-03-02 00:36:17 +03:00
|
|
|
|
|
|
|
|
|
char save_to[4096] = "/tmp0/1/Downloads/";
|
2015-03-16 17:20:32 +03:00
|
|
|
|
byte cleft = 15;
|
|
|
|
|
|
|
|
|
|
byte downloader_opened;
|
|
|
|
|
|
|
|
|
|
byte download_state;
|
|
|
|
|
enum { STATE_NOT_STARTED, STATE_IN_PROGRESS, STATE_COMPLETED };
|
2015-03-02 00:36:17 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Downloader()
|
|
|
|
|
{
|
|
|
|
|
int key, btn;
|
|
|
|
|
mouse m;
|
|
|
|
|
char notify_message[4296];
|
|
|
|
|
|
|
|
|
|
if (DL_URL[0]) {
|
|
|
|
|
StartDownloading();
|
|
|
|
|
}
|
|
|
|
|
else strcpy(#DL_URL, "http://");
|
|
|
|
|
DL_address_box.size = DL_address_box.pos = DL_address_box.shift = DL_address_box.shift_old = strlen(#DL_URL);
|
|
|
|
|
|
|
|
|
|
downloaded_size = full_size = 0;
|
2015-03-16 17:20:32 +03:00
|
|
|
|
downloader_opened = 1;
|
2015-03-02 00:36:17 +03:00
|
|
|
|
|
|
|
|
|
SetEventMask(0x27);
|
|
|
|
|
loop()
|
|
|
|
|
{
|
|
|
|
|
WaitEventTimeout(40);
|
|
|
|
|
switch(EAX & 0xFF)
|
|
|
|
|
{
|
|
|
|
|
CASE evMouse:
|
|
|
|
|
if (!CheckActiveProcess(DL_Form.ID)) break;
|
|
|
|
|
if (DL_http_transfer <= 0) edit_box_mouse stdcall (#DL_address_box);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case evButton:
|
|
|
|
|
btn=GetButtonID();
|
|
|
|
|
DL_Scan(btn);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case evKey:
|
|
|
|
|
key = GetKey();
|
|
|
|
|
if (DL_address_box.flags & 0b10)
|
|
|
|
|
{
|
|
|
|
|
EAX=key<<8;
|
|
|
|
|
edit_box_key stdcall(#DL_address_box);
|
|
|
|
|
}
|
|
|
|
|
if (key==13) DL_Scan(301);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case evReDraw:
|
|
|
|
|
sc.get();
|
2015-03-16 17:20:32 +03:00
|
|
|
|
DefineAndDrawWindow(215, 100, 420, 120, 0x74, sc.work, DL_WINDOW_HEADER, 0);
|
2015-03-02 00:36:17 +03: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 17:20:32 +03:00
|
|
|
|
if (DL_Form.width==0) || (DL_http_transfer <= 0) break;
|
2015-03-02 00:36:17 +03:00
|
|
|
|
http_process stdcall (DL_http_transfer);
|
2015-03-16 17:20:32 +03: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-02 00:36:17 +03:00
|
|
|
|
if (EAX == 0) {
|
|
|
|
|
ESI = DL_http_transfer;
|
|
|
|
|
DL_bufpointer = ESI.http_msg.content_ptr;
|
|
|
|
|
DL_bufsize = ESI.http_msg.content_received;
|
|
|
|
|
http_free stdcall (DL_http_transfer);
|
|
|
|
|
DL_http_transfer=0;
|
|
|
|
|
strcpy(#filepath, #save_to);
|
|
|
|
|
strcat(#filepath, #DL_URL+strrchr(#DL_URL, '/'));
|
|
|
|
|
if (WriteFile(DL_bufsize, DL_bufpointer, #filepath)==0)
|
|
|
|
|
{
|
|
|
|
|
strcpy(#notify_message, FILE_SAVED_AS);
|
|
|
|
|
strcat(#notify_message, #filepath);
|
|
|
|
|
strcat(#notify_message, "' -Dt");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
strcpy(#notify_message, "'Download manager\nError! Can\96t save file as ");
|
|
|
|
|
strcat(#notify_message, #filepath);
|
|
|
|
|
strcat(#notify_message, "' -Et");
|
|
|
|
|
}
|
|
|
|
|
notify(#notify_message);
|
|
|
|
|
DL_address_box.color = DL_address_box.blur_border_color = DL_address_box.focus_border_color = 0xFFFfff;
|
2015-03-16 17:20:32 +03:00
|
|
|
|
download_state = STATE_COMPLETED;
|
2015-03-02 00:36:17 +03:00
|
|
|
|
DL_Draw_Window();
|
2015-03-16 17:20:32 +03:00
|
|
|
|
break;
|
2015-03-02 00:36:17 +03: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-03-16 17:20:32 +03:00
|
|
|
|
DrawBar(0,0, DL_Form.cwidth, DL_Form.cheight, sc.work);
|
|
|
|
|
DeleteButton(305);
|
|
|
|
|
DeleteButton(306);
|
|
|
|
|
if (download_state == STATE_NOT_STARTED) || (download_state == STATE_COMPLETED)
|
2015-03-02 00:36:17 +03:00
|
|
|
|
{
|
2015-03-16 17:20:32 +03:00
|
|
|
|
DrawCaptButton(cleft, 50, 130, 27, 301, sc.work_button, sc.work_button_text, START_DOWNLOADING);
|
2015-03-02 00:36:17 +03:00
|
|
|
|
}
|
2015-03-16 17:20:32 +03:00
|
|
|
|
if (download_state == STATE_IN_PROGRESS)
|
2015-03-02 00:36:17 +03:00
|
|
|
|
{
|
2015-03-16 17:20:32 +03:00
|
|
|
|
DrawCaptButton(cleft, 50, 140, 27, 302, sc.work_button, sc.work_button_text, STOP_DOWNLOADING);
|
|
|
|
|
DrawDownloading();
|
2015-03-02 00:36:17 +03:00
|
|
|
|
}
|
2015-03-16 17:20:32 +03:00
|
|
|
|
if (download_state == STATE_COMPLETED)
|
2015-03-02 00:36:17 +03:00
|
|
|
|
{
|
2015-03-16 17:20:32 +03:00
|
|
|
|
DrawCaptButton(cleft+140, 50, 110, 27, 305, sc.work_button, sc.work_button_text, SHOW_IN_FOLDER);
|
|
|
|
|
DrawCaptButton(cleft+260, 50, 120, 27, 306, sc.work_button, sc.work_button_text, OPEN_FILE);
|
2015-03-02 00:36:17 +03:00
|
|
|
|
}
|
|
|
|
|
WriteText(cleft, DL_address_box.top + 4, 0x80, sc.work_text, "URL:");
|
|
|
|
|
DL_address_box.left = strlen("URL:")*6 + 10 + cleft;
|
|
|
|
|
DL_address_box.width = DL_Form.cwidth - DL_address_box.left - cleft - 3;
|
|
|
|
|
DL_address_box.offset=0;
|
|
|
|
|
edit_box_draw stdcall(#DL_address_box);
|
2015-03-16 17:20:32 +03:00
|
|
|
|
DrawRectangle(DL_address_box.left-1, DL_address_box.top-1, DL_address_box.width+2, 16, DL_address_box.color);
|
|
|
|
|
DrawRectangle(DL_address_box.left-2, DL_address_box.top-2, DL_address_box.width+4, 18, border_color);
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-02 00:36:17 +03:00
|
|
|
|
|
2015-03-16 17:20:32 +03:00
|
|
|
|
void DrawDownloading()
|
|
|
|
|
{
|
|
|
|
|
dword tmp;
|
|
|
|
|
char bytes_received[70];
|
|
|
|
|
|
|
|
|
|
tmp = ConvertSizeToKb(downloaded_size);
|
|
|
|
|
strcpy(#bytes_received, tmp);
|
|
|
|
|
strcat(#bytes_received, KB_RECEIVED);
|
|
|
|
|
DrawBar(DL_progress_bar.left, DL_progress_bar.top + 17, DL_Form.cwidth - DL_progress_bar.left, 9, sc.work);
|
|
|
|
|
WriteText(DL_progress_bar.left, DL_progress_bar.top + 17, 0x80, sc.work_text, #bytes_received);
|
|
|
|
|
progressbar_draw stdcall(#DL_progress_bar);
|
2015-03-02 00:36:17 +03:00
|
|
|
|
}
|
|
|
|
|
|
2015-03-16 17:20:32 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-03-02 00:36:17 +03:00
|
|
|
|
void DL_Scan(int id)
|
|
|
|
|
{
|
2015-03-16 17:20:32 +03:00
|
|
|
|
if (id==001) {
|
|
|
|
|
downloader_opened=0;
|
|
|
|
|
StopDownloading();
|
|
|
|
|
ExitProcess();
|
|
|
|
|
}
|
2015-03-02 00:36:17 +03: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-03-16 17:20:32 +03:00
|
|
|
|
download_state = STATE_NOT_STARTED;
|
2015-03-02 00:36:17 +03:00
|
|
|
|
if (DL_http_transfer<>0)
|
|
|
|
|
{
|
|
|
|
|
EAX = DL_http_transfer;
|
|
|
|
|
EAX = EAX.http_msg.content_ptr; // get pointer to data
|
|
|
|
|
$push EAX // save it on the stack
|
|
|
|
|
http_free stdcall (DL_http_transfer); // abort connection
|
|
|
|
|
$pop EAX
|
|
|
|
|
mem_Free(EAX); // free data
|
|
|
|
|
DL_http_transfer=0;
|
|
|
|
|
DL_bufsize = 0;
|
|
|
|
|
DL_bufpointer = mem_Free(DL_bufpointer);
|
|
|
|
|
downloaded_size = full_size = 0;
|
|
|
|
|
}
|
|
|
|
|
DL_address_box.color = DL_address_box.blur_border_color = DL_address_box.focus_border_color = 0xFFFfff;
|
|
|
|
|
DL_Draw_Window();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StartDownloading()
|
|
|
|
|
{
|
|
|
|
|
StopDownloading();
|
|
|
|
|
if (strncmp(#DL_URL,"http:",5)==0)
|
|
|
|
|
{
|
2015-03-16 17:20:32 +03:00
|
|
|
|
download_state = STATE_IN_PROGRESS;
|
|
|
|
|
DL_address_box.color = DL_address_box.blur_border_color = DL_address_box.focus_border_color = 0xdddDDD;
|
2015-03-02 00:36:17 +03:00
|
|
|
|
http_get stdcall (#DL_URL, #accept_language);
|
|
|
|
|
DL_http_transfer = EAX;
|
2015-03-16 17:20:32 +03:00
|
|
|
|
DL_progress_bar.value = 0;
|
2015-03-02 00:36:17 +03: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://");
|
|
|
|
|
}
|
|
|
|
|
}
|