source: titan/titan/extensions.h @ 24338

Last change on this file since 24338 was 24338, checked in by obi, 10 years ago

fix

File size: 14.4 KB
Line 
1#ifndef EXTENSIONS_H
2#define EXTENSIONS_H
3
4void screenfeed()
5{
6        char* tmpstr = NULL, *line = NULL, *lastline = NULL;
7        char* pos = NULL;
8
9        tmpstr = readsys(getconfig("feed", NULL), 3); //line3
10        tmpstr = string_replace("src/gz secret http://", "", tmpstr, 1);
11
12        if(tmpstr != NULL)
13                pos = strchr(tmpstr, '/');
14        if(pos != NULL)
15                pos[0] = '\0';
16
17        if(tmpstr == NULL || ostrcmp(tmpstr, "") == 0 || ostrcmp(tmpstr, "\n") == 0)
18                tmpstr = ostrcat(tmpstr, "000.000.000.000", 1, 0);
19
20        lastline = numinput(_("Feed"), tmpstr, "000.000.000.000", 1);
21
22        //for devs, who have secret feed not in mind
23        if(ostrcmp("999.999.999.999", lastline) == 0)
24        {
25                free(lastline); lastline = NULL;
26                lastline = ostrcat("097.074.032.010", NULL, 0, 0);
27        }
28
29        if(lastline != NULL)
30        {
31                free(tmpstr); tmpstr = NULL;
32                tmpstr = fixip(lastline, 1);
33                free(lastline); lastline = tmpstr;
34
35                tmpstr = readsys(getconfig("feed", NULL), 1); //line1
36                if(tmpstr == NULL || (tmpstr != NULL && strlen(tmpstr) == 0))
37                        line = ostrcat(line, "#", 1, 0);
38                else
39                        line = ostrcat(line, tmpstr, 1, 0);
40                free(tmpstr); tmpstr = NULL;
41
42                if(line[strlen(line) - 1] != '\n')
43                        line = ostrcat(line, "\n", 1, 0);
44
45                tmpstr = readsys(getconfig("feed", NULL), 2); //line2
46                if(tmpstr == NULL || (tmpstr != NULL && strlen(tmpstr) == 0))
47                        line = ostrcat(line, "#\n", 1, 0);
48                else
49                        line = ostrcat(line, tmpstr, 1, 0);
50                free(tmpstr); tmpstr = NULL;
51
52                if(line[strlen(line) - 1] == '\n')
53                        tmpstr = ostrcat(line, "src/gz secret http://", 0, 0);
54                else
55                        tmpstr = ostrcat(line, "\nsrc/gz secret http://", 0, 0);
56
57                if(strlen(lastline) == 0)
58                {
59                        free(tmpstr);
60                        tmpstr = ostrcat(line, NULL, 0, 0);
61                }
62
63                tmpstr = ostrcat(tmpstr, lastline, 1, 0);
64                tmpstr = ostrcat(tmpstr, "/svn/tpk/sh4", 1, 0);
65                writesys(getconfig("feed", NULL), tmpstr, 0);
66        }
67
68        free(tmpstr);
69        free(line);
70        free(lastline);
71}
72
73//flag 0: install ok
74//flag 1: install err
75//flag 2: remove ok
76//flag 3: remove err
77char* gettpklog(char* installpath, int flag)
78{
79        char* tmpstr = NULL;
80
81        if(flag == 0 || flag == 1)
82                tmpstr = ostrcat(tmpstr, _("Installation start"), 1, 0);
83        else
84                tmpstr = ostrcat(tmpstr, _("Remove start"), 1, 0);
85        tmpstr = ostrcat(tmpstr, "\n\n", 1, 0);
86       
87        tmpstr = ostrcat(tmpstr, readfiletomem(TPKLOG, 0), 1, 1);
88       
89        tmpstr = ostrcat(tmpstr, "\n\n", 1, 0);
90       
91        if(installpath != NULL)
92        {
93                tmpstr = ostrcat(tmpstr, _("New free space (KB): "), 1, 0);
94                tmpstr = ostrcat(tmpstr, ollutoa(getfreespace(installpath) / 1024), 1, 1);
95                tmpstr = ostrcat(tmpstr, "\n", 1, 0);
96        }
97       
98        if(flag == 0)
99                tmpstr = ostrcat(tmpstr, _("Install success"), 1, 0);
100        if(flag == 1)
101                tmpstr = ostrcat(tmpstr, _("Install error"), 1, 0);
102        if(flag == 2)
103                tmpstr = ostrcat(tmpstr, _("Remove success"), 1, 0);
104        if(flag == 3)
105                tmpstr = ostrcat(tmpstr, _("Remove error"), 1, 0);
106               
107        if(installpath == NULL || ostrcmp("/var/swap", installpath) == 0)
108                sync();
109       
110        return tmpstr;
111}
112
113char* getinstallpath(char* path, char* size)
114{
115        int count = 0, isize = 0;
116        char* tmpstr = NULL;
117        struct menulist* mlist = NULL, *mbox = NULL, *tmpmlist = NULL;
118       
119        if(size != NULL) isize = atoi(size);
120       
121        if(path == NULL || path[0] == '*' || ostrstr(path, "mnt") != NULL)
122        {
123                if(tpkchecksize(NULL, "/mnt/swapextensions", isize) == 0)
124                {
125                        tmpmlist = addmenulist(&mlist, "Install to FLASH", NULL, NULL, 0, 0);
126                        changemenulistparam(tmpmlist, "/mnt/swapextensions", NULL, NULL, NULL);
127                        free(tmpstr); tmpstr = NULL;
128                        tmpstr = ostrcat("/mnt/swapextensions", NULL, 0, 0);
129                        count++;
130                }
131        }
132       
133        if(path == NULL || path[0] == '*' || ostrstr(path, "var") != NULL)
134        {
135                if(tpkchecksize(NULL, "/var", isize) == 0)
136                {
137                        tmpmlist = addmenulist(&mlist, "Install to MNT", NULL, NULL, 0, 0);
138                        changemenulistparam(tmpmlist, "/var", NULL, NULL, NULL);
139                        free(tmpstr); tmpstr = NULL;
140                        tmpstr = ostrcat("/var", NULL, 0, 0);
141                        count++;
142                }
143        }
144       
145        if(path == NULL || path[0] == '*' || ostrstr(path, "swap") != NULL)
146        {
147                if(file_exist("/tmp/.swapextensionsdev") == 1)
148                {
149                        if(tpkchecksize(NULL, "/var/swap", isize) == 0)
150                        {
151                                tmpmlist = addmenulist(&mlist, "Install to SWAP", NULL, NULL, 0, 0);
152                                changemenulistparam(tmpmlist, "/var/swap", NULL, NULL, NULL);
153                                free(tmpstr); tmpstr = NULL;
154                                tmpstr = ostrcat("/var/swap", NULL, 0, 0);
155                                count++;
156                        }
157                }
158        }
159       
160        //if(count > 1) // if only 1 installpath, don't show choicebox
161        if(count > 0) // show always choicebox
162        {
163                free(tmpstr); tmpstr = NULL;
164                mbox = menulistbox(mlist, "tpkinstallinfo", "Choice Install Medium", NULL, NULL, 0, 0);
165                if(mbox != NULL)
166                        tmpstr = ostrcat(mbox->param, NULL, 0, 0);
167        }
168        else if(count == 0)
169        {
170                textbox(_("Tpk Install Info"), _("Can't install Package. Package to big."), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 800, 200, 0, 0);
171                free(tmpstr); tmpstr = NULL;
172        }
173       
174        freemenulist(mlist, 0); mlist = NULL;
175        return tmpstr;
176}
177
178void screenextensions(int mode, char* path, char* defentry, int first)
179{
180        char* tmpstr = NULL, *tmpinfo = NULL, *installpath = NULL;
181        struct menulist* mlist = NULL, *mbox = NULL;
182        struct menulist* mlist1 = NULL, *mbox1 = NULL;
183        struct skin* load = getscreen("loading");
184               
185        status.hangtime = 99999;
186        unlink(TPKLOG);
187       
188        if(mode == 0)
189        {
190                drawscreen(load, 0, 0);
191
192                if(first == 1) tpkgetindex(0);
193                tpklist();
194
195                clearscreen(load);
196
197                mbox = tpkmenulist(mlist, NULL, "Tpk Install - select section", NULL, NULL, 1, defentry, 0);
198
199                if(mbox != NULL)
200                {
201                        debug(130, "section: %s", mbox->name);
202                        mbox1 = tpkmenulist(mlist1, "tpkinstall", "Tpk Install - select file", "/tmp/tpk", mbox->name, 2, NULL, 1);
203                       
204                        if(mbox1 != NULL && mbox1->param != NULL && mbox1->param1 != NULL)
205                        {
206                                debug(130, "file: %s", mbox1->name);
207                               
208                                installpath = getinstallpath(mbox1->param2, mbox1->param3);
209        if(installpath != NULL)
210        {
211                                        tmpinfo = ostrcat(tmpinfo, _("Installing"), 1, 0);
212                                        tmpinfo = ostrcat(tmpinfo, " ", 1, 0);
213                                        tmpinfo = ostrcat(tmpinfo, mbox->name, 1, 0);
214                                        tmpinfo = ostrcat(tmpinfo, "-", 1, 0);
215                                        tmpinfo = ostrcat(tmpinfo, mbox1->name, 1, 0);
216                                        tmpinfo = ostrcat(tmpinfo, " ", 1, 0);
217                                        tmpinfo = ostrcat(tmpinfo, _("started"), 1, 0);
218                                        tmpinfo = ostrcat(tmpinfo, " ?", 1, 0);
219               
220                                        if(textbox(_("Tpk Install Info"), _(tmpinfo), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 1000, 200, 0, 0) == 1)
221                                        {
222                                                drawscreen(load, 0, 0);
223                                                resettvpic();
224                                                char* log = NULL;
225                                                if(tpkgetpackage(mbox1->param, mbox1->param1, installpath) == 0)
226                                                {
227                                                        log = gettpklog(installpath, 0);
228                                                        textbox(_("Tpk Install Info - Install OK"), _(log), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 1000, 600, 0, 2);
229                                                }
230                                                else
231                                                {
232                                                        log = gettpklog(installpath, 1);
233                                                        textbox(_("Tpk Install Info - Install ERROR"), _(log), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 1000, 600, 0, 2);
234                                                }
235                                                textbox(_("Message"), _("Some plugins needs restart.\nIf the plugin is not active\nreboot the box."), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 1000, 200, 0, 0);
236                                                loadplugin();
237                                                free(log), log = NULL;
238                                                unlink(TPKLOG);
239                                                if(file_exist("/tmp/.tpk_needs_reboot"))
240                                                {
241                                                        textbox(_("Message"), _("TPK Install done, your system will reboot !"), "EXIT", getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, NULL, 0, 800, 200, 0, 0);
242                                                        system("init 6");
243                                                }
244                                        }
245                                }
246                        }
247                }
248                free(installpath); installpath = NULL;
249                free(tmpstr); tmpstr = NULL;   
250                freemenulist(mlist1, 0); mlist1 = NULL;
251                if(mbox != NULL) tmpstr = ostrcat(mbox->name, NULL, 0, 0);
252                freemenulist(mlist, 0); mlist = NULL;
253                free(tmpinfo); tmpinfo = NULL;
254                freetpk();
255                if(mbox != NULL) screenextensions(0, path, tmpstr, 0);
256                free(tmpstr); tmpstr = NULL;
257        }
258        else if(mode == 1)
259        {
260                tpklistinstalled(0);
261                mbox = tpkmenulist(mlist, NULL, "Tpk Remove - select file", NULL, NULL, 1, defentry, 2);
262               
263                if(mbox != NULL && mbox->param != NULL)
264                {
265                        debug(130, "file: %s", mbox->name);
266
267                        tmpinfo = ostrcat(tmpinfo, _("Removeing"), 1, 0);
268                        tmpinfo = ostrcat(tmpinfo, " ", 1, 0);
269                        tmpinfo = ostrcat(tmpinfo, mbox->name, 1, 0);
270                        tmpinfo = ostrcat(tmpinfo, " ?", 1, 0);
271
272                        if(textbox(_("Tpk Remove Info"), _(tmpinfo), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 800, 200, 0, 0) == 1)
273                        {
274                                drawscreen(load, 0, 0);
275                                resettvpic();
276                                char* log = NULL;
277                                if(tpkremove(mbox->param, 0, 0) == 0)
278                                {
279                                        log = gettpklog(NULL, 2);
280                                        textbox(_("Tpk Remove Info - Remove OK"), _(log), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 1000, 600, 0, 2);
281                                        //del plugin from memory if Titanname is defined in plugin control file
282                                        if(mbox->param1 != NULL && mbox->param1[0] != '*') delplugin(mbox->param1);
283                                }
284                                else
285                                {
286                                        log = gettpklog(NULL, 3);
287                                        textbox(_("Tpk Remove Info - Remove ERROR"), _(log), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 1000, 600, 0, 2);
288                                }
289                                textbox(_("Message"), _("Some plugins needs restart.\nIf the plugin is not active\nreboot the box."), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 1000, 200, 0, 0);
290                                free(log); log = NULL;
291                                unlink(TPKLOG);
292                                if(file_exist("/tmp/.tpk_needs_reboot"))
293                                {
294                                        textbox(_("Message"), _("TPK Remove done, your system will reboot !"), "EXIT", getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, NULL, 0, 800, 200, 0, 0);
295                                        system("init 6");
296                                }
297                        }
298                }
299                free(tmpstr); tmpstr = NULL;
300                freemenulist(mlist, 0); mlist = NULL;
301                if(mbox != NULL) tmpstr = ostrcat(mbox->name, NULL, 0, 0);
302                free(tmpinfo); tmpinfo = NULL;
303                freetpk();
304                if(mbox != NULL) screenextensions(1, path, tmpstr, 0);
305                free(tmpstr); tmpstr = NULL;
306        }
307        else if(mode == 2)
308        {
309                char* text1 = "Tpk Tmp Install - select file";
310                char* text2 = "Tpk Tmp Info";
311
312                if(path == NULL)
313                        tmpstr = gettpktmplist("/tmp");
314                else
315                {
316                        tmpstr = gettpktmplist(path);
317                        text1 = "Tpk Media Install - select file";
318                        text2 = "Tpk Media Info";
319                }
320   
321                if(tmpstr == NULL || strlen(tmpstr) == 0)
322                {
323                        textbox(_("Message"), _("No plugin found."), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 0, 0);
324                }
325                else
326                {
327                        addmenulistall(&mlist, tmpstr, NULL, 0, defentry);
328                        mbox = menulistbox(mlist, NULL, text1, NULL, "/skin/plugin.png", 1, 0);
329                }
330               
331                free(tmpstr); tmpstr = NULL;
332               
333                if(mbox != NULL)
334                {
335                        installpath = getinstallpath(NULL, 0);
336                        if(installpath != NULL)
337                        {
338                                debug(130, "file: %s", mbox->name);
339       
340                                tmpinfo = ostrcat(tmpinfo, _("Installing"), 1, 0);
341                                tmpinfo = ostrcat(tmpinfo, " ", 1, 0);
342                                tmpinfo = ostrcat(tmpinfo, mbox->name, 1, 0);
343                                tmpinfo = ostrcat(tmpinfo, " ", 1, 0);
344                                tmpinfo = ostrcat(tmpinfo, _("started"), 1, 0);
345                                tmpinfo = ostrcat(tmpinfo, " ?", 1, 0);
346       
347                                if(textbox(_(text2), _(tmpinfo), "EXIT", getrcconfigint("rcexit", NULL), "OK", getrcconfigint("rcok", NULL), NULL, 0, NULL, 0, 1000, 200, 0, 0) == 2)
348                                {
349                                        char* log = NULL;
350                                        int ret = 0;                           
351                                        drawscreen(load, 0, 0);
352                                        resettvpic();                           
353                                        if(path == NULL)
354                                        {
355                                                tmpstr = ostrcat(tmpstr, "/tmp", 1, 0);
356                                                tmpstr = ostrcat(tmpstr, "/", 1, 0);
357                                                tmpstr = ostrcat(tmpstr, mbox->name, 1, 0);
358                                                ret = tpkinstall(tmpstr, installpath);
359                                                free(tmpstr); tmpstr = NULL;
360                                        }
361                                        else
362                                        {
363                                                tmpstr = ostrcat(tmpstr, path, 1, 0);
364                                                tmpstr = ostrcat(tmpstr, "/", 1, 0);
365                                                tmpstr = ostrcat(tmpstr, mbox->name, 1, 0);
366                                                ret = tpkinstall(tmpstr, installpath);
367                                                free(tmpstr); tmpstr = NULL;
368                                        }
369       
370                                        if(ret != 0) log = gettpklog(installpath, 1);
371                                        if(ret == 0) log = gettpklog(installpath, 0);
372                                        textbox(_(text2), log, "EXIT", getrcconfigint("rcexit", NULL), "OK", getrcconfigint("rcok", NULL), NULL, 0, NULL, 0, 1000, 600, 0, 0);
373                                        free(log); log = NULL;
374                                        unlink(TPKLOG);
375                                        textbox(_("Message"), _("Some plugins needs restart.\nIf the plugin is not active\nreboot the box."), "EXIT", getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, NULL, 0, 1000, 200, 0, 0);
376                                        loadplugin();
377                                        if(file_exist("/tmp/.tpk_needs_reboot"))
378                                        {
379                                                textbox(_("Message"), _("TPK Tmp Install done, your system will reboot !"), "EXIT", getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, NULL, 0, 600, 200, 0, 0);
380                                                system("init 6");
381                                        }
382                                }
383                        }
384                }
385                free(installpath); installpath = NULL;
386                free(tmpstr); tmpstr = NULL;
387                freemenulist(mlist, 0); mlist = NULL;
388                if(mbox != NULL) tmpstr = ostrcat(mbox->name, NULL, 0, 0);
389                free(tmpinfo); tmpinfo = NULL;
390                if(mbox != NULL) screenextensions(2, path, tmpstr, 0);
391                free(tmpstr); tmpstr = NULL;
392        }
393        else if(mode == 3)
394        {
395                drawscreen(load, 0, 0);
396                resettvpic();
397                if(first == 1)
398                {
399                        if(tpkgetindex(0) != 0)
400                                textbox(_("Tpk Update Info - Update ERROR"), _("Can't get all TPK index !"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 0, 0);
401                }
402                writesys("/tmp/.tpk_upgrade_start", "0", 0);
403                if(tpkupdate() != 0)
404                        textbox(_("Tpk Update Info - Update ERROR"), _("Can't update all packages !"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 0, 0);
405                loadplugin();
406                clearscreen(load);
407                drawscreen(skin, 0, 0);
408                unlink(TPKLOG);
409
410                if(file_exist("/tmp/.tpk_needs_reboot"))
411                {
412                        textbox(_("Message"), _("TPK Upgrade done, your system will reboot !"), "EXIT", getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, NULL, 0, 600, 200, 0, 0);
413                        system("init 6");
414                }
415                unlink("/tmp/.tpk_upgrade_start");
416        }
417
418        if(first == 1) tpkcleantmp(0);
419        status.hangtime = getconfigint("hangtime", NULL);
420}
421
422//flag 0: without message
423//flag 1: with message
424void screenextensions_check(int flag)
425{
426        int treffer = 0;
427        struct hdd *node = NULL;
428        char* tmpstr = NULL, *tmpstr1 = NULL;
429
430        if(status.security == 1)
431        {
432                addhddall();
433                node = hdd;
434
435                while(node != NULL)
436                {
437                        if(node->partition != 0)
438                        {
439                                tmpstr = ostrcat("/autofs/", node->device, 0, 0);
440                                tmpstr1 = gettpktmplist(tmpstr);
441
442                                if(tmpstr1 != NULL)
443                                {
444                                        treffer = 1;
445                                        screenextensions(2, tmpstr, NULL, 1);
446                                }
447
448                                free(tmpstr); tmpstr = NULL;
449                                free(tmpstr1); tmpstr1 = NULL;
450                        }
451                        node = node->next;
452                }
453
454                if(flag == 1 && treffer == 0)
455                        textbox(_("Tpk Install Info"), _("No plugin found."), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 0, 0);
456        }
457}
458
459#endif
Note: See TracBrowser for help on using the repository browser.