⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 msdsys.c

📁 Dos6.0
💻 C
📖 第 1 页 / 共 5 页
字号:
/*********************************************************************
 * Microsoft Diagnostics Version 2.0
 *
 * A diagnostic utility to detect as much useful information about a
 *   customer's computer system as is possible.
 *
 * Microsoft Diagnostics:  We detect the World.
 *
 * MSDSYS.C - Source file for system related code (ie file I/O).
 ********************************************************************/


/* Include Files */

#include "msd.h"


/********************************************************************
 * OpenFile - Opens a file and provides appropriate error handling.
 *
 * pszFilename - Name of file
 * pszMode     - Mode to open the file.
 * fShowError  - Displays errors when TRUE.
 *
 * Returns: FILE handle, or NULL if an error condition occured.
 ********************************************************************/

FILE * OpenFile (PSZ pszFilename, PSZ pszMode, BOOL fShowError)
{
  FILE *fp;           /* Local storage for the file pointer */

  /* Open the file */

  fp = fopen (pszFilename, pszMode);

  /* Give appropriate error message, if necessary */

  if (fShowError && (fp == NULL || fCriticalError))
    {
      fCriticalError = FALSE;

      ShowError (ERR_OK_BUTTON, pszErrorOpening, pszFilename, 
                 _strerror (NULL));

      return (NULL);
    }

  /* If all went well, return the file pointer to the calling routine */

  return (fp);
}


/********************************************************************
 * CloseFile - Closes a file and provides appropriate error handling.
 *
 * fp - File handle to close
 *
 * Returns: TRUE if an error occured.
 ********************************************************************/

BOOL CloseFile (FILE *fp)
{
  WORD wReturnValue;  /* Return value from fclose */


  /* Close the file */
  wReturnValue = fclose (fp);

  /* Give appropriate error message, if necessary */
  if (wReturnValue == EOF)
    {
      fCriticalError = FALSE;

      ShowError (ERR_OK_BUTTON, pszErrorClosing, NULL, _strerror (NULL));

      return (TRUE);
    }

  return (FALSE);
}


/**********************************************************************
 * CreateTempFile - Uses a DOS 3+ call to create a unique file
 *
 * pszPathname - Path to where the temp file needs to go.
 *
 * Returns: Error number:
 *          03 - Path not found.
 *          04 - No more handles.
 *          05 - Access denied.
 **********************************************************************/

WORD CreateTempFile (PSZ pszPathname)
{
  union REGS inregs, outregs;   /* Register values for int86x */
  struct SREGS sregs;           /* Segment register values */
  CHAR FAR * fpszPathname = (CHAR FAR *) pszPathname;

  inregs.h.ah = 0x5A;
  inregs.x.cx = 0;
  sregs.ds    = (WORD) FP_SEG (fpszPathname);
  inregs.x.dx = (WORD) FP_OFF (fpszPathname);

  int86x (0x21, &inregs, &outregs, &sregs);

  if (outregs.x.cflag)
    return (outregs.x.ax);
  else
    return (0);
}


/**********************************************************************
 * DeleteFile - Deletes file specified by pszFilename
 *
 * pszFilename - File to delete
 *
 * Returns: Error number:
 *          02 - File not found.
 *          03 - Path not found.
 *          05 - Access denied.
 **********************************************************************/

WORD DeleteFile (PSZ pszPathname)
{
  union REGS inregs, outregs;   /* Register values for intdos */
  struct SREGS sregs;           /* Segment register values */
  CHAR FAR * fpszPathname = (CHAR FAR *) pszPathname;

  inregs.h.ah = 0x41;
  sregs.ds    = (WORD) FP_SEG (fpszPathname);
  inregs.x.dx = (WORD) FP_OFF (fpszPathname);

  int86x (0x21, &inregs, &outregs, &sregs);

  if (outregs.x.cflag)
    return (outregs.x.ax);
  else
    return (0);
}


/**********************************************************************
 * RenameFile - Renames a file.
 *
 * pszPathname1 - File to rename.
 * pszPathname2 - New filename.
 *
 * Returns: Error number:
 *          02 - File not found.
 *          03 - Path not found.
 *          05 - Access denied.
 *          17 - (11H) Not the same device.
 **********************************************************************/

WORD RenameFile (PSZ pszPathname1, PSZ pszPathname2)
{
  union REGS inregs, outregs;   /* Register values for intdos */
  struct SREGS sregs;           /* Segment register values */
  CHAR FAR * fpszPathname1 = (CHAR FAR *) pszPathname1;
  CHAR FAR * fpszPathname2 = (CHAR FAR *) pszPathname2;

  inregs.h.ah = 0x56;
  sregs.ds    = (WORD) FP_SEG (fpszPathname1);
  inregs.x.dx = (WORD) FP_OFF (fpszPathname1);
  sregs.es    = (WORD) FP_SEG (fpszPathname2);
  inregs.x.di = (WORD) FP_OFF (fpszPathname2);

  int86x (0x21, &inregs, &outregs, &sregs);

  if (outregs.x.cflag)
    return (outregs.x.ax);
  else
    return (0);
}

