?login_element?

Subversion Repositories NedoOS

Rev

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