source: titan/titan/extensions.h @ 25665

Last change on this file since 25665 was 25665, checked in by gost, 10 years ago

[titan] workaround... flicker when reboot

File size: 15.8 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 MNT", 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 FLASH", 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                                if(ostrstr(mbox1->name, _("It may only be a package to be installed. If they want to install another package of this section, they only remove the installed packet. Is not the plugin after reinstalling the software TitanNit in TitanNit Menu Visible then perform an update by Tpk to: ")) == NULL)
208                                {
209                                        installpath = getinstallpath(mbox1->param2, mbox1->param3);
210                                        if(installpath != NULL)
211                                        {
212                                                tmpinfo = ostrcat(tmpinfo, _("Installing"), 1, 0);
213                                                tmpinfo = ostrcat(tmpinfo, " ", 1, 0);
214                                                tmpinfo = ostrcat(tmpinfo, mbox->name, 1, 0);
215                                                tmpinfo = ostrcat(tmpinfo, "-", 1, 0);
216                                                tmpinfo = ostrcat(tmpinfo, mbox1->name, 1, 0);
217                                                tmpinfo = ostrcat(tmpinfo, " ", 1, 0);
218                                                tmpinfo = ostrcat(tmpinfo, _("starting"), 1, 0);
219                                                tmpinfo = ostrcat(tmpinfo, " ?", 1, 0);
220                       
221                                                if(textbox(_("Tpk Install Info"), _(tmpinfo), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 1000, 200, 0, 0) == 1)
222                                                {
223                                                        drawscreen(load, 0, 0);
224                                                        resettvpic();
225                                                        char* log = NULL;
226                                                        if(tpkgetpackage(mbox1->param, mbox1->param1, installpath, 0) == 0)
227                                                        {
228                                                                log = gettpklog(installpath, 0);
229                                                                textbox(_("Tpk Install Info - Install OK"), _(log), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 1000, 600, 0, 2);
230                                                        }
231                                                        else
232                                                        {
233                                                                log = gettpklog(installpath, 1);
234                                                                textbox(_("Tpk Install Info - Install ERROR"), _(log), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 1000, 600, 0, 2);
235                                                        }
236        //                                              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);
237                                                        loadplugin();
238                                                        free(log), log = NULL;
239                                                        unlink(TPKLOG);
240                                                        if(file_exist("/tmp/.tpk_needs_reboot"))
241                                                        {
242                                                                textbox(_("Message"), _("TPK Install done, your system will reboot !"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 800, 200, 0, 0);
243                                                                writerc(getrcconfigint("rcexit", NULL));
244                                                                writerc(getrcconfigint("rcexit", NULL));
245                                                                writerc(getrcconfigint("rcexit", NULL));
246                                                                writerc(getrcconfigint("rcexit", NULL));
247                                                                //write only config file
248                                                                writeallconfig(3);
249                                                                system("init 6");
250                                                        }
251                                                }
252                                        }
253                                }
254                        }
255                }
256                free(installpath); installpath = NULL;
257                free(tmpstr); tmpstr = NULL;   
258                freemenulist(mlist1, 0); mlist1 = NULL;
259                if(mbox != NULL) tmpstr = ostrcat(mbox->name, NULL, 0, 0);
260                freemenulist(mlist, 0); mlist = NULL;
261                free(tmpinfo); tmpinfo = NULL;
262                freetpk();
263                if(mbox != NULL) screenextensions(0, path, tmpstr, 0);
264                free(tmpstr); tmpstr = NULL;
265        }
266        else if(mode == 1)
267        {
268                tpklistinstalled(0);
269                mbox = tpkmenulist(mlist, NULL, "Tpk Remove - select file", NULL, NULL, 1, defentry, 2);
270               
271                if(mbox != NULL && mbox->param != NULL)
272                {
273                        debug(130, "file: %s", mbox->name);
274
275                        tmpinfo = ostrcat(tmpinfo, _("Removeing"), 1, 0);
276                        tmpinfo = ostrcat(tmpinfo, " ", 1, 0);
277                        tmpinfo = ostrcat(tmpinfo, mbox->name, 1, 0);
278                        tmpinfo = ostrcat(tmpinfo, " ?", 1, 0);
279
280                        if(textbox(_("Tpk Remove Info"), _(tmpinfo), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 800, 200, 0, 0) == 1)
281                        {
282                                drawscreen(load, 0, 0);
283                                resettvpic();
284                                char* log = NULL;
285                                if(tpkremove(mbox->param, 0, 0) == 0)
286                                {
287                                        log = gettpklog(NULL, 2);
288                                        textbox(_("Tpk Remove Info - Remove OK"), _(log), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 1000, 600, 0, 2);
289                                        //del plugin from memory if Titanname is defined in plugin control file
290                                        if(mbox->param1 != NULL && mbox->param1[0] != '*') delplugin(mbox->param1);
291                                }
292                                else
293                                {
294                                        log = gettpklog(NULL, 3);
295                                        textbox(_("Tpk Remove Info - Remove ERROR"), _(log), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 1000, 600, 0, 2);
296                                }
297//                              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);
298                                free(log); log = NULL;
299                                unlink(TPKLOG);
300                                if(file_exist("/tmp/.tpk_needs_reboot"))
301                                {
302                                        textbox(_("Message"), _("TPK Remove done, your system will reboot !"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 800, 200, 0, 0);
303                                        writerc(getrcconfigint("rcexit", NULL));
304                                        writerc(getrcconfigint("rcexit", NULL));
305                                        writerc(getrcconfigint("rcexit", NULL));
306                                        writerc(getrcconfigint("rcexit", NULL));
307                                        //write only config file
308                                        writeallconfig(3);
309                                        system("init 6");
310                                }
311                        }
312                }
313                free(tmpstr); tmpstr = NULL;
314                freemenulist(mlist, 0); mlist = NULL;
315                if(mbox != NULL) tmpstr = ostrcat(mbox->name, NULL, 0, 0);
316                free(tmpinfo); tmpinfo = NULL;
317                freetpk();
318                if(mbox != NULL) screenextensions(1, path, tmpstr, 0);
319                free(tmpstr); tmpstr = NULL;
320        }
321        else if(mode == 2)
322        {
323                char* text1 = "Tpk Tmp Install - select file";
324                char* text2 = "Tpk Tmp Info";
325
326                if(path == NULL)
327                        tmpstr = gettpktmplist("/tmp");
328                else
329                {
330                        tmpstr = gettpktmplist(path);
331                        text1 = "Tpk Media Install - select file";
332                        text2 = "Tpk Media Info";
333                }
334   
335                if(tmpstr == NULL || strlen(tmpstr) == 0)
336                {
337                        textbox(_("Message"), _("No plugin found."), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 0, 0);
338                }
339                else
340                {
341                        addmenulistall(&mlist, tmpstr, NULL, 0, defentry);
342                        mbox = menulistbox(mlist, NULL, text1, NULL, "/skin/plugin.png", 1, 0);
343                }
344               
345                free(tmpstr); tmpstr = NULL;
346               
347                if(mbox != NULL)
348                {
349                        installpath = getinstallpath(NULL, 0);
350                        if(installpath != NULL)
351                        {
352                                debug(130, "file: %s", mbox->name);
353       
354                                tmpinfo = ostrcat(tmpinfo, _("Installing"), 1, 0);
355                                tmpinfo = ostrcat(tmpinfo, " ", 1, 0);
356                                tmpinfo = ostrcat(tmpinfo, mbox->name, 1, 0);
357                                tmpinfo = ostrcat(tmpinfo, " ", 1, 0);
358                                tmpinfo = ostrcat(tmpinfo, _("starting"), 1, 0);
359                                tmpinfo = ostrcat(tmpinfo, " ?", 1, 0);
360       
361                                if(textbox(_(text2), _(tmpinfo), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 1000, 200, 0, 0) == 2)
362                                {
363                                        char* log = NULL;
364                                        int ret = 0;                           
365                                        drawscreen(load, 0, 0);
366                                        resettvpic();                           
367                                        if(path == NULL)
368                                        {
369                                                tmpstr = ostrcat(tmpstr, "/tmp", 1, 0);
370                                                tmpstr = ostrcat(tmpstr, "/", 1, 0);
371                                                tmpstr = ostrcat(tmpstr, mbox->name, 1, 0);
372                                                ret = tpkinstall(tmpstr, installpath, 0);
373                                                free(tmpstr); tmpstr = NULL;
374                                        }
375                                        else
376                                        {
377                                                tmpstr = ostrcat(tmpstr, path, 1, 0);
378                                                tmpstr = ostrcat(tmpstr, "/", 1, 0);
379                                                tmpstr = ostrcat(tmpstr, mbox->name, 1, 0);
380                                                ret = tpkinstall(tmpstr, installpath, 0);
381                                                free(tmpstr); tmpstr = NULL;
382                                        }
383       
384                                        if(ret != 0) log = gettpklog(installpath, 1);
385                                        if(ret == 0) log = gettpklog(installpath, 0);
386                                        textbox(_(text2), log, _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 1000, 600, 0, 0);
387                                        free(log); log = NULL;
388                                        unlink(TPKLOG);
389                                        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);
390                                        loadplugin();
391                                        if(file_exist("/tmp/.tpk_needs_reboot"))
392                                        {
393                                                textbox(_("Message"), _("TPK Tmp Install done, your system will reboot !"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 0, 0);
394                                                writerc(getrcconfigint("rcexit", NULL));
395                                                writerc(getrcconfigint("rcexit", NULL));
396                                                writerc(getrcconfigint("rcexit", NULL));
397                                                writerc(getrcconfigint("rcexit", NULL));
398                                                //write only config file
399                                                writeallconfig(3);
400                                                system("init 6");
401                                        }
402                                }
403                        }
404                }
405                free(installpath); installpath = NULL;
406                free(tmpstr); tmpstr = NULL;
407                freemenulist(mlist, 0); mlist = NULL;
408                if(mbox != NULL) tmpstr = ostrcat(mbox->name, NULL, 0, 0);
409                free(tmpinfo); tmpinfo = NULL;
410                if(mbox != NULL) screenextensions(2, path, tmpstr, 0);
411                free(tmpstr); tmpstr = NULL;
412        }
413        else if(mode == 3)
414        {
415                drawscreen(load, 0, 0);
416                resettvpic();
417                if(first == 1)
418                {
419                        if(tpkgetindex(0) != 0)
420                                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);
421                }
422                writesys("/tmp/.tpk_upgrade_start", "0", 0);
423                if(tpkupdate() != 0)
424                        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);
425                loadplugin();
426                clearscreen(load);
427                drawscreen(skin, 0, 0);
428                unlink(TPKLOG);
429
430                if(file_exist("/tmp/.tpk_needs_reboot"))
431                {
432                        textbox(_("Message"), _("TPK Upgrade done, your system will reboot !"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 0, 0);
433                        writerc(getrcconfigint("rcexit", NULL));
434                        writerc(getrcconfigint("rcexit", NULL));
435                        writerc(getrcconfigint("rcexit", NULL));
436                        writerc(getrcconfigint("rcexit", NULL));
437                        //write only config file
438                        writeallconfig(3);
439                        system("init 6");
440                }
441                unlink("/tmp/.tpk_upgrade_start");
442        }
443
444        if(first == 1) tpkcleantmp(0);
445        status.hangtime = getconfigint("hangtime", NULL);
446}
447
448//flag 0: without message
449//flag 1: with message
450void screenextensions_check(int flag)
451{
452        int treffer = 0;
453        struct hdd *node = NULL;
454        char* tmpstr = NULL, *tmpstr1 = NULL;
455
456        if(status.security == 1)
457        {
458                addhddall();
459                node = hdd;
460
461                while(node != NULL)
462                {
463                        if(node->partition != 0)
464                        {
465                                tmpstr = ostrcat("/autofs/", node->device, 0, 0);
466                                tmpstr1 = gettpktmplist(tmpstr);
467
468                                if(tmpstr1 != NULL)
469                                {
470                                        treffer = 1;
471                                        screenextensions(2, tmpstr, NULL, 1);
472                                }
473
474                                free(tmpstr); tmpstr = NULL;
475                                free(tmpstr1); tmpstr1 = NULL;
476                        }
477                        node = node->next;
478                }
479
480                if(flag == 1 && treffer == 0)
481                        textbox(_("Tpk Install Info"), _("No plugin found."), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 0, 0);
482        }
483}
484
485#endif
Note: See TracBrowser for help on using the repository browser.