WORD wNmbrFound = 0;

/*********************************************************************
 * FindFile - Finds all of the pszFilename files on the system.
 *
 * pszFilename   - Filename to find.
 *
 * pszPathname   - Path to start searching from (NULL if it's to be
 *                 ignored).
 *
 * fSearchFlags  - SEARCH_FLOPPIES          Search floppies.
 *                 SEARCH_LOCAL_DRIVES      Search local hard disks.
 *                 SEARCH_NET_DRIVES        Search net drives (and
 *                                          all other drives).
 *                 SEARCH_ROOT              Search the root directory.
 *                 RECURSE_INTO_SUB_DIRS    Search recursively into
 *                                          subdirectories.
 *
 *                 Only one of the following should be specified at
 *                   one time:
 *                 SEARCH_LANMAN_ROOT       Searches in the LANMAN
 *                                          root directory.
 *                 SEARCH_WINDIR            Uses the "windir="
 *                                          environment variable.
 *                 SEARCH_BOOT_DRIVE        Search just the boot drive.
 *
 * chDriveLetter - If fSearchFlags does not specify the drive type(s)
 *                 to search, this contains the drive letter to
 *                 search.  ('\0' to search current drive).
 *
 * Returns:  Pointer to an array of strings to pszFilename files, the
 *           last pointer is a NULL pointer.  If pszFilename could
 *           not be found, or an error occured, the first pointer is a
 *           NULL.
 *********************************************************************/

