Rev 7282 | Rev 7506 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
7284 | leency | 1 | DOWNLOADER downloader; |
2 | |||
5493 | leency | 3 | #ifdef LANG_RUS |
7281 | leency | 4 | #define DL_WINDOW_HEADER "Менеджер загрузок" |
5 | #define START_DOWNLOADING "Начать закачку" |
||
6 | #define STOP_DOWNLOADING "Остановить" |
||
7 | #define SHOW_IN_FOLDER "Показать в папке" |
||
8 | #define OPEN_FILE_TEXT "Открыть файл" |
||
9 | #define FILE_SAVED_AS "'Менеджер загрузок\nФайл сохранен как " |
||
10 | #define KB_RECEIVED "Идет скачивание... %s получено" |
||
5493 | leency | 11 | #else |
7281 | leency | 12 | #define DL_WINDOW_HEADER "Download Manager" |
13 | #define START_DOWNLOADING "Start downloading" |
||
14 | #define STOP_DOWNLOADING "Stop downloading" |
||
15 | #define SHOW_IN_FOLDER "Show in folder" |
||
16 | #define OPEN_FILE_TEXT "Open file" |
||
17 | #define FILE_SAVED_AS "'Download manager\nFile saved as " |
||
18 | #define KB_RECEIVED "Downloading... %s received" |
||
5493 | leency | 19 | #endif |
6366 | leency | 20 | char save_to[4096] = "/tmp0/1/Downloads"; |
6374 | guillem | 21 | |
5493 | leency | 22 | proc_info DL_Form; |
6001 | leency | 23 | char downloader_edit[10000]; |
5493 | leency | 24 | char filepath[4096]; |
7281 | leency | 25 | edit_box ed = {NULL,57,20,0xffffff,0x94AECE,0xffffff,0xffffff,0x10000000,sizeof(downloader_edit),#downloader_edit,0,2,19,19}; |
6969 | leency | 26 | progress_bar pb = {0, 20, 58, 350, 17, 0, 0, 100, 0xFFFfff, 0x74DA00, 0x9F9F9F}; |
27 | //progress_bar pb = {0, 180, 55, 225, 12, 0, 0, 100, 0xFFFfff, 0x74DA00, 0x9F9F9F}; |
||
28 | //progress_bar: value, left, top, width, height, style, min, max, back_color, progress_color, frame_color; |
||
7281 | leency | 29 | |
6374 | guillem | 30 | |
7281 | leency | 31 | bool downloader_opened; |
6366 | leency | 32 | char downloader_stak[4096]; |
6374 | guillem | 33 | |
34 | |||
35 | |||
36 | void Downloader() |
||
5493 | leency | 37 | { |
7281 | leency | 38 | if (!dir_exists(#save_to)) CreateDir(#save_to); |
39 | downloader_opened = true; |
||
40 | SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER + EVM_STACK); |
||
6969 | leency | 41 | |
7281 | leency | 42 | system.color.get(); |
43 | pb.frame_color = system.color.work_dark; |
||
6374 | guillem | 44 | |
7281 | leency | 45 | filepath[0] = NULL; |
46 | |||
47 | downloader.Stop(); |
||
48 | if (downloader_edit[0]) StartDownloading(); else strcpy(#downloader_edit, "http://"); |
||
49 | ed.size = ed.pos = ed.shift = ed.shift_old = strlen(#downloader_edit); |
||
6374 | guillem | 50 | |
7281 | leency | 51 | loop() switch(WaitEvent()) |
52 | { |
||
53 | case evMouse: |
||
54 | edit_box_mouse stdcall (#ed); |
||
55 | break; |
||
6978 | leency | 56 | |
7281 | leency | 57 | case evButton: |
58 | Key_Scan(GetButtonID()); |
||
59 | break; |
||
6978 | leency | 60 | |
7281 | leency | 61 | case evKey: |
62 | GetKeys(); |
||
63 | edit_box_key stdcall(#ed); |
||
64 | if (key_scancode==SCAN_CODE_ENTER) Key_Scan(301); |
||
65 | break; |
||
6978 | leency | 66 | |
7281 | leency | 67 | case evReDraw: |
68 | DefineAndDrawWindow(215, 100, 580, 130, 0x74, system.color.work, DL_WINDOW_HEADER, 0); |
||
69 | GetProcessInfo(#DL_Form, SelfInfo); |
||
70 | if (DL_Form.status_window>2) break; |
||
71 | if (DL_Form.height<120) MoveSize(OLD,OLD,OLD,120); |
||
72 | if (DL_Form.width<280) MoveSize(OLD,OLD,280,OLD); |
||
73 | DL_Draw_Window(); |
||
74 | break; |
||
75 | |||
76 | default: |
||
77 | if (!downloader.MonitorProgress()) break; |
||
7282 | leency | 78 | pb.max = downloader.httpd.content_length; |
79 | if (pb.value != downloader.httpd.content_received) |
||
7281 | leency | 80 | { |
7282 | leency | 81 | pb.value = downloader.httpd.content_received; |
7281 | leency | 82 | progressbar_draw stdcall(#pb); |
83 | DrawDownloading(); |
||
84 | } |
||
85 | if (downloader.state == STATE_COMPLETED) |
||
86 | { |
||
87 | SaveDownloadedFile(); |
||
88 | StopDownloading(); |
||
89 | DL_Draw_Window(); |
||
90 | break; |
||
91 | } |
||
92 | } |
||
5493 | leency | 93 | } |
6374 | guillem | 94 | |
6001 | leency | 95 | void Key_Scan(int id) |
96 | { |
||
7281 | leency | 97 | if (id==001) { downloader_opened=false; StopDownloading(); ExitProcess(); } |
98 | if (id==301) && (downloader.httpd.transfer <= 0) StartDownloading(); |
||
99 | if (id==302) StopDownloading(); |
||
100 | if (id==305) RunProgram("/sys/File managers/Eolite", #save_to); |
||
101 | if (id==306) { |
||
102 | SetCurDir(#save_to); |
||
103 | RunProgram("/sys/@open", #filepath); |
||
104 | } |
||
6001 | leency | 105 | } |
6374 | guillem | 106 | |
5493 | leency | 107 | void DL_Draw_Window() |
6374 | guillem | 108 | { |
7281 | leency | 109 | int cleft = 15; |
110 | int but_x = 0; |
||
111 | int but_y = 58; |
||
112 | DrawBar(0,0, DL_Form.cwidth, DL_Form.cheight, system.color.work); |
||
113 | DeleteButton(301); |
||
114 | DeleteButton(302); |
||
115 | DeleteButton(305); |
||
116 | DeleteButton(306); |
||
117 | if (downloader.state == STATE_NOT_STARTED) || (downloader.state == STATE_COMPLETED) |
||
118 | { |
||
119 | but_x = cleft + DrawStandartCaptButton(cleft, but_y, 301, START_DOWNLOADING); |
||
120 | if (filepath[0]) |
||
121 | { |
||
122 | but_x += DrawStandartCaptButton(but_x, but_y, 305, SHOW_IN_FOLDER); |
||
123 | DrawStandartCaptButton(but_x, but_y, 306, OPEN_FILE_TEXT); |
||
124 | } |
||
125 | } |
||
126 | if (downloader.state == STATE_IN_PROGRESS) |
||
127 | { |
||
128 | DrawStandartCaptButton(DL_Form.width - 190, but_y, 302, STOP_DOWNLOADING); |
||
129 | DrawDownloading(); |
||
130 | } |
||
131 | WriteText(cleft, ed.top + 4, 0x90, system.color.work_text, "URL:"); |
||
6374 | guillem | 132 | ed.width = DL_Form.cwidth - ed.left - cleft - 3; |
7281 | leency | 133 | ed.offset=0; |
134 | DrawEditBox(#ed); |
||
5519 | leency | 135 | } |
6374 | guillem | 136 | |
6001 | leency | 137 | void StartDownloading() |
138 | { |
||
7281 | leency | 139 | StopDownloading(); |
140 | if (strncmp(#downloader_edit,"http://",7)!=0) { |
||
141 | notify("'File address should start from http://' -E"); |
||
142 | return; |
||
143 | } |
||
144 | if (!downloader.Start(#downloader_edit)) { |
||
145 | notify("'Error while starting download process.\nPlease, check entered path and internet connection.' -E"); |
||
146 | StopDownloading(); |
||
147 | return; |
||
148 | } |
||
149 | ed.blur_border_color = 0xCACACA; |
||
150 | ed.flags = 100000000000b; |
||
151 | pb.value = 0; |
||
152 | DL_Draw_Window(); |
||
6001 | leency | 153 | } |
6374 | guillem | 154 | |
5519 | leency | 155 | void DrawDownloading() |
156 | { |
||
7281 | leency | 157 | char bytes_received[70]; |
7282 | leency | 158 | sprintf(#bytes_received, KB_RECEIVED, ConvertSizeToKb(downloader.httpd.content_received) ); |
7281 | leency | 159 | DrawBar(15, pb.top + 22, strlen(#bytes_received+4)*12, 16, system.color.work); |
160 | WriteText(15, pb.top + 22, 0x90, system.color.work_text, #bytes_received); |
||
161 | progressbar_draw stdcall(#pb); |
||
5493 | leency | 162 | } |
6374 | guillem | 163 | |
5493 | leency | 164 | void StopDownloading() |
165 | { |
||
7281 | leency | 166 | downloader.Stop(); |
167 | ed.blur_border_color = 0xFFFfff; |
||
168 | ed.flags = 10b; |
||
169 | DL_Draw_Window(); |
||
170 | } |
||
171 | |||
172 | void SaveDownloadedFile() |
||
173 | { |
||
174 | int i; |
||
175 | char aux[2048]; |
||
176 | char notify_message[4296]; |
||
177 | |||
178 | // Clean all slashes at the end |
||
179 | strcpy(#aux, #downloader_edit); |
||
180 | while (aux[strlen(#aux)-1] == '/') { |
||
181 | aux[strlen(#aux)-1] = 0; |
||
182 | } |
||
183 | sprintf(#filepath, "%s/%s", #save_to, #aux+strrchr(#aux, '/')); |
||
184 | |||
185 | for (i=0; i |
||
186 | |||
7282 | leency | 187 | if (CreateFile(downloader.httpd.content_received, downloader.bufpointer, #filepath)==0) |
7281 | leency | 188 | sprintf(#notify_message, "%s%s%s",FILE_SAVED_AS,#filepath,"' -Dt"); |
189 | else |
||
190 | sprintf(#notify_message, "%s%s%s","'Download manager\nError! Can\96t save file as ",#filepath,"' -Et"); |
||
191 | |||
192 | notify(#notify_message); |
||
6374 | guillem | 193 | }=>280)>120)> |