Rev 5651 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4662 | leency | 1 | #define MEMSIZE 0x100000 |
2 | //libraries |
||
3 | #include "..\lib\kolibri.h" |
||
4 | #include "..\lib\strings.h" |
||
5499 | leency | 5 | #include "..\lib\gui.h" |
4666 | leency | 6 | #include "..\lib\encoding.h" |
7 | #include "..\lib\draw_buf.h" |
||
4662 | leency | 8 | #include "..\lib\file_system.h" |
9 | #include "..\lib\mem.h" |
||
10 | #include "..\lib\dll.h" |
||
11 | #include "..\lib\list_box.h" |
||
12 | //*.obj libraries |
||
5499 | leency | 13 | #include "..\lib\obj\box_lib.h" |
14 | #include "..\lib\obj\libio_lib.h" |
||
15 | #include "..\lib\obj\http.h" |
||
4662 | leency | 16 | |
4667 | leency | 17 | char header[]="New Downloader v0.6"; |
4662 | leency | 18 | |
19 | #ifdef LANG_RUS |
||
20 | char accept_language[]= "Accept-Language: ru\n"; |
||
21 | #else |
||
22 | char accept_language[]= "Accept-Language: en\n"; |
||
23 | #endif |
||
24 | |||
25 | proc_info Form; |
||
26 | #define WIN_W 400 |
||
4666 | leency | 27 | #define WIN_H 220 |
5674 | pavelyakov | 28 | |
4662 | leency | 29 | #define URL param |
30 | |||
31 | int mouse_twb; |
||
32 | edit_box address_box= {250,20,20,0xffffff,0x94AECE,0xffffff,0xffffff,0,sizeof(URL),#URL,#mouse_twb,2,19,19}; |
||
33 | |||
34 | dword speed[2000]; |
||
35 | dword speed_position; |
||
36 | dword bufpointer; |
||
37 | dword bufsize; |
||
38 | |||
39 | dword http_transfer = 0; |
||
40 | dword http_buffer; |
||
41 | |||
4666 | leency | 42 | DrawBufer diagram; |
4662 | leency | 43 | |
44 | void main() |
||
45 | { |
||
46 | int key, btn; |
||
5640 | pavelyakov | 47 | |
4662 | leency | 48 | char filepath[4096]; |
49 | char notify_message[4296]; |
||
50 | |||
5626 | leency | 51 | load_dll(boxlib, #box_lib_init,0); |
52 | load_dll(libio, #libio_init,1); |
||
53 | load_dll(libHTTP, #http_lib_init,1); |
||
4662 | leency | 54 | if (!URL) strcpy(#URL, "http://builds.kolibrios.org/eng/latest-iso.7z"); |
55 | address_box.size = address_box.pos = strlen(#URL); |
||
56 | |||
4666 | leency | 57 | SetEventMask(0x27); //a7 |
4662 | leency | 58 | loop() |
59 | { |
||
60 | WaitEventTimeout(40); |
||
61 | switch(EAX & 0xFF) |
||
62 | { |
||
63 | CASE evMouse: |
||
64 | if (!CheckActiveProcess(Form.ID)) break; |
||
65 | if (http_transfer <= 0) edit_box_mouse stdcall (#address_box); |
||
66 | break; |
||
67 | |||
68 | case evButton: |
||
69 | btn=GetButtonID(); |
||
70 | if (btn==1) ExitProcess(); |
||
71 | Scan(btn); |
||
72 | break; |
||
73 | |||
74 | case evKey: |
||
75 | key = GetKey(); |
||
76 | if (address_box.flags & 0b10) |
||
77 | { |
||
78 | EAX=key<<8; |
||
79 | edit_box_key stdcall(#address_box); |
||
80 | } |
||
81 | if (key==13) Scan(301); |
||
82 | break; |
||
83 | |||
84 | case evReDraw: |
||
5674 | pavelyakov | 85 | system.color.get(); |
86 | DefineAndDrawWindow(215,100,WIN_W,WIN_H,0x73,system.color.work,#header,0); |
||
4662 | leency | 87 | GetProcessInfo(#Form, SelfInfo); |
5493 | leency | 88 | if (Form.status_window>2) break; |
4662 | leency | 89 | if (Form.height<120) MoveSize(OLD,OLD,OLD,120); |
90 | if (Form.width<280) MoveSize(OLD,OLD,280,OLD); |
||
4666 | leency | 91 | diagram.Init(20, 87, Form.cwidth - 40, Form.cheight - 87 - 28); |
4662 | leency | 92 | Draw_Window(); |
93 | break; |
||
94 | |||
95 | default: |
||
96 | if (Form.width==0) break; |
||
97 | if (http_transfer <= 0) break; |
||
5534 | hidnplayr | 98 | http_receive stdcall (http_transfer); |
4662 | leency | 99 | if (EAX == 0) { |
100 | ESI = http_transfer; |
||
101 | bufpointer = ESI.http_msg.content_ptr; |
||
102 | bufsize = ESI.http_msg.content_received; |
||
103 | http_free stdcall (http_transfer); |
||
104 | http_transfer=0; |
||
105 | strcpy(#filepath, "/tmp0/1/"); |
||
106 | strcat(#filepath, #URL+strrchr(#URL, '/')); |
||
5493 | leency | 107 | if (!WriteFile(bufsize, bufpointer, #filepath)) |
4662 | leency | 108 | { |
109 | strcpy(#notify_message, "File saved as "); |
||
110 | } |
||
111 | else |
||
112 | { |
||
113 | strcpy(#notify_message, "Error! Can't save file as "); |
||
114 | } |
||
115 | strcat(#notify_message, #filepath); |
||
116 | notify(#notify_message); |
||
117 | address_box.color = address_box.blur_border_color = address_box.focus_border_color = 0xFFFfff; |
||
118 | Draw_Window(); |
||
119 | } |
||
120 | ESI = http_transfer; |
||
121 | speed[speed_position] = ESI.http_msg.content_received; |
||
122 | DrawSpeed(); |
||
123 | speed_position++; |
||
124 | } |
||
125 | } |
||
126 | } |
||
127 | |||
128 | void DrawSpeed() |
||
129 | { |
||
130 | int i; |
||
4666 | leency | 131 | int speed_in_position, speed_string; |
4662 | leency | 132 | int max_speed, start_from; |
133 | char bytes_received[70]; |
||
134 | |||
4666 | leency | 135 | diagram.Fill(0xFCF8F7); |
4662 | leency | 136 | max_speed = speed[speed_position]; |
4666 | leency | 137 | if (speed_position < diagram.bufw) start_from = 0; else start_from = speed_position - diagram.bufw + 1; |
4667 | leency | 138 | if (speed_position>0) for (i = 0; i <= speed_position-start_from; i++) |
4662 | leency | 139 | { |
140 | if (max_speed>0) |
||
141 | { |
||
4666 | leency | 142 | speed_in_position = diagram.bufh - 1 * speed[i+start_from] / max_speed; |
143 | diagram.DrawBar(i, diagram.bufh - speed_in_position, 1, speed_in_position, 0x00A3CB); |
||
4662 | leency | 144 | } |
145 | } |
||
4666 | leency | 146 | diagram.Show(); |
4662 | leency | 147 | if (speed_position==0) return; |
148 | if (http_transfer > 0) |
||
149 | { |
||
150 | strcpy(#bytes_received, "Downloading... "); |
||
151 | } |
||
152 | else |
||
153 | { |
||
154 | strcpy(#bytes_received, "Downloading competle. "); |
||
155 | } |
||
4666 | leency | 156 | speed_string = ConvertSize(speed[speed_position-1]); |
157 | strcat(#bytes_received, speed_string); |
||
158 | strcat(#bytes_received, " received."); |
||
5674 | pavelyakov | 159 | DrawBar(diagram.bufx, diagram.bufy + diagram.bufh + 10, diagram.bufw, 9, system.color.work); |
160 | WriteText(diagram.bufx, diagram.bufy + diagram.bufh + 10, 0x80, system.color.work_text, #bytes_received); |
||
4662 | leency | 161 | } |
162 | |||
163 | void Draw_Window() |
||
164 | { |
||
5674 | pavelyakov | 165 | DrawBar(0,0,Form.cwidth,Form.cheight,system.color.work); //bg |
4666 | leency | 166 | if (http_transfer <= 0) |
167 | { |
||
5674 | pavelyakov | 168 | DrawCaptButton(diagram.bufx, 50, 120, 20, 301, system.color.work_button, system.color.work_button_text, "Start downloading"); |
4666 | leency | 169 | } |
170 | else |
||
171 | { |
||
5674 | pavelyakov | 172 | DrawCaptButton(diagram.bufx, 50, 120, 20, 302, system.color.work_button, system.color.work_button_text, "Stop downloading"); |
4666 | leency | 173 | } |
4662 | leency | 174 | if (http_transfer <= 0) && (speed_position>0) |
175 | { |
||
5674 | pavelyakov | 176 | DrawCaptButton(diagram.bufx+130, 50, 120, 20, 305, system.color.work_button, system.color.work_button_text, "Show in folder"); |
4662 | leency | 177 | } |
5674 | pavelyakov | 178 | WriteText(diagram.bufx, address_box.top + 4, 0x80, system.color.work_text, "URL:"); |
4666 | leency | 179 | address_box.left = strlen("URL:")*6 + 10 + diagram.bufx; |
180 | address_box.width = Form.cwidth - address_box.left - diagram.bufx - 3; |
||
4662 | leency | 181 | address_box.offset=0; |
182 | edit_box_draw stdcall(#address_box); |
||
183 | DrawRectangle(address_box.left-1, address_box.top-1, address_box.width+2, 16,address_box.color); |
||
5674 | pavelyakov | 184 | DrawRectangle(address_box.left-2, address_box.top-2, address_box.width+4, 18,system.color.work_graph); |
4662 | leency | 185 | |
5674 | pavelyakov | 186 | DrawRectangle(diagram.bufx-2, diagram.bufy-2, diagram.bufw+2, diagram.bufh+2, system.color.work_graph); |
4662 | leency | 187 | DrawSpeed(); |
188 | } |
||
189 | |||
190 | void Scan(int id) |
||
191 | { |
||
4667 | leency | 192 | if (id==301) && (http_transfer <= 0) StartDownloading(); |
4662 | leency | 193 | if (id==302) StopDownloading(); |
194 | if (id==305) RunProgram("/sys/File managers/Eolite", "/tmp0/1/"); |
||
195 | } |
||
196 | |||
197 | |||
198 | void StopDownloading() |
||
199 | { |
||
200 | if (http_transfer<>0) |
||
201 | { |
||
202 | EAX = http_transfer; |
||
203 | EAX = EAX.http_msg.content_ptr; // get pointer to data |
||
204 | $push EAX // save it on the stack |
||
205 | http_free stdcall (http_transfer); // abort connection |
||
206 | $pop EAX |
||
207 | mem_Free(EAX); // free data |
||
208 | http_transfer=0; |
||
209 | bufsize = 0; |
||
210 | bufpointer = mem_Free(bufpointer); |
||
211 | } |
||
212 | address_box.color = address_box.blur_border_color = address_box.focus_border_color = 0xFFFfff; |
||
4667 | leency | 213 | speed_position = 0; |
4662 | leency | 214 | Draw_Window(); |
215 | } |
||
216 | |||
217 | void StartDownloading() |
||
218 | { |
||
219 | StopDownloading(); |
||
220 | speed_position = 0; |
||
221 | if (strncmp(#URL,"http:",5)==0) |
||
222 | { |
||
223 | address_box.color = address_box.blur_border_color = address_box.focus_border_color = 0xededed; |
||
5534 | hidnplayr | 224 | http_get stdcall (#URL, 0, 0, #accept_language); |
4662 | leency | 225 | http_transfer = EAX; |
4667 | leency | 226 | Draw_Window(); |
4662 | leency | 227 | if (http_transfer == 0) |
228 | { |
||
229 | StopDownloading(); |
||
230 | bufsize = 0; |
||
231 | bufpointer = mem_Free(bufpointer); |
||
232 | return; |
||
233 | } |
||
234 | } |
||
235 | else |
||
236 | { |
||
5493 | leency | 237 | notify("File adress should starts from http://"); |
4662 | leency | 238 | } |
239 | } |
||
240 | |||
241 | |||
242 | |||
243 | stop:>=>=>=>=>>=>280)>120)>8;><8;>=> |