Rev 5493 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5493 | Rev 5519 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | #ifdef LANG_RUS |
1 | #ifdef LANG_RUS |
2 | #define DL_WINDOW_HEADER "Download Manager" |
2 | #define DL_WINDOW_HEADER "¥¥¤¦¥à § £à㧮ª" |
3 | #define START_DOWNLOADING "Start downloading" |
3 | #define START_DOWNLOADING " ç âì § ª çªã" |
4 | #define STOP_DOWNLOADING "Stop downloading" |
4 | #define STOP_DOWNLOADING "áâ ®¢¨âì ᪠稢 ¨¥" |
5 | #define FILE_SAVED_AS "'Download manager\nFile saved as " |
5 | #define SHOW_IN_FOLDER "®ª § âì ¢ ¯ ¯ª¥" |
6 | #define DOWNLOADING_COMPLETE "Downloading complete." |
6 | #define OPEN_FILE "âªàëâì ä ©«" |
- | 7 | #define FILE_SAVED_AS "'¥¥¤¦¥à § £à㧮ª\n ©« á®åà ¥ ª ª " |
|
- | 8 | #define KB_RECEIVED " ¯®«ã祮" |
|
7 | #else |
9 | #else |
8 | #define DL_WINDOW_HEADER "Download Manager" |
10 | #define DL_WINDOW_HEADER "Download Manager" |
9 | #define START_DOWNLOADING "Start downloading" |
11 | #define START_DOWNLOADING "Start downloading" |
10 | #define STOP_DOWNLOADING "Stop downloading" |
12 | #define STOP_DOWNLOADING "Stop downloading" |
- | 13 | #define SHOW_IN_FOLDER "Show in folder" |
|
- | 14 | #define OPEN_FILE "Open file" |
|
11 | #define FILE_SAVED_AS "'Download manager\nFile saved as " |
15 | #define FILE_SAVED_AS "'Download manager\nFile saved as " |
12 | #define DOWNLOADING_COMPLETE "Downloading complete." |
16 | #define KB_RECEIVED " received" |
13 | #endif |
17 | #endif |
Line 14... | Line 18... | ||
14 | 18 | ||
15 | proc_info DL_Form; |
19 | proc_info DL_Form; |
16 | system_colors sc; |
20 | system_colors sc; |
17 | char DL_URL[10000]; |
- | |
18 | dword DL_bufpointer; |
- | |
19 | dword DL_bufsize; |
21 | char DL_URL[10000]; |
20 | dword DL_http_transfer; |
- | |
21 | dword DL_http_buffer; |
22 | dword DL_bufpointer, DL_bufsize, DL_http_transfer, DL_http_buffer; |
22 | char filepath[4096]; |
23 | char filepath[4096]; |
23 | int downloaded_size, full_size; |
24 | int downloaded_size, full_size; |
24 | int mouse_twbi; |
25 | int mouse_twbi; |
- | 26 | edit_box DL_address_box = {250,20,20,0xffffff,0x94AECE,0xffffff,0xffffff,0,sizeof(DL_URL),#DL_URL,#mouse_twbi,2,19,19}; |
|
Line 25... | Line 27... | ||
25 | edit_box DL_address_box = {250,20,20,0xffffff,0x94AECE,0xffffff,0xffffff,0,sizeof(DL_URL),#DL_URL,#mouse_twbi,2,19,19}; |
27 | progress_bar DL_progress_bar = {0, 170, 51, 225, 12, 0, 0, 100, 0xFFFfff, 0x74DA00, 0x9F9F9F}; |
26 | 28 | ||
- | 29 | char save_to[4096] = "/tmp0/1/Downloads/"; |
|
- | 30 | byte cleft = 15; |
|
- | 31 | ||
- | 32 | byte downloader_opened; |
|
- | 33 | ||
Line 27... | Line 34... | ||
27 | char save_to[4096] = "/tmp0/1/Downloads/"; |
34 | byte download_state; |
28 | byte cleft = 10; |
35 | enum { STATE_NOT_STARTED, STATE_IN_PROGRESS, STATE_COMPLETED }; |
29 | 36 | ||
Line 39... | Line 46... | ||
39 | } |
46 | } |
40 | else strcpy(#DL_URL, "http://"); |
47 | else strcpy(#DL_URL, "http://"); |
41 | DL_address_box.size = DL_address_box.pos = DL_address_box.shift = DL_address_box.shift_old = strlen(#DL_URL); |
48 | DL_address_box.size = DL_address_box.pos = DL_address_box.shift = DL_address_box.shift_old = strlen(#DL_URL); |
Line 42... | Line 49... | ||
42 | 49 | ||
- | 50 | downloaded_size = full_size = 0; |
|
Line 43... | Line 51... | ||
43 | downloaded_size = full_size = 0; |
51 | downloader_opened = 1; |
44 | 52 | ||
45 | SetEventMask(0x27); |
53 | SetEventMask(0x27); |
46 | loop() |
54 | loop() |
Line 53... | Line 61... | ||
53 | if (DL_http_transfer <= 0) edit_box_mouse stdcall (#DL_address_box); |
61 | if (DL_http_transfer <= 0) edit_box_mouse stdcall (#DL_address_box); |
54 | break; |
62 | break; |
Line 55... | Line 63... | ||
55 | 63 | ||
56 | case evButton: |
64 | case evButton: |
57 | btn=GetButtonID(); |
- | |
58 | if (btn==1) ExitProcess(); |
65 | btn=GetButtonID(); |
59 | DL_Scan(btn); |
66 | DL_Scan(btn); |
Line 60... | Line 67... | ||
60 | break; |
67 | break; |
61 | 68 | ||
Line 69... | Line 76... | ||
69 | if (key==13) DL_Scan(301); |
76 | if (key==13) DL_Scan(301); |
70 | break; |
77 | break; |
Line 71... | Line 78... | ||
71 | 78 | ||
72 | case evReDraw: |
79 | case evReDraw: |
73 | sc.get(); |
80 | sc.get(); |
74 | DefineAndDrawWindow(215, 100, 420, 150, 0x74, sc.work, DL_WINDOW_HEADER, 0); |
81 | DefineAndDrawWindow(215, 100, 420, 120, 0x74, sc.work, DL_WINDOW_HEADER, 0); |
75 | GetProcessInfo(#DL_Form, SelfInfo); |
82 | GetProcessInfo(#DL_Form, SelfInfo); |
76 | if (DL_Form.status_window>2) break; |
83 | if (DL_Form.status_window>2) break; |
77 | if (DL_Form.height<120) MoveSize(OLD,OLD,OLD,120); |
84 | if (DL_Form.height<120) MoveSize(OLD,OLD,OLD,120); |
78 | if (DL_Form.width<280) MoveSize(OLD,OLD,280,OLD); |
85 | if (DL_Form.width<280) MoveSize(OLD,OLD,280,OLD); |
79 | DL_Draw_Window(); |
86 | DL_Draw_Window(); |
Line 80... | Line 87... | ||
80 | break; |
87 | break; |
81 | - | ||
82 | default: |
88 | |
83 | if (DL_Form.width==0) break; |
89 | default: |
- | 90 | if (DL_Form.width==0) || (DL_http_transfer <= 0) break; |
|
- | 91 | http_process stdcall (DL_http_transfer); |
|
- | 92 | $push EAX |
|
- | 93 | ESI = DL_http_transfer; |
|
- | 94 | DL_progress_bar.max = ESI.http_msg.content_length; |
|
- | 95 | if (DL_progress_bar.value != ESI.http_msg.content_received) |
|
- | 96 | { |
|
- | 97 | DL_progress_bar.value = ESI.http_msg.content_received; |
|
- | 98 | progressbar_draw stdcall(#DL_progress_bar); |
|
84 | if (DL_http_transfer <= 0) break; |
99 | } |
85 | http_process stdcall (DL_http_transfer); |
100 | $pop EAX |
86 | if (EAX == 0) { |
101 | if (EAX == 0) { |
87 | ESI = DL_http_transfer; |
102 | ESI = DL_http_transfer; |
88 | DL_bufpointer = ESI.http_msg.content_ptr; |
103 | DL_bufpointer = ESI.http_msg.content_ptr; |
Line 103... | Line 118... | ||
103 | strcat(#notify_message, #filepath); |
118 | strcat(#notify_message, #filepath); |
104 | strcat(#notify_message, "' -Et"); |
119 | strcat(#notify_message, "' -Et"); |
105 | } |
120 | } |
106 | notify(#notify_message); |
121 | notify(#notify_message); |
107 | DL_address_box.color = DL_address_box.blur_border_color = DL_address_box.focus_border_color = 0xFFFfff; |
122 | DL_address_box.color = DL_address_box.blur_border_color = DL_address_box.focus_border_color = 0xFFFfff; |
- | 123 | download_state = STATE_COMPLETED; |
|
108 | DL_Draw_Window(); |
124 | DL_Draw_Window(); |
- | 125 | break; |
|
109 | } |
126 | } |
110 | ESI = DL_http_transfer; |
127 | ESI = DL_http_transfer; |
111 | downloaded_size = ESI.http_msg.content_received; |
128 | downloaded_size = ESI.http_msg.content_received; |
112 | full_size = ESI.http_msg.content_length; |
129 | full_size = ESI.http_msg.content_length; |
113 | DrawDownloading(); |
130 | DrawDownloading(); |
114 | } |
131 | } |
115 | } |
132 | } |
116 | } |
133 | } |
Line 117... | Line -... | ||
117 | - | ||
118 | void DrawDownloading() |
- | |
119 | { |
- | |
120 | dword tmp; |
- | |
121 | char bytes_received[70], percent[30]; |
- | |
122 | - | ||
Line 123... | Line -... | ||
123 | percent[0]=0; |
- | |
124 | - | ||
125 | if (DL_http_transfer > 0) |
- | |
126 | { |
- | |
127 | strcpy(#bytes_received, "Downloading... "); |
- | |
128 | tmp = ConvertSizeToKb(downloaded_size); |
- | |
129 | strcat(#bytes_received, tmp); |
- | |
130 | strcat(#bytes_received, " received."); |
- | |
131 | if (full_size>0) |
- | |
132 | { |
- | |
133 | tmp = itoa(downloaded_size * 100 / full_size); |
- | |
134 | strcpy(#percent, tmp); |
- | |
135 | strcat(#percent, " \x25"); |
- | |
136 | } |
- | |
137 | } |
- | |
138 | else |
- | |
139 | { |
- | |
140 | strcpy(#bytes_received, DOWNLOADING_COMPLETE); |
- | |
141 | } |
- | |
142 | DrawBar(cleft, 90, DL_Form.cwidth - cleft, 9, sc.work); |
- | |
143 | WriteText(cleft, 90, 0x80, sc.work_text, #bytes_received); |
- | |
Line 144... | Line 134... | ||
144 | WriteText(DL_Form.cwidth - 50, 90, 0x80, sc.work_text, #percent); |
134 | |
145 | } |
135 | |
146 | 136 | ||
- | 137 | void DL_Draw_Window() |
|
147 | void DL_Draw_Window() |
138 | { |
- | 139 | DrawBar(0,0, DL_Form.cwidth, DL_Form.cheight, sc.work); |
|
148 | { |
140 | DeleteButton(305); |
149 | DrawBar(0,0,DL_Form.cwidth,DL_Form.cheight,sc.work); //bg |
141 | DeleteButton(306); |
150 | if (DL_http_transfer <= 0) |
142 | if (download_state == STATE_NOT_STARTED) || (download_state == STATE_COMPLETED) |
151 | { |
143 | { |
152 | DrawCaptButton(cleft, 50, 120, 20, 301, sc.work_button, sc.work_button_text, START_DOWNLOADING); |
144 | DrawCaptButton(cleft, 50, 130, 27, 301, sc.work_button, sc.work_button_text, START_DOWNLOADING); |
153 | } |
145 | } |
- | 146 | if (download_state == STATE_IN_PROGRESS) |
|
154 | else |
147 | { |
155 | { |
148 | DrawCaptButton(cleft, 50, 140, 27, 302, sc.work_button, sc.work_button_text, STOP_DOWNLOADING); |
156 | DrawCaptButton(cleft, 50, 120, 20, 302, sc.work_button, sc.work_button_text, STOP_DOWNLOADING); |
149 | DrawDownloading(); |
157 | } |
150 | } |
158 | if (DL_http_transfer <= 0) |
151 | if (download_state == STATE_COMPLETED) |
159 | { |
152 | { |
160 | DrawCaptButton(cleft+130, 50, 120, 20, 305, sc.work_button, sc.work_button_text, "Show in folder"); |
153 | DrawCaptButton(cleft+140, 50, 110, 27, 305, sc.work_button, sc.work_button_text, SHOW_IN_FOLDER); |
161 | DrawCaptButton(cleft+260, 50, 120, 20, 306, sc.work_button, sc.work_button_text, "Open file"); |
154 | DrawCaptButton(cleft+260, 50, 120, 27, 306, sc.work_button, sc.work_button_text, OPEN_FILE); |
162 | } |
155 | } |
163 | WriteText(cleft, DL_address_box.top + 4, 0x80, sc.work_text, "URL:"); |
156 | WriteText(cleft, DL_address_box.top + 4, 0x80, sc.work_text, "URL:"); |
164 | DL_address_box.left = strlen("URL:")*6 + 10 + cleft; |
157 | DL_address_box.left = strlen("URL:")*6 + 10 + cleft; |
165 | DL_address_box.width = DL_Form.cwidth - DL_address_box.left - cleft - 3; |
158 | DL_address_box.width = DL_Form.cwidth - DL_address_box.left - cleft - 3; |
166 | DL_address_box.offset=0; |
159 | DL_address_box.offset=0; |
- | 160 | edit_box_draw stdcall(#DL_address_box); |
|
Line -... | Line 161... | ||
- | 161 | DrawRectangle(DL_address_box.left-1, DL_address_box.top-1, DL_address_box.width+2, 16, DL_address_box.color); |
|
167 | edit_box_draw stdcall(#DL_address_box); |
162 | DrawRectangle(DL_address_box.left-2, DL_address_box.top-2, DL_address_box.width+4, 18, border_color); |
- | 163 | } |
|
- | 164 | ||
- | 165 | ||
- | 166 | void DrawDownloading() |
|
- | 167 | { |
|
- | 168 | dword tmp; |
|
- | 169 | char bytes_received[70]; |
|
- | 170 | ||
- | 171 | tmp = ConvertSizeToKb(downloaded_size); |
|
- | 172 | strcpy(#bytes_received, tmp); |
|
168 | DrawRectangle(DL_address_box.left-1, DL_address_box.top-1, DL_address_box.width+2, 16,DL_address_box.color); |
173 | strcat(#bytes_received, KB_RECEIVED); |
Line -... | Line 174... | ||
- | 174 | DrawBar(DL_progress_bar.left, DL_progress_bar.top + 17, DL_Form.cwidth - DL_progress_bar.left, 9, sc.work); |
|
- | 175 | WriteText(DL_progress_bar.left, DL_progress_bar.top + 17, 0x80, sc.work_text, #bytes_received); |
|
- | 176 | progressbar_draw stdcall(#DL_progress_bar); |
|
169 | DrawRectangle(DL_address_box.left-2, DL_address_box.top-2, DL_address_box.width+4, 18,sc.work_graph); |
177 | } |
170 | 178 | ||
- | 179 | ||
- | 180 | ||
- | 181 | ||
- | 182 | void DL_Scan(int id) |
|
- | 183 | { |
|
171 | DrawDownloading(); |
184 | if (id==001) { |
172 | } |
185 | downloader_opened=0; |
173 | 186 | StopDownloading(); |
|
174 | void DL_Scan(int id) |
187 | ExitProcess(); |
175 | { |
188 | } |
Line 176... | Line 189... | ||
176 | if (id==301) && (DL_http_transfer <= 0) StartDownloading(); |
189 | if (id==301) && (DL_http_transfer <= 0) StartDownloading(); |
177 | if (id==302) StopDownloading(); |
190 | if (id==302) StopDownloading(); |
- | 191 | if (id==305) RunProgram("/sys/File managers/Eolite", #save_to); |
|
178 | if (id==305) RunProgram("/sys/File managers/Eolite", #save_to); |
192 | if (id==306) RunProgram("@open", #filepath); |
179 | if (id==306) RunProgram("@open", #filepath); |
193 | } |
180 | } |
194 | |
181 | 195 | ||
182 | 196 | void StopDownloading() |
|
Line 202... | Line 216... | ||
202 | void StartDownloading() |
216 | void StartDownloading() |
203 | { |
217 | { |
204 | StopDownloading(); |
218 | StopDownloading(); |
205 | if (strncmp(#DL_URL,"http:",5)==0) |
219 | if (strncmp(#DL_URL,"http:",5)==0) |
206 | { |
220 | { |
- | 221 | download_state = STATE_IN_PROGRESS; |
|
207 | DL_address_box.color = DL_address_box.blur_border_color = DL_address_box.focus_border_color = 0xededed; |
222 | DL_address_box.color = DL_address_box.blur_border_color = DL_address_box.focus_border_color = 0xdddDDD; |
208 | http_get stdcall (#DL_URL, #accept_language); |
223 | http_get stdcall (#DL_URL, #accept_language); |
209 | DL_http_transfer = EAX; |
224 | DL_http_transfer = EAX; |
- | 225 | DL_progress_bar.value = 0; |
|
210 | DL_Draw_Window(); |
226 | DL_Draw_Window(); |
211 | if (DL_http_transfer == 0) |
227 | if (DL_http_transfer == 0) |
212 | { |
228 | { |
213 | StopDownloading(); |
229 | StopDownloading(); |
214 | DL_bufsize = 0; |
230 | DL_bufsize = 0; |