Rev 8281 | Rev 8305 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 8281 | Rev 8291 | ||
---|---|---|---|
Line 4... | Line 4... | ||
4 | #include "../lib/gui.h" |
4 | #include "../lib/gui.h" |
5 | #include "../lib/random.h" |
5 | #include "../lib/random.h" |
Line 6... | Line 6... | ||
6 | 6 | ||
7 | #include "../lib/obj/box_lib.h" |
7 | #include "../lib/obj/box_lib.h" |
8 | #include "../lib/obj/http.h" |
- | |
Line 9... | Line 8... | ||
9 | #include "../lib/obj/libini.h" |
8 | #include "../lib/obj/http.h" |
Line 10... | Line 9... | ||
10 | 9 | ||
Line 11... | Line 10... | ||
11 | #include "../lib/patterns/http_downloader.h" |
10 | #include "../lib/patterns/http_downloader.h" |
12 | 11 | ||
Line 13... | Line 12... | ||
13 | #include "const.h" |
12 | #include "const.h" |
14 | 13 | ||
15 | DOWNLOADER downloader; |
14 | DOWNLOADER downloader; |
16 | checkbox autoclose = { T_AUTOCLOSE, true }; |
15 | checkbox autoclose = { T_AUTOCLOSE, false }; |
Line 28... | Line 27... | ||
28 | void main() |
27 | void main() |
29 | { |
28 | { |
30 | dword shared_url; |
29 | dword shared_url; |
31 | load_dll(boxlib, #box_lib_init,0); |
30 | load_dll(boxlib, #box_lib_init,0); |
32 | load_dll(libHTTP, #http_lib_init,1); |
31 | load_dll(libHTTP, #http_lib_init,1); |
33 | load_dll(libini, #lib_init,1); |
- | |
Line 34... | Line 32... | ||
34 | 32 | ||
Line 35... | Line 33... | ||
35 | if (!dir_exists(#save_to)) CreateDir(#save_to); |
33 | if (!dir_exists(#save_to)) CreateDir(#save_to); |
36 | 34 | ||
Line 72... | Line 70... | ||
72 | DrawWindow(); |
70 | DrawWindow(); |
73 | break; |
71 | break; |
Line 74... | Line 72... | ||
74 | 72 | ||
75 | default: |
73 | default: |
76 | if (!downloader.MonitorProgress()) break; |
74 | if (!downloader.MonitorProgress()) break; |
77 | pb.max = downloader.httpd.content_length / 100; |
75 | pb.max = downloader.content_length / 100; |
78 | EDI = downloader.httpd.content_received/100; |
76 | EDI = downloader.content_received/100; |
79 | if (pb.value != EDI) |
77 | if (pb.value != EDI) |
80 | { |
78 | { |
81 | pb.value = EDI; |
79 | pb.value = EDI; |
82 | progressbar_draw stdcall(#pb); |
80 | progressbar_draw stdcall(#pb); |
Line 95... | Line 93... | ||
95 | 93 | ||
96 | void ProcessEvent(int id) |
94 | void ProcessEvent(int id) |
97 | { |
95 | { |
98 | autoclose.click(id); |
96 | autoclose.click(id); |
99 | if (id==001) { StopDownloading(); ExitProcess(); } |
97 | if (id==001) { StopDownloading(); ExitProcess(); } |
100 | if (id==301) && (downloader.httpd.transfer <= 0) StartDownloading(); |
98 | if (id==301) && (downloader.transfer <= 0) StartDownloading(); |
101 | if (id==302) StopDownloading(); |
99 | if (id==302) StopDownloading(); |
102 | if (id==305) RunProgram("/sys/File managers/Eolite", #filepath); |
100 | if (id==305) RunProgram("/sys/File managers/Eolite", #filepath); |
103 | if (id==306) { |
101 | if (id==306) { |
104 | SetCurDir(#save_to); |
102 | SetCurDir(#save_to); |
Line 139... | Line 137... | ||
139 | { |
137 | { |
140 | char http_url[URL_SIZE]; |
138 | char http_url[URL_SIZE]; |
141 | char proxy_url[URL_SIZE]; |
139 | char proxy_url[URL_SIZE]; |
142 | StopDownloading(); |
140 | StopDownloading(); |
143 | if (!strncmp(#downloader_edit,"https://",7)) { |
141 | if (!strncmp(#downloader_edit,"https://",7)) { |
144 | notify("'HTTPS for download is not supported, trying to download the file via HTTP' -W"); |
142 | //notify("'HTTPS for download is not supported, trying to download the file via HTTP' -W"); |
145 | miniprintf(#http_url, "http://%s", #downloader_edit+8); |
143 | //miniprintf(#http_url, "http://%s", #downloader_edit+8); |
146 | if (!downloader.Start(#http_url)) { |
144 | //if (!downloader.Start(#http_url)) { |
147 | notify("'Download failed.' -E"); |
- | |
148 | StopDownloading(); |
- | |
149 | } |
- | |
150 | //sprintf(#proxy_url, "http://gate.aspero.pro/?site=%s", #downloader_edit); |
- | |
151 | //if (!downloader.Start(#proxy_url)) { |
- | |
152 | // notify("'Download failed.' -E"); |
145 | // notify("'Download failed.' -E"); |
153 | // StopDownloading(); |
146 | // StopDownloading(); |
154 | //} |
147 | //} |
- | 148 | miniprintf(#proxy_url, "http://gate.aspero.pro/?site=%s", #downloader_edit); |
|
- | 149 | if (!downloader.Start(#proxy_url)) { |
|
- | 150 | notify("'Download failed.' -E"); |
|
- | 151 | StopDownloading(); |
|
- | 152 | } |
|
155 | DrawWindow(); |
153 | DrawWindow(); |
156 | return; |
154 | return; |
157 | } |
155 | } |
158 | if (!downloader.Start(#downloader_edit)) { |
156 | if (!downloader.Start(#downloader_edit)) { |
159 | if (exit_when_done) ExitProcess(); |
157 | if (exit_when_done) ExitProcess(); |
Line 183... | Line 181... | ||
183 | time.cur = GetStartTime(); |
181 | time.cur = GetStartTime(); |
Line 184... | Line 182... | ||
184 | 182 | ||
185 | if (time.old) { |
183 | if (time.old) { |
186 | time.gone = time.cur - time.old; |
184 | time.gone = time.cur - time.old; |
187 | if (time.gone > 200) { |
185 | if (time.gone > 200) { |
188 | speed = downloader.httpd.content_received - netdata_received / time.gone * 100; |
186 | speed = downloader.content_received - netdata_received / time.gone * 100; |
189 | debugval("speed", speed); |
187 | debugval("speed", speed); |
190 | debugln(ConvertSizeToKb(speed) ); |
188 | debugln(ConvertSizeToKb(speed) ); |
191 | time.old = time.cur; |
189 | time.old = time.cur; |
192 | netdata_received = downloader.httpd.content_received; |
190 | netdata_received = downloader.content_received; |
193 | } |
191 | } |
194 | } |
192 | } |
195 | else time.old = time.cur; |
193 | else time.old = time.cur; |
196 | } |
194 | } |
Line 197... | Line 195... | ||
197 | */ |
195 | */ |
198 | 196 | ||
199 | void DrawDownloading() |
197 | void DrawDownloading() |
200 | { |
198 | { |
201 | char bytes_received[70]; |
199 | char bytes_received[70]; |
202 | miniprintf(#bytes_received, KB_RECEIVED, ConvertSizeToKb(downloader.httpd.content_received) ); |
200 | miniprintf(#bytes_received, KB_RECEIVED, ConvertSizeToKb(downloader.content_received) ); |
203 | WriteTextWithBg(GAPX, pb.top + 22, 0xD0, sc.work_text, #bytes_received, sc.work); |
201 | WriteTextWithBg(GAPX, pb.top + 22, 0xD0, sc.work_text, #bytes_received, sc.work); |
204 | //CalculateSpeed(); |
202 | //CalculateSpeed(); |
Line 230... | Line 228... | ||
230 | chrcat(#filepath, '/'); |
228 | chrcat(#filepath, '/'); |
231 | strcat(#filepath, #aux+strrchr(#aux, '/')); |
229 | strcat(#filepath, #aux+strrchr(#aux, '/')); |
Line 232... | Line 230... | ||
232 | 230 | ||
Line 233... | Line 231... | ||
233 | for (i=0; i |
231 | for (i=0; i |
234 | 232 | ||
235 | if (CreateFile(downloader.httpd.content_received, downloader.bufpointer, #filepath)==0) { |
233 | if (CreateFile(downloader.content_received, downloader.bufpointer, #filepath)==0) { |
236 | miniprintf(#notify_message, FILE_SAVED_AS, #filepath); |
234 | miniprintf(#notify_message, FILE_SAVED_AS, #filepath); |
237 | } else { |
235 | } else { |
Line 238... | Line 236... | ||
238 | miniprintf(#notify_message, FILE_NOT_SAVED, #filepath); |
236 | miniprintf(#notify_message, FILE_NOT_SAVED, #filepath); |
239 | } |
237 | } |
240 | 238 | ||
241 | /* |
239 | /* |
242 | if (CreateFile(downloader.httpd.content_received, downloader.bufpointer, #filepath)==0) { |
240 | if (CreateFile(downloader.content_received, downloader.bufpointer, #filepath)==0) { |
243 | strcpy(#notify_message, "'Download complete' -Dt"); |
241 | strcpy(#notify_message, "'Download complete' -Dt"); |
244 | } else { |
242 | } else { |