1,33 → 1,40 |
#ifdef LANG_RUS |
#define DL_WINDOW_HEADER "Download Manager" |
#define START_DOWNLOADING "Start downloading" |
#define STOP_DOWNLOADING "Stop downloading" |
#define FILE_SAVED_AS "'Download manager\nFile saved as " |
#define DOWNLOADING_COMPLETE "Downloading complete." |
#define DL_WINDOW_HEADER "¥¥¤¦¥à § £à㧮ª" |
#define START_DOWNLOADING " ç âì § ª çªã" |
#define STOP_DOWNLOADING "áâ ®¢¨âì ᪠稢 ¨¥" |
#define SHOW_IN_FOLDER "®ª § âì ¢ ¯ ¯ª¥" |
#define OPEN_FILE "âªàëâì ä ©«" |
#define FILE_SAVED_AS "'¥¥¤¦¥à § £à㧮ª\n ©« á®åà ¥ ª ª " |
#define KB_RECEIVED " ¯®«ã祮" |
#else |
#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 "Open file" |
#define FILE_SAVED_AS "'Download manager\nFile saved as " |
#define DOWNLOADING_COMPLETE "Downloading complete." |
#define KB_RECEIVED " received" |
#endif |
|
proc_info DL_Form; |
system_colors sc; |
char DL_URL[10000]; |
dword DL_bufpointer; |
dword DL_bufsize; |
dword DL_http_transfer; |
dword DL_http_buffer; |
dword DL_bufpointer, DL_bufsize, DL_http_transfer, DL_http_buffer; |
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}; |
progress_bar DL_progress_bar = {0, 170, 51, 225, 12, 0, 0, 100, 0xFFFfff, 0x74DA00, 0x9F9F9F}; |
|
char save_to[4096] = "/tmp0/1/Downloads/"; |
byte cleft = 10; |
byte cleft = 15; |
|
byte downloader_opened; |
|
byte download_state; |
enum { STATE_NOT_STARTED, STATE_IN_PROGRESS, STATE_COMPLETED }; |
|
|
void Downloader() |
{ |
int key, btn; |
41,6 → 48,7 |
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; |
downloader_opened = 1; |
|
SetEventMask(0x27); |
loop() |
55,7 → 63,6 |
|
case evButton: |
btn=GetButtonID(); |
if (btn==1) ExitProcess(); |
DL_Scan(btn); |
break; |
|
71,7 → 78,7 |
|
case evReDraw: |
sc.get(); |
DefineAndDrawWindow(215, 100, 420, 150, 0x74, sc.work, DL_WINDOW_HEADER, 0); |
DefineAndDrawWindow(215, 100, 420, 120, 0x74, sc.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); |
80,9 → 87,17 |
break; |
|
default: |
if (DL_Form.width==0) break; |
if (DL_http_transfer <= 0) break; |
if (DL_Form.width==0) || (DL_http_transfer <= 0) break; |
http_process stdcall (DL_http_transfer); |
$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 |
if (EAX == 0) { |
ESI = DL_http_transfer; |
DL_bufpointer = ESI.http_msg.content_ptr; |
105,7 → 120,9 |
} |
notify(#notify_message); |
DL_address_box.color = DL_address_box.blur_border_color = DL_address_box.focus_border_color = 0xFFFfff; |
download_state = STATE_COMPLETED; |
DL_Draw_Window(); |
break; |
} |
ESI = DL_http_transfer; |
downloaded_size = ESI.http_msg.content_received; |
115,50 → 132,26 |
} |
} |
|
void DrawDownloading() |
{ |
dword tmp; |
char bytes_received[70], percent[30]; |
|
percent[0]=0; |
|
if (DL_http_transfer > 0) |
{ |
strcpy(#bytes_received, "Downloading... "); |
tmp = ConvertSizeToKb(downloaded_size); |
strcat(#bytes_received, tmp); |
strcat(#bytes_received, " received."); |
if (full_size>0) |
{ |
tmp = itoa(downloaded_size * 100 / full_size); |
strcpy(#percent, tmp); |
strcat(#percent, " \x25"); |
} |
} |
else |
{ |
strcpy(#bytes_received, DOWNLOADING_COMPLETE); |
} |
DrawBar(cleft, 90, DL_Form.cwidth - cleft, 9, sc.work); |
WriteText(cleft, 90, 0x80, sc.work_text, #bytes_received); |
WriteText(DL_Form.cwidth - 50, 90, 0x80, sc.work_text, #percent); |
} |
|
void DL_Draw_Window() |
{ |
DrawBar(0,0,DL_Form.cwidth,DL_Form.cheight,sc.work); //bg |
if (DL_http_transfer <= 0) |
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) |
{ |
DrawCaptButton(cleft, 50, 120, 20, 301, sc.work_button, sc.work_button_text, START_DOWNLOADING); |
DrawCaptButton(cleft, 50, 130, 27, 301, sc.work_button, sc.work_button_text, START_DOWNLOADING); |
} |
else |
if (download_state == STATE_IN_PROGRESS) |
{ |
DrawCaptButton(cleft, 50, 120, 20, 302, sc.work_button, sc.work_button_text, STOP_DOWNLOADING); |
DrawCaptButton(cleft, 50, 140, 27, 302, sc.work_button, sc.work_button_text, STOP_DOWNLOADING); |
DrawDownloading(); |
} |
if (DL_http_transfer <= 0) |
if (download_state == STATE_COMPLETED) |
{ |
DrawCaptButton(cleft+130, 50, 120, 20, 305, sc.work_button, sc.work_button_text, "Show in folder"); |
DrawCaptButton(cleft+260, 50, 120, 20, 306, sc.work_button, sc.work_button_text, "Open file"); |
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); |
} |
WriteText(cleft, DL_address_box.top + 4, 0x80, sc.work_text, "URL:"); |
DL_address_box.left = strlen("URL:")*6 + 10 + cleft; |
166,13 → 159,33 |
DL_address_box.offset=0; |
edit_box_draw stdcall(#DL_address_box); |
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,sc.work_graph); |
DrawRectangle(DL_address_box.left-2, DL_address_box.top-2, DL_address_box.width+4, 18, border_color); |
} |
|
DrawDownloading(); |
|
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); |
} |
|
|
|
|
void DL_Scan(int id) |
{ |
if (id==001) { |
downloader_opened=0; |
StopDownloading(); |
ExitProcess(); |
} |
if (id==301) && (DL_http_transfer <= 0) StartDownloading(); |
if (id==302) StopDownloading(); |
if (id==305) RunProgram("/sys/File managers/Eolite", #save_to); |
182,6 → 195,7 |
|
void StopDownloading() |
{ |
download_state = STATE_NOT_STARTED; |
if (DL_http_transfer<>0) |
{ |
EAX = DL_http_transfer; |
204,9 → 218,11 |
StopDownloading(); |
if (strncmp(#DL_URL,"http:",5)==0) |
{ |
DL_address_box.color = DL_address_box.blur_border_color = DL_address_box.focus_border_color = 0xededed; |
download_state = STATE_IN_PROGRESS; |
DL_address_box.color = DL_address_box.blur_border_color = DL_address_box.focus_border_color = 0xdddDDD; |
http_get stdcall (#DL_URL, #accept_language); |
DL_http_transfer = EAX; |
DL_progress_bar.value = 0; |
DL_Draw_Window(); |
if (DL_http_transfer == 0) |
{ |