Subversion Repositories NedoOS

Rev

Rev 2233 | Rev 2263 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <intrz80.h>
  4. #include <stdlib.h>
  5. #include <oscalls.h>
  6. #include <../common/terminal.c>
  7. #include <tcp.h>
  8. #include <osfs.h>
  9. #include <intrz80.h>
  10. #include <ctype.h>
  11. #include <math.h>
  12. //
  13. #define true 1
  14. #define false 0
  15.  
  16. unsigned int RBR_THR = 0xf8ef;
  17. unsigned int IER = 0xf9ef;
  18. unsigned int IIR_FCR = 0xfaef;
  19. unsigned int LCR = 0xfbef;
  20. unsigned int MCR = 0xfcef;
  21. unsigned int LSR = 0xfdef;
  22. unsigned int MSR = 0xfeef;
  23. unsigned int SR = 0xffef;
  24. unsigned int divider = 1;
  25. unsigned char comType = 0;
  26. unsigned int espType = 32;
  27. unsigned char netDriver = 0;
  28.  
  29. unsigned char uVer[] = "0.90";
  30. unsigned char curPath[128];
  31. unsigned char curLetter;
  32. unsigned char oldBinExt;
  33. unsigned int errn, headlng;
  34. unsigned long contLen;
  35. unsigned char saveFlag, saveBak;
  36. unsigned char crlf[2] = {13, 10};
  37.  
  38. unsigned char status, curFormat;
  39.  
  40. struct sockaddr_in targetadr;
  41. struct readstructure readStruct;
  42. struct sockaddr_in dnsaddress;
  43.  
  44. FILE *fp2;
  45.  
  46. struct window
  47. {
  48.         unsigned char x;
  49.         unsigned char y;
  50.         unsigned char w;
  51.         unsigned char h;
  52.         unsigned char text;
  53.         unsigned char back;
  54.         unsigned char tittle[80];
  55.  
  56. } cw;
  57.  
  58. struct configuration
  59. {
  60.         unsigned char kernelName[32];
  61.         unsigned char machineName[32];
  62.         unsigned char kernelLink[256];
  63.         unsigned char is_atm;
  64. } config;
  65.  
  66. unsigned char netbuf[4096];
  67.  
  68. unsigned char cmdlist1[] = " HTTP/1.1\r\nHost: nedoos.ru\r\nUser-Agent: Mozilla/4.0 (compatible; MSIE5.01; NedoOS)\r\n\r\n\0";
  69. unsigned char binLink[] = "http://nedoos.ru/images/sysbin.zip";
  70. unsigned char pkunzipLink[] = "/svn/dl.php?repname=NedoOS&path=/release/bin/pkunzip.com";
  71. unsigned char tarLink[] = "/svn/dl.php?repname=NedoOS&path=/release/bin/tar.com";
  72. unsigned char cmdLink[] = "/svn/dl.php?repname=NedoOS&path=/release/bin/cmd.com";
  73. unsigned char termLink[] = "/svn/dl.php?repname=NedoOS&path=/release/bin/term.com";
  74. unsigned char updLink[] = "/svn/dl.php?repname=NedoOS&path=/release/bin/updater.com";
  75. unsigned char newsLink[] = "/svn/dl.php?repname=NedoOS&path=/release/doc/updater.new";
  76. unsigned char wizNetLink[] = "/svn/dl.php?repname=NedoOS&path=/release/bin/wizcfg.com";
  77. unsigned char netIniLink[] = "/svn/dl.php?repname=NedoOS&path=/release/bin/net.ini";
  78. unsigned char relLink[] = "http://nedoos.ru/images/release.zip";
  79. unsigned char nameBuf1[512];
  80. unsigned char *nameBuf = nameBuf1;
  81. const unsigned char sendOk[] = "SEND OK";
  82. const unsigned char gotWiFi[] = "WIFI GOT IP";
  83. unsigned char cmd[512];
  84. unsigned char link[512];
  85. unsigned char dataBuffer[4096];
  86.  
  87. void clearStatus(void)
  88. {
  89.         AT(1, 24);
  90.         printf("                                                                                \r");
  91. }
  92.  
  93. void printTable(void)
  94. {
  95.         unsigned int cycle;
  96.  
  97.         for (cycle = 32; cycle < 256; cycle++)
  98.         {
  99.                 printf("%03u:", cycle);
  100.                 putchar(cycle);
  101.                 printf(" ");
  102.                 if (cycle % 10 == 0)
  103.                 {
  104.                         printf("\r\n");
  105.                 }
  106.         }
  107. }
  108.  
  109. void delay(unsigned long counter)
  110. {
  111.         unsigned long start, finish;
  112.         counter = counter / 20;
  113.         if (counter < 1)
  114.         {
  115.                 counter = 1;
  116.         }
  117.         start = time();
  118.         finish = start + counter;
  119.  
  120.         while (start < finish)
  121.         {
  122.                 start = time();
  123.         }
  124. }
  125. void printNews(void) // max 20 lines in total and 59 col.
  126. {
  127.         FILE *fpNews;
  128.         unsigned char str[1];
  129.         unsigned char curLine, nbyte;
  130.  
  131.         fpNews = OS_OPENHANDLE("updater.new", 0x80);
  132.         if (((int)fpNews) & 0xff)
  133.         {
  134. #include <printnews.c>
  135.                 return;
  136.         }
  137.         curLine = 0;
  138.         while (curLine < 21)
  139.         {
  140.                 AT(20, 2 + curLine);
  141.                 while (1)
  142.                 {
  143.                         OS_READHANDLE(str, fpNews, sizeof(str));
  144.  
  145.                         if (errno != 0)
  146.                         {
  147.                                 OS_CLOSEHANDLE(fpNews);
  148.                                 return;
  149.                         }
  150.  
  151.                         nbyte = str[0];
  152.  
  153.                         if (nbyte != 13)
  154.                         {
  155.                                 putchar(nbyte);
  156.                         }
  157.                         else
  158.                         {
  159.                                 break;
  160.                         }
  161.                 }
  162.                 OS_READHANDLE(str, fpNews, sizeof(str));
  163.                 curLine++;
  164.         }
  165.         OS_CLOSEHANDLE(fpNews);
  166. }
  167.  
  168. void drawWindow(struct window w)
  169. {
  170.         unsigned char wcount, tempx, tittleStart;
  171.  
  172.         AT(w.x, w.y - 1);
  173.         tittleStart = w.x + (w.w / 2) - (strlen(w.tittle) / 2) + 1;
  174.         BOX(w.x, w.y, w.w + 1, w.h, w.back, 32);
  175.         AT(w.x, w.y);
  176.         ATRIB(w.text);
  177.         putchar(201);
  178.         for (wcount = 0; wcount < w.w; wcount++)
  179.         {
  180.                 putchar(205);
  181.         }
  182.         putchar(187);
  183.  
  184.         AT(w.x, w.y + w.h);
  185.         putchar(200);
  186.         for (wcount = 0; wcount < w.w; wcount++)
  187.         {
  188.                 putchar(205);
  189.         }
  190.         putchar(188);
  191.  
  192.         tempx = w.x + w.w + 1;
  193.         for (wcount = 1; wcount < w.h; wcount++)
  194.         {
  195.                 AT(w.x, w.y + wcount);
  196.                 putchar(186);
  197.                 AT(tempx, w.y + wcount);
  198.                 putchar(186);
  199.         }
  200.  
  201.         AT(w.x, w.y + 2);
  202.         putchar(199);
  203.         for (wcount = 0; wcount < w.w; wcount++)
  204.         {
  205.                 putchar(196);
  206.         }
  207.         putchar(182);
  208.  
  209.         AT(tittleStart, w.y + 1);
  210.         printf("%s", w.tittle);
  211. }
  212.  
  213. void fatalError(unsigned char *message)
  214. {
  215.         strcpy(cw.tittle, "FATAL ERROR!");
  216.  
  217.         if (strlen(message) > strlen(cw.tittle))
  218.         {
  219.                 cw.w = strlen(message) + 2;
  220.         }
  221.         else
  222.                 cw.w = strlen(cw.tittle) + 2;
  223.         cw.x = 80 / 2 - cw.w / 2;
  224.         cw.y = 11;
  225.         cw.h = 4;
  226.         cw.text = 97;
  227.         cw.back = 41;
  228.         drawWindow(cw);
  229.         AT(cw.x + 2, cw.y + 3);
  230.         printf("%s", message);
  231.         AT(1, 1);
  232.         do
  233.         {
  234.                 YIELD();
  235.         } while (_low_level_get() == 0);
  236.         exit(0);
  237. }
  238.  
  239. void infoBox(unsigned char *message)
  240. {
  241.         strcpy(cw.tittle, "nedoOS system updater ");
  242.         strcat(cw.tittle, uVer);
  243.  
  244.         if (strlen(message) > strlen(cw.tittle))
  245.         {
  246.                 cw.w = strlen(message) + 2;
  247.         }
  248.         else
  249.                 cw.w = strlen(cw.tittle) + 2;
  250.         cw.x = 80 / 2 - cw.w / 2;
  251.         cw.y = 15;
  252.         cw.h = 4;
  253.         cw.text = 97;
  254.         cw.back = 42;
  255.  
  256.         drawWindow(cw);
  257.         AT(cw.x + 2, cw.y + 3);
  258.         printf("%s", message);
  259.         AT(1, 1);
  260. }
  261.  
  262. unsigned char OS_SHELL(unsigned char *command)
  263. {
  264.         unsigned char fileName[] = "bin/cmd.com";
  265.         unsigned char appCmd[128] = "cmd.com ";
  266.         unsigned int shellSize, loaded, loop, adr;
  267.         unsigned char pgbak;
  268.         union APP_PAGES shell_pg;
  269.         union APP_PAGES main_pg;
  270.         FILE *fp3;
  271.         main_pg.l = OS_GETMAINPAGES();
  272.         pgbak = main_pg.pgs.window_3;
  273.         OS_GETPATH((unsigned int)&curPath);
  274.         OS_CHDIR("/");
  275.  
  276.         strcat(appCmd, command);
  277.         fp3 = OS_OPENHANDLE(fileName, 0x80);
  278.         if (((int)fp3) & 0xff)
  279.         {
  280.                 clearStatus();
  281.                 AT(1, 24);
  282.                 printf("%s", fileName);
  283.                 printf(" not found.");
  284.                 do
  285.                 {
  286.                         YIELD();
  287.                 } while (_low_level_get() == 0);
  288.                 exit(0);
  289.         }
  290.  
  291.         shellSize = OS_GETFILESIZE(fp3);
  292.  
  293.         OS_CHDIR(curPath);
  294.  
  295.         OS_NEWAPP((unsigned int)&shell_pg);
  296.         shell_pg.l = OS_GETAPPMAINPAGES(shell_pg.pgs.pId);
  297.         SETPG32KHIGH(shell_pg.pgs.window_0);
  298.         memcpy((unsigned char *)(0xC080), (unsigned char *)(&appCmd), strlen(appCmd) + 1);
  299.  
  300.         loop = 0;
  301.         while (loop < shellSize)
  302.         {
  303.                 loaded = OS_READHANDLE(netbuf, fp3, sizeof(netbuf));
  304.                 adr = 0xC100 + loop;
  305.                 memcpy((unsigned char *)(adr), &netbuf, loaded);
  306.                 loop = loop + loaded;
  307.         }
  308.         OS_CLOSEHANDLE(fp3);
  309.         SETPG32KHIGH(pgbak);
  310.         clearStatus();
  311.         AT(1, 24);
  312.         printf("Shell [pId:%u][%s][%s]", shell_pg.pgs.pId, curPath, appCmd);
  313.         AT(1, 24);
  314.         delay(300);
  315.         OS_RUNAPP(shell_pg.pgs.pId);
  316.         AT(1, 4);
  317.         OS_WAITPID(shell_pg.pgs.pId);
  318.         return shell_pg.pgs.pId;
  319. }
  320.  
  321. ///////////////////////////
  322. #include <../common/esp-com.c>
  323. #include <../common/network.c>
  324. //////////////////////////
  325.  
  326. unsigned char saveBuf(unsigned char *fileNamePtr, unsigned char operation, unsigned int sizeOfBuf)
  327. {
  328.         if (operation == 00)
  329.         {
  330.                 fp2 = OS_CREATEHANDLE(fileNamePtr, 0x80);
  331.                 if (((int)fp2) & 0xff)
  332.                 {
  333.                         clearStatus();
  334.                         AT(1, 24);
  335.                         printf("%s", fileNamePtr);
  336.                         printf(" creating error.");
  337.                         exit(0);
  338.                 }
  339.                 OS_CLOSEHANDLE(fp2);
  340.  
  341.                 fp2 = OS_OPENHANDLE(fileNamePtr, 0x80);
  342.                 if (((int)fp2) & 0xff)
  343.                 {
  344.                         clearStatus();
  345.                         AT(1, 24);
  346.                         printf("%s", fileNamePtr);
  347.                         printf(" opening error. ");
  348.  
  349.                         exit(0);
  350.                 }
  351.                 AT(1, 24);
  352.                 return 0;
  353.         }
  354.  
  355.         if (operation == 01)
  356.         {
  357.                 OS_WRITEHANDLE(netbuf + headlng, fp2, sizeOfBuf);
  358.                 return 0;
  359.         }
  360.  
  361.         if (operation == 02)
  362.         {
  363.                 OS_CLOSEHANDLE(fp2);
  364.                 return 0;
  365.         }
  366.         return 0;
  367. }
  368.  
  369. unsigned int cutHeader(unsigned int todo)
  370. {
  371.         unsigned int err;
  372.         unsigned char *count1;
  373.  
  374.         err = httpError();
  375.         if (err != 200)
  376.         {
  377.                 BOX(1, 1, 80, 25, 40, 32);
  378.                 AT(1, 1);
  379.                 printf("HTTP ERROR %u", err);
  380.                 puts("^^^^^^^^^^^^^^^^^^^^^");
  381.                 puts(netbuf);
  382.                 getchar();
  383.                 fatalError("Server response error!");
  384.         }
  385.         count1 = strstr(netbuf, "Content-Length:");
  386.         if (count1 == NULL)
  387.         {
  388.                 printf("contLen  not found \r\n");
  389.                 contLen = 0;
  390.         }
  391.         else
  392.         {
  393.                 contLen = atol(count1 + 15);
  394.                 // printf("Content-Length: %lu \n\r", contLen);
  395.         }
  396.  
  397.         count1 = strstr(netbuf, "\r\n\r\n");
  398.         if (count1 == NULL)
  399.         {
  400.                 printf("header not found\r\n");
  401.         }
  402.         else
  403.         {
  404.                 headlng = ((unsigned int)count1 - (unsigned int)netbuf + 4);
  405.                 // printf("header %u bytes\r\n", headlng);
  406.         }
  407.         return todo - headlng;
  408. }
  409.  
  410. unsigned char getFile(unsigned char *fileLink, unsigned char *fileNamePtr)
  411. {
  412.         int todo;
  413.         char socket, firstPacket ;
  414.         unsigned int fileSize1;
  415.         unsigned long downloaded = 0;
  416.  
  417.         unsigned char sizeLink;
  418.         unsigned char byte, count = 0, try = 0;
  419.         unsigned char *count1;
  420.  
  421.         strcpy(netbuf, "GET ");
  422.         strcat(netbuf, fileLink);
  423.         strcat(netbuf, cmdlist1);
  424.         clearStatus();
  425.         AT(1, 24);
  426.         printf("%s", fileNamePtr);
  427.  
  428.         if (netDriver == 0)
  429.         {
  430.                 clearStatus();
  431.                 socket = OpenSock(AF_INET, SOCK_STREAM);
  432.                 testOperation("OS_NETSOCKET", socket);
  433.  
  434.                 todo = netConnect(socket, 10);
  435.                 testOperation("OS_NETCONNECT", todo);
  436.  
  437.                 todo = tcpSend(socket, (unsigned int)&netbuf, strlen(netbuf), 10);
  438.                 testOperation("OS_WIZNETWRITE", todo);
  439.                 clearStatus();
  440.                 firstPacket = true;
  441.                 do
  442.                 {
  443.                         headlng = 0;
  444.                         todo = tcpRead(socket, 10);
  445.                         testOperation("OS_WIZNETREAD", todo);
  446.                         if (todo == 0)
  447.                         {
  448.                                 break;
  449.                         }
  450.                         if (firstPacket)
  451.                         {
  452.                                 todo = cutHeader(todo);
  453.                                 fileSize1 = contLen / 1024;
  454.                                 saveBuf(fileNamePtr, 00, 0);
  455.                                 firstPacket = false;
  456.                         }
  457.                         downloaded = downloaded + todo;
  458.                         printf(" %lu of %u kb   \r", downloaded / 1024, fileSize1);
  459.                         saveBuf(fileNamePtr, 01, todo);
  460.                         if (_low_level_get() == 27)
  461.                         {
  462.                                 fatalError("File download aborted!");
  463.                         }
  464.                 } while (downloaded < contLen);
  465.                 netShutDown(socket, 0);
  466.                 saveBuf(fileNamePtr, 02, 00);
  467.  
  468.                 if (downloaded != contLen)
  469.                 {
  470.                         fatalError("File download error!");
  471.                 }
  472.         }
  473.         if (netDriver == 1)
  474.         {
  475.                 strcpy(link, netbuf);
  476.                 sizeLink = strlen(link);
  477.                 try = 0;
  478.                 do
  479.                 {
  480.                         try++;
  481.                         if (try > 1)
  482.                         {
  483.                                 clearStatus();
  484.                                 printf("----->Retry:%u", try);
  485.                                 delay(500);
  486.                         }
  487.                         sendcommand("AT+CIPSTART=\"TCP\",\"nedoos.ru\",80");
  488.                         getAnswer2(); // CONNECT or ERROR or link is not valid
  489.                         count1 = strstr(netbuf, "CONNECT");
  490.                 } while (count1 == NULL);
  491.  
  492.                 getAnswer2(); // OK
  493.  
  494.                 sprintf(cmd, "AT+CIPSEND=%u", sizeLink + 2); // second CRLF in send command
  495.                 sendcommand(cmd);
  496.                 getAnswer2();
  497.                 do
  498.                 {
  499.                         byte = uart_readBlock();
  500.                         // putchar(byte);
  501.                 } while (byte != '>');
  502.                 sendcommand(link);
  503.                 count = 0;
  504.  
  505.                 do
  506.                 {
  507.                         byte = uart_readBlock();
  508.                         if (byte == sendOk[count])
  509.                         {
  510.                                 count++;
  511.                         }
  512.                         else
  513.                         {
  514.                                 count = 0;
  515.                         }
  516.                 } while (count < strlen(sendOk));
  517.                 uart_readBlock(); // CR
  518.                 uart_readBlock(); // LF
  519.                 clearStatus();
  520.                 firstPacket = true;
  521.                 do
  522.                 {
  523.                         headlng = 0;
  524.                         todo = recvHead();
  525.                         getdataEsp(todo); // Requested size
  526.                         if (firstPacket)
  527.                         {
  528.                                 todo = cutHeader(todo);
  529.                                 fileSize1 = contLen / 1024;
  530.                                 saveBuf(fileNamePtr, 00, 0);
  531.                                 firstPacket = false;
  532.                         }
  533.                         downloaded = downloaded + todo;
  534.                         printf("%lu of %u kb   \r", downloaded / 1024, fileSize1);
  535.                         saveBuf(fileNamePtr, 01, todo);
  536.  
  537.                         if (_low_level_get() == 27)
  538.                         {
  539.                                 fatalError("File download aborted!");
  540.                         }
  541.                 } while (downloaded < contLen);
  542.                 saveBuf(fileNamePtr, 02, 00);
  543.                 sendcommand("AT+CIPCLOSE");
  544.                 getAnswer2(); // CLOSED
  545.                 getAnswer2(); // OK
  546.         }
  547.         return 0;
  548. }
  549.  
  550. unsigned char getConfig(void)
  551. {
  552.         config.is_atm = (unsigned char)OS_GETCONFIG();
  553.         // H=system drive, L= 1-Evo 2-ATM2 3-ATM3 6-p2.666 ;E=pgsys(system page) D= TR-DOS page
  554.         switch ((config.is_atm))
  555.         {
  556.         case 1:
  557.                 strcpy(config.machineName, "ZX-Evolution");
  558.                 strcpy(config.kernelName, "sd_boot.$C");
  559.                 strcpy(config.kernelLink, "/svn/dl.php?repname=NedoOS&path=/release/sd_boot.%24C");
  560.                 break;
  561.         case 2:
  562.                 strcpy(config.machineName, "TURBO 2+");
  563.                 strcpy(config.kernelName, "osatm2hd.$C");
  564.                 strcpy(config.kernelLink, "/svn/dl.php?repname=NedoOS&path=/release/osatm2hd.%24C");
  565.  
  566.                 break;
  567.  
  568.         case 3: // SD HDD versions
  569.                 strcpy(config.machineName, "TURBO 3 [SD]");
  570.                 strcpy(config.kernelName, "osatm3hd.$C");
  571.                 strcpy(config.kernelLink, "/svn/dl.php?repname=NedoOS&path=/release/osatm3hd.%24C");
  572.                 break;
  573.         case 6: // SD HDD versions
  574.                 strcpy(config.machineName, "P2.666 [SD]");
  575.                 strcpy(config.kernelName, "osp26sd.$C");
  576.                 strcpy(config.kernelLink, "/svn/dl.php?repname=NedoOS&path=/release/osp26sd.%24C");
  577.                 break;
  578.  
  579.         default:
  580.                 strcpy(config.machineName, "NOT DETECED (ZX-Evo)");
  581.                 strcpy(config.kernelName, "sd_boot.$C");
  582.                 strcpy(config.kernelLink, "/svn/dl.php?repname=NedoOS&path=/release/sd_boot.s%24C");
  583.                 break;
  584.         }
  585.         return config.is_atm;
  586. }
  587. // Downloading minimal tools for updating/boot
  588. void getTools(void)
  589. {
  590.         ATRIB(cw.text);
  591.         ATRIB(cw.back);
  592.         getFile(wizNetLink, "bin/wizcfg.com");
  593.         getFile(newsLink, "updater.new");
  594.         getFile(pkunzipLink, "bin/pkunzip.com");
  595.         getFile(tarLink, "bin/tar.com");
  596.         getFile(cmdLink, "bin/cmd.com");
  597.         getFile(termLink, "bin/term.com");
  598.         getFile(updLink, "bin/updater.com");
  599.         getFile(netIniLink, "bin/net.ini");
  600. }
  601.  
  602. unsigned char ren2old(unsigned char *name)
  603. {
  604.         unsigned char counter = 255; // For OLD must be 255
  605.         OS_MKDIR((void *)name);
  606.         sprintf(nameBuf, "%s.old", name);
  607.         while (OS_RENAME((void *)name, (void *)nameBuf) != 0)
  608.         {
  609.                 counter++;
  610.                 sprintf(nameBuf, "%s.%u", name, counter);
  611.                 if (counter == 255)
  612.                 {
  613.                         fatalError("Unable to rename old folder");
  614.                 }
  615.         }
  616.         return counter;
  617. }
  618.  
  619. void ren2tar(void)
  620. {
  621.         unsigned int counter = 2400;
  622.         do
  623.         {
  624.                 sprintf(nameBuf, "bin.r%u", counter);
  625.  
  626.                 errn = OS_RENAME((void *)nameBuf, "bin.tar");
  627.                 counter--;
  628.                 if (counter < 2000)
  629.                 {
  630.                         fatalError("Unable to rename TAR file");
  631.                 }
  632.         } while (errn != 0);
  633. }
  634.  
  635. void ren2bin(void)
  636. {
  637.         unsigned char counter = 20;
  638.         sprintf(nameBuf, "bin.r%u", counter);
  639.         do
  640.         {
  641.                 errn = OS_RENAME((void *)nameBuf, "bin");
  642.                 counter++;
  643.                 sprintf(nameBuf, "bin.r%u", counter);
  644.                 if (counter > 99)
  645.                 {
  646.                         fatalError("Unable to rename BIN folder");
  647.                 }
  648.         } while (errn != 0);
  649. }
  650.  
  651. void restoreConfig(unsigned char oldBinExt)
  652. {
  653.         unsigned char count;
  654.         errn = OS_CHDIR("/");
  655.         errn = OS_RENAME("bin/autoexec.bat", "bin/autoexec.bat.new");
  656.         errn = OS_RENAME("bin/net.ini", "bin/net.ini.new");
  657.         errn = OS_RENAME("bin/nv.ext", "bin/nv.ext.new");
  658.         errn = OS_RENAME("bin/gp/gp.ini", "bin/gp/gp.ini.new");
  659.         errn = OS_RENAME("/bin/browser/index.gph", "/bin/browser/index.gph.new");
  660.         if (oldBinExt == 255)
  661.         {
  662.                 errn = OS_SHELL("copy bin.old/autoexec.bat bin/autoexec.bat >>updlog.txt");
  663.                 errn = OS_SHELL("copy bin.old/net.ini bin/net.ini >>updlog.txt");
  664.                 errn = OS_SHELL("copy bin.old/nv.ext bin/nv.ext >>updlog.txt");
  665.                 errn = OS_SHELL("copy bin.old/gp/gp.ini bin/gp/gp.ini >>updlog.txt");
  666.                 errn = OS_SHELL("copy bin.old/browser/index.gph bin/browser/index.gph >>updlog.txt");
  667.         }
  668.         else
  669.         {
  670.                 sprintf(nameBuf, "copy bin.%u/autoexec.bat bin/autoexec.bat >>updlog.txt", oldBinExt);
  671.                 OS_SHELL((void *)nameBuf);
  672.                 sprintf(nameBuf, "copy bin.%u/net.ini bin/net.ini >>updlog.txt", oldBinExt);
  673.                 OS_SHELL((void *)nameBuf);
  674.                 sprintf(nameBuf, "copy bin.%u/nv.ext bin/nv.ext >>updlog.txt", oldBinExt);
  675.                 OS_SHELL((void *)nameBuf);
  676.                 sprintf(nameBuf, "copy bin.%u/gp/gp.ini bin/gp/gp.ini >>updlog.txt", oldBinExt);
  677.                 OS_SHELL((void *)nameBuf);
  678.                 sprintf(nameBuf, "copy bin.%u/browser/index.gph bin/browser/index.gph >>updlog.txt", oldBinExt);
  679.                 OS_SHELL((void *)nameBuf);
  680.         }
  681.         AT(1, 4);
  682.         ATRIB(40);
  683.         for (count = 0; count < 15; count++)
  684.         {
  685.                 putchar(176);
  686.         }
  687.         errn = OS_RENAME("bin/autoexec.bat.new", "bin/autoexec.bat"); // If file already exist we dont rename
  688.         errn = OS_RENAME("bin/net.ini.new", "bin/net.ini");
  689.         errn = OS_RENAME("bin/nv.ext.new", "bin/nv.ext");
  690.         errn = OS_RENAME("bin/gp/gp.ini.new", "bin/gp/gp.ini");
  691.         errn = OS_RENAME("bin/browser/index.gph.new", "bin/browser/index.gph");
  692. }
  693.  
  694. // Download, backup, unpack release.bin
  695. void fullUpdate(void)
  696. {
  697.         BOX(1, 1, 80, 25, 40, 176);
  698.         cw.x = 20;
  699.         cw.y = 5;
  700.         cw.w = 40;
  701.         cw.h = 7;
  702.         cw.text = 97;
  703.         cw.back = 45;
  704.  
  705.         AT(1, 1);
  706.         ATRIB(cw.text);
  707.         ATRIB(cw.back);
  708.         printf("                   [FULL UPDATE - UPDATING ALL SYSTEM FILES]                    ");
  709.  
  710.         strcpy(cw.tittle, "nedoOS FULL updater ");
  711.         strcat(cw.tittle, uVer);
  712.         getConfig();
  713.  
  714.         errn = OS_CHDIR("/");
  715.  
  716.         strcat(cw.tittle, " (");
  717.         strcat(cw.tittle, config.machineName);
  718.         strcat(cw.tittle, ")");
  719.         drawWindow(cw);
  720.  
  721.         OS_DELETE("release.zip");
  722.  
  723.         clearStatus();
  724.         AT(cw.x + 2, cw.y + 3);
  725.         printf("1.Downloading release.zip...");
  726.         YIELD();
  727.         errn = getFile(relLink, "release.zip"); //  Downloading the file
  728.  
  729.         clearStatus();
  730.         AT(cw.x + 2, cw.y + 4);
  731.         printf("2.Backuping old system...\r\n");
  732.         YIELD();
  733.         oldBinExt = ren2old("bin");
  734.         ren2old("doc");
  735.         ren2old("ini");
  736.         ren2old("nedodemo");
  737.         ren2old("nedogame");
  738.  
  739.         AT(cw.x + 2, cw.y + 5);
  740.         printf("3.Downloading tools...\r\n");
  741.  
  742.         OS_MKDIR("bin");
  743.         YIELD();
  744.         getTools();
  745.  
  746.         BOX(1, 1, 80, 25, 40, 32);
  747.         AT(1, 1);
  748.         printf("Depacking release. Its take about 5 hours. Please wait.\r\n");
  749.  
  750.         printNews();
  751.         YIELD();
  752.  
  753.         OS_SHELL("pkunzip.com release.zip");
  754.  
  755.         BOX(1, 1, 80, 25, 40, 176);
  756.         drawWindow(cw);
  757.         AT(cw.x + 2, cw.y + 3);
  758.         printf("1.Downloading release.zip...");
  759.         AT(cw.x + 2, cw.y + 4);
  760.         printf("2.Backuping old system...\r\n");
  761.         AT(cw.x + 2, cw.y + 5);
  762.         printf("3.Downloading tools...\r\n");
  763.         AT(cw.x + 2, cw.y + 6);
  764.         ATRIB(cw.text);
  765.         ATRIB(cw.back);
  766.         printf("Restoring configs...");
  767. }
  768.  
  769. unsigned char testConect(void)
  770. {
  771.         unsigned char *count1;
  772.         if (netDriver == 1)
  773.         {
  774.                 sendcommand("AT+CIPSTART=\"TCP\",\"nedoos.ru\",80");
  775.                 getAnswer2(); // CONNECT or ERROR or link is not valid
  776.                 count1 = strstr(netbuf, "CONNECT");
  777.  
  778.                 if (count1 == NULL)
  779.                 {
  780.                         YIELD();
  781.                         uart_flush();
  782.                         return 0;
  783.                 }
  784.                 getAnswer2(); // OK
  785.                 sendcommand("AT+CIPCLOSE");
  786.                 getAnswer2(); // CLOSED
  787.                 getAnswer2(); // OK
  788.         }
  789.         return 1;
  790. }
  791.  
  792. // Updating only BIN folders, where is OS lives.
  793. void binUpdate(void)
  794. {
  795.         BOX(1, 1, 80, 25, 40, 176);
  796.         cw.x = 20;
  797.         cw.y = 5;
  798.         cw.w = 40;
  799.         cw.h = 11;
  800.         cw.text = 97;
  801.         cw.back = 44;
  802.  
  803.         AT(1, 1);
  804.         ATRIB(cw.text);
  805.         ATRIB(cw.back);
  806.         printf("                  [STANDART UPDATE - UPDATING ONLY BIN FOLDER]                  ");
  807.  
  808.         strcpy(cw.tittle, "nedoOS BIN updater ");
  809.         strcat(cw.tittle, uVer);
  810.         getConfig();
  811.         strcat(cw.tittle, " (");
  812.         strcat(cw.tittle, config.machineName);
  813.         strcat(cw.tittle, ")");
  814.         drawWindow(cw);
  815.  
  816.         OS_CHDIR("/");
  817.         clearStatus();
  818.         AT(cw.x + 2, cw.y + 10);
  819.         printf(">To full update start 'updater.com F'<");
  820.  
  821.         OS_SHELL("time2 >updlog.txt");
  822.  
  823.         AT(cw.x + 2, cw.y + 3);
  824.         printf("1.Downloading bin.zip...");
  825.         YIELD();
  826.         getFile(binLink, "bin/bin.zip"); //  Downloading the file
  827.  
  828.         clearStatus();
  829.         AT(cw.x + 2, cw.y + 4);
  830.         ATRIB(cw.text);
  831.         ATRIB(cw.back);
  832.         printf("2.Backuping bin to bin.old...");
  833.         YIELD();
  834.         oldBinExt = ren2old("bin");
  835.         OS_MKDIR("bin");
  836.  
  837.         clearStatus();
  838.         AT(cw.x + 2, cw.y + 5);
  839.         printf("3.Downloading tools...");
  840.         getTools();
  841.  
  842.         if (oldBinExt != 255)
  843.         {
  844.                 sprintf(nameBuf, "bin.%u/bin.zip", oldBinExt);
  845.         }
  846.         else
  847.         {
  848.                 sprintf(nameBuf, "bin.old/bin.zip");
  849.         }
  850.         errn = OS_RENAME((void *)nameBuf, "bin/bin.zip");
  851.  
  852.         BOX(1, 1, 80, 25, 40, 32);
  853.         AT(1, 1);
  854.         printf("Depacking release. Its take about 10 minutes. Please wait...\r\n");
  855.         printNews();
  856.         YIELD();
  857.  
  858.         OS_CHDIR("bin");
  859.         OS_SHELL("pkunzip.com bin.zip");
  860.  
  861.         BOX(1, 1, 80, 25, 40, 176);
  862.         AT(1, 1);
  863.         ATRIB(cw.text);
  864.         ATRIB(cw.back);
  865.         printf("                  [STANDART UPDATE - UPDATING ONLY BIN FOLDER]                  ");
  866.         drawWindow(cw);
  867.  
  868.         ATRIB(cw.text);
  869.         ATRIB(cw.back);
  870.         AT(cw.x + 2, cw.y + 3);
  871.         printf("2.Downloading bin.zip...");
  872.         AT(cw.x + 2, cw.y + 4);
  873.         printf("1.Backuping bin to bin.old...");
  874.         AT(cw.x + 2, cw.y + 5);
  875.         printf("3.Downloading tools...");
  876.         AT(cw.x + 2, cw.y + 6);
  877.         printf("4.Downloading kernel [%s]...", config.machineName);
  878.         errn = OS_CHDIR("/");
  879.         errn = getFile(config.kernelLink, config.kernelName); //  Downloading the file
  880.         AT(cw.x + 2, cw.y + 7);
  881.         ATRIB(cw.text);
  882.         ATRIB(cw.back);
  883.         printf("5.Restoring configs...");
  884. }
  885.  
  886. C_task main(int argc, char *argv[])
  887. {
  888.         unsigned char test;
  889.         os_initstdio();
  890.  
  891.         targetadr.family = AF_INET;
  892.         targetadr.porth = 00;
  893.         targetadr.portl = 80;
  894.         targetadr.b1 = 31;
  895.         targetadr.b2 = 31;
  896.         targetadr.b3 = 65;
  897.         targetadr.b4 = 35;
  898.  
  899.         clearStatus();
  900.  
  901.         OS_GETPATH((unsigned int)&curPath);
  902.         curLetter = curPath[0];
  903.  
  904.         if (argc > 1)
  905.         {
  906.                 if (argv[1][0] == 'F')
  907.                 {
  908.                         netDriver = 0;
  909.                         get_dns();
  910.                         test = dnsResolve("nedoos.ru");
  911.                         if (test)
  912.                         {
  913.                                 fullUpdate();
  914.                         }
  915.                 }
  916.                 else if (argv[1][0] == 'e')
  917.                 {
  918.                         netDriver = 1;
  919.                         clearStatus();
  920.                         printf("    ESP-COM mode enabled...");
  921.                         loadEspConfig();
  922.                         uart_init(divider);
  923.                         espReBoot();
  924.                         test = testConect();
  925.                         if (test)
  926.                         {
  927.                                 binUpdate();
  928.                         }
  929.                 }
  930.                 else if (argv[1][0] == 'E')
  931.                 {
  932.                         netDriver = 1;
  933.                         clearStatus();
  934.                         printf("    ESP-COM mode enabled...");
  935.                         loadEspConfig();
  936.                         uart_init(divider);
  937.                         espReBoot();
  938.                         test = testConect();
  939.                         if (test)
  940.                         {
  941.                                 fullUpdate();
  942.                         }
  943.                 }
  944.                 else
  945.                 {
  946.                         AT(1, 1);
  947.                         // printTable();
  948.                         //  printNews();
  949.                         // getchar();
  950.                         fatalError("Use 'F' key to FULL update");
  951.                         exit(0);
  952.                 }
  953.         }
  954.         else
  955.         {
  956.                 netDriver = 0;
  957.                 get_dns();
  958.                 test = dnsResolve("nedoos.ru");
  959.                 if (test)
  960.                 {
  961.                         binUpdate();
  962.                 }
  963.         }
  964.  
  965.         if (!test)
  966.         {
  967.                 fatalError("Check connection to the server!");
  968.         }
  969.         restoreConfig(oldBinExt);
  970.         OS_DELETE("bin/bin.zip");
  971.         clearStatus();
  972.         infoBox("System Updated successfully!");
  973.         delay(2000);
  974.         OS_SHELL("time2 >>updlog.txt");
  975.         // getchar();
  976.         // OS_DELETE("release.zip");
  977.         ATRIB(40);
  978.         ATRIB(32);
  979.         AT(1, 25);
  980.         exit(0);
  981. }
  982.