?login_element?

Subversion Repositories NedoOS

Rev

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

  1. //("�⪨����� �� ᯨ��� ��᫠ � �⤮孨�, ����");
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <intrz80.h>
  5. #include <stdlib.h>
  6. #include <oscalls.h>
  7. #include <terminal.c>
  8. #include <tcp.h>
  9. #include <osfs.h>
  10. #include <intrz80.h>
  11. #include <ctype.h>
  12. #include <math.h>
  13. unsigned char uVer[] = "0.36";
  14. unsigned char curPath[128];
  15. unsigned char curLetter;
  16. unsigned char oldBinExt;
  17. unsigned char is_atm;
  18. unsigned int errn;
  19. unsigned long contLen;
  20. unsigned char saveFlag, saveBak;
  21. unsigned char crlf[2] = {13, 10};
  22. unsigned long bytecount, downloaded;
  23. unsigned char status, key, curFormat;
  24. struct sockaddr_in targetadr;
  25. struct readstructure readStruct;
  26. FILE *fp2;
  27.  
  28.  
  29. struct window
  30. {
  31.         unsigned char x;
  32.         unsigned char y;
  33.         unsigned char w;
  34.         unsigned char h;
  35.         unsigned char text;
  36.         unsigned char back;
  37.         unsigned char tittle[80];
  38.  
  39. } cw;
  40. unsigned char kernelName[32];
  41. unsigned char machineName[32];
  42. unsigned char kernelLink[256];
  43.  
  44. unsigned int bufSize = 2048; // Some memory corruption at this point, some QnD
  45. unsigned char netbuf[4000];
  46.  
  47. void clearStatus(void)
  48. {
  49.         AT(1, 24);
  50.         printf("                                                                                ");
  51. }
  52.  
  53. void printTable(void)
  54. {
  55.         unsigned int cycle;
  56.  
  57.         for (cycle = 32; cycle < 256; cycle++)
  58.         {
  59.                 printf("%03u:", cycle);
  60.                 putchar(cycle);
  61.                 printf(" ");
  62.                 if (cycle % 10 == 0)
  63.                 {
  64.                         printf("\r\n");
  65.                 }
  66.         }
  67. }
  68.  
  69. void delay(unsigned long counter)
  70. {
  71.         unsigned long start, finish;
  72.         counter = counter / 20;
  73.         if (counter < 1)
  74.         {
  75.                 counter = 1;
  76.         }
  77.         start = time();
  78.         finish = start + counter;
  79.  
  80.         while (start < finish)
  81.         {
  82.                 start = time();
  83.                 YIELD();
  84.         }
  85. }
  86.  
  87. #include <printNews().c>
  88.  
  89. void drawWindow(struct window w)
  90. {
  91.         unsigned char wcount, tempx, tittleStart;
  92.  
  93.         AT(w.x, w.y - 1);
  94.         tittleStart = w.x + (w.w / 2) - (strlen(w.tittle) / 2) + 1;
  95.         BOX(w.x, w.y, w.w + 1, w.h, w.back, 32);
  96.         AT(w.x, w.y);
  97.         ATRIB(w.text);
  98.         putchar(201);
  99.         for (wcount = 0; wcount < w.w; wcount++)
  100.         {
  101.                 putchar(205);
  102.         }
  103.         putchar(187);
  104.  
  105.         AT(w.x, w.y + w.h);
  106.         putchar(200);
  107.         for (wcount = 0; wcount < w.w; wcount++)
  108.         {
  109.                 putchar(205);
  110.         }
  111.         putchar(188);
  112.  
  113.         tempx = w.x + w.w + 1;
  114.         for (wcount = 1; wcount < w.h; wcount++)
  115.         {
  116.                 AT(w.x, w.y + wcount);
  117.                 putchar(186);
  118.                 AT(tempx, w.y + wcount);
  119.                 putchar(186);
  120.         }
  121.  
  122.         AT(w.x, w.y + 2);
  123.         putchar(199);
  124.         for (wcount = 0; wcount < w.w; wcount++)
  125.         {
  126.                 putchar(196);
  127.         }
  128.         putchar(182);
  129.  
  130.         AT(tittleStart, w.y + 1);
  131.         printf("%s", w.tittle);
  132. }
  133.  
  134. void fatalError(unsigned char *message)
  135. {
  136.         strcpy(cw.tittle, "FATAL ERROR!");
  137.  
  138.         if (strlen(message) > strlen(cw.tittle))
  139.         {
  140.                 cw.w = strlen(message) + 2;
  141.         }
  142.         else
  143.                 cw.w = strlen(cw.tittle) + 2;
  144.         cw.x = 80 / 2 - cw.w / 2;
  145.         cw.y = 11;
  146.         cw.h = 4;
  147.         cw.text = 97;
  148.         cw.back = 41;
  149.  
  150.         drawWindow(cw);
  151.         AT(cw.x + 2, cw.y + 3);
  152.         printf(message);
  153.         AT(1, 1);
  154.         getchar();
  155.         exit(0);
  156. }
  157.  
  158. void infoBox(unsigned char *message)
  159. {
  160.         strcpy(cw.tittle, "nedoOS system updater ");
  161.         strcat(cw.tittle, uVer);
  162.  
  163.         if (strlen(message) > strlen(cw.tittle))
  164.         {
  165.                 cw.w = strlen(message) + 2;
  166.         }
  167.         else
  168.                 cw.w = strlen(cw.tittle) + 2;
  169.         cw.x = 80 / 2 - cw.w / 2;
  170.         cw.y = 15;
  171.         cw.h = 4;
  172.         cw.text = 97;
  173.         cw.back = 42;
  174.  
  175.         drawWindow(cw);
  176.         AT(cw.x + 2, cw.y + 3);
  177.         printf(message);
  178.         AT(1, 1);
  179. }
  180.  
  181. unsigned char OS_SHELL(unsigned char *command)
  182. {
  183.         unsigned char fileName[] = "bin/cmd.com";
  184.         unsigned char appCmd[128] = "cmd.com ";
  185.         unsigned int shellSize, loaded, loop, adr;
  186.         unsigned char pgbak;
  187.         union APP_PAGES shell_pg;
  188.         union APP_PAGES main_pg;
  189.         FILE *fp3;
  190.         main_pg.l = OS_GETMAINPAGES();
  191.         pgbak = main_pg.pgs.window_3;
  192.         OS_GETPATH((unsigned int)&curPath);
  193.         strcat(appCmd, command);
  194.         fp3 = OS_OPENHANDLE(fileName, 0x80);
  195.         if (((int)fp3) & 0xff)
  196.         {
  197.                 clearStatus();
  198.                 AT(1, 24);
  199.                 printf(fileName);
  200.                 printf(" not found.");
  201.                 getchar();
  202.                 exit(0);
  203.         }
  204.         shellSize = OS_GETFILESIZE(fp3);
  205.  
  206.         OS_NEWAPP((unsigned int)&shell_pg);
  207.  
  208.         shell_pg.l = OS_GETAPPMAINPAGES(shell_pg.pgs.pId);
  209.  
  210.         SETPG32KHIGH(shell_pg.pgs.window_0);
  211.  
  212.         memcpy((char *)(0xC080), (char *)(&appCmd), sizeof(appCmd));
  213.  
  214.         loop = 0;
  215.         while (loop < shellSize)
  216.         {
  217.                 loaded = OS_READHANDLE(netbuf, fp3, sizeof(netbuf));
  218.                 adr = 0xC100 + loop;
  219.                 memcpy((char *)(adr), &netbuf, loaded);
  220.                 loop = loop + loaded;
  221.         }
  222.  
  223.         OS_CLOSEHANDLE(fp3);
  224.         SETPG32KHIGH(pgbak);
  225.         clearStatus();
  226.         AT(1, 24);
  227.         printf("Running shell [pId:%u][%s][%s]", shell_pg.pgs.pId, curPath, appCmd);
  228.         AT(1, 24);
  229.         delay(300);
  230.         OS_RUNAPP(shell_pg.pgs.pId);
  231.         AT(1, 4);
  232.         OS_WAITPID(shell_pg.pgs.pId);
  233.         return shell_pg.pgs.pId;
  234. }
  235. //////////////// NETWORK PART //////////////////////
  236. #include <network.c>
  237. ////////////////////////////////////////////////////
  238.  
  239. unsigned char getConfig(void)
  240. {
  241.         is_atm = (unsigned char)OS_GETCONFIG();
  242.         // H=system drive, L= 1-Evo 2-ATM2 3-ATM3 6-p2.666 ;E=pgsys(system page) D= TR-DOS page
  243.         switch ((is_atm))
  244.         {
  245.         case 1:
  246.                 strcpy(machineName, "ZX-Evolution");
  247.                 strcpy(kernelName, "sd_boot.$C");
  248.                 strcpy(kernelLink, "/svn/dl.php?repname=NedoOS&path=%2Frelease%2Fsd_boot.%24C");
  249.                 break;
  250.         case 2:
  251.                 strcpy(machineName, "TURBO 2+");
  252.                 strcpy(kernelName, "osatm2hd.$C");
  253.                 strcpy(kernelLink, "/svn/dl.php?repname=NedoOS&path=%2Frelease%2Fosatm2hd.%24C");
  254.  
  255.                 break;
  256.  
  257.         case 3: // SD HDD versions
  258.                 strcpy(machineName, "TURBO 3 [SD]");
  259.                 strcpy(kernelName, "osatm3hd.$C");
  260.                 strcpy(kernelLink, "/svn/dl.php?repname=NedoOS&path=%2Frelease%2Fosatm3hd.%24C");
  261.                 break;
  262.         case 6: // SD HDD versions
  263.                 strcpy(machineName, "P2.666 [SD]");
  264.                 strcpy(kernelName, "osp26sd.$C");
  265.                 strcpy(kernelLink, "/svn/dl.php?repname=NedoOS&path=%2Frelease%2Fosp26sd.%24C");
  266.                 break;
  267.  
  268.         default:
  269.                 strcpy(machineName, "NOT DETECED (ZX-Evo)");
  270.                 strcpy(kernelName, "sd_boot.$C");
  271.                 strcpy(kernelLink, "/svn/dl.php?repname=NedoOS&path=%2Frelease%2Fsd_boot.%24C");
  272.                 break;
  273.         }
  274.         return is_atm;
  275. }
  276. // Downloading minimal tools for updating/boot
  277. void getTools(void)
  278. {
  279.         unsigned char pkunzipLink[] = "/svn/dl.php?repname=NedoOS&path=%2Frelease%2Fbin%2Fpkunzip.com";
  280.         unsigned char tarLink[] = "/svn/dl.php?repname=NedoOS&path=%2Frelease%2Fbin%2Ftar.com";
  281.         unsigned char cmdLink[] = "/svn/dl.php?repname=NedoOS&path=%2Frelease%2Fbin%2Fcmd.com";
  282.         unsigned char termLink[] = "/svn/dl.php?repname=NedoOS&path=%2Frelease%2Fbin%2Fterm.com";
  283.         unsigned char updLink[] = "/svn/dl.php?repname=NedoOS&path=%2Frelease%2Fbin%2Fupdater.com";
  284.  
  285.         errn = OS_MKDIR("bin"); // Create if not exist
  286.         ATRIB(cw.text);
  287.         ATRIB(cw.back);
  288.         errn = getFile(pkunzipLink, "bin/pkunzip.com");
  289.         errn = getFile(tarLink, "bin/tar.com");
  290.         errn = getFile(cmdLink, "bin/cmd.com");
  291.         errn = getFile(termLink, "bin/term.com");
  292.         errn = getFile(updLink, "bin/updater.com");
  293. }
  294.  
  295. void deleteWorkFiles(void)
  296. {
  297.         OS_DELETE("bin.zip");
  298.         OS_DELETE("bin.tar");
  299.         OS_DELETE("bin.old"); // deleting not empty folders not supported
  300.         OS_DELETE("bin.r17");
  301.         OS_DELETE("bin.r18");
  302.         OS_DELETE("bin.r19");
  303.         OS_DELETE("bin.r20");
  304. }
  305.  
  306. unsigned char ren2old(unsigned char *name)
  307. {
  308.         unsigned char *oldName = "0000000000000000000000000000000000";
  309.         unsigned char counter = 255;
  310.         OS_MKDIR((void *)name);
  311.         sprintf(oldName, "%s.old", name);
  312.         while (OS_RENAME((void *)name, (void *)oldName) != 0)
  313.         {
  314.                 counter++;
  315.                 if (counter == 255)
  316.                 {
  317.                         fatalError("Unable to rename old folder");
  318.                 }
  319.  
  320.                 sprintf(oldName, "%s.%u", name, counter);
  321.         }
  322.         return counter;
  323. }
  324.  
  325. void ren2tar(void)
  326. {
  327.         unsigned char *name = "0000000000000000000000000000000000";
  328.         unsigned char counter = 17;
  329.         errn = 255;
  330.         sprintf(name, "bin.r%u", counter);
  331.         while (errn != 0)
  332.         {
  333.                 errn = OS_RENAME((void *)name, "bin.tar");
  334.                 counter++;
  335.                 sprintf(name, "bin.r%u", counter);
  336.                 if (counter > 99)
  337.                 {
  338.                         fatalError("Unable to rename TAR file");
  339.                 }
  340.         }
  341. }
  342.  
  343. void ren2bin(void)
  344. {
  345.         unsigned char *name = "0000000000000000000000000000000000";
  346.         unsigned char counter = 17;
  347.         errn = 255;
  348.         sprintf(name, "bin.r%u", counter);
  349.         while (errn != 0)
  350.         {
  351.                 errn = OS_RENAME((void *)name, "bin");
  352.                 counter++;
  353.                 sprintf(name, "bin.r%u", counter);
  354.                 if (counter > 99)
  355.                 {
  356.                         fatalError("Unable to rename BIN folder");
  357.                 }
  358.         }
  359. }
  360.  
  361. void restoreConfig(unsigned char oldBinExt)
  362. {
  363.         unsigned char *name = "0000000000000000000000000000000000";
  364.         unsigned char count;
  365.         errn = OS_CHDIR("/");
  366.         errn = OS_RENAME("bin/autoexec.bat", "bin/autoexec.new");
  367.         errn = OS_RENAME("bin/net.ini", "bin/net.new");
  368.         errn = OS_RENAME("bin/nv.ext", "bin/nv.new");
  369.         errn = OS_RENAME("bin/gp/gp.ini", "bin/gp/gpini.new");
  370.  
  371.         errn = OS_CHDIR("/");
  372.  
  373.         if (oldBinExt == 255)
  374.         {
  375.                 errn = OS_SHELL("copy bin.old/autoexec.bat bin/autoexec.bat");
  376.  
  377.                 errn = OS_SHELL("copy bin.old/net.ini bin/net.ini");
  378.  
  379.                 errn = OS_SHELL("copy bin.old/nv.ext bin/nv.ext");
  380.  
  381.                 errn = OS_SHELL("copy bin.old/nv.pth bin/nv.pth");
  382.  
  383.                 errn = OS_SHELL("copy bin.old/gp/gp.ini bin/gp/gp.ini");
  384.         }
  385.         else
  386.         {
  387.                 sprintf(name, "copy bin.%u/autoexec.bat bin/autoexec.bat", oldBinExt);
  388.                 OS_SHELL((void *)name);
  389.  
  390.                 sprintf(name, "copy bin.%u/net.ini bin/net.ini", oldBinExt);
  391.                 OS_SHELL((void *)name);
  392.  
  393.                 sprintf(name, "copy bin.%u/nv.ext bin/nv.ext", oldBinExt);
  394.                 OS_SHELL((void *)name);
  395.                 sprintf(name, "copy bin.%u/nv.pth bin/nv.pth", oldBinExt);
  396.                 OS_SHELL((void *)name);
  397.                 sprintf(name, "copy bin.%u/gp/gp.ini bin/gp/gp.ini", oldBinExt);
  398.                 OS_SHELL((void *)name);
  399.  
  400.         }
  401.         AT(1, 4);
  402.         for (count = 0; count < 15; count++)
  403.         {
  404.                 putchar(176);
  405.         }
  406.         errn = OS_RENAME("bin/autoexec.new", "bin/autoexec.bat"); // If file already exist we dont rename
  407.         errn = OS_RENAME("bin/net.new", "bin/net.ini");
  408.         errn = OS_RENAME("bin/nv.new", "bin/nv.ext");
  409.         errn = OS_RENAME("bin/gp/gpini.new", "bin/gp/gp.ini");
  410. }
  411.  
  412. // Download, backup, unpack release.bin
  413. void fullUpdate(void)
  414. {
  415.         unsigned char relLink[] = "http://nedoos.ru/images/release.zip";
  416.  
  417.         BOX(1, 1, 80, 25, 40, 176);
  418.         cw.x = 20;
  419.         cw.y = 5;
  420.         cw.w = 40;
  421.         cw.h = 7;
  422.         cw.text = 97;
  423.         cw.back = 45;
  424.         strcpy(cw.tittle, "nedoOS FULL updater ");
  425.         strcat(cw.tittle, uVer);
  426.  
  427.         getConfig();
  428.  
  429.         OS_GETPATH((unsigned int)&curPath);
  430.         curLetter = curPath[0];
  431.         errn = OS_CHDIR("/");
  432.  
  433.         strcat(cw.tittle, " (");
  434.         strcat(cw.tittle, machineName);
  435.         strcat(cw.tittle, ")");
  436.         drawWindow(cw);
  437.  
  438.         OS_DELETE("release.zip");
  439.         OS_DELETE("bin.old");
  440.         OS_DELETE("doc.old");
  441.         OS_DELETE("nedodemo.old");
  442.         OS_DELETE("nedogame.old");
  443.  
  444.         clearStatus();
  445.         AT(cw.x + 2, cw.y + 3);
  446.         printf("1.Downloading release.zip...");
  447.  
  448.         errn = getFile(relLink, "release.zip"); //  Downloading the file
  449.  
  450.         clearStatus();
  451.         AT(cw.x + 2, cw.y + 4);
  452.         printf("2.Backuping old system...\r\n");
  453.  
  454.         oldBinExt = ren2old("bin");
  455.         ren2old("doc");
  456.         ren2old("nedodemo");
  457.         ren2old("nedogame");
  458.  
  459.         clearStatus();
  460.         AT(cw.x + 2, cw.y + 5);
  461.         printf("3.Downloading tools...\r\n");
  462.  
  463.         getTools();
  464.  
  465.         BOX(1, 1, 80, 25, 40, 32);
  466.         AT(1, 1);
  467.         printf("Depacking release. Its take about 10 hours. Please wait.\r\n");
  468.         printf("First hours going without signs of life.\r\n");
  469.         printNews();
  470.         YIELD();
  471.         OS_SHELL("pkunzip.com release.zip");
  472.         BOX(1, 1, 80, 25, 40, 176);
  473.         drawWindow(cw);
  474.         AT(cw.x + 2, cw.y + 3);
  475.         ATRIB(cw.text);
  476.         ATRIB(cw.back);
  477.         printf("Restoring configs...");
  478. }
  479. // Updating only BIN folders, where is OS lives.
  480. void binUpdate(void)
  481. {
  482.         unsigned char binLink[] = "/svn/dl.php?repname=NedoOS&path=%2Frelease%2Fbin%2F&isdir=1";
  483.         BOX(1, 1, 80, 25, 40, 176);
  484.         cw.x = 20;
  485.         cw.y = 5;
  486.         cw.w = 40;
  487.         cw.h = 10;
  488.         cw.text = 97;
  489.         cw.back = 44;
  490.         strcpy(cw.tittle, "nedoOS BIN updater ");
  491.         strcat(cw.tittle, uVer);
  492.         getConfig();
  493.         strcat(cw.tittle, " (");
  494.         strcat(cw.tittle, machineName);
  495.         strcat(cw.tittle, ")");
  496.         drawWindow(cw);
  497.  
  498.         errn = OS_CHDIR("/");
  499.         OS_GETPATH((unsigned int)&curPath);
  500.         curLetter = curPath[0];
  501.  
  502.         deleteWorkFiles();
  503.  
  504.         clearStatus();
  505.         AT(cw.x + 2, cw.y + 3);
  506.         printf("1.Downloading bin.zip...");
  507.  
  508.         errn = getFile(binLink, "bin.zip"); //  Downloading the file
  509.  
  510.         clearStatus();
  511.         AT(cw.x + 2, cw.y + 4);
  512.         printf("2.Downloading tools...");
  513.  
  514.         getTools();
  515.  
  516.         BOX(1, 1, 80, 25, 40, 32);
  517.         AT(1, 1);
  518.         printf("Please, make sure you don't have bin.r* folder on disk!!!\r\n");
  519.         printf("Depacking release. Its take about 10 minutes. Please wait...\r\n");
  520.  
  521.         printNews();
  522.         YIELD();
  523.  
  524.         OS_SHELL("pkunzip.com bin.zip");
  525.         BOX(1, 1, 80, 25, 40, 176);
  526.         drawWindow(cw);
  527.         clearStatus();
  528.         AT(cw.x + 2, cw.y + 3);
  529.         ATRIB(cw.text);
  530.         ATRIB(cw.back);
  531.         printf("3.Renaming bin.r?? to bin.tar...");
  532.  
  533.         ren2tar();
  534.  
  535.         AT(cw.x + 2, cw.y + 4);
  536.         ATRIB(cw.text);
  537.         ATRIB(cw.back);
  538.         printf("4.Untaring bin.tar, please wait...");
  539.         clearStatus();
  540.         OS_SHELL("tar.com bin.tar");
  541.  
  542.         AT(cw.x + 2, cw.y + 5);
  543.         ATRIB(cw.text);
  544.         ATRIB(cw.back);
  545.         printf("5.Backuping old bin to bin.old...");
  546.  
  547.         oldBinExt = ren2old("bin");
  548.  
  549.         AT(cw.x + 2, cw.y + 6);
  550.         ATRIB(cw.text);
  551.         ATRIB(cw.back);
  552.         printf("6.Renaming NEW BIN...");
  553.  
  554.         ren2bin();
  555.  
  556.         AT(cw.x + 2, cw.y + 7);
  557.         ATRIB(cw.text);
  558.         ATRIB(cw.back);
  559.         printf("7.Deleting zip & tar...");
  560.  
  561.         AT(cw.x + 2, cw.y + 8);
  562.         ATRIB(cw.text);
  563.         ATRIB(cw.back);
  564.         printf("8.Downloading kernel [%s]...", machineName);
  565.         errn = OS_CHDIR("/");
  566.         errn = getFile(kernelLink, kernelName); //  Downloading the file
  567.         AT(cw.x + 2, cw.y + 9);
  568.         ATRIB(cw.text);
  569.         ATRIB(cw.back);
  570.         printf("9.Restoring configs...");
  571. }
  572.  
  573. C_task main(int argc, char *argv[])
  574. {
  575.         os_initstdio();
  576.  
  577.         if (argc > 1)
  578.         {
  579.                 if (argv[1][0] == 'F')
  580.                 {
  581.                         fullUpdate();
  582.                 }
  583.                 else
  584.                 {
  585.                         AT(1, 1);
  586.                         //printTable();
  587.                         //getchar();
  588.                         fatalError("Use 'F' key to FULL update");
  589.  
  590.                 }
  591.         }
  592.         else
  593.         {
  594.                 binUpdate();
  595.         }
  596.         restoreConfig(oldBinExt);
  597.         deleteWorkFiles();
  598.         clearStatus();
  599.         infoBox("System Updated successfully!");
  600.         getchar();
  601.         OS_DELETE("release.zip");
  602.         ATRIB(40);
  603.         ATRIB(32);
  604.         exit(0);
  605. }
  606.