?login_element?

Subversion Repositories NedoOS

Rev

Rev 1942 | Rev 1968 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

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