当前位置: 首页>>代码示例>>C++>>正文


C++ GetDriveType函数代码示例

本文整理汇总了C++中GetDriveType函数的典型用法代码示例。如果您正苦于以下问题:C++ GetDriveType函数的具体用法?C++ GetDriveType怎么用?C++ GetDriveType使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了GetDriveType函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Q_D

QIcon QFileIconProvider::icon(const QFileInfo &info) const
{
    Q_D(const QFileIconProvider);

    QIcon platformIcon = qt_guiPlatformPlugin()->fileSystemIcon(info);
    if (!platformIcon.isNull())
        return platformIcon;

#if defined(Q_WS_X11) && !defined(QT_NO_STYLE_GTK)
    if (X11->desktopEnvironment == DE_GNOME) {
        QIcon gtkIcon = QGtkStylePrivate::getFilesystemIcon(info);
        if (!gtkIcon.isNull())
            return gtkIcon;
    }
#endif

#ifdef Q_WS_MAC
    QIcon retIcon = d->getMacIcon(info);
    if (!retIcon.isNull())
        return retIcon;
#elif defined Q_WS_WIN
    QIcon icon = d->getWinIcon(info);
    if (!icon.isNull())
        return icon;
#elif defined Q_WS_HAIKU
    QIcon icon = d->getHaikuIcon(info);
    if (!icon.isNull())
        return icon;
#endif
    if (info.isRoot())
#if defined (Q_WS_WIN) && !defined(Q_WS_WINCE)
    {
        UINT type = GetDriveType((wchar_t *)info.absoluteFilePath().utf16());

        switch (type) {
        case DRIVE_REMOVABLE:
            return d->getIcon(QStyle::SP_DriveFDIcon);
        case DRIVE_FIXED:
            return d->getIcon(QStyle::SP_DriveHDIcon);
        case DRIVE_REMOTE:
            return d->getIcon(QStyle::SP_DriveNetIcon);
        case DRIVE_CDROM:
            return d->getIcon(QStyle::SP_DriveCDIcon);
        case DRIVE_RAMDISK:
        case DRIVE_UNKNOWN:
        case DRIVE_NO_ROOT_DIR:
        default:
            return d->getIcon(QStyle::SP_DriveHDIcon);
        }
    }
#else
    return d->getIcon(QStyle::SP_DriveHDIcon);
#endif
    if (info.isFile()) {
        if (info.isSymLink())
            return d->getIcon(QStyle::SP_FileLinkIcon);
        else
            return d->getIcon(QStyle::SP_FileIcon);
    }
  if (info.isDir()) {
    if (info.isSymLink()) {
      return d->getIcon(QStyle::SP_DirLinkIcon);
    } else {
      if (info.absoluteFilePath() == d->homePath) {
        return d->getIcon(QStyle::SP_DirHomeIcon);
      } else {
        return d->getIcon(QStyle::SP_DirIcon);
      }
    }
  }
  return QIcon();
}
开发者ID:diversys,项目名称:qt4,代码行数:72,代码来源:qfileiconprovider.cpp

示例2: defined

void Engine::checkCD() {
#if defined(WIN32) && !defined(_WIN32_WCE) && !defined(__SYMBIAN32__)
	// It is a known bug under Windows that games that play CD audio cause
	// ScummVM to crash if the data files are read from the same CD. Check
	// if this appears to be the case and issue a warning.

	// If we can find a compressed audio track, then it should be ok even
	// if it's running from CD.

#ifdef USE_VORBIS
	if (Common::File::exists("track1.ogg") ||
	    Common::File::exists("track01.ogg"))
		return;
#endif
#ifdef USE_FLAC
	if (Common::File::exists("track1.fla") ||
            Common::File::exists("track1.flac") ||
	    Common::File::exists("track01.fla") ||
	    Common::File::exists("track01.flac"))
		return;
#endif
#ifdef USE_MAD
	if (Common::File::exists("track1.mp3") ||
	    Common::File::exists("track01.mp3"))
		return;
#endif

	char buffer[MAXPATHLEN];
	int i;

	const Common::FSNode gameDataDir(ConfMan.get("path"));

	if (gameDataDir.getPath().empty()) {
		// That's it! I give up!
		if (getcwd(buffer, MAXPATHLEN) == NULL)
			return;
	} else
		Common::strlcpy(buffer, gameDataDir.getPath().c_str(), sizeof(buffer));

	for (i = 0; i < MAXPATHLEN - 1; i++) {
		if (buffer[i] == '\\')
			break;
	}

	buffer[i + 1] = 0;

	if (GetDriveType(buffer) == DRIVE_CDROM) {
		GUI::MessageDialog dialog(
			_("You appear to be playing this game directly\n"
			"from the CD. This is known to cause problems,\n"
			"and it is therefore recommended that you copy\n"
			"the data files to your hard disk instead.\n"
			"See the README file for details."), _("OK"));
		dialog.runModal();
	} else {
		// If we reached here, the game has audio tracks,
		// it's not ran from the CD and the tracks have not
		// been ripped.
		GUI::MessageDialog dialog(
			_("This game has audio tracks in its disk. These\n"
			"tracks need to be ripped from the disk using\n"
			"an appropriate CD audio extracting tool in\n"
			"order to listen to the game's music.\n"
			"See the README file for details."), _("OK"));
		dialog.runModal();
	}
#endif
}
开发者ID:DouglasLiuGamer,项目名称:residualvm,代码行数:68,代码来源:engine.cpp

示例3: GetLogicalDriveStrings

Driver *CFileServer::GetDrivers(int &Count)
{
	try
	{
		TCHAR szDrivesList[256]; // Format when filled : "C:\<NULL>D:\<NULL>....Z:\<NULL><NULL>"
		TCHAR szDrive[4];
		TCHAR szTheDrive[32];
		// TCHAR szName[255];
		TCHAR szType[16];
		UINT nType = 0;
		DWORD dwLen;
		int nIndex = 0;
		dwLen = GetLogicalDriveStrings(256, szDrivesList);
		Driver *driver = NULL;
		Driver *p = NULL;
		int k = 0;

		//Add the desktop to the driver list
		driver = new Driver;
		if(StrCmp(gl_strLanguageId, CHINESE) == 0)
			sprintf_s(driver->DriverName, "%s", szDesktop_CH);
		else
			sprintf_s(driver->DriverName, "%s", szDesktop_EN);
		p = driver;
		k ++;
		if(StrCmp(gl_strLanguageId, CHINESE) == 0)
			sprintf_s(szType, "%s", szLocalDisk_CH);
		else
			sprintf_s(szType, "%s", szLocalDisk_EN);


		// Parse the list of drives	
		while (nIndex < (int)(dwLen - 3))
		{
			strcpy_s(szDrive, szDrivesList + nIndex);
			nIndex += 4;
			szDrive[2] = '\0'; // remove the '\'
			sprintf_s(szTheDrive, "(%s)", szDrive);

			// szName[0] = '\0';
			szType[0] = '\0';

			strcat_s(szDrive, "\\");

			// GetVolumeInformation(szDrive, szName, sizeof(szName), NULL, NULL, NULL, NULL, NULL);

			// Get infos on the Drive (type and Name)
			nType = GetDriveType(szDrive);
			switch (nType)
			{
			case DRIVE_FIXED:
				if(StrCmp(gl_strLanguageId, CHINESE) == 0)
					sprintf_s(szType, "%s", szLocalDisk_CH);
				else
					sprintf_s(szType, "%s", szLocalDisk_EN);
				break;

			case DRIVE_REMOVABLE:
				if(StrCmp(gl_strLanguageId, CHINESE) == 0)
					sprintf_s(szType, "%s", szFloppy_CH);
				else
					sprintf_s(szType, "%s", szFloppy_EN);
				break;

			case DRIVE_CDROM:
				sprintf_s(szType, "%s", "CD-ROM");
				break;

			case DRIVE_REMOTE:
				if(StrCmp(gl_strLanguageId, CHINESE) == 0)
					sprintf_s(szType, "%s", szNetDriver_CH);
				else
					sprintf_s(szType, "%s", szNetDriver_EN);
				break;

			default:
				if(StrCmp(gl_strLanguageId, CHINESE) == 0)
					sprintf_s(szType, "%s", szUnknowDriver_CH);
				else
					sprintf_s(szType, "%s", szUnknowDriver_EN);
				break;
			}

			// Prepare it for Combo Box and add it
			strcat_s(szTheDrive, " - ");
			strcat_s(szTheDrive, szType);

			Driver *newDriver = new Driver;
			sprintf_s(newDriver->DriverName, szTheDrive);
			if(NULL == driver)
			{
				driver = newDriver;
				p = driver;
			}
			else
			{
				p->next = newDriver;
				p = newDriver;
			}
			k++;
//.........这里部分代码省略.........
开发者ID:uvbs,项目名称:myhistoryprojects,代码行数:101,代码来源:FileServer.cpp

示例4: SetErrorMode

BOOL bigfilehelper::GetAllVols(std::vector<VolInfo>& vVols)
{
    BOOL retval = FALSE;
    CAtlArray<TCHAR> buffer;
    TCHAR* pBuffer = NULL;
    DWORD dwSize;
    std::vector<CString> logicalDrvs;
    CString strDrv;
    POSITION pos = NULL;
    POSITION max_size_pos = NULL;
    ULONGLONG uMaxSize = 0;
    DWORD dwSectorsPerCluster;
    DWORD dwBytesPerSector;
    DWORD dwNumberOfFreeClusters;
    DWORD dwTotalNumberOfClusters;
    TCHAR szVolName[MAX_PATH+1] = { 0 };
    TCHAR szFileSystem[MAX_PATH+1] = { 0 };
    BOOL fRetCode;
    VolInfo volInfo;
    size_t idx;

    SetErrorMode(SEM_NOOPENFILEERRORBOX | SEM_FAILCRITICALERRORS);

    buffer.SetCount(512);
    pBuffer = buffer.GetData();
    dwSize = (DWORD)buffer.GetCount();
    memset(pBuffer, 0, dwSize * sizeof(TCHAR));
    dwSize = GetLogicalDriveStrings(dwSize, buffer.GetData());

    if (dwSize > 2)
    {
        strDrv = pBuffer;
        logicalDrvs.push_back(strDrv);

        for (DWORD i = 3; i < dwSize; ++i) 
        {
            if (pBuffer[i] != 0 && pBuffer[i - 1] == 0) 
            {
                strDrv = pBuffer + i;
                logicalDrvs.push_back(strDrv);
            }
        }
    }

    for (idx = 0; idx < logicalDrvs.size(); ++idx)
    {
        CString _drv = logicalDrvs[idx];
        BOOL bRemovable = FALSE;

        if (_drv.CompareNoCase(_T("a:\\")) == 0 || 
            _drv.CompareNoCase(_T("b:\\")) == 0)
        {
            continue;
        }

        UINT uType = GetDriveType(_drv);
        if (uType != DRIVE_FIXED &&
            uType != DRIVE_REMOVABLE)
        {
            continue;
        }

        if (DRIVE_REMOVABLE == uType)
            bRemovable = TRUE;

        RtlZeroMemory(szVolName, sizeof(szVolName));
        RtlZeroMemory(szFileSystem, sizeof(szFileSystem));
        fRetCode = GetVolumeInformation(
            _drv,
            szVolName,
            MAX_PATH+1,
            NULL,
            NULL,
            NULL,
            szFileSystem,
            MAX_PATH+1
            );
        if (!fRetCode)
        {
            continue;
        }

        fRetCode = GetDiskFreeSpace(
            _drv,
            &dwSectorsPerCluster,
            &dwBytesPerSector,
            &dwNumberOfFreeClusters,
            &dwTotalNumberOfClusters
            );
        if (!fRetCode)
        {
            continue;
        }

        volInfo.cVol = (char)_drv[0];
        volInfo.strVolName = szVolName;
        if (volInfo.strVolName.IsEmpty())
            volInfo.strVolName = _T("本地磁盘");
        volInfo.qwTotalSize = (ULONGLONG)dwTotalNumberOfClusters * dwBytesPerSector * dwSectorsPerCluster;
        volInfo.qwFreeSize = (ULONGLONG)dwNumberOfFreeClusters * dwBytesPerSector * dwSectorsPerCluster;
//.........这里部分代码省略.........
开发者ID:dreamsxin,项目名称:PcManager,代码行数:101,代码来源:bigfilehelper.cpp

示例5: LayThongTinODia

void LayThongTinODia(TCHAR *szODia, TCHAR *szThongTin)
{
	// Nhung bien nay dung cho ham GetVolumeInformation
	TCHAR szVolumeName[256];
	DWORD DWVolumeSerialNumber;
	DWORD DWMaximumComponentLength;
	DWORD DWFileSystemFlags;
	
	// Tat cac thong bao loi
	SetErrorMode(SEM_FAILCRITICALERRORS);

	DWErr = GetVolumeInformation(szODia, 
			szVolumeName, 256,
			&DWVolumeSerialNumber,
			&DWMaximumComponentLength,
			&DWFileSystemFlags,
			NULL, 0);
	if (DWErr == 0)
	{
		if (GetLastError() == 21) // Loi khong co dia trong o dia mem hoac CD-ROM
		{
			UINT t = GetDriveType(szODia);
			switch (t)
			{
			case DRIVE_CDROM:
				wcscpy_s(szVolumeName, _T("CD-ROM Drive"));
				break;
			case DRIVE_REMOVABLE:
				wcscpy_s(szVolumeName, _T("Floppy Drive"));
				break;
			}
		}
		else
			ErrorExit(_T("\"GetVolumeInformation\""));		
	}

	// Truong hop o dia khong co ten
	if (_tcslen(szVolumeName) == 0)
	{
		UINT t = GetDriveType(szODia);
		switch (t)
		{
		case DRIVE_CDROM:
			wcscpy_s(szVolumeName, _T("CD-ROM Drive"));
			break;
		case DRIVE_REMOVABLE:
			wcscpy_s(szVolumeName, _T("Removable Hard Disk"));
			break;
		case DRIVE_RAMDISK:
			wcscpy_s(szVolumeName, _T("RAM Disk"));
			break;
		case DRIVE_FIXED:
			wcscpy_s(szVolumeName, _T("Local Disk"));
			break;
		}
	}

	szODia[2] = '\0';
	wsprintf(szThongTin, _T("%s (%s)"), szVolumeName, szODia); 
	szODia[2] = '\\';

	// Bat lai cac thong bao loi
	SetErrorMode(0);
}
开发者ID:anhvinhitus,项目名称:myprojects2005-2009,代码行数:64,代码来源:stdafx.cpp

示例6: LogWarningF

/*
** Read the options specified in the ini file.
**
*/
void MeasureDiskSpace::ReadOptions(ConfigParser& parser, const WCHAR* section)
{
	double oldMaxValue = m_MaxValue;

	Measure::ReadOptions(parser, section);

	m_Drive = parser.ReadString(section, L"Drive", L"C:\\");
	if (m_Drive.empty())
	{
		LogWarningF(this, L"FreeDiskSpace: Drive= empty");
		m_Value = 0.0;
		m_MaxValue = 0.0;
		m_OldTotalBytes = 0;
		m_StringValue.clear();
	}
	else
	{
		// A trailing backslash is required for GetDiskFreeSpaceEx().
		PathUtil::AppendBacklashIfMissing(m_Drive);
	}

	m_Type = (1 == parser.ReadInt(section, L"Type", 0));
	m_Total = (1 == parser.ReadInt(section, L"Total", 0));
	m_Label = (1 == parser.ReadInt(section, L"Label", 0));
	m_IgnoreRemovable = (1 == parser.ReadInt(section, L"IgnoreRemovable", 1));
	m_DiskQuota = (1 == parser.ReadInt(section, L"DiskQuota", 1));
	
	// Set the m_MaxValue
	if (!m_Initialized)
	{
		BOOL result = FALSE;
		ULONGLONG i64TotalBytes;

		if (!m_Drive.empty())
		{
			const WCHAR* drive = m_Drive.c_str();
			UINT type = GetDriveType(drive);
			if (type != DRIVE_NO_ROOT_DIR &&
				type != DRIVE_CDROM &&
				(!m_IgnoreRemovable || type != DRIVE_REMOVABLE))  // Ignore CD-ROMS and removable drives
			{
				result = GetDiskFreeSpaceEx(drive, nullptr, (PULARGE_INTEGER)&i64TotalBytes, nullptr);
			}
		}

		if (result)
		{
			m_MaxValue = (double)(__int64)i64TotalBytes;
			m_OldTotalBytes = i64TotalBytes;
		}
		else
		{
			m_MaxValue = 0.0;
			m_OldTotalBytes = 0;
		}
	}
	else
	{
		if (m_Type)
		{
			m_MaxValue = DRIVETYPE_MAX;
			m_OldTotalBytes = 0;
		}
		else
		{
			m_MaxValue = oldMaxValue;
		}
	}
}
开发者ID:Geargia,项目名称:rainmeter,代码行数:73,代码来源:MeasureDiskSpace.cpp

示例7: is_cdrom

// takes a root drive path, returns true if it is a cdrom drive
bool is_cdrom(const char drive[])
{
	return (DRIVE_CDROM == GetDriveType(drive));
}
开发者ID:Everscent,项目名称:dolphin-emu,代码行数:5,代码来源:CDUtils.cpp

示例8: _tmain

int _tmain(int argc, _TCHAR* argv[])
{
	_tprintf ( _T(" Vireio DLL link Install/Uninstall Utility\r\n"));
	_tprintf ( _T(" -------------------------------------\r\n"));
	_tprintf ( _T("\r\n"));
	_tprintf ( _T("NOTE: THIS TOOL IS ONLY REQUIRED IF VIREIO DOES NOT INJECT WITH THE\r\n"));
	_tprintf ( _T("PERCEPTION APP RUNNING WHEN YOU START THE GAME\r\n"));
	_tprintf ( _T("\r\n"));
	std::string instructions;
	instructions += "This will create symbolic links to the Vireio DLLs in the target\r\n";
	instructions += "folder rather than physically copying them.\r\n";
	instructions += "To uninstall the symbolic links just run this application again\r\n";
	instructions += "and select the game folder and the symbolic links will be removed\r\n";
	instructions += "This means if you upgrade Vireio and put it in the same location as the\r\n";
	instructions += "previous version there is no need to re-run this installation tool\r\n";
	instructions += "This application needs to run as Administrator to create symlinks\r\n";
	instructions += "\r\n";
	instructions += "** Please select target game root folder in selection dialog **\r\n";
	_tprintf ( instructions.c_str());

	std::string rootFolder = GetLastPath();
	if (rootFolder.length() == 0)
	{
		std::string localDriveList;
		DWORD dw = GetLogicalDrives();
		char d[] = {'A', 0};
		while (dw)
		{
			if (dw & 1)
			{
				std::string drive = std::string(d) + ":\\";
				if (GetDriveType(drive.c_str()) == DRIVE_FIXED)
					localDriveList += d;
			}
			dw = dw >> 1;
			d[0]++;
		}

		std::vector<std::string> steamLocations;
		steamLocations.push_back(":\\Program Files (x86)\\Steam\\SteamApps\\common");
		steamLocations.push_back(":\\Program Files\\Steam\\SteamApps\\common");
		steamLocations.push_back(":\\Steam\\SteamApps\\common");

		bool foundPath = false;
		std::string steamLocation;
		for (int i = 0; (i < localDriveList.length() && !foundPath); i++)
		{
			//Attempt to find the right root folder
			int location = 0;
			while (location < (int)steamLocations.size())
			{
				std::string path = localDriveList[i] + steamLocations[location];
				if (PathFileExists(path.c_str()))
				{
					foundPath = true;
					steamLocation = path;
					break;
				}
				location++;
			}
		}

		if (!foundPath)
		{
			//Fail, just go to user's documents folder
			PWSTR pszPath = NULL;
			SHGetKnownFolderPath(FOLDERID_Documents, 0, NULL, &pszPath);
			char path[1024];
			size_t c  = 0;
			wcstombs_s(&c, path, pszPath, 1024);
			rootFolder = path;
		}
		else
			rootFolder =  steamLocation;
	}
开发者ID:blast007,项目名称:Perception,代码行数:75,代码来源:VireioDLLInstaller.cpp

示例9: GetDriveType

bool CSysInfo::GetDiskSpace(const std::string& drive,int& iTotal, int& iTotalFree, int& iTotalUsed, int& iPercentFree, int& iPercentUsed)
{
  bool bRet= false;
  ULARGE_INTEGER ULTotal= { { 0 } };
  ULARGE_INTEGER ULTotalFree= { { 0 } };

  if( !drive.empty() && drive != "*" )
  {
#ifdef TARGET_WINDOWS
    UINT uidriveType = GetDriveType(( drive + ":\\" ).c_str());
    if(uidriveType != DRIVE_UNKNOWN && uidriveType != DRIVE_NO_ROOT_DIR)
      bRet= ( 0 != GetDiskFreeSpaceEx( ( drive + ":\\" ).c_str(), NULL, &ULTotal, &ULTotalFree) );
#elif defined(TARGET_POSIX)
    bRet = (0 != GetDiskFreeSpaceEx(drive.c_str(), NULL, &ULTotal, &ULTotalFree));
#endif
  }
  else
  {
    ULARGE_INTEGER ULTotalTmp= { { 0 } };
    ULARGE_INTEGER ULTotalFreeTmp= { { 0 } };
#ifdef TARGET_WINDOWS
    char* pcBuffer= NULL;
    DWORD dwStrLength= GetLogicalDriveStrings( 0, pcBuffer );
    if( dwStrLength != 0 )
    {
      dwStrLength+= 1;
      pcBuffer= new char [dwStrLength];
      GetLogicalDriveStrings( dwStrLength, pcBuffer );
      int iPos= 0;
      do {
        if( DRIVE_FIXED == GetDriveType( pcBuffer + iPos  ) &&
            GetDiskFreeSpaceEx( ( pcBuffer + iPos ), NULL, &ULTotal, &ULTotalFree ) )
        {
          ULTotalTmp.QuadPart+= ULTotal.QuadPart;
          ULTotalFreeTmp.QuadPart+= ULTotalFree.QuadPart;
        }
        iPos += (strlen( pcBuffer + iPos) + 1 );
      }while( strlen( pcBuffer + iPos ) > 0 );
    }
    delete[] pcBuffer;
#else // for linux and osx
    if( GetDiskFreeSpaceEx( "/", NULL, &ULTotal, &ULTotalFree ) )
    {
      ULTotalTmp.QuadPart+= ULTotal.QuadPart;
      ULTotalFreeTmp.QuadPart+= ULTotalFree.QuadPart;
    }
#endif
    if( ULTotalTmp.QuadPart || ULTotalFreeTmp.QuadPart )
    {
      ULTotal.QuadPart= ULTotalTmp.QuadPart;
      ULTotalFree.QuadPart= ULTotalFreeTmp.QuadPart;
      bRet= true;
    }
  }

  if( bRet )
  {
    iTotal = (int)( ULTotal.QuadPart / MB );
    iTotalFree = (int)( ULTotalFree.QuadPart / MB );
    iTotalUsed = iTotal - iTotalFree;
    if( ULTotal.QuadPart > 0 )
    {
      iPercentUsed = (int)( 100.0f * ( ULTotal.QuadPart - ULTotalFree.QuadPart ) / ULTotal.QuadPart + 0.5f );
    }
    else
    {
      iPercentUsed = 0;
    }
    iPercentFree = 100 - iPercentUsed;
  }

  return bRet;
}
开发者ID:Inz999,项目名称:xbmc,代码行数:73,代码来源:SystemInfo.cpp

示例10: nt_get_filename_info


//.........这里部分代码省略.........
        /* FSCTL_GET_REPARSE_POINT? Enumerate mount points? */
        g_afNtfsDrives[iDrv] = 0;
        psz[0] = '\\';
        psz[1] = '\0';
#if 1
        hFile = CreateFile(pszFull,
                           GENERIC_READ,
                           FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
                           NULL,
                           OPEN_EXISTING,
                           FILE_FLAG_BACKUP_SEMANTICS,
                           NULL);
        if (hFile != INVALID_HANDLE_VALUE)
        {
            PMY_FILE_FS_ATTRIBUTE_INFORMATION pFsAttrInfo = (PMY_FILE_FS_ATTRIBUTE_INFORMATION)abBuf;

            memset(&Ios, 0, sizeof(Ios));
            rcNt = g_pfnNtQueryVolumeInformationFile(hFile, &Ios, abBuf, sizeof(abBuf),
                                                     MY_FileFsAttributeInformation);
            if (    rcNt >= 0
                //&&  pFsAttrInfo->FileSystemNameLength == 4
                &&  pFsAttrInfo->FileSystemName[0] == 'N'
                &&  pFsAttrInfo->FileSystemName[1] == 'T'
                &&  pFsAttrInfo->FileSystemName[2] == 'F'
                &&  pFsAttrInfo->FileSystemName[3] == 'S'
                &&  pFsAttrInfo->FileSystemName[4] == '\0')
            {
                memset(&Ios, 0, sizeof(Ios));
                rcNt = g_pfnNtQueryVolumeInformationFile(hFile, &Ios, &g_aVolumeInfo[iDrv],
                                                         sizeof(MY_FILE_FS_VOLUME_INFORMATION),
                                                         MY_FileFsVolumeInformation);
                if (rcNt >= 0)
                {
                    DWORD dwDriveType = GetDriveType(pszFull);
                    if (    dwDriveType == DRIVE_FIXED
                        ||  dwDriveType == DRIVE_RAMDISK)
                        g_afNtfsDrives[iDrv] = 1;
                }
            }
            CloseHandle(hFile);
        }
#else
        {
            char szFSName[32];
            if (    GetVolumeInformation(pszFull,
                                         NULL, 0,   /* volume name */
                                         NULL,      /* serial number */
                                         NULL,      /* max component */
                                         NULL,      /* volume attribs */
                                         szFSName,
                                         sizeof(szFSName))
                &&  !strcmp(szFSName, "NTFS"))
            {
                g_afNtfsDrives[iDrv] = 1;
            }
        }
#endif
    }
    if (!g_afNtfsDrives[iDrv])
        return -1;

    /*
     * Try open the path and query its file name information.
     */
    hFile = CreateFile(pszPath,
                       GENERIC_READ,
开发者ID:egraba,项目名称:kbuild_openbsd,代码行数:67,代码来源:nt_fullpath.c

示例11: eject_drive_letter

static BOOL
eject_drive_letter(WCHAR DriveLetter) {
    LPWSTR szRootPath = L"X:\\", 
           szDevicePath = L"X:", 
           szVolumeAccessPath = L"\\\\.\\X:";
    WCHAR  szDosDeviceName[MAX_PATH];
    long DeviceNumber, res, tries;
    HANDLE hVolume; 
    STORAGE_DEVICE_NUMBER sdn;
    DWORD dwBytesReturned;
    DEVINST DevInst;
    ULONG Status;
    ULONG ProblemNumber;
    UINT DriveType;
    PNP_VETO_TYPE VetoType;
    WCHAR VetoNameW[MAX_PATH];
    BOOL bSuccess;
    DEVINST DevInstParent;
    
    szRootPath[0] = DriveLetter;
    szDevicePath[0] = DriveLetter;
    szVolumeAccessPath[4] = DriveLetter;

    DeviceNumber = -1;

    hVolume = CreateFile(szVolumeAccessPath, 0,
                        FILE_SHARE_READ | FILE_SHARE_WRITE,
                        NULL, OPEN_EXISTING, 0, NULL);
    if (hVolume == INVALID_HANDLE_VALUE) {
        PyErr_SetString(PyExc_ValueError, "Invalid handle value for drive letter");
        return FALSE;
    }

    dwBytesReturned = 0;
    res = DeviceIoControl(hVolume,
                        IOCTL_STORAGE_GET_DEVICE_NUMBER,
                        NULL, 0, &sdn, sizeof(sdn),
                        &dwBytesReturned, NULL);
    if ( res ) {
        DeviceNumber = sdn.DeviceNumber;
    }
    CloseHandle(hVolume);

    if ( DeviceNumber == -1 ) {
        PyErr_SetString(PyExc_ValueError, "Can't find drive number");
        return FALSE;
    }

    res = QueryDosDevice(szDevicePath, szDosDeviceName, MAX_PATH);
    if ( !res ) {
       PyErr_SetString(PyExc_ValueError, "Can't find dos device");
       return FALSE;
    }

    DriveType = GetDriveType(szRootPath);

    DevInst = GetDrivesDevInstByDeviceNumber(DeviceNumber,
                  DriveType, szDosDeviceName);
    if (DevInst == 0) return FALSE;

    DevInstParent = 0;
    Status = 0;
    ProblemNumber = 0;
    bSuccess = FALSE;

    res = CM_Get_Parent(&DevInstParent, DevInst, 0);

    for ( tries = 0; tries < 3; tries++ ) {
        VetoNameW[0] = 0;

        res = CM_Request_Device_EjectW(DevInstParent,
                &VetoType, VetoNameW, MAX_PATH, 0);

        bSuccess = (res==CR_SUCCESS &&
                            VetoType==PNP_VetoTypeUnknown);
        if ( bSuccess )  {
            break;
        }

        Sleep(500); // required to give the next tries a chance!
    }
    if (!bSuccess)  PyErr_SetString(PyExc_ValueError, "Failed to eject drive after three tries");
    return bSuccess;
}
开发者ID:yeyanchao,项目名称:calibre,代码行数:84,代码来源:winutil.c

示例12: get_all_removable_disks

BOOL
get_all_removable_disks(struct tagDrives *g_drives)
{
    WCHAR	caDrive[4];
	WCHAR	volume[BUFSIZE];
	int		nLoopIndex;
	DWORD	dwDriveMask;
	unsigned int g_count=0;


	caDrive[0]	= 'A';
    caDrive[1]	= ':';
    caDrive[2]	= '\\';
    caDrive[3]	= 0;





	// Get all drives in the system.
    dwDriveMask = GetLogicalDrives();


	if(dwDriveMask == 0)
	{
		PyErr_SetString(DriveError, "GetLogicalDrives failed");
		return FALSE;
	}


	// Loop for all drives (MAX_DRIVES = 26)


    for(nLoopIndex = 0; nLoopIndex < MAX_DRIVES; nLoopIndex++)
    {
        // if a drive is present (we cannot ignore the A and B drives as there
        // are people out there that think mapping devices to use those letters
        // is a good idea, sigh)
		if(dwDriveMask & 1)
        {
            caDrive[0] = 'A' + nLoopIndex;


			// If a drive is removable
			if(GetDriveType(caDrive) == DRIVE_REMOVABLE)
			{
				//Get its volume info and store it in the global variable.
				if(GetVolumeNameForVolumeMountPoint(caDrive, volume, BUFSIZE))
	            {
		            g_drives[g_count].letter = caDrive[0];
					wcscpy_s(g_drives[g_count].volume, BUFSIZE, volume);
					g_count ++;
				}

			}
		}
		dwDriveMask >>= 1;
	}


	// success if atleast one removable drive is found.
	if(g_count == 0)
	{
	    PyErr_SetString(DriveError, "No removable drives found");
		return FALSE;
	}
	return TRUE;

}
开发者ID:yeyanchao,项目名称:calibre,代码行数:69,代码来源:winutil.c

示例13: GetSystemInfo


//.........这里部分代码省略.........
         }
         break;
      case VER_PLATFORM_WIN32_WINDOWS:
         if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 0)
         {
             strcat(sysinfo.os,"Microsoft Windows 95 ");
             if ( osvi.szCSDVersion[1] == 'C' || osvi.szCSDVersion[1] == 'B' )
                strcat(sysinfo.os,"OSR2 " );
         } 

         if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 10)
         {
             strcat(sysinfo.os,"Microsoft Windows 98 ");
             if ( osvi.szCSDVersion[1] == 'A' )
                strcat(sysinfo.os,"SE " );
         } 

         if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 90)
         {
             strcat(sysinfo.os,"Microsoft Windows Millennium Edition ");
         } 
         break;
    }
	///////////get disk space/////////////
	sysinfo.disk[0]=0;
	strcat(sysinfo.disk,"磁盘空间: ");
	DWORD maskdriver;
	ULONGLONG totalspace=0,freespace=0;
	ULONGLONG ulltotalspace,ullfreespace,freebyte;
	DWORD drivertype;
	char driver[10];
	if(!(maskdriver=GetLogicalDrives()))
		return false;
	for(int i=0;i<26;i++)
	{
		if(!(maskdriver>>i))
			break;
		if(maskdriver>>i&1)
		{
			driver[0]=i+'A';
			driver[1]=':';
			driver[2]='\\';
			driver[3]=0;
			drivertype=GetDriveType(driver);
			if(drivertype!=DRIVE_FIXED)
				continue;
			if(!GetDiskFreeSpaceEx (driver,
							(PULARGE_INTEGER)&freebyte,
							(PULARGE_INTEGER)&ulltotalspace,
							(PULARGE_INTEGER)&ullfreespace))
							return false;
			totalspace+=ulltotalspace;
			freespace+=ullfreespace;
		}
	}
	signed __int64 dfreespace=0.0,dtotalspace=0.0,lv;
	dfreespace=(signed __int64)freespace/(1024*1024*1024);
	dtotalspace=(signed __int64)totalspace/(1024*1024*1024);
	lv=(signed __int64)freespace/totalspace*100;
	char space[256];
	sprintf(space,"总磁盘空间为:%.2fG,剩余磁盘空间为:%.2fG(占%.2f%c)",dtotalspace,dfreespace,lv,'%');
	strcat(sysinfo.disk,space);
	////////////////get cpu info//////////////////
	sysinfo.processor[0]=0;
	strcat(sysinfo.processor,"CPU: ");
	HKEY hKey;
	char szcpuinfo[80];
	DWORD dwBufLen=80;
	RegOpenKeyEx( HKEY_LOCAL_MACHINE,
	   "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0",
	   0, KEY_QUERY_VALUE, &hKey );
	RegQueryValueEx( hKey, "VendorIdentifier", NULL, NULL,
	   (LPBYTE)szcpuinfo, &dwBufLen);
	szcpuinfo[dwBufLen]=0;
	strcat(sysinfo.processor,szcpuinfo);
	strcat(sysinfo.processor," ");
	memset(szcpuinfo,0,80);
	dwBufLen=80;
	RegQueryValueEx( hKey, "Identifier", NULL, NULL,
	   (LPBYTE)szcpuinfo, &dwBufLen);
	szcpuinfo[dwBufLen]=0;
	strcat(sysinfo.processor,szcpuinfo);
	DWORD f;
	dwBufLen=8;
	RegQueryValueEx( hKey, "~MHz", NULL, NULL,
	   (LPBYTE)&f, &dwBufLen);
	char hz[10];
	sprintf(hz," %dMHZ",f);
	strcat(sysinfo.processor,hz);
	RegCloseKey(hKey);
	/////////////get mem size////////////
	MEMORYSTATUS ms;
	GlobalMemoryStatus(&ms);
	char membuf[256];
	sprintf(membuf,"物理内存: 总物理内存:%dMB,可用内存:%dMB (占%.2f%s)",ms.dwTotalPhys/1024/1024,ms.dwAvailPhys/1024/1024
		,(double)ms.dwAvailPhys/ms.dwTotalPhys*100,"%");
	sysinfo.mem[0]=0;
	strcpy(sysinfo.mem,membuf);
	return true; 
}
开发者ID:dalinhuang,项目名称:screen-contorl,代码行数:101,代码来源:SystemInit.cpp

示例14: fileselector

int fileselector(char *name, char *path, char *filter, char *title, int filemode)
{
  int c, d, scrrep;
  int color;
  int files;
  int filepos = 0;
  int fileview = 0;
  int lastclick = 0;
  int lastfile = 0;
  int lowest;
  int exitfilesel;

  DIR *dir;
  struct dirent *de;
  struct stat st;
  #ifdef __WIN32__
  char drivestr[] = "A:\\";
  char driveexists[26];
  #endif
  char cmpbuf[MAX_PATHNAME];
  char tempname[MAX_PATHNAME];

  // Set initial path (if any)
  if (strlen(path)) chdir(path);

  // Scan for all existing drives
  #ifdef __WIN32__
  for (c = 0; c < 26; c++)
  {
    drivestr[0] = 'A'+c;
    if (GetDriveType(drivestr) > 1) driveexists[c] = 1;
    else driveexists[c] = 0;
  }
  #endif

  // Read new directory
  NEWPATH:
  getcwd(path, MAX_PATHNAME);
  files = 0;
  // Deallocate old names
  for (c = 0; c < MAX_DIRFILES; c++)
  {
    if (direntry[c].name)
    {
      free(direntry[c].name);
      direntry[c].name = NULL;
    }
  }
  #ifdef __WIN32__
  // Create drive letters
  for (c = 0; c < 26; c++)
  {
    if (driveexists[c])
    {
      drivestr[0] = 'A'+c;
      direntry[files].name = strdup(drivestr);
      direntry[files].attribute = 2;
      files++;
    }
  }
  #endif

  // Process directory
  #ifdef __amigaos__
  dir = opendir("");
  #else
  dir = opendir(".");
  #endif
  if (dir)
  {
    char *filtptr = strstr(filter, "*");
    if (!filtptr) filtptr = filter;
    else filtptr++;
    for (c = 0; c < strlen(filter); c++)
      filter[c] = tolower(filter[c]);

    while ((de = readdir(dir)))
    {
      if ((files < MAX_DIRFILES) && (strlen(de->d_name) < MAX_FILENAME))
      {
        direntry[files].name = strdup(de->d_name);
        direntry[files].attribute = 0;
        stat(de->d_name, &st);
        if (st.st_mode & S_IFDIR)
        {
          direntry[files].attribute = 1;
          files++;
        }
        else
        {
          int c;
          // If a file, must match filter
          strcpy(cmpbuf, de->d_name);
          if ((!strcmp(filtptr, "*")) || (!strcmp(filtptr, ".*")))
            files++;
          else
          {
            for (c = 0; c < strlen(cmpbuf); c++)
              cmpbuf[c] = tolower(cmpbuf[c]);
            if (strstr(cmpbuf, filtptr))
//.........这里部分代码省略.........
开发者ID:suda,项目名称:goattrk2,代码行数:101,代码来源:gfile.c

示例15: jnm_getdriveinfo

JNIEXPORT jobject JNICALL jnm_getdriveinfo(JNIEnv *env, jobject obj, jobject file)
{
  jclass dic = jnismooth_dll->findClass("jsmooth.DriveInfo");
  if (dic == 0)
    {
      return NULL;
    }

  jmethodID construc = jnismooth_dll->findMethod(dic, "<init>", "()V", false);
  if (construc == 0)
    {
      return NULL;
    }

  JMethodCaller canonicalcaller("java.io.File", "java.lang.String getCanonicalPath()");
  jvalue vals[0];

  jvalue canonicalval = canonicalcaller.invoke(*jnismooth_dll, file, vals);
  jstring jcanstr = (jstring)canonicalval.l;

  jboolean copy = true;
  const char* str = jnismooth_dll->env()->GetStringUTFChars(jcanstr, &copy);
  std::string canonicalfile = str;
  jnismooth_dll->env()->ReleaseStringUTFChars(jcanstr, str);

  //  int driveType = GetDriveType();
  jobject driveinfo = jnismooth_dll->env()->NewObject(dic, construc);
  if ((canonicalfile.length()>1) && (canonicalfile[1] == ':'))
    {
      std::string driveletter = canonicalfile[0] + std::string(":\\");
      int drivetype = GetDriveType(driveletter.c_str());
      jnismooth_dll->setIntField(dic, driveinfo, "m_driveType", drivetype);

      void * pGetDiskFreeSpaceEx = (void*)GetProcAddress(GetModuleHandle("kernel32.dll"), "GetDiskFreeSpaceExA");
      long freeBytes = 0, totalBytes = -1, totalFreeBytes = 0;

      if ((pGetDiskFreeSpaceEx != 0) && (drivetype > 1))
	{
	  unsigned __int64 lpFreeBytesAvailable, lpTotalNumberOfBytes, lpTotalNumberOfFreeBytes;
	  if (GetDiskFreeSpaceEx(driveletter.c_str(), (_ULARGE_INTEGER*)&lpFreeBytesAvailable, (_ULARGE_INTEGER*)&lpTotalNumberOfBytes, (_ULARGE_INTEGER*)&lpTotalNumberOfFreeBytes))
	    {
	      freeBytes = lpFreeBytesAvailable;
	      totalBytes = lpTotalNumberOfBytes;
	      totalFreeBytes = lpTotalNumberOfFreeBytes;
	    }
	}
      else if (drivetype > 1)
	{
	  DWORD dwSectPerClust, dwBytesPerSect, dwFreeClusters, dwTotalClusters;
	  if (GetDiskFreeSpace(driveletter.c_str(), &dwSectPerClust, &dwBytesPerSect, &dwFreeClusters, &dwTotalClusters))
	    {
	      freeBytes = ((long)dwBytesPerSect * (long)dwSectPerClust * (long)dwFreeClusters);
	      totalBytes = ((long)dwBytesPerSect * (long)dwSectPerClust * (long)dwTotalClusters);
	      totalFreeBytes = ((long)dwBytesPerSect * (long)dwSectPerClust * (long)dwFreeClusters);
	    }
	}

      jnismooth_dll->setLongField(dic, driveinfo, "m_freeBytesForUser", freeBytes);      
      jnismooth_dll->setLongField(dic, driveinfo, "m_totalFreeBytes", totalFreeBytes);      
      jnismooth_dll->setLongField(dic, driveinfo, "m_totalBytes", totalBytes);

      
      if (drivetype > 1)
	{
	  char volumename[MAX_PATH+1], filesystemname[MAX_PATH+1];
	  DWORD serialnumber, maxcomposize, systemflags;
	  if (GetVolumeInformation( driveletter.c_str(), volumename, MAX_PATH, 
				    &serialnumber, &maxcomposize, &systemflags,
				    filesystemname, MAX_PATH))
	    {
	      jnismooth_dll->setIntField(dic, driveinfo, "m_serialNumber", serialnumber);
	      jnismooth_dll->setIntField(dic, driveinfo, "m_maxComponentSize", maxcomposize);
	      jnismooth_dll->setIntField(dic, driveinfo, "m_systemFlags", systemflags);

	      jstring jvolumename = jnismooth_dll->newUTFString(volumename);
	      jstring jfilesystemname = jnismooth_dll->newUTFString(filesystemname);
	      jnismooth_dll->setObjectField(dic, driveinfo, "m_volumeName", "java.lang.String", (jobject)jvolumename);
	      jnismooth_dll->setObjectField(dic, driveinfo, "m_fileSystemName", "java.lang.String", (jobject)jfilesystemname);
	    }	  
	}
    }
  
    //  jfieldID binding = broker->env()->GetFieldID(nat, "m_", "I");
  // broker->env()->SetStaticBooleanField(nat, binding, JNI_TRUE);

  return driveinfo;
}
开发者ID:jamesdlow,项目名称:jsmooth,代码行数:87,代码来源:JniSmooth.cpp


注:本文中的GetDriveType函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。