home *** CD-ROM | disk | FTP | other *** search
/ Borland Programmer's Resource / Borland_Programmers_Resource_CD_1995.iso / fonts / cw_src / install / cwsetup.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-19  |  22.6 KB  |  995 lines

  1. #define    _WINDOWS
  2. #define    no_Protect_
  3.  
  4. #define    _Fast_
  5. #define    no_Trace_
  6.  
  7. //
  8. // CyrWin installation program
  9. //
  10. #define    NOMINMAX
  11. #include "c:\windev\include\windows.h"
  12. #include "c:\windev\include\memory.h"
  13. #include "c:\windev\include\string.h"
  14. #include "c:\windev\include\direct.h"
  15. #include "c:\windev\include\stdlib.h"
  16. #include "c:\windev\include\stdio.h"
  17. #include "cwinst.h"
  18. #include "ewtdebug.h"
  19.  
  20. extern    HANDLE hInst;
  21. extern    HANDLE hArrow, hWait;
  22. HANDLE    hMainWnd;
  23.  
  24. char    szSrcPath [132];            // source path
  25. char    szDstPath [132];            // dest. path (ROOT)
  26. char    szSysPath [132];            // syst. path (SYSTEM)
  27.  
  28. char    szSrcFile [132];            // source file name
  29. char    szDstFile [132];            // dest. file name
  30.  
  31. char    szDiskName [132];            // installation volume name
  32. char    szSetupInf []= "cwsetup.inf";        // .inf file name
  33. char    szSetupFile [132];            // full file name with path
  34.  
  35. char    szSetupStr [132];            // readed string
  36.  
  37. char    cCpBuff [20480];            // 20 Kbutes long buffer
  38. char    cFilBuff [5120];            // 5 Kbutes filenames buffer
  39. char    cTmpBuff [5120];            // 5 Kbutes temp buffer
  40. char    cTmpStr [256];
  41.  
  42. char    szDiskName [132];            // distribution disk name
  43. extern    char szTitle [];
  44.  
  45. static char szFonts[][4]= {
  46.     "FIX",
  47.     "SYS",
  48.     "866",
  49.     ""
  50. };
  51.  
  52. static char szSects[][13]= {
  53.     "fixedfon.fon",
  54.     "fonts.fon",
  55.     "oemfonts.fon",
  56.     ""
  57. };
  58.  
  59. static char szCards[][4]= {
  60.     "CGA",
  61.     "EGA",
  62.     "VGA",
  63.     "8514",
  64.     ""
  65. };
  66.  
  67. BOOL    FAR PASCAL Floppy (HWND, WORD, WORD, LONG);
  68. int    bCopyFile (PSTR, PSTR, PSTR);
  69. int    CopyErr (PSTR, PSTR, int);
  70. PSTR    _strup (PSTR);
  71. PSTR    pFontName (PSTR);
  72. BOOL    myssearch (PSTR, PSTR);
  73. BOOL    bSearchCyr (char *);
  74. #ifdef    _Protect_
  75. static    short Protect (char*);
  76. unsigned BiosSum (void);
  77. int    checkdsk (int);
  78. #endif
  79.  
  80. char    szUninstall[]= "uninstall";
  81.  
  82. #define    GetKey(app,key,str)    GetPrivateProfileString (app, key, "", str, sizeof str, szSetupFile)
  83. // #define    WriteChanges(file,str)    WritePrivateProfileString (szUninstall, file, str, szSetupFile)
  84. #define    WriteChanges(file,str)
  85. #define    AddSlash(str)        if (str [i= (strlen (str)-1)] != '\\')    \
  86.                     {                \
  87.                     str [++i]= '\\';        \
  88.                     str [++i]= 0;            \
  89.                     }
  90. #define    clear(x)        memset (x, 0, sizeof x)
  91.  
  92.  
  93. char    szContScaling[]= "CONTINUOUSSCALING";
  94.  
  95. typedef    struct
  96.     {
  97.     int    a, b, c;
  98.     char    cLetter;
  99.     } tag_fnt;
  100.  
  101. //
  102. // installations options
  103. //
  104. extern    int bInstallSys;
  105. extern    int bCommentFonts;
  106. extern    int bLangInfo;
  107. extern    int bLoadFonts;
  108. extern    int bLoadAuto;
  109.  
  110. typedef    struct
  111.     {
  112.     char    name [15];
  113.     int    *val;
  114.     } tagDefs;
  115.  
  116. tagDefs    instDefs []=
  117.     {
  118.     "INSTALLSYS", &bInstallSys,
  119.     "LANGINFO", &bLangInfo,
  120.     "LOADAUTO", &bLoadAuto,
  121.     "LOADFONTS", &bLoadFonts,
  122.     "COMMENTFONTS", &bCommentFonts,
  123.     "", NULL
  124.     };
  125.  
  126. //
  127. //    font parameter table
  128. //
  129. tag_fnt    fTypes [6]=
  130.     {
  131.     200,  96,  48,  'A',
  132.     133,  96,  72,  'B',
  133.      83,  60,  72,  'C',
  134.     167, 120,  72,  'D',
  135.     100,  96,  96,  'E',
  136.     100, 120, 120,  'F'
  137.     };
  138.  
  139. int    FontType (PSTR, tag_fnt *);        // returns font params
  140.  
  141. //
  142. //    Read installation defaults from cwinst.inf and copy this file
  143. //    to the Windows ROOT directory
  144. //
  145. int    cwDefaults (HWND hWnd)
  146.     {
  147.     int    iRetVal= 0;
  148.     int    i;
  149.     FARPROC    lpfnProc;
  150.     PSTR    cp;
  151.     int    iErr;
  152.     PSTR    cps;
  153.     char    b [255];
  154.     char    tmp1 [255];
  155.     char    tmp2 [255];
  156.     PSTR    pCard;
  157.     PSTR    pFontSect;
  158.     tag_fnt    dFont;
  159.     tagDefs    *td;
  160.  
  161.     hMainWnd= hWnd;
  162.     clear (szDstPath);
  163.     GetWindowsDirectory (szDstPath, sizeof szDstPath);
  164.     AddSlash (szDstPath);
  165.     strcpy (szSysPath, szDstPath); strcat (szSysPath, "SYSTEM\\");
  166.     clear (szSrcPath);
  167.     getcwd (szSrcPath, sizeof szSrcPath);
  168.     AddSlash (szSrcPath);
  169.  
  170.     //
  171.     // search cwsetup.inf file
  172.     //
  173.     for (;;)
  174.         {
  175.         strcpy (szSetupFile, szSrcPath);
  176.         strcat (szSetupFile, szSetupInf);
  177.         i= _lopen (szSetupFile, OF_READ);
  178.         if (i > 0)
  179.             {
  180.             _lclose (i);
  181.             break;
  182.             }
  183.         else
  184.             {
  185.             strcpy (szDiskName, "CyrWin distribution disk #1");
  186.             lpfnProc= MakeProcInstance (Floppy, hInst);
  187.             i= DialogBox (hInst, "FLOPPY", hWnd, lpfnProc);
  188.             FreeProcInstance (lpfnProc);
  189.             if (i)
  190.                 {
  191.                 AddSlash (szSrcPath);
  192.                 }
  193.             else
  194.                 return FALSE;
  195.             }
  196.         }                // 'for' get first disk
  197.  
  198.     strcpy (szSrcFile, szSrcPath); strcat (szSrcFile, szSetupInf);
  199.     strcpy (szDstFile, szDstPath); strcat (szDstFile, szSetupInf);
  200.     if (CopyErr (szSrcFile, szDstFile, bCopyFile (szSrcFile, szDstFile, "setup information file")))
  201.         return FALSE;
  202.     clear (szSetupFile);
  203.     strcpy (szSetupFile, szDstPath); strcat (szSetupFile, szSetupInf);
  204.  
  205.     for (td= &instDefs [0]; td->val != NULL; td++)
  206.         {
  207.         GetKey ("defaults", td->name, b);
  208.         if (b [0] == 't' || b [0] == 'T')
  209.             *(td->val)= 1;
  210.         else
  211.             *(td->val)= 0;
  212.         }
  213.  
  214.     WriteChanges (szSetupFile, "----");
  215.     return TRUE;
  216.     }
  217. //
  218. //    Start CyrWin installation
  219. //
  220. int    cwInst (HWND hWnd)
  221.     {
  222.     int    iRetVal= 0;
  223.     int    i;
  224.     FARPROC    lpfnProc;
  225.     PSTR    cp;
  226.     int    iErr;
  227.     PSTR    cps;
  228.     char    b [255];
  229.     char    tmp1 [255];
  230.     char    tmp2 [255];
  231.     PSTR    pCard;
  232.     PSTR    pFontSect;
  233.     tag_fnt    dFont;
  234.     tagDefs    *td;
  235.     BOOL    bNeedCopy;
  236.  
  237.     hMainWnd= hWnd;
  238.     clear (szDstPath);
  239.     GetWindowsDirectory (szDstPath, sizeof szDstPath);
  240.     AddSlash (szDstPath);
  241.     strcpy (szSysPath, szDstPath); strcat (szSysPath, "SYSTEM\\");
  242.     clear (szSrcPath);
  243.     getcwd (szSrcPath, sizeof szSrcPath);
  244.     AddSlash (szSrcPath);
  245.  
  246.     //
  247.     // search cwsetup.inf file
  248.     //
  249.     /*
  250.     for (;;)
  251.         {
  252.         strcpy (szSetupFile, szSrcPath);
  253.         strcat (szSetupFile, szSetupInf);
  254.         i= _lopen (szSetupFile, OF_READ);
  255.         if (i > 0)
  256.             {
  257.             _lclose (i);
  258.             break;
  259.             }
  260.         else
  261.             {
  262.             strcpy (szDiskName, "CyrWin distribution disk #1");
  263.             lpfnProc= MakeProcInstance (Floppy, hInst);
  264.             i= DialogBox (hInst, "FLOPPY", hWnd, lpfnProc);
  265.             FreeProcInstance (lpfnProc);
  266.             if (i)
  267.                 {
  268.                 AddSlash (szSrcPath);
  269.                 }
  270.             else
  271.                 return FALSE;
  272.             }
  273.         }                // 'for' get first disk
  274.     */
  275.     //
  276.     // szSrcPath - first disk!
  277.     // make win.bak and system.bak files
  278.     // copy cwsetup.inf to Windows directory
  279.     //
  280.     if (bInstallSys || bLangInfo || bLoadAuto || bLoadFonts)
  281.         {
  282.         strcpy (szSrcFile, szDstPath); strcpy (szDstFile, szDstPath);
  283.         strcat (szSrcFile, "WIN.INI"); strcat (szDstFile, "WIN.CW");
  284.         if (CopyErr (szSrcFile, szDstFile, bCopyFile (szSrcFile, szDstFile, "make backup of win.ini file")))
  285.             return FALSE;
  286.         strcpy (szSrcFile, szDstPath); strcpy (szDstFile, szDstPath);
  287.         strcat (szSrcFile, "SYSTEM.INI"); strcat (szDstFile, "SYSTEM.CW");
  288.         if (CopyErr (szSrcFile, szDstFile, bCopyFile (szSrcFile, szDstFile, "make backup of system.ini file")))
  289.             return FALSE;
  290.         MessageBox (hWnd, "Your win.ini and system.ini files was renamed to win.cw and system.cw files", szTitle, MB_ICONINFORMATION|MB_OK);
  291.         }
  292.  
  293. //    strcpy (szSrcFile, szSrcPath); strcat (szSrcFile, szSetupInf);
  294. //    strcpy (szDstFile, szDstPath); strcat (szDstFile, szSetupInf);
  295. //    if (CopyErr (szSrcFile, szDstFile, bCopyFile (szSrcFile, szDstFile, "setup information file")))
  296. //        return FALSE;
  297. //    clear (szSetupFile);
  298. //    strcpy (szSetupFile, szDstPath); strcat (szSetupFile, szSetupInf);
  299.  
  300.     //
  301.     // copy nesessary files
  302.     //
  303.     clear (cFilBuff);
  304.     GetKey ("nfiles", NULL, cFilBuff);
  305.     for (cp= cFilBuff; *cp; cp+= strlen (cp)+1)
  306.         {
  307.         GetKey ("nfiles", cp, szSetupStr);
  308.         for (cps= szSetupStr; *cps == ':'; *cps++);
  309.         clear (szDiskName); szDiskName [0]= *cps;
  310.         GetKey ("disks", szDiskName, szDiskName);
  311.         for (cps++; *cps == ':'; *cps++);
  312.         clear (b);
  313.         for (i= 0; *cps != ':'; i++)
  314.             b [i]= *cps++; cps++;
  315.         strcpy (tmp1, cps); _strup (tmp1);
  316.         if (!strcmp (tmp1, "TRUE"))
  317.             {
  318.             bNeedCopy= TRUE;
  319.             }
  320.         else
  321.             {
  322.             for (td= instDefs; td->val != NULL; td++)
  323.                 {
  324.                 if (!strcmp (tmp1, td->name))
  325.                     {
  326.                     bNeedCopy= *(td->val);
  327.                     break;
  328.                     }
  329.                 }
  330.             }
  331.  
  332.         if (!bNeedCopy)
  333.             continue;
  334. NeedRetry :    strcpy (szSrcFile, szSrcPath); strcat (szSrcFile, cp);
  335.         strcpy (szDstFile, szDstPath); strcat (szDstFile, cp);
  336.         iErr= (int) bCopyFile (szSrcFile, szDstFile, cps);
  337.         if (iErr == 1)
  338.             {
  339.             lpfnProc= MakeProcInstance (Floppy, hInst);
  340.             i= DialogBox (hInst, "FLOPPY", hMainWnd, lpfnProc);
  341.             FreeProcInstance (lpfnProc);
  342.             if (i)
  343.                 {
  344.                 AddSlash (szSrcPath); goto NeedRetry;
  345.                 }
  346.             else
  347.                 return FALSE;
  348.             }
  349.         else if (iErr)
  350.             {
  351.             CopyErr (szSrcFile, szDstFile, iErr);
  352.             return FALSE;
  353.             }
  354.         WriteChanges (szDstFile, "----");
  355.         }                // 'for' - copy nesessary files
  356.  
  357.     if (bLoadAuto)
  358.         {
  359.         GetProfileString ("windows", "load", "", b, 255);
  360. //        PutString ("readed string from win.ini [load]", b);
  361.         if (!myssearch (b, "altkeyb.exe"))
  362.             {
  363.             clear (tmp2);
  364.             strcpy (tmp2, b);
  365.             strcat (b, " altkeyb.exe");
  366.             strcpy (tmp1, "win.ini-windows-load-");
  367.             strcat (tmp1, b); strcat (tmp1, "-"); strcat (tmp1, tmp2);
  368.             clear (tmp2); strcpy (tmp2, szDstPath); strcat (tmp2, "ALTKEYB.EXE");
  369.             WriteChanges (tmp2, tmp1);
  370.             WriteProfileString ("windows", "load", b);
  371.             clear (tmp1);
  372.             }
  373.         }
  374.     if (bLangInfo)
  375.         {
  376.         WritePrivateProfileString ("keyboard", "oemansi.bin", "xlat866.bin", "system.ini");
  377.         WritePrivateProfileString ("boot", "language.dll", "langcyr.dll", "system.ini");
  378.         WriteChanges ("langinfo", "TRUE");
  379.         }
  380.     //
  381.     // copy and install screen fonts
  382.     //
  383.     if (!bInstallSys)
  384.         goto NoInstallSys;
  385.     // determine type of video adapter, pCard -> type string
  386.  
  387.     GetPrivateProfileString ("boot", "fonts.fon", NULL, b, 255, "system.ini");
  388.     for (pCard= szCards[0]; *pCard; pCard+= strlen (pCard)+1)
  389.         {
  390.         char * _strup (char *b);
  391.         if (!strncmp ( _strup (b), pCard, strlen (pCard)))
  392.             break;
  393.         }
  394.     if (!(*pCard))
  395.         {
  396.         MessageBox (hMainWnd, "Cannot identify video adapter", szTitle, NULL);
  397.         return FALSE;
  398.         }
  399.  
  400.     //
  401.     // copy screen fonts
  402.     //
  403.     if (bInstallSys)
  404.         {
  405.         for (cp= szFonts [0], pFontSect= szSects [0]; *cp; cp+= 4)
  406.             {
  407.             strcpy (b, pCard); strcat (b, cp); strcat (b, ".FON");
  408.             GetKey ("sfonts", b, szSetupStr);
  409.             for (cps= szSetupStr; *cps == ':'; *cps++);
  410.             clear (szDiskName); szDiskName [0]= *cps;
  411.             GetKey ("disks", szDiskName, szDiskName);
  412. NeedSfRetry :        strcpy (szSrcFile, szSrcPath); strcat (szSrcFile, b);
  413.             strcpy (szDstFile, szDstPath); strcat (szDstFile, b);
  414.             iErr= bCopyFile (szSrcFile, szDstFile, pFontName (szSrcFile));
  415.             if (iErr == 1)
  416.                 {
  417.                 lpfnProc= MakeProcInstance (Floppy, hInst);
  418.                 i= DialogBox (hInst, "FLOPPY", hMainWnd, lpfnProc);
  419.                 FreeProcInstance (lpfnProc);
  420.                 if (i)
  421.                     {
  422.                     AddSlash (szSrcPath); goto NeedSfRetry;
  423.                     }
  424.                 else
  425.                     {
  426.                     return FALSE;
  427.                     }
  428.                 }        // 'if' iErr == 1
  429.             else if (iErr)
  430.                 {
  431.                 CopyErr (szSrcFile, szDstFile, iErr);
  432.                 return FALSE;
  433.                 }
  434.                 WritePrivateProfileString ("boot", pFontSect, b,"system.ini");
  435. //                PutString (pFontSect, b);
  436.                 pFontSect+= 13;
  437.             }            // 'for' - copy screen fonts
  438.         }
  439.  
  440. NoInstallSys:
  441.  
  442.     if (!bLoadFonts)
  443.         goto NoInstallFonts;
  444.     //
  445.     // copy fonts (from [pfonts] section of 'cwsetup.inf'
  446.     //
  447.     clear (cFilBuff);
  448. //    PutString ("install fonts", "");
  449.     GetProfileString ("fonts", NULL, "", cFilBuff, sizeof cFilBuff);
  450.     for (cp= cFilBuff; *cp; cp+= strlen (cp)+1)
  451.         {
  452. //        PutString ("check font", cp);
  453.         if (bSearchCyr (cp))
  454.             continue;
  455. //        PutString ("this font is not cyrillic", "");
  456.         clear (b); clear (tmp1); clear (tmp2);
  457.         tmp1 [0]= ';';
  458.         GetProfileString ("fonts", cp, "", b, sizeof b);
  459. //        PutString ("font file name", b);
  460.         strcpy (tmp1+1, cp); strcpy (tmp2, b); _strup (tmp2);
  461.         //
  462.         // tmp2 - contains font file name
  463.         //
  464.         //
  465.         // Built cyrillic font name here
  466.         //
  467.         clear (cTmpStr);
  468.         for (i= 0; tmp2 [i] != '.'; i++)
  469.             cTmpStr [i]= tmp2 [i];
  470.         strcat (cTmpStr, "CYR");
  471.         strcpy (cTmpStr+8, ".FON");
  472. //        PutString ("cyrillic font name", cTmpStr);
  473.         clear (szDiskName);
  474.         GetKey ("fonts", cTmpStr, szDiskName);
  475.         if (!szDiskName [0])
  476.             {
  477. //            PutString ("font not found", ""); Halt ();
  478.             continue;
  479.             }
  480.         GetKey ("disks", szDiskName, szDiskName);
  481. NeedFRetry:    clear (szSrcFile); clear (szDstFile);
  482.         strcpy (szSrcFile, szSrcPath);
  483.         strcpy (szDstFile, szDstPath);
  484.         strcat (szDstFile, cTmpStr);
  485.         strcat (szSrcFile, cTmpStr);
  486. //        PutString (szSrcFile, szDstFile);
  487.         iErr= (int) bCopyFile (szSrcFile, szDstFile, pFontName (szSrcFile));
  488.         if (iErr == 1)
  489.             {
  490.             lpfnProc= MakeProcInstance (Floppy, hInst);
  491.             i= DialogBox (hInst, "FLOPPY", hMainWnd, lpfnProc);
  492.             FreeProcInstance (lpfnProc);
  493.             if (i)
  494.                 {
  495.                 AddSlash (szSrcPath); goto NeedFRetry;
  496.                 }
  497.             else
  498.                 return FALSE;
  499.             }
  500.         else if (iErr)
  501.             {
  502.             CopyErr (szSrcFile, szDstFile, iErr);
  503.             return FALSE;
  504.             }
  505.         //
  506.         // font file cTmpStr copied Ok here
  507.         // Read it FONTRES string and add it to win.ini file
  508.         // and, if bCommentFont == TRUE, comment old font
  509.         //
  510.  
  511.         strcpy (cTmpBuff, szDstPath);
  512.         strcat (cTmpBuff, cTmpStr);
  513.         if ((cps= pFontName (cTmpBuff)) == NULL)
  514.             {
  515.             return FALSE;
  516.             }
  517. //        PutString (cps, cTmpStr); Halt ();
  518.         WriteProfileString ("fonts", cps, cTmpStr);
  519.         if (bCommentFonts)
  520.             {
  521.             WriteProfileString ("fonts", tmp1+1, NULL);
  522.             WriteProfileString ("fonts", tmp1, tmp2);
  523.             }
  524.         }
  525. NoInstallFonts:
  526.     //
  527.     // Protect keyboard driver here
  528.     //
  529. #ifdef    _Protect_
  530.     strcpy (b, szDstPath); strcat (b, "ALTKEYB.EXE");
  531.     i= toupper (szSrcPath [0])-'A';
  532. //    PutInt ("drive Id for protection is", i);
  533.     if (i > 3)
  534.         i= 0;
  535.     iErr= checkdsk (i);
  536.     if (iErr == 0)
  537.         {
  538.         if (Protect (b) != 1)
  539.             {
  540.             SetCursor (hArrow);
  541.             MessageBox (GetFocus (), "Cannot correctly install keyboard driver", szTitle, MB_ICONSTOP|MB_OK);
  542.             return FALSE;
  543.             }
  544.         }
  545. #endif
  546.  
  547.     return TRUE;
  548.     }
  549.  
  550.  
  551.  
  552.  
  553. BOOL    FAR PASCAL Floppy (hDlg, wMsg, wParam, lParam)
  554.     register HWND hDlg;
  555.     register WORD wMsg;
  556.     WORD    wParam;
  557.     LONG    lParam;
  558.     {
  559.     switch (wMsg)
  560.         {
  561.     case WM_INITDIALOG:
  562.         SetDlgItemText (hDlg, IDF_TEXT, szDiskName);
  563.         SetDlgItemText (hDlg, IDF_EDIT, szSrcPath);
  564.         SetFocus (GetDlgItem (hDlg, IDF_EDIT));
  565.         return TRUE;
  566.     case WM_COMMAND:
  567.         switch (wParam)
  568.             {
  569.         case IDOK:
  570.             clear (szSrcPath);
  571.             GetDlgItemText (hDlg, IDF_EDIT, szSrcPath, sizeof szSrcPath);
  572.             EndDialog (hDlg, TRUE);
  573.             SetCursor (hWait);
  574.             return TRUE;
  575.         case IDCANCEL:
  576.             EndDialog (hDlg, FALSE);
  577.             SetCursor (hWait);
  578.             return TRUE;
  579.             }
  580.         break;
  581.         }
  582.     return FALSE;
  583.     }
  584.  
  585. BOOL    FAR PASCAL Options (hDlg, wMsg, wParam, lParam)
  586.     register HWND hDlg;
  587.     register WORD wMsg;
  588.     WORD wParam;
  589.     LONG    lParam;
  590.     {
  591.     static int bTmpCFonts;
  592.     static int bTmpSysFonts;
  593.  
  594.     switch (wMsg)
  595.         {
  596.     case WM_INITDIALOG:
  597.         bTmpCFonts= bCommentFonts;
  598.         bTmpSysFonts= bInstallSys;
  599.         CheckDlgButton (hDlg, IDO_CFONTS, bCommentFonts);
  600.         CheckDlgButton (hDlg, IDO_SYSFONTS, bInstallSys);
  601.         return TRUE;
  602.     case WM_COMMAND:
  603.         switch (wParam)
  604.             {
  605.         case IDO_OK:
  606.             bCommentFonts= bTmpCFonts;
  607.             bInstallSys= bTmpSysFonts;
  608.             SetCursor (hWait);
  609.             EndDialog (hDlg, TRUE);
  610.             return FALSE;
  611.         case IDO_CAN:
  612.             SetCursor (hWait);
  613.             EndDialog (hDlg, FALSE);
  614.             return FALSE;
  615.         case IDO_CFONTS:
  616.             bTmpCFonts^= 1;
  617.             CheckDlgButton (hDlg, IDO_CFONTS, bTmpCFonts);
  618.             break;
  619.         case IDO_SYSFONTS:
  620.             bTmpSysFonts^= 1;
  621.             CheckDlgButton (hDlg, IDO_SYSFONTS, bTmpSysFonts);
  622.             break;
  623.             }
  624.         break;
  625.         }
  626.     return FALSE;
  627.     }
  628.  
  629. //
  630. //    Copy file pSrc -> pDst and display message 'copying' in hWnd window
  631. //
  632. //    return codes:
  633. //        0 - Ok
  634. //        1 - cannot open pSrc file
  635. //        2 - cannot create pDst file
  636. //        3 - error reading source file
  637. //        4 - error writing destination file
  638. //
  639. int    bCopyFile (pSrc, pDst, pMessage)
  640.     PSTR    pSrc;                // src file name
  641.     PSTR    pDst;                // dst file name
  642.     PSTR    pMessage;            // file description
  643.                         // (of == NULL, then
  644.                         // display file name)
  645.     {
  646.     short    fSrc, fDst;
  647.     int    iReaded;
  648.     int    iRetVal= 0;
  649.  
  650.     if (pMessage == NULL)
  651.         pMessage= pSrc;
  652.  
  653.     SetDlgItemText (hMainWnd, IDC_HTEXT, "Copying file");
  654.     SetDlgItemText (hMainWnd, IDC_TEXT, pMessage);
  655.  
  656.     if ((fSrc= _lopen (pSrc, OF_READ)) < 0)
  657.         {
  658.         iRetVal= 1;
  659.         goto CopyRet;
  660.         }
  661.  
  662.     _lclose (_lcreat (pDst, 0));
  663.     if ((fDst= _lopen (pDst, OF_WRITE)) < 0)
  664.         {
  665.         iRetVal= 2;
  666.         goto CopyRet;
  667.         }
  668.  
  669.     do
  670.         {
  671. #ifdef    _Fast_
  672.         iReaded= _lread (fSrc, cCpBuff, sizeof cCpBuff);
  673. #else
  674.         iReaded= _lread (fSrc, cCpBuff, 10);
  675. #endif
  676.         if (iReaded < 0)
  677.             {
  678.             iRetVal= 3;
  679.             goto CopyRet;
  680.             }
  681.         if (_lwrite (fDst, cCpBuff, iReaded) != iReaded)
  682.             {
  683.             iRetVal= 4;
  684.             goto CopyRet;
  685.             }
  686.         }
  687.     while (iReaded > 0);
  688. CopyRet    :
  689.     _lclose (fSrc);
  690.     _lclose (fDst);
  691.     SetDlgItemText (hMainWnd, IDC_HTEXT, "");
  692.     SetDlgItemText (hMainWnd, IDC_TEXT, "");
  693.     return iRetVal;
  694.     }
  695.  
  696. //
  697. //    Display error message
  698. //
  699. char    szErrMessage [256];
  700.  
  701. int    CopyErr (pSrc, pDst, iError)
  702.     PSTR    pSrc;
  703.     PSTR    pDst;
  704.     int    iError;
  705.     {
  706.  
  707.     switch (iError)
  708.         {
  709.     case 0:
  710.         return 0;
  711.     case 1:
  712.         strcpy (szErrMessage, "Error opening file ");
  713.         strcat (szErrMessage, pSrc);
  714.         break;
  715.     case 2:
  716.         strcpy (szErrMessage, "Cannot create file ");
  717.         strcat (szErrMessage, pDst);
  718.         break;
  719.     case 3:
  720.         strcpy (szErrMessage, "Error reading file ");
  721.         strcat (szErrMessage, pSrc);
  722.         break;
  723.     case 4:
  724.         strcpy (szErrMessage, "Error writing file ");
  725.         strcat (szErrMessage, pDst);
  726.         break;
  727.     default:
  728.         strcpy (szErrMessage, "unknown error while copying");
  729.         break;
  730.         }
  731.     MessageBox (hMainWnd, szErrMessage, szTitle, MB_ICONSTOP|MB_OK);
  732. ErrRet    :
  733.     return iError;
  734.     }
  735.  
  736. //
  737. //    _strup
  738. //
  739. PSTR    _strup (char *b)
  740.     {
  741.     register int i;
  742.  
  743.     for (i= 0; i< strlen (b); i++)
  744.         b [i]= toupper (b [i]);
  745.     return b;
  746.     }
  747.  
  748. //
  749. //    search s2 in s1 (of Ok, returns TRUE)
  750. //
  751. BOOL    myssearch (PSTR s1, PSTR s2)
  752.     {
  753.     register int i;
  754.  
  755.     _strup (s1); _strup (s2);
  756.     for (i= 0; strlen (s1+i) >= strlen (s2); i++)
  757.         {
  758.         if (!strncmp (s1+i, s2, strlen (s2)))
  759.             {
  760.             return i+1;
  761.             }
  762.         }
  763.  
  764.     return FALSE;
  765.     }
  766.  
  767. char    patch []= "FONTRES";
  768. //
  769. //    returns null terminated string with font description
  770. //
  771. PSTR    pFontName (PSTR pFont)
  772.     {
  773.     short flabel;
  774.     register int i;
  775.  
  776.     clear (cCpBuff);
  777.     flabel= _lopen (pFont, OF_READ);
  778.     if (flabel < 0)
  779.         return cCpBuff;
  780.     _lread (flabel, cCpBuff, sizeof cCpBuff);
  781.     _lclose (flabel);
  782.  
  783.     for (i= 0; i< sizeof cCpBuff; i++)
  784.         {
  785.         if (!strncmp (cCpBuff+i, patch, strlen (patch)))
  786.             {
  787.             for (i+= sizeof patch;i< sizeof cCpBuff; i++)
  788.                 {
  789.                 if (cCpBuff [i] == ':')
  790.                     {
  791.                     for (i++;i< sizeof cCpBuff; i++)
  792.                         {
  793.                         if (cCpBuff [i] != ' ')
  794.                             {
  795.                             return cCpBuff+i;
  796.                             }
  797.                         }
  798.                     }
  799.                 }
  800.             }
  801.  
  802.         }
  803.     return NULL;
  804.     }
  805.  
  806.  
  807. char    szCyrillic []= "CYRILLIC";
  808. char    szSearch [256];
  809.  
  810. BOOL    bSearchCyr (char *cpStr)
  811.     {
  812.     int    i;
  813.  
  814.     strcpy (szSearch, cpStr); _strup (szSearch);
  815.  
  816.     for (i= 0; i< strlen (szSearch) - sizeof szCyrillic - 1; i++)
  817.         {
  818.         if (!strncmp (szSearch+i, szCyrillic, strlen (szCyrillic)))
  819.             {
  820.             return TRUE;
  821.             }
  822.         }
  823.     return FALSE;
  824.     }
  825.  
  826. //
  827. //    Remove all CyrWin files and restore saved win.ini and system.ini
  828. //    files
  829. //
  830. BOOL    bUninstall (HWND hWnd)
  831.     {
  832.     int    iRetVal= 0;
  833.     int    i;
  834.     FARPROC    lpfnProc;
  835.     PSTR    cp;
  836.     int    iErr;
  837.     PSTR    cps;
  838.     char    b [255];
  839.     char    tmp1 [255];
  840.     char    tmp2 [255];
  841.     PSTR    pCard;
  842.     PSTR    pFontSect;
  843.     tag_fnt    dFont;
  844.     tagDefs    *td;
  845.  
  846.     if (MessageBox (hWnd, "Are you sure to UNINSTALL CyrWin ?", szTitle, MB_ICONQUESTION|MB_YESNOCANCEL) != IDYES)
  847.         return FALSE;
  848.     //
  849.     // uninstall cyrwin from the windows directory
  850.     //
  851.     GetWindowsDirectory (szDstPath, sizeof szDstPath); AddSlash (szDstPath);
  852.     strcpy (szSetupFile, szDstPath); strcat (szSetupFile, szSetupInf);
  853.     if ((i= _lopen (szSetupFile, OF_READ)) < 0)
  854.         {
  855.         MessageBox (hWnd, "Cannot find cwsetup.inf\n"
  856.                   "Uninstall failed", szTitle, MB_ICONSTOP|MB_OK);
  857.         return FALSE;
  858.         }
  859.     _lclose (i);
  860.     //
  861.     // ensure that .cw files are Ok
  862.     //
  863.     strcpy (b, szDstPath); strcat (b, "win.cw");
  864.     if ((i= _lopen (b, OF_READ)) < 0)
  865.         {
  866.         MessageBox (hWnd, "Cannot find win.cw\n"
  867.                   "Uninstall failed", szTitle, MB_ICONSTOP|MB_OK);
  868.         return FALSE;
  869.         }
  870.     _lclose (i);
  871.     strcpy (b, szDstPath); strcat (b, "system.cw");
  872.     if ((i= _lopen (b, OF_READ)) < 0)
  873.         {
  874.         MessageBox (hWnd, "Cannot find system.cw\n"
  875.                   "Uninstall failed", szTitle, MB_ICONSTOP|MB_OK);
  876.         return FALSE;
  877.         }
  878.     _lclose (i);
  879.  
  880.     //
  881.     // delete cyrwin changes from win.ini and system.ini files
  882.     //
  883.  
  884.     // 1. delete altkeyb.exe from the [windows]-load entry of win.ini
  885.  
  886.     clear (b);
  887.     GetProfileString ("windows", "load", "", b, sizeof b);
  888.     if (i= myssearch (_strup (b), "ALTKEYB.EXE"))
  889.         {
  890. //        PutInt ("index", i); PutString ("in", b); Halt ();
  891.         clear (tmp1); strncpy (tmp1, b, i-1); strcpy (tmp1, b+i+12);
  892. //        PutString (b, tmp1); Halt ();
  893.         WriteProfileString ("windows", "load", tmp1);
  894.         }
  895.  
  896.     // 2. restore system fonts in system.ini file
  897.     // (copy from .cw files)
  898.  
  899.     GetPrivateProfileString ("boot", "fonts.fon", "", b, 255, "system.cw");
  900.     WritePrivateProfileString ("boot", "fonts.fon", b,"system.ini");
  901.     GetPrivateProfileString ("boot", "oemfonts.fon", "", b, 255, "system.cw");
  902.     WritePrivateProfileString ("boot", "oemfonts.fon", b,"system.ini");
  903.     GetPrivateProfileString ("boot", "fixedfon.fon", "", b, 255, "system.cw");
  904.     WritePrivateProfileString ("boot", "fixedfon.fon", b,"system.ini");
  905.  
  906.     // 3. restore langdll and oem2ansi table in system.ini file
  907.     // (copy from .cw files)
  908.     GetPrivateProfileString ("boot", "language.dll", "", b, 255, "system.cw");
  909.     WritePrivateProfileString ("boot", "language.dll", b,"system.ini");
  910.  
  911.     GetPrivateProfileString ("boot", "oemansi.bin", "", b, 255, "system.cw");
  912.     WritePrivateProfileString ("boot", "oemansi.bin", b,"system.ini");
  913.  
  914.     // 3. restore fonts section in win.ini file
  915.     // (copy from .cw files)
  916.  
  917.     // clear fonts section in win.ini file
  918.  
  919.     GetProfileString ("fonts", NULL, "", cFilBuff, sizeof cFilBuff);
  920.     for (cp= cFilBuff; *cp; cp+= strlen (cp)+1)
  921.         {
  922.         WriteProfileString ("fonts", cp, NULL);
  923.         }
  924.     
  925.     //
  926.     // copy fonts from old file
  927.     //
  928.     GetPrivateProfileString ("fonts", NULL, "", cFilBuff, sizeof cFilBuff, "win.cw");
  929.     for (cp= cFilBuff; *cp; cp+= strlen (cp)+1)
  930.         {
  931.         GetPrivateProfileString ("fonts", cp, "", b, sizeof b, "win.cw");
  932.         WriteProfileString ("fonts", cp, b);
  933.         }
  934.     //
  935.     // delete CyrWin files
  936.     //
  937.     strcpy (b, szDstPath); strcat (b, "win.cw"); unlink (b);
  938.     strcpy (b, szDstPath); strcat (b, "system.cw"); unlink (b);
  939.  
  940.     GetKey ("nfiles", NULL, cFilBuff);
  941.     for (cp= cFilBuff; *cp; cp+= strlen (cp)+1)
  942.         {
  943.         strcpy (b, szDstPath); strcat (b, cp); unlink (b);
  944.         }
  945.  
  946.     strcpy (b, szDstPath); strcat (b, szSetupInf); unlink (b);
  947.  
  948.     return TRUE;
  949.     }
  950.  
  951. #ifdef    _Protect_
  952.  
  953. #include "io.h"
  954. #include "fcntl.h"
  955.  
  956. char    cKeys[]= { "Ole" };
  957.  
  958. short    Protect (char *file)
  959.     {
  960.     short    f, c;
  961.     char    *cp;
  962.     unsigned int BiosChk= 0;
  963.     int fleng;
  964.     int i;
  965.  
  966.     f= open (file, O_RDWR|O_BINARY);
  967.     clear (cCpBuff);
  968.     fleng= read (f, cCpBuff, sizeof cCpBuff);
  969.     if (f < 0)
  970.         return 0;
  971.  
  972.     for (i= 0, cp= cKeys; i< fleng ;i++)
  973.         {
  974.         if (cCpBuff [i] == *cp)
  975.             cp++;
  976.         else
  977.             cp= cKeys;
  978.         if (!*cp)
  979.             break;
  980.         }
  981.     if (!*cp)
  982.         {
  983.         BiosChk= BiosSum ();
  984.         lseek (f, (LONG) i+3, SEEK_SET);
  985.         write (f, &BiosChk, 2);
  986.         (short) BiosChk= 1;
  987.         }
  988.     close (f);
  989.     return BiosChk;
  990.     }
  991.  
  992.  
  993. #endif
  994.  
  995. /* *** */