home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / k95source / ctl3dins.c < prev    next >
C/C++ Source or Header  |  2020-01-01  |  7KB  |  186 lines

  1. /*
  2.   Author: Jeffrey Altman (jaltman@columbia.edu),
  3.   Columbia University Academic Information Systems, New York City.
  4.  
  5.   Copyright (C) 1985, 1997, Trustees of Columbia University in the City of New
  6.   York.
  7. */
  8.  
  9. /* Installs CTL3D32.DLL and MSVCRT.DLL into the proper directory */
  10.  
  11. #include <windows.h>
  12.  
  13. void
  14. DisplayHelp( char * name )
  15. {
  16.     printf("%s [-f]: Installs CTL3D32.DLL and MSVCRT.DLL.  -f forces the install upon error.\n\n",name);
  17. }
  18.  
  19. void
  20. InstallFile(char * prgname, char * srcfile, char * destfile, int forceinstall) {
  21.     char   curdir[1024];
  22.     char   windir[1024];
  23.     char   curpath[1024];
  24.     DWORD  curlen = 1024;
  25.     char   destpath[1024];
  26.     DWORD  destlen = 1024;
  27.     char   tmpfile[1024];
  28.     DWORD  tmplen = 1024;
  29.     DWORD  vff_bitmask = 0;
  30.     DWORD  vif_bitmask = 0;
  31.     int    deletetmpfile = 0;
  32.  
  33.     GetWindowsDirectory( windir, 1024 );
  34.     GetCurrentDirectory( 1024, curdir );
  35.  
  36.     /* Use VerFindFile() to figure out where CTL3D32.DLL */
  37.     /* should be installed                               */
  38.     vff_bitmask = VerFindFile( VFFF_ISSHAREDFILE,
  39.                                destfile,
  40.                                windir,
  41.                                curdir,
  42.                                curpath, &curlen,
  43.                                destpath, &destlen );
  44.     if ( vff_bitmask & VFF_CURNEDEST ) {
  45.         printf("%s is installed but in the wrong directory\n",destfile);
  46.         printf("Currently in \"%s\" but should be in \"%s\"\n",
  47.                 curpath, destpath );
  48.     }
  49.     if ( vff_bitmask & VFF_FILEINUSE ) {
  50.         printf("%s is installed and in use.\n",destfile);
  51.     }
  52.  
  53.     printf("Installing %s as %s in \"%s\".\n",
  54.             srcfile, destfile, destpath);
  55.  
  56.     /* Use VerInstallFile() to actually install it     */
  57.     vif_bitmask = VerInstallFile( forceinstall ? VIFF_FORCEINSTALL : 0,
  58.                                   srcfile,
  59.                                   destfile,
  60.                                   curdir,
  61.                                   destpath,
  62.                                   curpath,
  63.                                   tmpfile,
  64.                                   &tmplen);
  65.  
  66.     if ( vif_bitmask & VIF_TEMPFILE ) {
  67.         printf("The temporary copy of the new file is in \"%s\".\n\n",
  68.                 tmpfile);
  69.         deletetmpfile = 1;
  70.     }
  71.     if ( vif_bitmask & VIF_MISMATCH ) {
  72.         printf("The new and preexisting files differ in one or more attributes.\n");
  73.         printf("To force the installation, run %s again with the \"-f\" switch.",prgname);;
  74.     }
  75.     if ( vif_bitmask & VIF_SRCOLD ) {
  76.         printf("The file to install is older than the preexisting file.\n");
  77.         printf("To force the installation, run %s again with the \"-f\" switch.",prgname);;
  78.     }
  79.     if ( vif_bitmask & VIF_DIFFLANG ) {
  80.         printf("The new and preexisting files have different language or code-page\n");
  81.         printf("values.\n\n");
  82.         printf("To force the installation, run %s again with the \"-f\" switch.",prgname);;
  83.     }   
  84.     if ( vif_bitmask & VIF_DIFFCODEPG ) {
  85.         printf("The new file requires a code page that cannot be displayed by the\n");
  86.         printf("version of Windows currently running.\n\n");
  87.         printf("To force the installation, run %s again with the \"-f\" switch.",prgname);;
  88.     }
  89.     if ( vif_bitmask & VIF_DIFFTYPE ) {
  90.         printf("The new file has a different type, subtype, or operating system\n");
  91.         printf("from the preexisting file.\n\n");
  92.         printf("To force the installation, run %s again with the \"-f\" switch.",prgname);;
  93.     }
  94.     if ( vif_bitmask & VIF_WRITEPROT ) {
  95.         printf("The preexisting file is write protected\n\n");
  96.         printf("To force the installation, run %s again with the \"-f\" switch.",prgname);;
  97.     }
  98.     if ( vif_bitmask & VIF_FILEINUSE ) {
  99.         printf("The preexisting file is in use and cannot be deleted\n\n");
  100.     }
  101.     if ( vif_bitmask & VIF_OUTOFSPACE ) {
  102.         printf("The function cannot create the temporary file due to insufficient\n");
  103.         printf("disk space on the destination drive.\n\n");
  104.     }
  105.     if ( vif_bitmask & VIF_ACCESSVIOLATION ) {
  106.         printf("A read, create, delete, or rename operation failed due to a access\n");
  107.         printf("violation.\n\n");
  108.     }
  109.     if ( vif_bitmask & VIF_SHARINGVIOLATION ) {
  110.         printf("A read, create, delete, or rename operation failed due to a sharing\n");
  111.         printf("violation.\n\n");
  112.     }
  113.     if ( vif_bitmask & VIF_CANNOTCREATE ) {
  114.         printf("The temporary file cannot be created.\n\n");
  115.     }
  116.     if ( vif_bitmask & VIF_CANNOTDELETE ) {
  117.         printf("Either cannot delete the destination file or a preexisting file in\n");
  118.         printf("another directory.\n\n");
  119.     }
  120.     if ( vif_bitmask & VIF_CANNOTDELETECUR ) {
  121.         printf("The preexisting version of the file could not be deleted.\n\n");
  122.     }
  123.     if ( vif_bitmask & VIF_CANNOTRENAME ) {
  124.         printf("The temporary file cannot be renamed but the preexisting file\n");
  125.         printf("has already been deleted.\n\n");
  126.     }
  127.     if ( vif_bitmask & VIF_OUTOFMEMORY ) {
  128.         printf("Ran out of memory.\n\n");
  129.     }
  130.     if ( vif_bitmask & VIF_CANNOTREADSRC ) {
  131.         printf("Source file could not be read.\n\n");
  132.     }
  133.     if ( vif_bitmask & VIF_CANNOTREADDST ) {
  134.         printf("Destination file could not be read.\n");
  135.     }
  136.     if ( vif_bitmask & VIF_BUFFTOOSMALL ) {
  137.         printf("one of the string buffers is too small.\n");
  138.     }
  139. }
  140.  
  141. int
  142. main( int argc, char * argv[] )
  143. {
  144.     OSVERSIONINFO osverinfo ;
  145.     char * srcfile = NULL;
  146.     char * destfile = "ctl3d32.dll";
  147.     int    forceinstall = 0;
  148.  
  149.     if ( argc > 2 ) {
  150.         DisplayHelp( argv[0] );
  151.         return 1;
  152.     }
  153.  
  154.     if ( argc == 2 ) {
  155.         if ( (argv[1][0] == '/' || argv[1][0] == '-') && 
  156.              (argv[1][1] == 'f' || argv[1][1] == 'F') )
  157.             forceinstall = 1;
  158.         else {
  159.             DisplayHelp( argv[0] );
  160.             return 1;
  161.         }
  162.     }
  163.  
  164.     /* Determine if we are on Windows 95 or Windows NT */
  165.     /* and set the proper file names                   */
  166.     osverinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO) ;
  167.     GetVersionEx( &osverinfo ) ;
  168.     switch ( osverinfo.dwPlatformId ) {
  169.     case VER_PLATFORM_WIN32_WINDOWS:
  170.         srcfile = "ctl3d95.dll";
  171.         break;
  172.     case VER_PLATFORM_WIN32_NT:
  173.         srcfile = "ctl3dnt.dll";
  174.         break;
  175.     default:
  176.         printf("Invalid operating system type\n");
  177.         return 2;
  178.     }
  179.  
  180.     InstallFile(argv[0],srcfile,"ctl3d32.dll",forceinstall);
  181.     InstallFile(argv[0],"msvcrt__.dll","msvcrt.dll",forceinstall);
  182.  
  183.     return 0;
  184. }
  185.  
  186.