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