1 | #ifndef BGDOWNLOAD_H |
---|
2 | #define BGDOWNLOAD_H |
---|
3 | |
---|
4 | //flag 0: no msg |
---|
5 | //flag 1: with msg |
---|
6 | void delbgdownload(int nr, int flag) |
---|
7 | { |
---|
8 | if(nr >= MAXBGDOWNLOAD) return; |
---|
9 | |
---|
10 | int count = 0; |
---|
11 | struct skin* load = getscreen("loading"); |
---|
12 | struct download* dnode = bgdownload[nr]; |
---|
13 | |
---|
14 | if(dnode != NULL) |
---|
15 | { |
---|
16 | if(dnode->connfd > -1) |
---|
17 | { |
---|
18 | if(flag == 1) drawscreen(load, 0, 0); |
---|
19 | sockclose(&dnode->connfd); |
---|
20 | while(dnode->ret < 0 && count < 10) |
---|
21 | { |
---|
22 | count++; |
---|
23 | sleep(1); |
---|
24 | } |
---|
25 | if(flag == 1) clearscreen(load); |
---|
26 | } |
---|
27 | |
---|
28 | free(dnode->host); dnode->host = NULL; |
---|
29 | free(dnode->page); dnode->page = NULL; |
---|
30 | free(dnode->filename); dnode->filename = NULL; |
---|
31 | free(dnode->auth); dnode->auth = NULL; |
---|
32 | |
---|
33 | dnode->port = -1; |
---|
34 | dnode->ret = -1; |
---|
35 | dnode->timeout = 0; |
---|
36 | dnode->flag = 0; |
---|
37 | |
---|
38 | if(count < 10) |
---|
39 | { |
---|
40 | free(dnode); |
---|
41 | dnode = NULL; |
---|
42 | } |
---|
43 | else |
---|
44 | addoldentry((void*)dnode, 1, time(NULL) + 7200, NULL); |
---|
45 | |
---|
46 | bgdownload[nr] = NULL; |
---|
47 | } |
---|
48 | } |
---|
49 | |
---|
50 | void freebgdownload() |
---|
51 | { |
---|
52 | int i = 0; |
---|
53 | |
---|
54 | for(i = 0; i < MAXBGDOWNLOAD; i++) |
---|
55 | delbgdownload(i, 0); |
---|
56 | } |
---|
57 | |
---|
58 | //flag 0: with play |
---|
59 | //flag 1: without play |
---|
60 | void screenbgdownload(int flag) |
---|
61 | { |
---|
62 | int rcret = -1, i = 0; |
---|
63 | struct skin* screenbgdownload = getscreen("bgdownload"); |
---|
64 | struct skin* listbox = getscreennode(screenbgdownload, "listbox"); |
---|
65 | struct skin* progress = getscreennode(screenbgdownload, "progress"); |
---|
66 | struct skin* b4 = getscreennode(screenbgdownload, "b4");; |
---|
67 | struct skin* tmp = NULL; |
---|
68 | char* tmpstr = NULL; |
---|
69 | |
---|
70 | if(flag == 0) |
---|
71 | b4->hidden = NO; |
---|
72 | else |
---|
73 | b4->hidden = YES; |
---|
74 | |
---|
75 | for(i = 0; i < MAXBGDOWNLOAD; i++) |
---|
76 | { |
---|
77 | tmp = addlistbox(screenbgdownload, listbox, NULL, 1); |
---|
78 | if(tmp != NULL) |
---|
79 | { |
---|
80 | if(bgdownload[i] != NULL) |
---|
81 | { |
---|
82 | if(bgdownload[i]->ret == 0) |
---|
83 | tmpstr = ostrcat(tmpstr, "OK - ", 1, 0); |
---|
84 | else if(bgdownload[i]->ret == 1) |
---|
85 | tmpstr = ostrcat(tmpstr, "ERR - ", 1, 0); |
---|
86 | tmpstr = ostrcat(tmpstr, bgdownload[i]->filename, 1, 0); |
---|
87 | changetext(tmp, tmpstr); |
---|
88 | free(tmpstr); tmpstr = NULL; |
---|
89 | tmp->progresssize = bgdownload[i]->proz; |
---|
90 | tmp->handle = (void*)(i + 1); |
---|
91 | } |
---|
92 | else |
---|
93 | { |
---|
94 | changetext(tmp, _("unknown")); |
---|
95 | tmp->progresssize = 0; |
---|
96 | tmp->handle = (void*)(i + 1); |
---|
97 | } |
---|
98 | |
---|
99 | tmp->textposx = progress->width + 10; |
---|
100 | struct skin* tmp1 = NULL; |
---|
101 | tmp1 = addlistbox(screenbgdownload, tmp, tmp, 2); |
---|
102 | if(tmp1 != NULL) |
---|
103 | { |
---|
104 | tmp1->progresscol = progress->progresscol; |
---|
105 | tmp1->posy = progress->posy; |
---|
106 | tmp1->width = progress->width; |
---|
107 | tmp1->height = progress->height; |
---|
108 | tmp1->bordersize = progress->bordersize; |
---|
109 | tmp1->bordercol = progress->bordercol; |
---|
110 | tmp1->prozwidth = 0; |
---|
111 | tmp1->handle = (void*)(i + 1); |
---|
112 | } |
---|
113 | } |
---|
114 | } |
---|
115 | |
---|
116 | drawscreen(screenbgdownload, 0, 0); |
---|
117 | addscreenrc(screenbgdownload, listbox); |
---|
118 | |
---|
119 | while(1) |
---|
120 | { |
---|
121 | rcret = waitrc(screenbgdownload, 1000, 0); |
---|
122 | |
---|
123 | if(rcret == RCTIMEOUT) |
---|
124 | { |
---|
125 | tmp = listbox; |
---|
126 | while(tmp != NULL) |
---|
127 | { |
---|
128 | if(tmp->del > 0) |
---|
129 | { |
---|
130 | int nr = ((int)tmp->handle) - 1; |
---|
131 | if(nr > -1 && nr < MAXBGDOWNLOAD) |
---|
132 | { |
---|
133 | struct download* dnode = bgdownload[nr]; |
---|
134 | if(dnode != NULL) |
---|
135 | { |
---|
136 | if(tmp->del == 1) |
---|
137 | { |
---|
138 | if(dnode->ret == 0) |
---|
139 | tmpstr = ostrcat(tmpstr, "OK - ", 1, 0); |
---|
140 | else if(dnode->ret == 1) |
---|
141 | tmpstr = ostrcat(tmpstr, "ERR - ", 1, 0); |
---|
142 | tmpstr = ostrcat(tmpstr, dnode->filename, 1, 0); |
---|
143 | changetext(tmp, tmpstr); |
---|
144 | free(tmpstr); tmpstr = NULL; |
---|
145 | } |
---|
146 | if(tmp->del == 2) |
---|
147 | tmp->progresssize = dnode->proz; |
---|
148 | } |
---|
149 | else |
---|
150 | { |
---|
151 | if(tmp->del == 1) |
---|
152 | changetext(tmp, _("unknown")); |
---|
153 | if(tmp->del == 2) |
---|
154 | tmp->progresssize = 0; |
---|
155 | } |
---|
156 | } |
---|
157 | } |
---|
158 | tmp = tmp->next; |
---|
159 | } |
---|
160 | } |
---|
161 | drawscreen(screenbgdownload, 0, 0); |
---|
162 | |
---|
163 | if(rcret == getrcconfigint("rcexit", NULL)) break; |
---|
164 | |
---|
165 | if(rcret == getrcconfigint("rcred", NULL) && listbox->select != NULL && listbox->select->handle != NULL) //stop download |
---|
166 | { |
---|
167 | int nr = ((int)listbox->select->handle) - 1; |
---|
168 | if(nr > -1 && nr < MAXBGDOWNLOAD) |
---|
169 | { |
---|
170 | struct download* dnode = bgdownload[nr]; |
---|
171 | if(dnode != NULL && dnode->ret == -1) |
---|
172 | { |
---|
173 | if(textbox(_("Message"), _("Really stop download ?"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 0, 0) == 1) |
---|
174 | delbgdownload(nr, 1); |
---|
175 | drawscreen(screenbgdownload, 0, 0); |
---|
176 | } |
---|
177 | } |
---|
178 | } |
---|
179 | |
---|
180 | if(flag == 0 && rcret == getrcconfigint("rcyellow", NULL) && listbox->select != NULL && listbox->select->handle != NULL) //play download |
---|
181 | { |
---|
182 | int nr = ((int)listbox->select->handle) -1; |
---|
183 | if(nr > -1 && nr < MAXBGDOWNLOAD) |
---|
184 | { |
---|
185 | struct download* dnode = bgdownload[nr]; |
---|
186 | if(dnode != NULL && dnode->flag == 1) |
---|
187 | { |
---|
188 | if(status.mcaktiv == 0) |
---|
189 | { |
---|
190 | int ret = servicestop(status.aktservice, 1, 1); |
---|
191 | if(ret == 1) return; |
---|
192 | } |
---|
193 | screenplay(dnode->filename, dnode->filename, 2, 0); |
---|
194 | if(status.mcaktiv == 0) |
---|
195 | servicecheckret(servicestart(status.lastservice->channel, NULL, NULL, 0), 0); |
---|
196 | drawscreen(screenbgdownload, 0, 0); |
---|
197 | } |
---|
198 | } |
---|
199 | } |
---|
200 | } |
---|
201 | |
---|
202 | delmarkedscreennodes(screenbgdownload, 2); |
---|
203 | delmarkedscreennodes(screenbgdownload, 1); |
---|
204 | delownerrc(screenbgdownload); |
---|
205 | clearscreen(screenbgdownload); |
---|
206 | } |
---|
207 | |
---|
208 | //flag 0: normal download |
---|
209 | //flag 1: playable download |
---|
210 | int startbgdownload(char* host, char* page, int port, char* filename, char* auth, int timeout, int flag) |
---|
211 | { |
---|
212 | int i = 0; |
---|
213 | struct download* dnode = NULL; |
---|
214 | |
---|
215 | if(filename == NULL) |
---|
216 | { |
---|
217 | err("filename = NULL"); |
---|
218 | return 1; |
---|
219 | } |
---|
220 | |
---|
221 | for(i = 0; i < MAXBGDOWNLOAD; i++) |
---|
222 | { |
---|
223 | if(bgdownload[i] == NULL) |
---|
224 | break; //found unused slot |
---|
225 | else if(bgdownload[i]->ret >= 0) |
---|
226 | { |
---|
227 | delbgdownload(i, 0); |
---|
228 | break; //found unused slot |
---|
229 | } |
---|
230 | } |
---|
231 | |
---|
232 | if(i >= MAXBGDOWNLOAD) return 1; |
---|
233 | |
---|
234 | dnode = calloc(1, sizeof(struct download)); |
---|
235 | if(dnode == NULL) |
---|
236 | { |
---|
237 | err("no mem"); |
---|
238 | return 1; |
---|
239 | } |
---|
240 | |
---|
241 | bgdownload[i] = dnode; |
---|
242 | dnode->host = ostrcat(host, NULL, 0, 0); |
---|
243 | dnode->page = ostrcat(page, NULL, 0, 0); |
---|
244 | dnode->port = port; |
---|
245 | dnode->filename = ostrcat(filename, NULL, 0, 0); |
---|
246 | dnode->auth = ostrcat(auth, NULL, 0, 0); |
---|
247 | dnode->connfd = -1; |
---|
248 | dnode->ret = -1; |
---|
249 | dnode->timeout = timeout; |
---|
250 | dnode->flag = flag; |
---|
251 | |
---|
252 | addtimer(&gethttpstructmsg, START, 1000, 1, (void*)dnode, NULL, NULL); |
---|
253 | |
---|
254 | return 0; |
---|
255 | } |
---|
256 | |
---|
257 | #endif |
---|