FILE_INFO FAR *FindFile (PSZ  pszFilename,
                         PSZ  pszPathname,
                         BOOL fSearchFlags,
                         CHAR chDriveLetter)
{
  CHAR chCurrentPath[_MAX_PATH + 1];  /* Stores current drive & directory  */
  WORD wCurrentDrive;                 /* Stores the current drive number   */
  WORD i;                             /* Looping variable                  */
  DISK_STRUCT *pDisk = NULL;          /* Pointer to disk drive info        */
                                      /*   structure                       */
  OS_VERSION_STRUCT *pOsVer = NULL;   /* Pointer to DOS info structure     */
  BOOL fReturnValue = FALSE;          /* Stores the return value from      */
                                      /*   fuctions                        */
  FILE_INFO FAR *pFileInfo = NULL;    /* Pointer to file info linked list  */
  FILE_INFO FAR *pfi = NULL;          /* Another pointer to file info list */
                                      /*   (this one is changed by the     */
                                      /*   called routines).               */


  /* Save the current drive and directory */
  wCurrentDrive = _getdrive();
  _getdcwd (wCurrentDrive, chCurrentPath, _MAX_PATH);


  /* Allocate enough room for the find file info */
  pFileInfo = _fmalloc (sizeof (FILE_INFO));
  if (pFileInfo == NULL)
    {
      OutOfMemory();
      return (NULL);
    }
  pfi = pFileInfo;


  /* Set the first pointer to null, to show that */
  /*   this is the last on the list.             */
  pFileInfo->fpNextFileInfo = NULL;


  /* Get the disk and operating system structures */
  fReturnValue = GetFindFileInfo (&pDisk, &pOsVer, fSearchFlags);
  if (fReturnValue)
    {
      FreeFileInfo (pFileInfo);
      return (NULL);
    }


  /* Zero out the counter for files found */
  wNmbrFound = 0;

  /* Change to the appropriate drive and directory if necessary */
  if (pszPathname != NULL)
    {
      /* Check to see if a drive was passed to us */
      if (pszPathname[1] == ':')
        {
          WORD wDrive = toupper (pszPathname[0]) - 'A' + 1;
          if (_chdrive (wDrive))
            {
              MessageBox ("Drive does not exist", pszPathname, NULL, MB_OK | 0x8000);
              return (NULL);
            }
          if (chdir (&pszPathname[2]))
            {
              MessageBox (pszPathNotThere, pszPathname, NULL, MB_OK | 0x8000);
              return (NULL);
            }
        }
      else
        if (chdir (pszPathname))
          {
            MessageBox (pszPathNotThere, pszPathname, NULL, MB_OK | 0x8000);
            return (NULL);
          }
    }


  /* Boot drive search */
  if (fSearchFlags & SEARCH_BOOT_DRIVE)
    {
      FindOnBootDrive (&pfi,
                       pDisk,
                       pOsVer,
                       pszFilename,
                       fSearchFlags);
    }
  else if (fSearchFlags & SEARCH_WINDIR)
    {
      /* Find the "windir=" environment variable */
      for (i = 0;
           environ[i][0] != '\0' && memcmp ("windir=", environ[i], 7) != 0;
           ++i)
        ;

      /* If found, put the fully qualified path into chWinDir */
      if (environ[i][0] == 'w')
        {
          /* Change to the drive and directory of the file */
          chDriveLetter = environ[i][7];
          chdir (&environ[i][9]);

          /* Find the file */
          FindFileOnDrive (&pfi,
                           pszFilename,
                           fSearchFlags,
                           chDriveLetter);
        }
      else
        {
          /* Free up pFileInfo */
          _ffree (pFileInfo);

          /* Set the flags for finding the windows file the hard way */
          fSearchFlags = SEARCH_LOCAL_DRIVES   |
                         SEARCH_ROOT           |
                         RECURSE_INTO_SUB_DIRS;

          /* Find the file */
          pFileInfo = FindFile (pszFilename, pszPathname,
                                fSearchFlags, chDriveLetter);
        }
    }
  else if (fSearchFlags & SEARCH_LANMAN_ROOT)
    {
      unsigned short int err=0, ta=0;
      struct wksta_info_0 *wksta0;
      char wkstabuf[BUFSIZ];
      CHAR chBuffer[_MAX_PATH + 1];

      /* Get the LANMAN root */
      err = NetWkstaGetInfo (NULL, 0, wkstabuf, BUFSIZ, &ta);
      if (err == 0)
        {
          wksta0 = (struct wksta_info_0 *) wkstabuf;
          _fmemcpy (chBuffer, wksta0->wki0_root, _MAX_PATH);

          /* Change to the drive and directory of the file */
          chDriveLetter = chBuffer[0];
          chdir (&chBuffer[2]);

          /* Find the file */
          FindFileOnDrive (&pfi,
                           pszFilename,
                           fSearchFlags,
                           chDriveLetter);
        }
      else
        {
          /* Free up pFileInfo */
          _ffree (pFileInfo);

          /* Set the flags for finding the LANMAN file the hard way */
          fSearchFlags = SEARCH_LOCAL_DRIVES   |
                         SEARCH_ROOT           |
                         RECURSE_INTO_SUB_DIRS;

          /* Find the file */
          pFileInfo = FindFile (pszFilename, pszPathname,
                                fSearchFlags, chDriveLetter);
        }
    }
  else if ((fSearchFlags & (SEARCH_FLOPPIES     |
                            SEARCH_LOCAL_DRIVES |
                            SEARCH_NET_DRIVES   |
                            SEARCH_BOOT_DRIVE)) == 0)
    {
      /* Single drive search */
      FindFileOnDrive (&pfi,
                       pszFilename,
                       fSearchFlags,
                       chDriveLetter);
    }
  else
    {
      /* Search 'em all */
      for (i = 0; i < pDisk->wNmbrDrives; ++i)
        {
          /* Floppy Search */
          if ((fSearchFlags & SEARCH_FLOPPIES) &&
              (pDisk->asdi[i].wDriveType == DISK_FLOPPY_DRIVE          ||
               pDisk->asdi[i].wDriveType == DISK_525_360K              ||
               pDisk->asdi[i].wDriveType == DISK_525_12M               ||
               pDisk->asdi[i].wDriveType == DISK_35_720K               ||
               pDisk->asdi[i].wDriveType == DISK_SINGLE_DENSITY_8_INCH ||
               pDisk->asdi[i].wDriveType == DISK_DOUBLE_DENSITY_8_INCH ||
               pDisk->asdi[i].wDriveType == DISK_35_144M               ||
               pDisk->asdi[i].wDriveType == DISK_OPTICAL_DISK          ||
               pDisk->asdi[i].wDriveType == DISK_35_288M))
            {
              FindFileOnDrive (&pfi,
                               pszFilename,
                               fSearchFlags,
                               pDisk->asdi[i].chDriveLetter);
            }

          /* Local drive search */
          if ((fSearchFlags & SEARCH_LOCAL_DRIVES) &&
              (pDisk->asdi[i].wDriveType == DISK_FIXED_DISK   ||
               pDisk->asdi[i].wDriveType == DISK_RAM_DISK     ||
               pDisk->asdi[i].wDriveType == DISK_CD_ROM_DRIVE ||
               pDisk->asdi[i].wDriveType == DISK_SUBST_DRIVE  ||
               pDisk->asdi[i].wDriveType == DISK_ASSIGN_DRIVE))
            {
              FindFileOnDrive (&pfi,
                               pszFilename,
                               fSearchFlags,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -