📄 msdsys.c
字号:
pDisk->asdi[i].chDriveLetter);
}
/* Remote/Net drive search */
if ((fSearchFlags & SEARCH_NET_DRIVES) &&
pDisk->asdi[i].wDriveType == DISK_REMOTE_DRIVE)
{
FindFileOnDrive (&pfi,
pszFilename,
fSearchFlags,
pDisk->asdi[i].chDriveLetter);
}
}
}
/* Restore the current drive and directory */
_chdrive (wCurrentDrive);
chdir (chCurrentPath);
/* Free up the disk and operating system info */
free (pDisk);
free (pOsVer);
return (pFileInfo);
}
/*********************************************************************
* FindOnBootDrive - Finds a particular file on the boot drive. If
* the operating system does not have the ability
* to return the boot drive, it will check the first
* hard disk, the first floppy, then all other
* drives on the system (based on the flags set in
* fSearchFlags, of course).
*
* ppFileInfo - Pointer to file info structure's pointer.
* pszFilename - Filename to search for.
* fSearchFlags - Flags to control the search.
*
* Returns: TRUE if an error occured.
*********************************************************************/
BOOL FindOnBootDrive (FILE_INFO FAR * FAR *ppFileInfo,
DISK_STRUCT *pDisk,
OS_VERSION_STRUCT *pOsVer,
PSZ pszFilename,
BOOL fSearchFlags)
{
BOOL fSkipFirstFloppy = TRUE; /* Allows us to skip drives */
BOOL fSkipFirstHardDisk = TRUE; /* we already checked */
/* Check to see if DOS can tell us it's boot drive */
if (pOsVer->wDosMajor >= 4)
{
/* Set the flags for the appropriate search */
fSearchFlags = fSearchFlags | SEARCH_ROOT;
/* Find it */
FindFileOnDrive (ppFileInfo,
pszFilename,
fSearchFlags,
pOsVer->chDosBootDrive);
}
else
{
WORD i; /* Looping variable */
/* We have to hunt for a suitable boot drive */
/* Set the flags for the appropriate search */
fSearchFlags = fSearchFlags |
SEARCH_FLOPPIES |
SEARCH_LOCAL_DRIVES |
SEARCH_ROOT;
/* Check the first hard disk */
if (fSearchFlags & SEARCH_LOCAL_DRIVES)
{
for (i = 0; i < pDisk->wNmbrDrives; ++i)
{
if (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 (ppFileInfo,
pszFilename,
fSearchFlags,
pDisk->asdi[i].chDriveLetter);
break;
}
}
}
/* Check the first floppy */
if (fSearchFlags & SEARCH_FLOPPIES)
{
for (i = 0; i < pDisk->wNmbrDrives; ++i)
{
if (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 (ppFileInfo,
pszFilename,
fSearchFlags,
pDisk->asdi[i].chDriveLetter);
break;
}
}
}
/* Check all other drives */
for (i = 0; i < pDisk->wNmbrDrives; ++i)
{
/* Floppy drive check */
if (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)
{
if (fSearchFlags & SEARCH_FLOPPIES)
{
/* This is a floppy and we are */
/* searching floppies. */
if (fSkipFirstFloppy)
{
fSkipFirstFloppy = FALSE;
continue;
}
FindFileOnDrive (ppFileInfo,
pszFilename,
fSearchFlags,
pDisk->asdi[i].chDriveLetter);
continue;
}
else
{
/* This is a floppy, and we aren't */
/* searching floppies. */
continue;
}
}
/* Hard Disk check */
if (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)
{
if (fSearchFlags & SEARCH_LOCAL_DRIVES)
{
/* This is a hard disk and we are */
/* searching hard disks. */
if (fSkipFirstHardDisk)
{
fSkipFirstHardDisk = FALSE;
continue;
}
FindFileOnDrive (ppFileInfo,
pszFilename,
fSearchFlags,
pDisk->asdi[i].chDriveLetter);
continue;
}
else
{
/* This is a hard disk, and we aren't */
/* searching hard disks. */
continue;
}
}
/* Network drive type check */
if (pDisk->asdi[i].wDriveType == DISK_REMOTE_DRIVE)
{
if (fSearchFlags & SEARCH_NET_DRIVES)
{
/* This is a remote drive and we are */
/* searching remote drives. */
FindFileOnDrive (ppFileInfo,
pszFilename,
fSearchFlags,
pDisk->asdi[i].chDriveLetter);
continue;
}
else
{
/* This is a remote drive, and we aren't */
/* searching remote drives. */
continue;
}
}
}
}
return (FALSE);
}
/*********************************************************************
* FindFileOnDrive - Searches a single drive for the appropriate
* file(s).
*
* ppFileInfo - Pointer to current file info structure.
* pszFilename - Pointer to filename to search for.
* fSearchFlags - Flags to control the searching method.
* chDriveLetter - Drive to search.
*
* Returns: TRUE if an error occured.
*********************************************************************/
BOOL FindFileOnDrive (FILE_INFO FAR * FAR *ppFileInfo,
PSZ pszFilename,
BOOL fSearchFlags,
CHAR chDriveLetter)
{
CHAR chCurrentPath[_MAX_PATH + 1]; /* Stores current drive & directory */
WORD wCurrentDrive; /* Stores the current drive number */
WORD wReturnValue; /* Return value from some functions */
/* Change to the requested drive */
if (chDriveLetter != '\0')
{
wReturnValue = _chdrive (chDriveLetter - 'A' + 1);
if (wReturnValue != 0 || fCriticalError)
{
fCriticalError = FALSE;
return (TRUE);
}
}
/* Save the current drive and directory */
wCurrentDrive = _getdrive();
_getdcwd (wCurrentDrive, chCurrentPath, _MAX_PATH);
/* Change to the root directory, if necessary */
if (fSearchFlags & SEARCH_ROOT)
{
wReturnValue = chdir ("\\");
if (wReturnValue != 0 || fCriticalError)
{
fCriticalError = FALSE;
return (TRUE);
}
}
/* Search the current working directory */
wReturnValue = FindFileInCwd (ppFileInfo, pszFilename, fSearchFlags);
if (wReturnValue)
return (wReturnValue);
/* Restore the current drive and directory */
_chdrive (wCurrentDrive);
chdir (chCurrentPath);
return (FALSE);
}
/*********************************************************************
* FindFileInCwd - Searches the current working directory for the
* appropriate file(s).
*
* ppFileInfo - Pointer to current file info structure.
* pszFilename - Pointer to filename to search for.
* fSearchFlags - Flags to control the searching method.
*
* Returns: TRUE if an error occured.
*********************************************************************/
BOOL FindFileInCwd (FILE_INFO FAR * FAR *ppFileInfo,
PSZ pszFilename,
BOOL fSearchFlags)
{
WORD wReturnValue; /* Return value from _dos_findfirst/next */
struct find_t ft; /* Structure of file data */
FILE_INFO FAR *pfi = NULL; /* Far pointer to a file info structure */
PSZ pszCurrentDir = NULL; /* Stores current directory */
wReturnValue = _dos_findfirst (pszFilename, 0xFFFF, &ft);
if (wReturnValue == 0 && fCriticalError == FALSE)
{
do
{
/* Search was successful */
if (++wNmbrFound > 255)
{
MessageBox ("255 Files Maximum", NULL, NULL, MB_OK | 0x8000);
return (TRUE);
}
/* Find a new place to store information */
pfi = _fmalloc (sizeof (FILE_INFO));
if (pfi == NULL)
{
OutOfMemory();
return (TRUE);
}
/* Zero out pfi's "next" pointer */
pfi->fpNextFileInfo = NULL;
/* Make current pointer's "next" pointer point to */
/* this new location. */
(*ppFileInfo)->fpNextFileInfo = (VOID FAR *) pfi;
/* Fill in the values */
(*ppFileInfo)->bAttrib = ft.attrib;
(*ppFileInfo)->wTime = ft.wr_time;
(*ppFileInfo)->wDate = ft.wr_date;
(*ppFileInfo)->dwSize = ft.size;
/* Put in the fully qualified path */
pszCurrentDir = malloc (_MAX_PATH + 1);
if (pszCurrentDir == NULL)
{
OutOfMemory();
return (TRUE);
}
if (_getdcwd (0, pszCurrentDir, _MAX_PATH) == NULL)
{
free (pszCurrentDir);
OutOfMemory();
return (TRUE);
}
if (pszCurrentDir[strlen (pszCurrentDir) - 1] != '\\')
strcat (pszCurrentDir, "\\");
strcat (pszCurrentDir, ft.name);
/* Find a new place to store the path to the file */
(*ppFileInfo)->fpszPathToFile =
_fmalloc (strlen (pszCurrentDir) + 1);
if ((*ppFileInfo)->fpszPathToFile == NULL)
{
free (pszCurrentDir);
OutOfMemory();
return (TRUE);
}
_fstrcpy ((*ppFileInfo)->fpszPathToFile,
(CHAR FAR *) pszCurrentDir);
/* Get the version number info */
if (fSearchFlags & SEARCH_VERSION)
{
BYTE * pVer, * pVer2; /* VS_VERSION_INFO "struct" */
VS_FIXEDFILEINFO *pValue; /* VS_FIXEDFILEINFO struct */
/* Get the version "structs" */
pVer = GetFileVersion (pszCurrentDir, TRUE);
/* Store a duplicate for free'ing purposes */
pVer2 = pVer;
if (pVer != NULL)
{
/* Align pVer on a 32 bit boundary */
pVer = DWORDUP (pVer);
/* Move past the first two WORDs */
pVer += 4;
/* Move past the string */
while (*pVer != '\0')
++pVer;
/* Set the pValue structure pointer */
pValue = (VS_FIXEDFILEINFO *) (DWORDUP (pVer + 1));
/* Set the values in the fileinfo structure */
(*ppFileInfo)->dwFileVersionMS = pValue->dwFileVersionMS;
(*ppFileInfo)->dwFileVersionLS = pValue->dwFileVersionLS;
/* Free up the memory allocated in GetFileVersion */
free (pVer2);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -