home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / i18nv102.zip / SAMPLE / INSTALL / INSTALL.C < prev    next >
C/C++ Source or Header  |  1995-08-28  |  73KB  |  1,499 lines

  1. /*
  2.  
  3.  
  4. ===============================================================================
  5.       Internationalization (I18N) For OS/2                 March 31, 1995
  6. ===============================================================================
  7.  
  8.                    Copyright IBM Corporation -- 1993, 1995
  9.  
  10. DISCLAIMER: This I18N package has been made available solely to gauge OS/2
  11. developer interest in the industry standard XPG4 internationalization
  12. programming model. This does not mean that IBM will introduce a product based
  13. on the contents of this package. This package is not a full implementation of
  14. the X/Open XPG4 specification and does not make any claims of XPG4 branding.
  15. It implements only the portions of the XPG4 specification which deal with
  16. internationalization.
  17.  
  18. X/Open is a trademark of the X/Open Company Limited.
  19.  
  20. ===============================================================================
  21.  
  22.  
  23. ===============================================================================
  24.                            INSTALLATION PROGRAM
  25. ===============================================================================
  26.  
  27. Function:          This I18N install program can be used to control the
  28.                    installation of the run-time required information.
  29.                    Presentation Manager windows are shown to control the
  30.                    installation process.
  31.  
  32.                    An application can modify this source for their specific
  33.                    installation environment.  There are several #DEFINE
  34.                    statements which should be reviewed and modified as needed:
  35.                      1.  This defines the number of ZIP files which exist on
  36.                          the diskettes which contain the I18N files.
  37.                                 #define INSTALL_ZIP_NUM   n
  38.                      2.  This defines the name of the ZIP file which contains
  39.                          the I18N run-time code (setloc.dll).  The name must
  40.                          contain the letters "DLL".
  41.                                 #define INSTALL_ZIP1      "\\I18NDLL.ZIP"
  42.                      3.  This defines the name of the ZIP file which contains
  43.                          the 1st part of the I18N locale files.  There may
  44.                          be several of these files if they exist on more than
  45.                          one diskette.  The names must contain the letters "LOC".
  46.                                 #define INSTALL_ZIP2      "\\I18NLOC1.ZIP"
  47.                                 #define INSTALL_ZIP3      "\\I18NLOC2.ZIP"
  48.                                 #define INSTALL_ZIP4      "\\I18NLOC3.ZIP"
  49.  
  50. Parameters:        Parameters are optional.  When the program is invoked
  51.                    without any parameters, the following default values are
  52.                    used:
  53.                               1st:   C       (Default drive C:)
  54.                               2nd:   none    (Do not force to a specific drive)
  55.                               3rd:   If LANG is currently set, use its value.
  56.                                      Otherwise, use "enus437".
  57.                               4th:   Y       (Show PM user interface)
  58.                               5th:   Y       (Ask user if install drive is OK)
  59.                               6th:   A       (Ask user if to update CONFIG.SYS)
  60.  
  61.                    When another install program is invoking this program,
  62.                    the following parameters can be used to control the install
  63.                    processing:
  64.  
  65.                    1st  -   The drive letter on which to install the I18N
  66.                             package if the package is not already installed.
  67.                             Must be an alphabetic letter, C-Z.  If "A", "B" or
  68.                             non-alphabetic, will use the default value.
  69.  
  70.                    2nd  -   The drive letter on which to force the installation
  71.                             of the I18N package, regardless whether the package
  72.                             is already installed.  Could be used if installing
  73.                             package on a server drive and already have package
  74.                             installed on a local drive. Must be an alphabetic
  75.                             letter, C-Z.  If "A", "B" or non-alphabetic, will
  76.                             use the normal default value specified by 1st parm.
  77.  
  78.                    3rd  -   The default LANG variable value to use when updating
  79.                             CONFIG.SYS. The first letter must be alphabetic,
  80.                             else the normal default value will be used.
  81.  
  82.                    4th  -   Whether the PM user interface is to be shown.
  83.                             "N"  Do not show any PM windows, except if error
  84.                                  conditions are found.
  85.                             Otherwise, the normal PM interface is shown.
  86.  
  87.                    5th  -   Whether to ask the user to select the drive on
  88.                             which to install the I18N package.
  89.                             "N"  Do not ask the user.  Use the default value
  90.                                  defined by the 1st and 2nd parameters.
  91.                             "U"  Ask the user only if the I18N package has
  92.                                  never been installed.  If the I18N package
  93.                                  exists, do not ask the user.
  94.                             Otherwise, the user will be shown a PM window and
  95.                             asked to select a drive.
  96.  
  97.                    6th  -   Whether to update the CONFIG.SYS file with I18N
  98.                             information.
  99.                             "A"  Ask the user whether to update CONFIG.SYS.
  100.                             "Y"  Update CONFIG.SYS with I18N information.
  101.                             Otherwise, CONFIG.SYS will not be updated.
  102.  
  103. ===============================================================================
  104. */
  105.  
  106. /******************************************************************************
  107. /***     Include files                                                     ***/
  108. /*****************************************************************************/
  109.  
  110. #define INCL_DOS                        /* Use DOS function.                 */
  111. #include "install.h"                    /* Include data for this application */
  112.  
  113. /*****************************************************************************/
  114. /***     Predefined constants                                              ***/
  115. /*****************************************************************************/
  116.  
  117. #include <version.h>             /* Version of I18N we are installing */
  118.  
  119. #define INSTALL_ZIP_NUM 3                   /* Number of diskette files.     */
  120. #define INSTALL_ZIP1    "\\I18NDLL.ZIP"     /* 1st diskette file.            */
  121. #define INSTALL_ZIP2    "\\I18NLOC1.ZIP"    /* 2nd diskette file.            */
  122. #define INSTALL_ZIP3    "\\I18NLOC2.ZIP"    /* 3rd diskette file.            */
  123. #define INSTALL_ZIP4    ""                  /* 4th diskette file.            */
  124.  
  125. #define DEFAULT_DRIVE    "C:"           /* Default drive for installed I18N. */
  126. #define DEFAULT_LANG     "enus437"      /* Default language for I18N.        */
  127. #define DEFAULT_USERINT  "Y"            /* Default if user interface active. */
  128. #define DEFAULT_ASKDRIVE "Y"            /* Default if ask user about drive.  */
  129. #define DEFAULT_UPDATECONFIG "A"        /* Default if ask user about config. */
  130.  
  131. #define I18N_DIR         "\\I18N"       /* I18N directory.                   */
  132. #define I18N_DLL_DIR     "\\DLL"        /* I18N DLL directory.               */
  133. #define I18N_LOCALE_DIR  "\\LOCALE"     /* I18N locale file directory.       */
  134. #define I18N_NLSPATH_DIR "\\MESSAGES"   /* I18N NLSPATH value.               */
  135. #define I18N_NLSPATH_VARS "\\%L\\%N"    /* I18N NLSPATH variables.           */
  136. #define I18N_LIBPATH_VAR "LIBPATH="     /* I18N LIBPATH variable.            */
  137. #define I18N_LANG_VAR    "LANG="        /* I18N LANG    variable.            */
  138. #define I18N_LOCPATH_VAR "LOCPATH="     /* I18N LOCPATH variable.            */
  139. #define I18N_NLSPATH_VAR "NLSPATH="     /* I18N NLSPATH variable.            */
  140.  
  141. #define UNZIP_TEMP_FILEN       "\\I18NUZIP.TMP" /* Temp file for unzipping.  */
  142. #define CONFIG_SYS_FILEN       "\\CONFIG.SYS"   /* Config file: CONFIG.SYS   */
  143. #define CONFIG_SYS_BACKUP_FILEN "\\CONFIG.I18"  /* Backup file for CONFIG.SYS*/
  144. #define CONFIG_SYS_WORK_FILEN  "\\CONFIG18.TMP" /* Work file for CONFIG.SYS  */
  145.  
  146. #define NO_ERROR         0              /* Useful return code.               */
  147. #define STRC_PROC        "strcoll"      /* A function to search for in DLL.  */
  148. #define VER_PROC         "get_i18n_version"  /* Func to get the version num. */
  149.  
  150. /*****************************************************************************/
  151. /***     Global variables                                                 ***/
  152. /*****************************************************************************/
  153.  
  154.   char        error_title[BUF_SIZE];    /* Text for error window title.      */
  155.   char        error_text[BUF_SIZE];     /* Text for error window message.    */
  156.   char        string_text[BUF_SIZE];    /* Text from STRINGTABLE entry.      */
  157.   char        message_text[BUF_SIZE];   /* Text for general message.         */
  158.  
  159.   char        I18N_dll_dir[BUF_SIZE];       /* DLL directory.                */
  160.   char        I18N_locale_dir[BUF_SIZE];    /* Locale direcrtory.            */
  161.   char        I18N_messages_dir[BUF_SIZE];  /* Messages directory.           */
  162.  
  163.   char        unzip_temp_file[BUF_SIZE];        /* Temp file for unzipping.  */
  164.   char        config_sys_file[BUF_SIZE];        /* Config file: CONFIG.SYS   */
  165.   char        config_sys_backup_file[BUF_SIZE]; /* Backup file for CONFIG.SYS*/
  166.   char        config_sys_work_file[BUF_SIZE];   /* Work file for CONFIG.SYS  */
  167.  
  168.  
  169.  
  170. /*****************************************************************************/
  171. /***                                                                       ***/
  172. /***     Initialization routine for program.                               ***/
  173. /***                                                                       ***/
  174. /*****************************************************************************/
  175.  
  176. void initialize(int argc, char *argv[])
  177. {
  178.   char    *ptrchar;
  179.   ULONG   drivemap, drivenum ;
  180.   APIRET  rc ;
  181.  
  182.   return_code = RC_NO_ERROR;            /* Default return code.              */
  183.                                         /* Initialize parameter variables.   */
  184.   parm_drive[0] = '\0';
  185.   parm_force[0] = '\0';
  186.   parm_lang[0] = '\0';
  187.   parm_userint[0] = '\0';
  188.   parm_askdrive[0] = '\0';
  189.   parm_updateconfig[0] = '\0';
  190.  
  191.                                         /* Find boot drive OS/2 installed on.*/
  192.   rc = DosQuerySysInfo( QSV_BOOT_DRIVE, QSV_BOOT_DRIVE,
  193.                         (PVOID)&drivenum, sizeof(drivenum) ) ;
  194.   if ( rc == NO_ERROR ) {
  195.      boot_drive[0] = toupper( drivenum+'@');
  196.   } else {
  197.      boot_drive[0] = 'C' ;
  198.   }
  199.   boot_drive[1] = ':' ;
  200.   boot_drive[2] = '\0' ;
  201.   sprintf( unzip_temp_file,        "%s%s", boot_drive, UNZIP_TEMP_FILEN ) ;
  202.   sprintf( config_sys_file,        "%s%s", boot_drive, CONFIG_SYS_FILEN ) ;
  203.   sprintf( config_sys_backup_file, "%s%s", boot_drive, CONFIG_SYS_BACKUP_FILEN ) ;
  204.   sprintf( config_sys_work_file,   "%s%s", boot_drive, CONFIG_SYS_WORK_FILEN ) ;
  205.  
  206.                                         /* Find drive installing from.       */
  207.   strcpy(parm_command, argv[0]);
  208.   if ( parm_command[1] == ':' )
  209.   {                                     /* Drive was specified on command.   */
  210.      install_from_drive[0] = toupper( parm_command[0] );
  211.   }
  212.   else
  213.   {                                     /* Use current drive as default.     */
  214.      DosQueryCurrentDisk( &drivenum, &drivemap ) ;
  215.      install_from_drive[0] = toupper( drivenum+'@');
  216.   }
  217.                                         /* Require install from diskette.    */
  218. /*if ( (install_from_drive[0]!='A') && (install_from_drive[0]!='B') ) 3-23-95*/
  219.  
  220.                                         /* Require install from valid drive. */
  221.   if ( ! isalpha(install_from_drive[0]) )
  222.   {
  223.      install_from_drive[0] = 'A';
  224.   }
  225.   install_from_drive[1] = ':';
  226.   install_from_drive[2] = '\0';
  227.  
  228.                                         /* If parameters were specified.     */
  229.   if ( argc > 1 )
  230.   {
  231.                                         /* 1st parm: default drive if I18N   */
  232.                                         /*  not already installed.           */
  233.      strcpy(parm_drive, argv[1]);
  234.      parm_drive[0] = toupper( parm_drive[0] );
  235.      if ( argc > 2 )
  236.      {
  237.                                         /* 2nd parm: force I18N to be        */
  238.                                         /*  installed on this drive.         */
  239.         strcpy(parm_force, argv[2]);
  240.         parm_force[0] = toupper( parm_force[0] );
  241.         if ( argc > 3 )
  242.         {
  243.                                         /* 3rd parm: default language.       */
  244.            strcpy(parm_lang, argv[3]);
  245.            if ( argc > 4 )
  246.            {
  247.                                         /* 4th parm: whether user wants      */
  248.                                         /*  user interface or not.           */
  249.               strcpy(parm_userint, argv[4]);
  250.               parm_userint[0] = toupper( parm_userint[0] );
  251.               if ( argc > 5 )
  252.               {
  253.                                         /* 5th parm: whether to ask user     */
  254.                                         /*  which drive to install on.       */
  255.                  strcpy(parm_askdrive, argv[5]);
  256.                  parm_askdrive[0] = toupper( parm_askdrive[0] );
  257.                  if ( argc > 6 )
  258.                  {
  259.                                         /* 6th parm: whether to ask user     */
  260.                                         /*  about updating config.sys file.  */
  261.                     strcpy(parm_updateconfig, argv[6]);
  262.                     parm_updateconfig[0] = toupper( parm_updateconfig[0] );
  263.                  }
  264.               }
  265.            }
  266.         }
  267.      }
  268.   }
  269.   /*------------------------------------------------------------------------*/
  270.   if ( isalpha(parm_drive[0]) )
  271.   {
  272.      strcpy(install_drive, parm_drive);
  273.      install_drive[1] = ':';
  274.      install_drive[2] = '\0';
  275.   }
  276.   else
  277.   {
  278.      strcpy(install_drive, boot_drive);
  279.   }
  280.   /*------------------------------------------------------------------------*/
  281.   if ( isalpha(parm_force[0]) )
  282.   {
  283.      strcpy(force_drive, parm_force);
  284.   }
  285.   else
  286.   {
  287.      force_drive[0] = '\0';
  288.   }
  289.   /*------------------------------------------------------------------------*/
  290.   if ( isalpha(parm_lang[0]) )
  291.   {
  292.      strcpy(install_lang, parm_lang);
  293.   }
  294.   else
  295.   {
  296.      ptrchar = getenv( "LANG" );
  297.      if ( ptrchar )
  298.      {
  299.         strcpy(install_lang, ptrchar);
  300.      }
  301.      else
  302.      {
  303.         strcpy(install_lang, DEFAULT_LANG);
  304.      }
  305.   }
  306.   /*------------------------------------------------------------------------*/
  307.   if ( isalpha(parm_askdrive[0]) )
  308.   {
  309.      strcpy(askdrive, parm_askdrive);
  310.   }
  311.   else
  312.   {
  313.      strcpy(askdrive, DEFAULT_ASKDRIVE);
  314.   }
  315.   /*------------------------------------------------------------------------*/
  316.   if ( isalpha(parm_updateconfig[0]) )
  317.   {
  318.      strcpy(updateconfig, parm_updateconfig);
  319.   }
  320.   else
  321.   {
  322.      strcpy(updateconfig, DEFAULT_UPDATECONFIG);
  323.   }
  324.   /*------------------------------------------------------------------------*/
  325.   if ( isalpha(parm_userint[0]) )
  326.   {
  327.      strcpy(userint, parm_userint);
  328.      if ( userint[0] == 'N' )
  329.      {
  330.         askdrive[0] = 'N';
  331.         if ( updateconfig[0] == 'A' )  updateconfig[0] = 'Y';
  332.      }
  333.   }
  334.   else
  335.   {
  336.      strcpy(userint, DEFAULT_USERINT);
  337.   }
  338.   /*------------------------------------------------------------------------*/
  339.  
  340. }
  341.  
  342.  
  343.  
  344. /*****************************************************************************/
  345. /***                                                                       ***/
  346. /***     Query if I18N is already installed                                ***/
  347. /***                                                                       ***/
  348. /*****************************************************************************/
  349.  
  350. int is_i18n_installed(double *ver_num, char *inst_drive)
  351. {
  352.   char    load_error[BUF_SIZE];         /* Returned buffer if API fails.     */
  353.   char    mod_name[BUF_SIZE];           /* Returned buffer for module name.  */
  354.   HMODULE mod_handle;                   /* Handle to SETLOC.DLL              */
  355.   int     rc, rc2;                      /* Return codes from the APIs.       */
  356.  
  357.                                         /* Function variable declarations for*/
  358.                                         /*  STRCOLL and GET_I18N_VERSION     */
  359.   int (* strcoll_addr) (const char *, const char *);
  360.   double (* get_version_addr) (void);
  361.  
  362.                                         /* Set default version number of     */
  363.                                         /*  installed I18N  to version 0.    */
  364.                                         /* Try to open up SETLOC.DLL         */
  365.                                         /* If we opened it without problem...*/
  366.                                         /*  Get the address for strcoll...   */
  367.                                         /*  (This makes sure that the SETLOC */
  368.                                         /*   DLL opened is really our I18N.) */
  369.   *ver_num = 0.0;
  370.   rc = DosLoadModule(load_error, sizeof(load_error), MODULE_NAME, &mod_handle);
  371.   if (rc == NO_ERROR)
  372.   {
  373.      rc = DosQueryProcAddr(mod_handle, 0, STRC_PROC,
  374.                            (PFN *) &strcoll_addr);
  375.  
  376.                                         /* Get the address of the get version*/
  377.                                         /*  API.                             */
  378.                                         /* If found (old versions of I18N    */
  379.                                         /*  did not have this API)...        */
  380.                                         /*  Call on function to get version  */
  381.                                         /*   number.                         */
  382.      rc2 = DosQueryProcAddr(mod_handle, 0, VER_PROC,
  383.                            (PFN *) &get_version_addr);
  384.      if (rc2 == NO_ERROR)
  385.      {
  386.         *ver_num = get_version_addr();
  387.                                         /* Get the drive, path and module    */
  388.                                         /*  name of this I18N DLL.           */
  389.                                         /* If found, set the drive which this*/
  390.                                         /*  DLL was found (from LIBPATH).    */
  391.         rc2 = DosQueryModuleName(mod_handle, sizeof(mod_name), mod_name);
  392.         if (rc2 == NO_ERROR)
  393.         {
  394.            inst_drive[0] = mod_name[0];
  395.         }
  396.      }
  397.                                         /*  Free the module handle.          */
  398.      DosFreeModule(mod_handle);
  399.   }
  400.                                         /* Return results of our open  and   */
  401.                                         /*  locate function attempt.         */
  402.   return(rc == NO_ERROR);
  403. }
  404.  
  405.  
  406.  
  407. /*****************************************************************************/
  408. /***                                                                       ***/
  409. /***     Select Installation drive procedure.                              ***/
  410. /***                                                                       ***/
  411. /*****************************************************************************/
  412.  
  413. MRESULT EXPENTRY select_drive(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  414. {
  415.   short   drive;
  416.   ULONG   drivemap, drivenum ;
  417.   char    new_drive[3];
  418.   char    drivevalue[] = " :";
  419.   BOOL    drive_match;
  420.  
  421.   switch(msg)
  422.   {
  423.                                         /* When we get the "init dialog" msg */
  424.     case WM_INITDLG:
  425.          {
  426.                                         /* Find all of the available drives  */
  427.                                         /* on which the I18N directory could */
  428.                                         /* be installed.                     */
  429.            DosQueryCurrentDisk( &drivenum, &drivemap ) ;
  430.  
  431.                                         /* Delete all entries from the list. */
  432.            WinSendDlgItemMsg( hwnd, DRIVE_COMBOBOX, LM_DELETEALL, NULL, NULL ) ;
  433.  
  434.                                         /* Determine which drive letters are */
  435.                                         /*  available on this system (ignore */
  436.                                         /*  drives A and B).                 */
  437.            drive_match = FALSE;
  438.            for ( drive = 0 ; drive < 26 ; drive++ )
  439.               if ( (drivemap & 1L << drive) && (drive>1) )
  440.               {
  441.                                         /* Convert drive number to letter.   */
  442.                  drivevalue[0] = (CHAR) (drive + 'A') ;
  443.                                         /* If default install drive was      */
  444.                                         /*  provided as a parameter, ensure  */
  445.                                         /*  that that drive is available.    */
  446.                  if ( drivevalue[0] == install_drive[0] )
  447.                  {
  448.                     drive_match = TRUE ;
  449.                  }
  450.                                         /* Add each available drive to list. */
  451.                  WinSendDlgItemMsg( hwnd, DRIVE_COMBOBOX, LM_INSERTITEM,
  452.                                     MPFROM2SHORT ( LIT_END, 0 ),
  453.                                     MPFROMP ( drivevalue ) ) ;
  454.               }
  455.                                         /* If parameter drive is not valid,  */
  456.                                         /*  reset install drive to default.  */
  457.            if ( ! drive_match )
  458.            {
  459.               strcpy(install_drive, boot_drive);
  460.            }
  461.                                         /* Set current install drive as the  */
  462.                                         /* default drive.                    */
  463.            WinSetDlgItemText( hwnd, DRIVE_COMBOBOX, install_drive ) ;
  464.  
  465.            break;
  466.          }
  467.     case WM_COMMAND:
  468.          switch(SHORT1FROMMP(mp1))
  469.          {
  470.                                         /* If they press the install button. */
  471.            case DRIVE_INSTALL_BUTTON:
  472.                                         /* Get the selected install drive,   */
  473.                                         /*  Set the new install drive,  and  */
  474.                                         /*  exit PM interface.               */
  475.                 WinQueryDlgItemText(hwnd, DRIVE_COMBOBOX,
  476.                                     sizeof(new_drive), new_drive);
  477.                 install_drive[0] = new_drive[0];
  478.                 WinPostMsg(hwnd, WM_CLOSE, NULL, NULL);
  479.                 WinPostMsg(hwnd, WM_QUIT, NULL, NULL);
  480.                 break;
  481.                                         /* If they cancel the install...     */
  482.            case DRIVE_CANCEL_BUTTON:
  483.                                         /* Close the dialog,                 */
  484.                                         /* and exit PM interface.            */
  485.                 install_drive[0] = '\0';
  486.                 return_code = RC_USER_CANCEL;
  487.                 WinPostMsg(hwnd, WM_CLOSE, NULL, NULL);
  488.                 WinPostMsg(hwnd, WM_QUIT, NULL, NULL);
  489.                 break;
  490.            default : break;
  491.          }
  492.          break;
  493.     default:
  494.          return(WinDefDlgProc(hwnd, msg, mp1, mp2));
  495.   }
  496.   return((MRESULT) 0);
  497. }
  498.  
  499.  
  500.  
  501. /*****************************************************************************/
  502. /***                                                                       ***/
  503. /***     Ask user which available drive to install the I18N package on.    ***/
  504. /***                                                                       ***/
  505. /*****************************************************************************/
  506.  
  507. void ask_user_which_drive(void)
  508. {
  509.                                         /* Register main window class        */
  510.   WinRegisterClass(habAnchor, CLS_CLIENT, select_drive, CS_SIZEREDRAW, 0);
  511.  
  512.   hwndFrame = WinLoadDlg( HWND_DESKTOP,  /* Place anywhere on desktop.       */
  513.                           HWND_DESKTOP,  /* Owned by frame                   */
  514.                           select_drive,  /* Address of dialog procedure      */
  515.                           0,             /* Module handle                    */
  516.                           DRIVE_DIALOG,  /* Dialog id in resource            */
  517.                           NULL ) ;       /* Initialization data              */
  518.   if (hwndFrame != NULLHANDLE)
  519.   {
  520.                                         /* Set the size of the dialog  and   */
  521.                                         /*  center it on the screen.         */
  522.      WinQueryWindowPos( hwndFrame, &screen_swp ) ;
  523.      WinSetWindowPos(hwndFrame, NULLHANDLE,
  524.                      (SHORT) (desktop_width - screen_swp.cx) / 2,
  525.                      (SHORT) (desktop_height - screen_swp.cy) / 2,
  526.                      0, 0,
  527.                      SWP_MOVE | SWP_ACTIVATE | SWP_SHOW);
  528.  
  529.                                         /*  Main message loop:               */
  530.                                         /*  While there are more messages... */
  531.                                         /*   Dispatch this message.          */
  532.      while (WinGetMsg(habAnchor, &qmMsg, NULLHANDLE, 0, 0))
  533.      {
  534.         WinDispatchMsg(habAnchor, &qmMsg);
  535.      }
  536.                                         /*  We're done.  Get rid of the main */
  537.                                         /*   window.                         */
  538.      WinDestroyWindow(hwndFrame);
  539.   }
  540. }
  541.  
  542.  
  543.  
  544. /*****************************************************************************/
  545. /***                                                                       ***/
  546. /***     Installing I18N package status panel.                             ***/
  547. /***                                                                       ***/
  548. /*****************************************************************************/
  549.  
  550. MRESULT EXPENTRY installing_I18N(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  551. {
  552.   static char        orig_zip_file[BUF_SIZE];
  553.   static char        zip_file[BUF_SIZE];
  554.   char        unzip_from_file[BUF_SIZE];
  555.   char        unzip_file[BUF_SIZE];
  556.   char        unzip_to_dir[BUF_SIZE];
  557.   char        unzip_to_file[BUF_SIZE];
  558.   char        zip_record[BUF_SIZE];
  559.   char        zip_command[BUF_SIZE];
  560.   char        *ptrchar;
  561.   int         pos ;
  562.   int         ret_code;
  563.   FILE       *file_unzip ;
  564.   static FILE       *file_zip ;
  565.  
  566.   switch(msg)
  567.   {
  568.                                         /* When we get the "init dialog" msg */
  569.     case WM_INITDLG:
  570.          {
  571.                                         /* Initialize variables,  and        */
  572.                                         /*  start process with 1st zip file. */
  573.            install_zip = 0;
  574.            WinPostMsg( hwnd, WM_COMMAND, MPFROMSHORT( INSTALLING_NEXT_ZIP ), NULL ) ;
  575.            break;
  576.          }
  577.     case WM_COMMAND:
  578.          switch(SHORT1FROMMP(mp1))
  579.          {
  580.                                         /* Find next ZIP file to install.    */
  581.            case INSTALLING_NEXT_ZIP:
  582.                                         /* Set next ZIP file to process.     */
  583.                 ++install_zip ;
  584.                 install_file = 0;
  585.                                         /* If previous ZIP list file is open,*/
  586.                 if ( file_zip )
  587.                 {
  588.                                         /* If no files installed from ZIP,   */
  589.                    if ( install_file == 0 )
  590.                    {
  591.                      /************* error ***************/
  592.                    }
  593.                                         /* Close the temporary ZIP list file.*/
  594.                    fclose( file_zip ) ;
  595.                                         /* Delete the temporary ZIP list file*/
  596.                    remove( unzip_temp_file ) ;
  597.                                         /* Delete the copied ZIP file from   */
  598.                                         /*  the installation drive.          */
  599.                    remove( zip_file ) ;
  600.                 }
  601.                                         /* If all ZIP file have been done,   */
  602.                                         /*  installation completed OK.       */
  603.                 if ( install_zip > INSTALL_ZIP_NUM )
  604.                 {
  605.                    WinPostMsg( hwnd, WM_COMMAND, MPFROMSHORT( INSTALLING_OK_BUTTON ), NULL ) ;
  606.                 }
  607.                 else
  608.                 {
  609.                                         /* Based on zip index, select the    */
  610.                                         /*  next zip file to process.        */
  611.                    if ( install_zip == 1 )  strcpy(zip_file, INSTALL_ZIP1 );
  612.                    if ( install_zip == 2 )  strcpy(zip_file, INSTALL_ZIP2 );
  613.                    if ( install_zip == 3 )  strcpy(zip_file, INSTALL_ZIP3 );
  614.                    if ( install_zip == 4 )  strcpy(zip_file, INSTALL_ZIP4 );
  615.                                         /* Set the ZIP file path on both the */
  616.                                         /*  diskette and the install drive.  */
  617.                    sprintf( orig_zip_file, "%s%s", install_from_drive, zip_file );
  618.                    ptrchar = strrchr( orig_zip_file, '\\' );
  619.                    sprintf( zip_file, "%s%s%s", install_drive, I18N_DIR, ptrchar );
  620.                    WinSetDlgItemText( hwnd, INSTALLING_FROM_FILE, orig_zip_file ) ;
  621.                    WinSetDlgItemText( hwnd, INSTALLING_TO_FILE, zip_file ) ;
  622.                    file_zip = fopen( orig_zip_file, "r" ) ;
  623.                                         /* If unable to open original zip    */
  624.                                         /*  file, then inform user and exit. */
  625.                    if ( ! file_zip )
  626.                    {
  627.                       WinLoadString(habAnchor, (HMODULE) NULL, S_INSTALL_TITLE,
  628.                                     sizeof(error_title), error_title );
  629.                       WinLoadString(habAnchor, (HMODULE) NULL, S_NEXT_DISKETTE,
  630.                                     sizeof(string_text), string_text );
  631.                       sprintf( error_text, string_text, orig_zip_file );
  632.                       ret_code = WinMessageBox( HWND_DESKTOP, NULLHANDLE,
  633.                                                 error_text, error_title, 0,
  634.                                                 MB_OKCANCEL | MB_DEFBUTTON1 |
  635.                                                 MB_WARNING | MB_APPLMODAL ) ;
  636.                       if ( ret_code == MBID_OK )
  637.                       {
  638.                          --install_zip ;
  639.                          WinPostMsg( hwnd, WM_COMMAND, MPFROMSHORT( INSTALLING_NEXT_ZIP ), NULL ) ;
  640.                       }
  641.                       else
  642.                       {
  643.                          WinPostMsg( hwnd, WM_COMMAND, MPFROMSHORT( INSTALLING_CANCEL_BUTTON ), NULL ) ;
  644.                       }
  645.                    }
  646.                    else
  647.                    {
  648.                       fclose( file_zip );
  649.                                         /* Copy the ZIP file from diskette   */
  650.                                         /*  to install drive for performance.*/
  651.                       sprintf( zip_command, "COPY %s %s",
  652.                                orig_zip_file, zip_file ) ;
  653.                       system( zip_command );
  654.                                         /* UNZIP to get a list of files to   */
  655.                                         /*  be installed.                    */
  656.                       sprintf( zip_command, "PKUNZIP2 -vb %s >%s",
  657.                                zip_file, unzip_temp_file ) ;
  658.                       system( zip_command );
  659.                       WinSetDlgItemText( hwnd, INSTALLING_TO_FILE, "" ) ;
  660.                                         /* Open UNZIP output which contains  */
  661.                                         /*  list of files in the ZIP file.   */
  662.                       file_zip = fopen( unzip_temp_file, "r" ) ;
  663.                                         /* If temporary file does not exist, */
  664.                                         /*  tell user and terminate install. */
  665.                       if ( ! file_zip )
  666.                       {
  667.                          WinLoadString(habAnchor, (HMODULE) NULL, S_ERROR_TITLE,
  668.                                        sizeof(error_title), error_title );
  669.                          WinLoadString(habAnchor, (HMODULE) NULL, S_ERROR_UNZIP_LIST_FAIL,
  670.                                        sizeof(string_text), string_text );
  671.                          sprintf( error_text, string_text, zip_file );
  672.                          WinMessageBox( HWND_DESKTOP, NULLHANDLE,
  673.                                         error_text, error_title, 0,
  674.                                         MB_CANCEL | MB_DEFBUTTON1 |
  675.                                         MB_ERROR | MB_APPLMODAL ) ;
  676.                          return_code = RC_FAILED;
  677.                          WinPostMsg( hwnd, WM_COMMAND, MPFROMSHORT( INSTALLING_OK_BUTTON ), NULL ) ;
  678.                       }
  679.                                         /* If temporary file does exist,     */
  680.                                         /*  start installation of files      */
  681.                                         /*  contained in this ZIP file.      */
  682.                       else
  683.                       {
  684.                          WinPostMsg( hwnd, WM_COMMAND, MPFROMSHORT( INSTALLING_NEXT_FILE ), NULL ) ;
  685.                       }
  686.                    }
  687.                 }
  688.                 break;
  689.                                         /* Find next I18N file to install.   */
  690.            case INSTALLING_NEXT_FILE:
  691.                 unzip_from_file[0] = '\0' ;
  692.                                         /* Read records from the temporary   */
  693.                                         /*  UNZIP listing until EOF reached  */
  694.                                         /*  or next .DLL found to install.   */
  695.                 while ( !unzip_from_file[0]  &&
  696.                         ( fgets( zip_record, sizeof(zip_record), file_zip ) != NULL ) )
  697.                 {
  698.                                         /* See if record contains name of a  */
  699.                                         /*  .DLL file to be installed.       */
  700.                    ptrchar = strstr( zip_record, ".DLL" );
  701.                    if ( !ptrchar ) ptrchar = strstr( zip_record, ".dll" );
  702.                                         /* If .DLL, then find name of the    */
  703.                                         /*  file to install from ZIP file.   */
  704.                    if ( ptrchar )
  705.                    {
  706.                       *(ptrchar+4) = '\0';
  707.                       for( ; ptrchar>zip_record && !isspace(*ptrchar) ; --ptrchar ) ;
  708.                       strcpy( unzip_from_file, ++ptrchar );
  709.                    }
  710.                 }
  711.                                         /* If file found to UNZIP,           */
  712.                 if ( unzip_from_file[0] )
  713.                 {
  714.                                         /* Convert "/" to "\".               */
  715.                    for( ptrchar=unzip_from_file; *ptrchar ; ++ptrchar)
  716.                    {
  717.                       if ( *ptrchar == '/' ) *ptrchar='\\' ;
  718.                    }
  719.                                         /* Find last "\" to find file name. */
  720.                    ptrchar = strrchr( unzip_from_file, '\\' );
  721.                    if ( ptrchar )
  722.                    {
  723.                       strcpy( unzip_file, ++ptrchar );
  724.                    }
  725.                    else
  726.                    {
  727.                       strcpy( unzip_file, unzip_from_file );
  728.                    }
  729.                                         /* If original ZIP file contains    */
  730.                                         /*  "DLL" then I18N code install.   */
  731.                    if ( strstr( orig_zip_file, "DLL" ) )
  732.                    {
  733.                       sprintf( unzip_to_dir, "%s%s%s", install_drive,
  734.                                              I18N_DIR, I18N_DLL_DIR );
  735.                    }
  736.                    else
  737.                                         /* else, I18N locale install.       */
  738.                    {
  739.                       sprintf( unzip_to_dir, "%s%s%s", install_drive,
  740.                                              I18N_DIR, I18N_LOCALE_DIR );
  741.                    }
  742.                                         /* Set file name being installed.   */
  743.                    sprintf( unzip_to_file, "%s\\%s", unzip_to_dir, unzip_file );
  744.                    WinSetDlgItemText( hwnd, INSTALLING_TO_FILE, unzip_to_file );
  745.                                         /* UNZIP this single I18N file.     */
  746.                    sprintf( zip_command, "PKUNZIP2 -o %s %s %s",
  747.                             zip_file, unzip_to_dir, unzip_from_file ) ;
  748.                    system( zip_command );
  749.                                         /* Open installed file to see if    */
  750.                                         /*  it was installed OK.            */
  751.                    file_unzip = fopen( unzip_to_file, "r" ) ;
  752.                                         /* if install failed,               */
  753.                                         /*  tell user and terminate.        */
  754.                    if ( ! file_unzip )
  755.                    {
  756.                       WinLoadString(habAnchor, (HMODULE) NULL, S_ERROR_TITLE,
  757.                                     sizeof(error_title), error_title );
  758.                       WinLoadString(habAnchor, (HMODULE) NULL, S_ERROR_UNZIP_FAIL,
  759.                                     sizeof(string_text), string_text );
  760.                       sprintf( error_text, string_text, unzip_to_file, unzip_from_file );
  761.                       WinMessageBox( HWND_DESKTOP, NULLHANDLE,
  762.                                      error_text, error_title, 0,
  763.                                      MB_CANCEL | MB_DEFBUTTON1 |
  764.                                      MB_ERROR | MB_APPLMODAL ) ;
  765.                       return_code = RC_FAILED;
  766.                       WinPostMsg( hwnd, WM_COMMAND, MPFROMSHORT( INSTALLING_OK_BUTTON ), NULL ) ;
  767.                    }
  768.                                         /* if install was successful,       */
  769.                                         /*  continue with next file.        */
  770.                    else
  771.                    {
  772.                       fclose( file_unzip ) ;
  773.                       WinPostMsg( hwnd, WM_COMMAND, MPFROMSHORT( INSTALLING_NEXT_FILE ), NULL ) ;
  774.                    }
  775.                 }
  776.                 else
  777.                 {
  778.                    WinPostMsg( hwnd, WM_COMMAND, MPFROMSHORT( INSTALLING_NEXT_ZIP ), NULL ) ;
  779.                 }
  780.                 break;
  781.                                         /* If installing completed.          */
  782.            case INSTALLING_OK_BUTTON:
  783.                                         /* Close the dialog,                 */
  784.                                         /* and exit PM interface.            */
  785.                 WinPostMsg(hwnd, WM_CLOSE, NULL, NULL);
  786.                 WinPostMsg(hwnd, WM_QUIT, NULL, NULL);
  787.                 break;
  788.                                         /* If they want no cancel installing.*/
  789.            case INSTALLING_CANCEL_BUTTON:
  790.                                         /* Close the dialog,                 */
  791.                                         /* and exit PM interface.            */
  792.                 return_code = RC_USER_CANCEL;
  793.                 WinPostMsg( hwnd, WM_COMMAND, MPFROMSHORT( INSTALLING_OK_BUTTON ), NULL ) ;
  794.                 break;
  795.            default : break;
  796.          }
  797.          break;
  798.     default:
  799.          return(WinDefDlgProc(hwnd, msg, mp1, mp2));
  800.   }
  801.   return((MRESULT) 0);
  802. }
  803.  
  804.  
  805.  
  806. /*****************************************************************************/
  807. /***                                                                       ***/
  808. /***     Install the I18N package.                                         ***/
  809. /***                                                                       ***/
  810. /*****************************************************************************/
  811.  
  812. void execute_install_I18N(void)
  813. {
  814.   char    I18N_dir[BUF_SIZE];           /* Directory path.                   */
  815.   char    I18N_dll_dir[BUF_SIZE];       /* Directory path.                   */
  816.   char    I18N_locale_dir[BUF_SIZE];    /* Directory path.                   */
  817.   char    I18N_nlspath_dir[BUF_SIZE];   /* Directory path.                   */
  818.  
  819.   PEAOP2  eabuf ;                       /* Extended attribute buffer.        */
  820.   int     ret_code;                     /* Return code from is_installed API.*/
  821.   int     user_swp_show;
  822.  
  823.  
  824.   eabuf = 0;
  825.   ret_code = DosSetDefaultDisk( install_drive[0]-'@' );
  826.   if ( ret_code == NO_ERROR )
  827.   {
  828.                                         /* Set installation directories      */
  829.      sprintf( I18N_dir, "%s%s", install_drive, I18N_DIR );
  830.      sprintf( I18N_dll_dir, "%s%s%s", install_drive, I18N_DIR, I18N_DLL_DIR );
  831.      sprintf( I18N_locale_dir, "%s%s%s", install_drive, I18N_DIR, I18N_LOCALE_DIR );
  832.      sprintf( I18N_nlspath_dir, "%s%s%s", install_drive, I18N_DIR, I18N_NLSPATH_DIR );
  833.  
  834.                                         /* Create all I18N directories, if   */
  835.                                         /*  they do not already exist.       */
  836.                                         /*  Handle if create fails.          */
  837.      ret_code = DosCreateDir( I18N_dir, eabuf );
  838.      ret_code = DosSetCurrentDir( I18N_dir );
  839.      if ( ret_code == NO_ERROR )
  840.      {
  841.         ret_code = DosCreateDir( I18N_dll_dir, eabuf );
  842.         ret_code = DosSetCurrentDir( I18N_dll_dir );
  843.         if ( ret_code == NO_ERROR )
  844.         {
  845.            ret_code = DosCreateDir( I18N_locale_dir, eabuf );
  846.            ret_code = DosSetCurrentDir( I18N_dll_dir );
  847.            if ( ret_code == NO_ERROR )
  848.            {
  849.               ret_code = DosCreateDir( I18N_nlspath_dir, eabuf );
  850.               ret_code = DosSetCurrentDir( I18N_nlspath_dir );
  851.               if ( ret_code == NO_ERROR )
  852.               {
  853.               }
  854.               else
  855.               {
  856.                  WinLoadString(habAnchor, (HMODULE) NULL, S_ERROR_TITLE,
  857.                                sizeof(error_title), error_title );
  858.                  WinLoadString(habAnchor, (HMODULE) NULL, S_ERROR_MISSING_DIR,
  859.                                sizeof(string_text), string_text );
  860.                  sprintf( error_text, string_text, I18N_nlspath_dir );
  861.                  WinMessageBox( HWND_DESKTOP, NULLHANDLE,
  862.                                 error_text, error_title, 0,
  863.                                 MB_CANCEL | MB_DEFBUTTON1 |
  864.                                 MB_ERROR | MB_APPLMODAL ) ;
  865.                  return_code = RC_FAILED;
  866.               }
  867.            }
  868.            else
  869.            {
  870.               WinLoadString(habAnchor, (HMODULE) NULL, S_ERROR_TITLE,
  871.                             sizeof(error_title), error_title );
  872.               WinLoadString(habAnchor, (HMODULE) NULL, S_ERROR_MISSING_DIR,
  873.                             sizeof(string_text), string_text );
  874.               sprintf( error_text, string_text, I18N_locale_dir );
  875.               WinMessageBox( HWND_DESKTOP, NULLHANDLE,
  876.                              error_text, error_title, 0,
  877.                              MB_CANCEL | MB_DEFBUTTON1 |
  878.                              MB_ERROR | MB_APPLMODAL ) ;
  879.               return_code = RC_FAILED;
  880.            }
  881.         }
  882.         else
  883.         {
  884.            WinLoadString(habAnchor, (HMODULE) NULL, S_ERROR_TITLE,
  885.                          sizeof(error_title), error_title );
  886.            WinLoadString(habAnchor, (HMODULE) NULL, S_ERROR_MISSING_DIR,
  887.                          sizeof(string_text), string_text );
  888.            sprintf( error_text, string_text, I18N_dll_dir );
  889.            WinMessageBox( HWND_DESKTOP, NULLHANDLE,
  890.                           error_text, error_title, 0,
  891.                           MB_CANCEL | MB_DEFBUTTON1 |
  892.                           MB_ERROR | MB_APPLMODAL ) ;
  893.            return_code = RC_FAILED;
  894.         }
  895.      }
  896.      else
  897.      {
  898.         WinLoadString(habAnchor, (HMODULE) NULL, S_ERROR_TITLE,
  899.                       sizeof(error_title), error_title );
  900.         WinLoadString(habAnchor, (HMODULE) NULL, S_ERROR_MISSING_DIR,
  901.                       sizeof(string_text), string_text );
  902.         sprintf( error_text, string_text, I18N_dir );
  903.         WinMessageBox( HWND_DESKTOP, NULLHANDLE,
  904.                        error_text, error_title, 0,
  905.                        MB_CANCEL | MB_DEFBUTTON1 |
  906.                        MB_ERROR | MB_APPLMODAL ) ;
  907.         return_code = RC_FAILED;
  908.      }
  909.   }
  910.   else
  911.   {
  912.      WinLoadString(habAnchor, (HMODULE) NULL, S_ERROR_TITLE,
  913.                    sizeof(error_title), error_title );
  914.      WinLoadString(habAnchor, (HMODULE) NULL, S_ERROR_MISSING_DRIVE,
  915.                    sizeof(string_text), string_text );
  916.      sprintf( error_text, string_text, install_drive );
  917.      WinMessageBox( HWND_DESKTOP, NULLHANDLE,
  918.                     error_text, error_title, 0,
  919.                     MB_CANCEL | MB_DEFBUTTON1 |
  920.                     MB_ERROR | MB_APPLMODAL ) ;
  921.      return_code = RC_FAILED;
  922.   }
  923.  
  924.   if ( ret_code == NO_ERROR )
  925.   {
  926.      WinRegisterClass(habAnchor, CLS_CLIENT, installing_I18N, CS_SIZEREDRAW, 0);
  927.  
  928.      hwndFrame = WinLoadDlg( HWND_DESKTOP,  /* Place anywhere on desktop.    */
  929.                              HWND_DESKTOP,  /* Owned by frame                */
  930.                              installing_I18N,  /* Address of dialog procedure*/
  931.                              0,             /* Module handle                 */
  932.                              INSTALLING_DIALOG,  /* Dialog id in resource    */
  933.                              NULL ) ;       /* Initialization data           */
  934.      if (hwndFrame != NULLHANDLE)
  935.      {
  936.         if ( userint[0] == 'N' )
  937.         {                                   /* If no user interface wanted.  */
  938.            user_swp_show = 0;
  939.         }
  940.         else
  941.         {                                   /* If user interface wanted.     */
  942.            user_swp_show = SWP_SHOW;
  943.         }
  944.                                         /* Set the size of the dialog  and   */
  945.                                         /*  center it on the screen.         */
  946.         WinQueryWindowPos( hwndFrame, &screen_swp ) ;
  947.         WinSetWindowPos(hwndFrame, NULLHANDLE,
  948.                         (SHORT) (desktop_width - screen_swp.cx) / 2,
  949.                         (SHORT) (desktop_height - screen_swp.cy) / 2,
  950.                         0, 0,
  951.                         SWP_MOVE | SWP_ACTIVATE | user_swp_show);
  952.  
  953.                                         /*  Main message loop:               */
  954.                                         /*  While there are more messages... */
  955.                                         /*   Dispatch this message.          */
  956.         while (WinGetMsg(habAnchor, &qmMsg, NULLHANDLE, 0, 0))
  957.         {
  958.            WinDispatchMsg(habAnchor, &qmMsg);
  959.         }
  960.                                         /*  We're done.  Get rid of the main */
  961.                                         /*   window.                         */
  962.         WinDestroyWindow(hwndFrame);
  963.   }
  964.   }
  965. }
  966.  
  967.  
  968.  
  969. /*****************************************************************************/
  970. /***                                                                       ***/
  971. /***     Determine the value to be used for the LANG variable.             ***/
  972. /***                                                                       ***/
  973. /*****************************************************************************/
  974.  
  975. MRESULT EXPENTRY select_lang(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  976. {
  977.   FILEFINDBUF3 findbuffer ;
  978.   char        filename[BUF_SIZE];
  979.   HDIR        findhandle ;
  980.   ULONG       findcount ;
  981.   int         ret_code;
  982.  
  983.   switch(msg)
  984.   {
  985.                                         /* When we get the "init dialog" msg */
  986.     case WM_INITDLG:
  987.          {
  988.  
  989.            findhandle = 0x0001 ;
  990.            findcount = 1 ;
  991.                                         /* Delete all entries from the list. */
  992.            WinSendDlgItemMsg( hwnd, LANG_COMBOBOX, LM_DELETEALL, NULL, NULL ) ;
  993.                                         /* Find the first locale which       */
  994.                                         /*  exists in the I18N directory.    */
  995.            strcpy( filename, install_drive );
  996.            strcat( filename, "\\I18N\\LOCALE\\*.DLL" );
  997.            ret_code = DosFindFirst( filename, &findhandle, 0x0000, &findbuffer,
  998.                                     sizeof(findbuffer), &findcount, FIL_STANDARD ) ;
  999.            while ( ret_code == NO_ERROR )
  1000.            {
  1001.                                         /* If a locale file name was found,  */
  1002.                                         /*  remove the .DLL extension,  and  */
  1003.                                         /*  add it to the list.              */
  1004.               findbuffer.achName[strlen(findbuffer.achName)-4] = '\0' ;
  1005.               WinSendDlgItemMsg( hwnd, LANG_COMBOBOX, LM_INSERTITEM,
  1006.                                  MPFROM2SHORT ( LIT_SORTASCENDING, 0 ),
  1007.                                  MPFROMP ( findbuffer.achName ) ) ;
  1008.  
  1009.                                         /* Get the next locale file from the */
  1010.                                         /*  list within the I18N directory.  */
  1011.               ret_code = DosFindNext( findhandle, &findbuffer,
  1012.                                       sizeof(findbuffer), &findcount ) ;
  1013.            }
  1014.            DosFindClose( findhandle );
  1015.                                         /* Set the default LANG value.       */
  1016.            WinSetDlgItemText( hwnd, LANG_COMBOBOX, install_lang ) ;
  1017.  
  1018.            break;
  1019.          }
  1020.     case WM_COMMAND:
  1021.          switch(SHORT1FROMMP(mp1))
  1022.          {
  1023.                                         /* If they press the LANG button.    */
  1024.            case LANG_OK_BUTTON:
  1025.                                         /* Close the dialog                  */
  1026.                                         /* and set the new LANG default.     */
  1027.                 WinQueryDlgItemText(hwnd, LANG_COMBOBOX,
  1028.                                     sizeof(install_lang), install_lang);
  1029.                 WinLoadString(habAnchor, (HMODULE) NULL, S_CONFIG_UPDATE_LINE2,
  1030.                               sizeof(string_text), string_text );
  1031.                 sprintf( message_text, string_text, I18N_LANG_VAR, install_lang );
  1032.                 WinSetDlgItemText( hwndFrame, CONFIG_LINE2, message_text ) ;
  1033.                 WinPostMsg(hwnd, WM_CLOSE, NULL, NULL);
  1034.                 break;
  1035.                                         /* If they want no update CONFIG.SYS */
  1036.            case LANG_CANCEL_BUTTON:
  1037.                                         /* Close the dialog                  */
  1038.                 WinPostMsg(hwnd, WM_CLOSE, NULL, NULL);
  1039.                 break;
  1040.            default : break;
  1041.          }
  1042.          break;
  1043.     default:
  1044.          return(WinDefDlgProc(hwnd, msg, mp1, mp2));
  1045.   }
  1046.   return((MRESULT) 0);
  1047. }
  1048.  
  1049.  
  1050.  
  1051. /*****************************************************************************/
  1052. /***                                                                       ***/
  1053. /***     Ask user which available LANG value should be set in CONFIG.SYS.  ***/
  1054. /***                                                                       ***/
  1055. /*****************************************************************************/
  1056.  
  1057. void ask_user_lang_value(void)
  1058. {
  1059.   SWP         lang_swp ;                /* Information about current window. */
  1060.  
  1061.   hwndClient = WinLoadDlg( hwndFrame,    /* Place anywhere on desktop.       */
  1062.                           hwndFrame,     /* Owned by frame                   */
  1063.                           select_lang,   /* Address of dialog procedure      */
  1064.                           0,             /* Module handle                    */
  1065.                           LANG_DIALOG,   /* Dialog id in resource            */
  1066.                           NULL ) ;       /* Initialization data              */
  1067.   if (hwndClient != NULLHANDLE)
  1068.   {
  1069.                                         /* Set the size of the dialog  and   */
  1070.                                         /*  center it on the screen.         */
  1071.      WinQueryWindowPos( hwndClient, &lang_swp ) ;
  1072.      WinSetWindowPos(hwndClient, NULLHANDLE,
  1073.                      (SHORT) (screen_swp.cx - lang_swp.cx) / 2,
  1074.                      (SHORT) (screen_swp.cy - lang_swp.cy) / 2,
  1075.                      0, 0,
  1076.                      SWP_MOVE | SWP_ACTIVATE | SWP_SHOW);
  1077.   }
  1078. }
  1079.  
  1080.  
  1081.  
  1082. /*****************************************************************************/
  1083. /***                                                                       ***/
  1084. /***     Determine whether to update CONFIG.SYS procedure.                 ***/
  1085. /***                                                                       ***/
  1086. /*****************************************************************************/
  1087.  
  1088. MRESULT EXPENTRY update_config(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  1089. {
  1090.  
  1091.   switch(msg)
  1092.   {
  1093.                                         /* When we get the "init dialog" msg */
  1094.     case WM_INITDLG:
  1095.          {
  1096.                                         /* Find all of the available drives  */
  1097.                                         /* on which the I18N directory could */
  1098.                                         /* be installed.                     */
  1099.            WinLoadString(habAnchor, (HMODULE) NULL, S_CONFIG_UPDATE_LINE1,
  1100.                          sizeof(string_text), string_text );
  1101.            sprintf( I18N_dll_dir, "%s%s%s", install_drive, I18N_DIR, I18N_DLL_DIR );
  1102.            sprintf( message_text, string_text, I18N_dll_dir );
  1103.            WinSetDlgItemText( hwnd, CONFIG_LINE1, message_text ) ;
  1104.            WinLoadString(habAnchor, (HMODULE) NULL, S_CONFIG_UPDATE_LINE2,
  1105.                          sizeof(string_text), string_text );
  1106.            sprintf( message_text, string_text, I18N_LANG_VAR, install_lang );
  1107.            WinSetDlgItemText( hwnd, CONFIG_LINE2, message_text ) ;
  1108.            WinLoadString(habAnchor, (HMODULE) NULL, S_CONFIG_UPDATE_LINE3,
  1109.                          sizeof(string_text), string_text );
  1110.            sprintf( I18N_locale_dir, "%s%s%s", install_drive, I18N_DIR, I18N_LOCALE_DIR );
  1111.            sprintf( message_text, string_text, I18N_LOCPATH_VAR, I18N_locale_dir );
  1112.            WinSetDlgItemText( hwnd, CONFIG_LINE3, message_text ) ;
  1113.            WinLoadString(habAnchor, (HMODULE) NULL, S_CONFIG_UPDATE_LINE4,
  1114.                          sizeof(string_text), string_text );
  1115.            sprintf( I18N_messages_dir, "%s%s%s%s", install_drive, I18N_DIR,
  1116.                                           I18N_NLSPATH_DIR, I18N_NLSPATH_VARS );
  1117.            sprintf( message_text, string_text, I18N_NLSPATH_VAR, I18N_messages_dir );
  1118.            WinSetDlgItemText( hwnd, CONFIG_LINE4, message_text ) ;
  1119.  
  1120.            break;
  1121.          }
  1122.     case WM_COMMAND:
  1123.          switch(SHORT1FROMMP(mp1))
  1124.          {
  1125.                                         /* If they press the LANG button.    */
  1126.            case CONFIG_LANG_BUTTON:
  1127.                                         /* Find out the value to be used for */
  1128.                                         /*  setting the LANG variable.       */
  1129.                 ask_user_lang_value() ;
  1130.                 break;
  1131.  
  1132.            case CONFIG_UPDATE_BUTTON:
  1133.                                         /* Close the dialog,                 */
  1134.                                         /* and exit PM interface.            */
  1135.                 updateconfig[0] = 'Y';
  1136.                 WinPostMsg(hwnd, WM_CLOSE, NULL, NULL);
  1137.                 WinPostMsg(hwnd, WM_QUIT, NULL, NULL);
  1138.                 break;
  1139.                                         /* If they want no update CONFIG.SYS */
  1140.            case CONFIG_NO_UPDATE_BUTTON:
  1141.                                         /* Close the dialog,                 */
  1142.                                         /* and exit PM interface.            */
  1143.                 updateconfig[0] = 'N';
  1144.                 WinPostMsg(hwnd, WM_CLOSE, NULL, NULL);
  1145.                 WinPostMsg(hwnd, WM_QUIT, NULL, NULL);
  1146.                 break;
  1147.            default : break;
  1148.          }
  1149.          break;
  1150.     default:
  1151.          return(WinDefDlgProc(hwnd, msg, mp1, mp2));
  1152.   }
  1153.   return((MRESULT) 0);
  1154. }
  1155.  
  1156.  
  1157.  
  1158. /*****************************************************************************/
  1159. /***                                                                       ***/
  1160. /***     Ask user whether to update the CONFIG.SYS file with the I18N      ***/
  1161. /***     required values.                                                  ***/
  1162. /***                                                                       ***/
  1163. /*****************************************************************************/
  1164.  
  1165. void ask_user_update_config(void)
  1166. {
  1167.   QMSG           qmMsg;                 /* A message to pull from queue.     */
  1168.  
  1169.                                         /* Register main window class        */
  1170.   WinRegisterClass(habAnchor, CLS_CLIENT, update_config, CS_SIZEREDRAW, 0);
  1171.  
  1172.   hwndFrame = WinLoadDlg( HWND_DESKTOP,  /* Place anywhere on desktop.       */
  1173.                           HWND_DESKTOP,  /* Owned by frame                   */
  1174.                           update_config, /* Address of dialog procedure      */
  1175.                           0,             /* Module handle                    */
  1176.                           CONFIG_DIALOG, /* Dialog id in resource            */
  1177.                           NULL ) ;       /* Initialization data              */
  1178.   if (hwndFrame != NULLHANDLE)
  1179.   {
  1180.      WinQueryWindowPos( hwndFrame, &screen_swp ) ;
  1181.      WinSetWindowPos(hwndFrame, NULLHANDLE,
  1182.                      (SHORT) (desktop_width - screen_swp.cx) / 2,
  1183.                      (SHORT) (desktop_height - screen_swp.cy) / 2,
  1184.                      0, 0,
  1185.                      SWP_MOVE | SWP_ACTIVATE | SWP_SHOW);
  1186.  
  1187.                                         /*  Main message loop:               */
  1188.                                         /*  While there are more messages... */
  1189.                                         /*   Dispatch this message.          */
  1190.      while (WinGetMsg(habAnchor, &qmMsg, NULLHANDLE, 0, 0))
  1191.      {
  1192.         WinDispatchMsg(habAnchor, &qmMsg);
  1193.      }
  1194.                                         /*  We're done.  Get rid of the main */
  1195.                                         /*   window.                         */
  1196.      if ( hwndClient )
  1197.      {
  1198.         WinDestroyWindow(hwndClient);
  1199.      }
  1200.      WinDestroyWindow(hwndFrame);
  1201.   }
  1202. }
  1203.  
  1204.  
  1205.  
  1206. /*****************************************************************************/
  1207. /***                                                                       ***/
  1208. /***     Add the specified directory to the beginning of the passed        ***/
  1209. /***     CONFIG.SYS statement.                                             ***/
  1210. /***                                                                       ***/
  1211. /*****************************************************************************/
  1212.  
  1213. void add_dir_config(char *line_text, char *line_upper, char *add_dir)
  1214. {
  1215.   char        work_line[CONFIG_SIZE];       /* Work record for CONFIG.SYS.   */
  1216.   char        *ptrchar;
  1217.   char        *ptrchar2;
  1218.                                             /* If directory data to be added */
  1219.                                             /*  does not yet exist on this   */
  1220.                                             /*  line, then add it at the     */
  1221.                                             /*  beginning of library list.   */
  1222.   ptrchar = strstr( line_upper, add_dir );
  1223.   if ( !ptrchar )
  1224.   {
  1225.                                             /* Save current line up to and   */
  1226.                                             /*  including the "=".           */
  1227.      strcpy( work_line, line_text );
  1228.      ptrchar = strchr( work_line, '=' );
  1229.      *(ptrchar+1) = '\0';
  1230.                                             /* Find start of data after "=". */
  1231.      ptrchar = strchr( line_text, '=' );
  1232.      for( ptrchar2=ptrchar+1; *ptrchar2 && isspace(*ptrchar2); ++ptrchar2 );
  1233.  
  1234.      strcat( work_line, add_dir );          /* Append new directory data.    */
  1235.      strcat( work_line, ";" );              /* Append ";" library separator. */
  1236.      strcat( work_line, ptrchar2 );         /* Append original data.         */
  1237.      strcpy( line_text, work_line );        /* Reset CONFIG.SYS line         */
  1238.   }
  1239. }
  1240.  
  1241.  
  1242.  
  1243. /*****************************************************************************/
  1244. /***                                                                       ***/
  1245. /***     Update the CONFIG.SYS file with the I18N statements.              ***/
  1246. /***                                                                       ***/
  1247. /*****************************************************************************/
  1248.  
  1249. void execute_update_config(void)
  1250. {
  1251.   FILE       *file_config;                 /* File for CONFIG.SYS update.    */
  1252.   FILE       *file_work;                   /* File for CONFIG.SYS update.    */
  1253.   char        config_record[CONFIG_SIZE];  /* Record from CONFIG.SYS file.   */
  1254.   char        config_upper[CONFIG_SIZE];   /* Record from CONFIG.SYS file.   */
  1255.   char        config_text[CONFIG_SIZE];    /* Record for CONFIG.SYS file.    */
  1256.   char        exec_command[BUF_SIZE];
  1257.   char        *ptrchar;
  1258.   BOOL        create_backup = TRUE;        /* Whether to create backup file. */
  1259.   BOOL        libpath_updated = FALSE;     /* Whether LIBPATH is done.       */
  1260.   BOOL        lang_updated = FALSE;        /* Whether LANG is done.          */
  1261.   BOOL        locpath_updated = FALSE;     /* Whether LOCPATH is done.       */
  1262.   BOOL        nlspath_updated = FALSE;     /* Whether NLSPATH is done.       */
  1263.   int         ret_code;
  1264.  
  1265.  
  1266.                                         /* If CONFIG.SYS backup file already */
  1267.                                         /*  exists, find out whether to      */
  1268.                                         /*  replace file or not.             */
  1269.   file_work = fopen( config_sys_backup_file, "r" ) ;
  1270.   if ( file_work )
  1271.   {
  1272.      WinLoadString(habAnchor, (HMODULE) NULL, S_INSTALL_TITLE,
  1273.                    sizeof(error_title), error_title );
  1274.      WinLoadString(habAnchor, (HMODULE) NULL, S_ERROR_CONFIG_BACKUP,
  1275.                    sizeof(string_text), string_text );
  1276.      sprintf( error_text, string_text, config_sys_backup_file );
  1277.      ret_code = WinMessageBox( HWND_DESKTOP, NULLHANDLE,
  1278.                                error_text, error_title, 0,
  1279.                                MB_YESNO | MB_DEFBUTTON1 |
  1280.                                MB_WARNING | MB_APPLMODAL ) ;
  1281.      if ( ret_code == MBID_NO )
  1282.      {
  1283.         create_backup = FALSE;
  1284.      }
  1285.      fclose( file_work );
  1286.   }
  1287.                                         /* Copy the current CONFIG.SYS to    */
  1288.                                         /*  the I18N backup file.            */
  1289.   if ( create_backup )
  1290.   {
  1291.      sprintf( exec_command, "COPY %s %s",
  1292.               config_sys_file, config_sys_backup_file ) ;
  1293.      system( exec_command );
  1294.   }
  1295.                                         /* Open input and output files.      */
  1296.   file_config = fopen( config_sys_file, "r" ) ;
  1297.   file_work = fopen( config_sys_work_file, "w+" ) ;
  1298.   if ( file_config && file_work )
  1299.   {
  1300.                                         /* Read from the input CONFIG.SYS,   */
  1301.                                         /*  writing out updated records.     */
  1302.      while ( fgets( config_record, sizeof(config_record), file_config ) != NULL )
  1303.      {
  1304.                                         /* Convert data to uppercase.       */
  1305.         strcpy( config_upper, config_record );
  1306.         strupr( config_upper );
  1307.                                         /* First 1st token from record.      */
  1308.         strcpy( config_text, config_upper );
  1309.         ptrchar = strtok( config_text, " " );
  1310.                                         /* If not a comment, analyze further.*/
  1311.         if ( ptrchar && strcmp( ptrchar, "REM" ) )
  1312.         {
  1313.                                         /* If LIBPATH line, add I18N path    */
  1314.                                         /*  information at beginning of data.*/
  1315.            if ( strstr( ptrchar, I18N_LIBPATH_VAR ) )
  1316.            {
  1317.               add_dir_config( config_record, config_upper, I18N_dll_dir );
  1318.               libpath_updated = TRUE;
  1319.            }
  1320.            else
  1321.            {
  1322.                                         /* If SET line, look for variable.   */
  1323.               if ( !strcmp( ptrchar, "SET" ) )
  1324.               {
  1325.                                         /* If LANG line, ignore for now as   */
  1326.                                         /*  it will be added at the end.     */
  1327.                  if ( strstr( config_upper, I18N_LANG_VAR ) )
  1328.                  {
  1329.                     continue ;          /* Force writing out new SET LANG=   */
  1330.                  }
  1331.                                         /* If LOCPATH line, add I18N path    */
  1332.                                         /*  information at beginning of data.*/
  1333.                  if ( strstr( config_upper, I18N_LOCPATH_VAR ) )
  1334.                  {
  1335.                     add_dir_config( config_record, config_upper, I18N_locale_dir );
  1336.                     locpath_updated = TRUE;
  1337.                  }
  1338.                                         /* If NLSPATH line, add I18N path    */
  1339.                                         /*  information at beginning of data.*/
  1340.                  if ( strstr( config_upper, I18N_NLSPATH_VAR ) )
  1341.                  {
  1342.                     add_dir_config( config_record, config_upper, I18N_messages_dir );
  1343.                     nlspath_updated = TRUE;
  1344.                  }
  1345.               }
  1346.            }
  1347.         }
  1348.                                         /* Write out previous or updated line*/
  1349.         ret_code = fputs( config_record, file_work );
  1350.         if ( ret_code == EOF ) return_code = RC_CONFIG_FAILED ;
  1351.      }
  1352.                                         /* If LIBPATH is not updated, add    */
  1353.                                         /* new line at end of file.          */
  1354.      if ( !libpath_updated )
  1355.      {
  1356.         sprintf( config_text, "%s%s\n",I18N_LIBPATH_VAR, I18N_dll_dir );
  1357.         ret_code = fputs( config_text, file_work );
  1358.         if ( ret_code == EOF ) return_code = RC_CONFIG_FAILED ;
  1359.      }
  1360.                                         /* If LANG is not updated, add       */
  1361.                                         /* new line at end of file.          */
  1362.      if ( !lang_updated )
  1363.      {
  1364.         WinLoadString(habAnchor, (HMODULE) NULL, S_CONFIG_UPDATE_LINE2,
  1365.                       sizeof(string_text), string_text );
  1366.         sprintf( config_text, string_text, I18N_LANG_VAR, install_lang );
  1367.         strcat( config_text, "\n" );
  1368.         ret_code = fputs( config_text, file_work );
  1369.         if ( ret_code == EOF ) return_code = RC_CONFIG_FAILED ;
  1370.      }
  1371.                                         /* If LOCPATH is not updated, add    */
  1372.                                         /* new line at end of file.          */
  1373.      if ( !locpath_updated )
  1374.      {
  1375.         WinLoadString(habAnchor, (HMODULE) NULL, S_CONFIG_UPDATE_LINE3,
  1376.                       sizeof(string_text), string_text );
  1377.         sprintf( config_text, string_text, I18N_LOCPATH_VAR, I18N_locale_dir );
  1378.         strcat( config_text, "\n" );
  1379.         ret_code = fputs( config_text, file_work );
  1380.         if ( ret_code == EOF ) return_code = RC_CONFIG_FAILED ;
  1381.      }
  1382.                                         /* If NLSPATH is not updated, add    */
  1383.                                         /* new line at end of file.          */
  1384.      if ( !nlspath_updated )
  1385.      {
  1386.         WinLoadString(habAnchor, (HMODULE) NULL, S_CONFIG_UPDATE_LINE4,
  1387.                       sizeof(string_text), string_text );
  1388.         sprintf( config_text, string_text, I18N_NLSPATH_VAR, I18N_messages_dir );
  1389.         strcat( config_text, "\n" );
  1390.         ret_code = fputs( config_text, file_work );
  1391.         if ( ret_code == EOF ) return_code = RC_CONFIG_FAILED ;
  1392.      }
  1393.   }
  1394.   else
  1395.   {
  1396.      return_code = RC_CONFIG_FAILED;
  1397.   }
  1398.                                         /* Close files.                      */
  1399.   if ( file_config ) fclose( file_config );
  1400.   if ( file_work ) fclose( file_work );
  1401.  
  1402.                                         /* If no problems, replace the real  */
  1403.                                         /* CONFIG.SYS file with updates.     */
  1404.   if ( return_code == RC_NO_ERROR )
  1405.   {
  1406.      sprintf( exec_command, "COPY %s %s",
  1407.               config_sys_work_file, config_sys_file ) ;
  1408.      system( exec_command );
  1409.   }
  1410.                                         /* Delete temporary file.            */
  1411.   remove( config_sys_work_file );
  1412.   if ( return_code != RC_NO_ERROR ) return_code = RC_CONFIG_FAILED;
  1413. }
  1414.  
  1415.  
  1416.  
  1417. /*****************************************************************************/
  1418. /*****************************************************************************/
  1419. /***                                                                       ***/
  1420. /***     Main program                                                      ***/
  1421. /***                                                                       ***/
  1422. /*****************************************************************************/
  1423. /*****************************************************************************/
  1424.  
  1425. INT main(int argc, char *argv[])
  1426. {
  1427.   double         installed_version;     /* Version number of I18N already    */
  1428.                                         /*  installed on the system.         */
  1429.   int ret_code;                         /* Return code from is_installed API.*/
  1430.  
  1431.  
  1432.  
  1433.                                         /* Initialize parameter variables.   */
  1434.   initialize( argc, argv );
  1435.  
  1436.                                         /* Call API to determine if I18N  is */
  1437.                                         /*  already installed.               */
  1438.   ret_code = is_i18n_installed(&installed_version, install_drive);
  1439.  
  1440.                                         /* If development wants to "force"   */
  1441.                                         /* installation on a specific drive, */
  1442.                                         /* handle this situation.            */
  1443.   if ( (force_drive[0]) && (force_drive[0] != install_drive[0]) )
  1444.   {
  1445.      installed_version = 0.01 ;
  1446.      install_drive[0] = force_drive[0];
  1447.   }
  1448.  
  1449.                                         /* If need to update the I18N package*/
  1450.                                         /*  perform necessary functions.     */
  1451.  
  1452.   if (installed_version <= I18N_VERSION_NUM)
  1453.   {
  1454.                                         /* Get the anchor block for program. */
  1455.                                         /* Create message queue for program. */
  1456.      habAnchor = WinInitialize(0);
  1457.      hmqQueue = WinCreateMsgQueue(habAnchor, 0);
  1458.      desktop_width = WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN);
  1459.      desktop_height = WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN);
  1460.                                         /* If need to ask user what drive to */
  1461.                                         /*  install package on, do it now.   */
  1462.      if ( ( askdrive[0] != 'N' ) &&
  1463.           ( ( askdrive[0] != 'U' ) ||
  1464.             ( installed_version == 0.0 ) ) )
  1465.      {
  1466.         ask_user_which_drive() ;
  1467.      }
  1468.                                         /* Install the I18N package.         */
  1469.      if ( install_drive[0] )
  1470.      {
  1471.         execute_install_I18N() ;
  1472.         if ( return_code == RC_NO_ERROR )
  1473.         {
  1474.                                         /* If need to ask user whether to    */
  1475.                                         /*  update CONFIG.SYS, do it now.    */
  1476.            if ( updateconfig[0] == 'A' )
  1477.            {
  1478.               ask_user_update_config() ;
  1479.            }
  1480.                                         /* If requested to updated CONFIG.SYS*/
  1481.                                         /*  add I18N information.            */
  1482.            if ( updateconfig[0] == 'Y' )
  1483.            {
  1484.               execute_update_config() ;
  1485.            }
  1486.         }
  1487.      }
  1488.                                         /* Get rid of the message queue.     */
  1489.                                         /* Get rid of the anchor block.      */
  1490.      WinDestroyMsgQueue(hmqQueue);
  1491.      WinTerminate(habAnchor);
  1492.   }                                     /* I18N versions are different.      */
  1493.  
  1494.                                         /* Terminate the program.            */
  1495.   return(return_code);
  1496. }
  1497. 
  1498.  
  1499.