source: titan/titan/extensions.h @ 24170

Last change on this file since 24170 was 24170, checked in by nit, 11 years ago

[titan] fix message

File size: 14.4 KB
RevLine 
[16000]1#ifndef EXTENSIONS_H
2#define EXTENSIONS_H
3
[16033]4void screenfeed()
[16000]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
[19415]22        //for devs, who have secret feed not in mind
[19426]23        if(ostrcmp("999.999.999.999", lastline) == 0)
[19415]24        {
25                free(lastline); lastline = NULL;
26                lastline = ostrcat("097.074.032.010", NULL, 0, 0);
27        }
28
[16000]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);
[23819]64                tmpstr = ostrcat(tmpstr, "/svn/tpk/sh4", 1, 0);
[16000]65                writesys(getconfig("feed", NULL), tmpstr, 0);
66        }
67
68        free(tmpstr);
69        free(line);
70        free(lastline);
71}
72
[23401]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)
[23408]99                tmpstr = ostrcat(tmpstr, _("Install success"), 1, 0);
[23401]100        if(flag == 1)
[23408]101                tmpstr = ostrcat(tmpstr, _("Install error"), 1, 0);
[23401]102        if(flag == 2)
[23408]103                tmpstr = ostrcat(tmpstr, _("Remove success"), 1, 0);
[23401]104        if(flag == 3)
[23408]105                tmpstr = ostrcat(tmpstr, _("Remove error"), 1, 0);
[23401]106               
107        if(installpath == NULL || ostrcmp("/var/swap", installpath) == 0)
108                sync();
109       
110        return tmpstr;
111}
112
[23288]113char* getinstallpath(char* path, char* size)
[23283]114{
[23289]115        int count = 0, isize = 0;
[23283]116        char* tmpstr = NULL;
117        struct menulist* mlist = NULL, *mbox = NULL, *tmpmlist = NULL;
118       
[23289]119        if(size != NULL) isize = atoi(size);
[23283]120       
[23765]121        if(path == NULL || path[0] == '*' || ostrstr(path, "mnt") != NULL)
[23288]122        {
[23290]123                if(tpkchecksize(NULL, "/mnt/swapextensions", isize) == 0)
124                {
[23302]125                        tmpmlist = addmenulist(&mlist, "Install to Flash (permanent)", NULL, NULL, 0, 0);
[23290]126                        changemenulistparam(tmpmlist, "/mnt/swapextensions", NULL, NULL, NULL);
127                        free(tmpstr); tmpstr = NULL;
128                        tmpstr = ostrcat("/mnt/swapextensions", NULL, 0, 0);
129                        count++;
130                }
[23288]131        }
[23283]132       
[23765]133        if(path == NULL || path[0] == '*' || ostrstr(path, "var") != NULL)
[23288]134        {
[23290]135                if(tpkchecksize(NULL, "/var", isize) == 0)
136                {
[23302]137                        tmpmlist = addmenulist(&mlist, "Install to Flash (temporary)", NULL, NULL, 0, 0);
[23290]138                        changemenulistparam(tmpmlist, "/var", NULL, NULL, NULL);
139                        free(tmpstr); tmpstr = NULL;
140                        tmpstr = ostrcat("/var", NULL, 0, 0);
141                        count++;
142                }
[23288]143        }
[23283]144       
[23765]145        if(path == NULL || path[0] == '*' || ostrstr(path, "swap") != NULL)
[23288]146        {
[23430]147                if(file_exist("/tmp/.swapextensionsdev") == 1)
[23290]148                {
[23392]149                        if(tpkchecksize(NULL, "/var/swap", isize) == 0)
150                        {
151                                tmpmlist = addmenulist(&mlist, "Install to Stick or HDD", 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                        }
[23290]157                }
[23288]158        }
[23283]159       
[23948]160        //if(count > 1) // if only 1 installpath, don't show choicebox
161        if(count > 0) // show always choicebox
[23288]162        {
163                free(tmpstr); tmpstr = NULL;
164                mbox = menulistbox(mlist, NULL, "Choice Install Medium", NULL, NULL, 0, 0);
165                if(mbox != NULL)
166                        tmpstr = ostrcat(mbox->param, NULL, 0, 0);
167        }
[23772]168        else if(count == 0)
[23720]169        {
[23290]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);
[23720]171                free(tmpstr); tmpstr = NULL;
172        }
[23288]173       
[23283]174        freemenulist(mlist, 0); mlist = NULL;
175        return tmpstr;
176}
177
[22605]178void screenextensions(int mode, char* path, char* defentry, int first)
[16000]179{
[23288]180        char* tmpstr = NULL, *tmpinfo = NULL, *installpath = NULL;
[16000]181        struct menulist* mlist = NULL, *mbox = NULL;
182        struct menulist* mlist1 = NULL, *mbox1 = NULL;
[17644]183        struct skin* load = getscreen("loading");
184               
[17604]185        status.hangtime = 99999;
[21635]186        unlink(TPKLOG);
[16000]187       
188        if(mode == 0)
189        {
[16511]190                drawscreen(load, 0, 0);
[16454]191
[23152]192                if(first == 1) tpkgetindex(0);
[21483]193                tpklist();
[16000]194
[16984]195                clearscreen(load);
196
[22605]197                mbox = tpkmenulist(mlist, NULL, "Tpk Install - select section", NULL, NULL, 1, defentry, 0);
[16000]198
199                if(mbox != NULL)
200                {
201                        debug(130, "section: %s", mbox->name);
[22605]202                        mbox1 = tpkmenulist(mlist1, "tpkinstall", "Tpk Install - select file", "/tmp/tpk", mbox->name, 2, NULL, 1);
[16000]203                       
[21506]204                        if(mbox1 != NULL && mbox1->param != NULL && mbox1->param1 != NULL)
[16000]205                        {
206                                debug(130, "file: %s", mbox1->name);
[21678]207                               
[23288]208                                installpath = getinstallpath(mbox1->param2, mbox1->param3);
209        if(installpath != NULL)
[21678]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);
[23288]219               
[21678]220                                        if(textbox(_("Tpk Install Info"), _(tmpinfo), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 800, 200, 0, 0) == 1)
[16000]221                                        {
[21678]222                                                drawscreen(load, 0, 0);
223                                                resettvpic();
224                                                char* log = NULL;
[23297]225                                                if(tpkgetpackage(mbox1->param, mbox1->param1, installpath) == 0)
[21678]226                                                {
[23401]227                                                        log = gettpklog(installpath, 0);
[21678]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                                                {
[23401]232                                                        log = gettpklog(installpath, 1);
[21678]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                                                {
[23722]241                                                        textbox(_("Message"), _("TPK Install done, your system will reboot !"), "EXIT", getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, NULL, 0, 800, 200, 0, 0);
[21678]242                                                        system("init 6");
243                                                }
[16000]244                                        }
245                                }
246                        }
247                }
[23288]248                free(installpath); installpath = NULL;
[22608]249                free(tmpstr); tmpstr = NULL;   
[21506]250                freemenulist(mlist1, 0); mlist1 = NULL;
[22608]251                if(mbox != NULL) tmpstr = ostrcat(mbox->name, NULL, 0, 0);
[21506]252                freemenulist(mlist, 0); mlist = NULL;
[16000]253                free(tmpinfo); tmpinfo = NULL;
[21483]254                freetpk();
[22608]255                if(mbox != NULL) screenextensions(0, path, tmpstr, 0);
256                free(tmpstr); tmpstr = NULL;
[16000]257        }
258        else if(mode == 1)
259        {
[21639]260                tpklistinstalled(0);
[22605]261                mbox = tpkmenulist(mlist, NULL, "Tpk Remove - select file", NULL, NULL, 1, defentry, 2);
[16000]262               
[21506]263                if(mbox != NULL && mbox->param != NULL)
[16000]264                {
265                        debug(130, "file: %s", mbox->name);
266
[17136]267                        tmpinfo = ostrcat(tmpinfo, _("Removeing"), 1, 0);
[17129]268                        tmpinfo = ostrcat(tmpinfo, " ", 1, 0);
[16000]269                        tmpinfo = ostrcat(tmpinfo, mbox->name, 1, 0);
270                        tmpinfo = ostrcat(tmpinfo, " ?", 1, 0);
271
[21603]272                        if(textbox(_("Tpk Remove Info"), _(tmpinfo), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 800, 200, 0, 0) == 1)
[16000]273                        {
[17644]274                                drawscreen(load, 0, 0);
[17671]275                                resettvpic();
[16000]276                                char* log = NULL;
[21506]277                                if(tpkremove(mbox->param, 0, 0) == 0)
[16000]278                                {
[23401]279                                        log = gettpklog(NULL, 2);
[21603]280                                        textbox(_("Tpk Remove Info - Remove OK"), _(log), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 1000, 600, 0, 2);
[21616]281                                        //del plugin from memory if Titanname is defined in plugin control file
[21626]282                                        if(mbox->param1 != NULL && mbox->param1[0] != '*') delplugin(mbox->param1);
[16000]283                                }
284                                else
285                                {
[23401]286                                        log = gettpklog(NULL, 3);
[21603]287                                        textbox(_("Tpk Remove Info - Remove ERROR"), _(log), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 1000, 600, 0, 2);
[16000]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);
[21483]290                                free(log); log = NULL;
291                                unlink(TPKLOG);
292                                if(file_exist("/tmp/.tpk_needs_reboot"))
[18439]293                                {
[23722]294                                        textbox(_("Message"), _("TPK Remove done, your system will reboot !"), "EXIT", getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, NULL, 0, 600, 200, 0, 0);
[18439]295                                        system("init 6");
296                                }
[16000]297                        }
298                }
[22608]299                free(tmpstr); tmpstr = NULL;
[21506]300                freemenulist(mlist, 0); mlist = NULL;
[22608]301                if(mbox != NULL) tmpstr = ostrcat(mbox->name, NULL, 0, 0);
[16000]302                free(tmpinfo); tmpinfo = NULL;
[21483]303                freetpk();
[22608]304                if(mbox != NULL) screenextensions(1, path, tmpstr, 0);
305                free(tmpstr); tmpstr = NULL;
[16000]306        }
307        else if(mode == 2)
308        {
[21483]309                char* text1 = "Tpk Tmp Install - select file";
310                char* text2 = "Tpk Tmp Info";
[17307]311
[16000]312                if(path == NULL)
[21483]313                        tmpstr = gettpktmplist("/tmp");
[16000]314                else
[17307]315                {
[21483]316                        tmpstr = gettpktmplist(path);
317                        text1 = "Tpk Media Install - select file";
318                        text2 = "Tpk Media Info";
[17307]319                }
[16000]320   
[17307]321                if(tmpstr == NULL || strlen(tmpstr) == 0)
322                {
[16000]323                        textbox(_("Message"), _("No plugin found."), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 0, 0);
[17307]324                }
325                else
326                {
[22605]327                        addmenulistall(&mlist, tmpstr, NULL, 0, defentry);
[17307]328                        mbox = menulistbox(mlist, NULL, text1, NULL, "/skin/plugin.png", 1, 0);
329                }
[16000]330               
331                free(tmpstr); tmpstr = NULL;
332               
333                if(mbox != NULL)
334                {
[23288]335                        installpath = getinstallpath(NULL, 0);
336                        if(installpath != NULL)
[16000]337                        {
[23288]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, 800, 200, 0, 0) == 2)
[21483]348                                {
[23288]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);
[23297]358                                                ret = tpkinstall(tmpstr, installpath);
[23288]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);
[23297]366                                                ret = tpkinstall(tmpstr, installpath);
[23288]367                                                free(tmpstr); tmpstr = NULL;
368                                        }
369       
[23401]370                                        if(ret != 0) log = gettpklog(installpath, 1);
371                                        if(ret == 0) log = gettpklog(installpath, 0);
[23288]372                                        textbox(_(text2), log, "EXIT", getrcconfigint("rcexit", NULL), "OK", getrcconfigint("rcok", NULL), NULL, 0, NULL, 0, 800, 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, 600, 200, 0, 0);
376                                        loadplugin();
377                                        if(file_exist("/tmp/.tpk_needs_reboot"))
378                                        {
[23722]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);
[23288]380                                                system("init 6");
381                                        }
[21483]382                                }
[16000]383                        }
384                }
[23288]385                free(installpath); installpath = NULL;
[22608]386                free(tmpstr); tmpstr = NULL;
[21506]387                freemenulist(mlist, 0); mlist = NULL;
[22608]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);
[16000]391                free(tmpstr); tmpstr = NULL;
392        }
393        else if(mode == 3)
394        {
[16677]395                drawscreen(load, 0, 0);
[17671]396                resettvpic();
[22050]397                if(first == 1)
398                {
399                        if(tpkgetindex(0) != 0)
[22757]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);
[22050]401                }
[21483]402                writesys("/tmp/.tpk_upgrade_start", "0", 0);
[22050]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);
[16000]405                loadplugin();
[18278]406                clearscreen(load);
407                drawscreen(skin, 0, 0);
[21635]408                unlink(TPKLOG);
[18439]409
[21483]410                if(file_exist("/tmp/.tpk_needs_reboot"))
[18439]411                {
[23722]412                        textbox(_("Message"), _("TPK Upgrade done, your system will reboot !"), "EXIT", getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, NULL, 0, 600, 200, 0, 0);
[18439]413                        system("init 6");
414                }
[21483]415                unlink("/tmp/.tpk_upgrade_start");
[16000]416        }
[21506]417
418        if(first == 1) tpkcleantmp(0);
[17604]419        status.hangtime = getconfigint("hangtime", NULL);
[16000]420}
421
[16001]422//flag 0: without message
423//flag 1: with message
[16037]424void screenextensions_check(int flag)
[16000]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);
[21483]440                                tmpstr1 = gettpktmplist(tmpstr);
[16000]441
442                                if(tmpstr1 != NULL)
443                                {
444                                        treffer = 1;
[22605]445                                        screenextensions(2, tmpstr, NULL, 1);
[16000]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)
[21483]455                        textbox(_("Tpk Install Info"), _("No plugin found."), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 0, 0);
[16000]456        }
457}
458
459#endif
Note: See TracBrowser for help on using the repository browser.