void ipod_device_t::get_capacity_information (drive_space_info_t & p_info) { if (mobile) { if (mobile_device.is_valid()) { in_mobile_device_api_handle_sync lockedAPI(mobile_device->m_api); if (lockedAPI.is_valid()) { afc_dictionary * p_dict = NULL; afc_error_t err = lockedAPI->AFCDeviceInfoOpen(mobile_device->m_pafc, &p_dict); //console::formatter() << "AFCDeviceInfoOpen called, Ret: " << err; _check_afc_ret(err, "AFCDeviceInfoOpen"); bool b_freefound = false, b_totalfound = false, b_clusterfound = false; char *key = NULL, *val = NULL; while ((lockedAPI->AFCKeyValueRead(p_dict, &key, &val) == MDERR_OK) && key && val) { if (!strcmp(key, "FSTotalBytes")) { p_info.m_capacity = strtoul64_n(val, pfc_infinite); b_totalfound = true; } else if (!strcmp(key, "FSFreeBytes")) { p_info.m_freespace = strtoul64_n(val, pfc_infinite); b_freefound = true; } else if (!strcmp(key, "FSBlockSize")) { p_info.m_blocksize = strtoul_n(val, pfc_infinite); b_clusterfound = true; } } lockedAPI->AFCKeyValueClose(p_dict); if (!b_totalfound) throw pfc::exception("AFCDeviceInfo: FSTotalBytes not found"); if (!b_freefound) throw pfc::exception("AFCDeviceInfo: FSFreeBytes not found"); if (!b_clusterfound) throw pfc::exception("AFCDeviceInfo: FSBlockSize not found"); #if 0 cfobject::object_t::ptr_t disk_usage; CFTypeRef ref = NULL; ref = api->AMDeviceCopyValue(p_ipod->mobile_device->m_device, mobile_device->m_api->_CFSTR("com.apple.disk_usage"), NULL); g_get_CFType_object(api, ref, disk_usage); if (ref) { api->CFRelease(ref); ref = NULL; } if (disk_usage.is_valid()) { t_size i, count = disk_usage->m_dictionary.get_count(); for (i=0; i<count; i++) { if (disk_usage->m_dictionary[i].m_key.is_valid() && disk_usage->m_dictionary[i].m_value.is_valid()) { if (!_wcsicmp(disk_usage->m_dictionary[i].m_key->m_string.get_ptr(), L"TotalDataCapacity")) { batteryLevel = (disk_usage->m_dictionary[i].m_value->m_integer); } } } } #endif } } else throw pfc::exception_bug_check(); } else { pfc::array_t<WCHAR> str; str.append_single(drive); str.append_fromptr(L":\\", 3); ULARGE_INTEGER ufree = {0}, utotal = {0}; GetDiskFreeSpaceEx (str.get_ptr(), &ufree, &utotal, NULL); p_info.m_freespace = ufree.QuadPart; p_info.m_capacity = utotal.QuadPart; DWORD sectorspercluster=NULL, bytespersector=NULL; GetDiskFreeSpace(str.get_ptr(), §orspercluster, &bytespersector, NULL, NULL); p_info.m_blocksize = bytespersector*sectorspercluster; } }
QList<DiskInfo> GetLocalDiskList(quint64 minSizeInGb, const QString &type, const QString &table){ QList<DiskInfo> disklist; QFileInfoList devlist = QDir::drives(); for (int i = 0; i < devlist.size(); ++i) { QString devname = QDir::toNativeSeparators(devlist.at(i).path().toUpper()).remove("\\"); if (GetDriveType(LPWSTR(devname.utf16())) == DRIVE_FIXED) { ULARGE_INTEGER FreeAv,TotalBytes,FreeBytes; if (!GetDiskFreeSpaceEx(LPWSTR(devname.utf16()),&FreeAv,&TotalBytes,&FreeBytes)) { continue; } if ((FreeBytes.QuadPart/(1024*1024*1024)) < minSizeInGb) { qDebug()<<"Skip Disk"<<devname<<"Space not enough"<<FreeBytes.QuadPart/(1024*1024*1024); continue; } PARTITION_INFORMATION_EX piex; Xapi::GetPartitionEx (devname, &piex); QString format = "Unknow"; PartitonStyle style; switch (piex.PartitionStyle) { case PARTITION_STYLE_MBR: style = MBRPartition; if (!table.toUpper ().contains ("MBR")) { qDebug()<<"Skip Disk"<<devname<<"MBR"; continue; } switch (piex.Mbr.PartitionType) { case PARTITION_FAT32: case PARTITION_FAT_16: format = "FAT"; break; case 0x4A: case PARTITION_IFS: format = "NTFS"; break; default: break; } if (!type.toUpper ().contains (format.toUpper ())) { qDebug()<<"Skip Disk"<<devname<<format<<"Not a NTFS Disk"; continue; } break; case PARTITION_STYLE_GPT: style = GPTPartition; if (!table.toUpper ().contains ("GPT")) { qDebug()<<"Skip Disk"<<devname<<"GPT"; continue; } GUID PARTITION_BASIC_DATA_GUID; PARTITION_BASIC_DATA_GUID.Data1 = 0xEBD0A0A2L; PARTITION_BASIC_DATA_GUID.Data2 = 0xB9E5; PARTITION_BASIC_DATA_GUID.Data3 = 0x4433; PARTITION_BASIC_DATA_GUID.Data4[0] = 0x87; PARTITION_BASIC_DATA_GUID.Data4[1] = 0xC0; PARTITION_BASIC_DATA_GUID.Data4[2] = 0x68; PARTITION_BASIC_DATA_GUID.Data4[3] = 0xB6; PARTITION_BASIC_DATA_GUID.Data4[4] = 0xB7; PARTITION_BASIC_DATA_GUID.Data4[5] = 0x26; PARTITION_BASIC_DATA_GUID.Data4[6] = 0x99; PARTITION_BASIC_DATA_GUID.Data4[7] = 0xC7; if (PARTITION_BASIC_DATA_GUID != piex.Gpt.PartitionType) { qDebug()<<"Skip Disk"<<devname<<"Not a NTFS Disk"; continue; } break; case PARTITION_STYLE_RAW: style = RAWPartition; if (!table.toUpper ().contains ("RAW")) { continue; } break; default: style = UnknowPartition; qDebug()<<"Disk Type"<<devname<<"Unknow"; continue; } DiskInfo diskinfo; diskinfo.Name = devname; diskinfo.Style = style; diskinfo.FreeSpace = FreeBytes.QuadPart/(1024*1024*1024); QString result = Xapi::SynExec( "cmd", QString("/C \"chcp 437 & %1\\manage-bde -status %2\" ").arg(Xapi::SystemDirtory()).arg(devname)); QStringList list = result.split("\r").filter("BitLocker Version"); diskinfo.Encrypt = list.size() ? !list.first().contains("None") : false; qDebug()<<devname<<"System Type"<<diskinfo.Encrypt; disklist.push_back(diskinfo); } } return disklist; }
CString GetHddDriveInfo() { int index=0; float fTotalSize=0; HANDLE hDevice; CString Result; CString HardDisk; DWORD junk; DISK_GEOMETRY pdg; BOOL bWin9X = FALSE; if (GetVersion() >= 0x80000000) { bWin9X = TRUE; } HardDisk.Format("\\\\.\\PhysicalDrive%d",index); hDevice=CreateFile(HardDisk,0,FILE_SHARE_READ | FILE_SHARE_WRITE,NULL,OPEN_EXISTING,0,NULL); if (hDevice==INVALID_HANDLE_VALUE) Result=="Error: Can not Query Hard Disk Drives."; while (hDevice!=INVALID_HANDLE_VALUE) { BOOL bResult=DeviceIoControl(hDevice,IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL,0, &pdg,sizeof(DISK_GEOMETRY), &junk, (LPOVERLAPPED) NULL); if (bResult) { CString Temp; Temp.Format("Hard Disk Drive %d : ",index+1); Result+=Temp; double DiskSize=pdg.Cylinders.QuadPart * pdg.TracksPerCylinder * pdg.SectorsPerTrack * pdg.BytesPerSector/1024/1024/1024.0; Temp.Format("%.2f GB\n", DiskSize); Result+=Temp; // fTotalSize += atof(Temp); } CloseHandle(hDevice); index++; HardDisk.Format("\\\\.\\PhysicalDrive%d",index); hDevice=CreateFile(HardDisk,0,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,0,NULL); } double dTotalSize = 0, dTotalFree = 0; ULARGE_INTEGER AvailableToCaller, Disk, Free; for (int iCounter=0; iCounter < MAX_OF_HARD_DISKS; iCounter++) { if (GetDriveType(HardDiskLetters[iCounter])==DRIVE_FIXED) { if (GetDiskFreeSpaceEx(HardDiskLetters[iCounter],&AvailableToCaller,&Disk,&Free)) { CString Temp; // Temp.Format("*** Hard Disk: (%s) ***\r\n",HardDiskLetters[iCounter]); // Result+=Temp; // Temp.Format("Total size: %I64d (MB)\r\n",Disk.QuadPart/1024/1024); // Result+=Temp; // ULONGLONG Used=Disk.QuadPart-Free.QuadPart; // Temp.Format("Used: %I64d (MB)\r\n",Used/1024/1024); // Result+=Temp; // Temp.Format("Free: %I64d (MB)\r\n\r\n",Free.QuadPart/1024/1024); // Result+=Temp; dTotalSize += (INT64)(Disk.QuadPart); dTotalFree += (INT64)(Free.QuadPart); if (bWin9X) { Temp.Format("Hard Disk Drive %d : %.2f GB\n", iCounter+1, dTotalSize/1024/1024/1024.0); Result += Temp; } } } } dTotalSize = dTotalSize/1024/1024/1024.0; dTotalFree = dTotalFree/1024/1024/1024.0; // CString Temp; // Temp.Format("Number of Hard Disk Drives: %d\n",index); CString strTotalSize, strTotalFree; strTotalSize.Format("%.2f Gigabytes Usable Hard Drive Capacity\n", dTotalSize/*fTotalSize*/); strTotalFree.Format("%.2f Gigabytes Hard Drive Free Space\n", dTotalFree); Result=strTotalSize+strTotalFree+Result; return Result + "\n"; }
bool GetSystemInfo(SYSTEMINIT& sysinfo) { /////get computer name/////// TCHAR computerbuf[256]; DWORD computersize=256; memset(computerbuf,0,256); if(!GetComputerName(computerbuf,&computersize)) return false; computerbuf[computersize]=0; sysinfo.computer[0]=0; strcat(sysinfo.computer,"计算机: "); strcat(sysinfo.computer,computerbuf); ///////get user name///////// TCHAR userbuf[256]; DWORD usersize=256; memset(userbuf,0,256); if(!GetUserName(userbuf,&usersize)) return false; userbuf[usersize]=0; sysinfo.user[0]=0; strcat(sysinfo.user,"用户名: "); strcat(sysinfo.user,userbuf); ///////get version////////// sysinfo.os[0]=0; strcat(sysinfo.os,"操作系统: "); OSVERSIONINFO osvi; memset(&osvi,0,sizeof(osvi)); osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); if(!GetVersionEx(&osvi)) return false; switch (osvi.dwPlatformId) { case VER_PLATFORM_WIN32_NT: if ( osvi.dwMajorVersion <= 4 ) strcat(sysinfo.os,"Microsoft Windows NT "); if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0 ) strcat(sysinfo.os,"Microsoft Windows 2000 "); HKEY hKey; char szProductType[80]; DWORD dwBufLen; RegOpenKeyEx( HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\ProductOptions", 0, KEY_QUERY_VALUE, &hKey ); RegQueryValueEx( hKey, "ProductType", NULL, NULL, (LPBYTE)szProductType, &dwBufLen); RegCloseKey(hKey); if ( lstrcmpi( "WINNT", szProductType) == 0 ) strcat(sysinfo.os,"Professional, " ); if ( lstrcmpi( "LANMANNT", szProductType) == 0 ) strcat(sysinfo.os,"Server, " ); if ( lstrcmpi( "SERVERNT", szProductType) == 0 ) strcat(sysinfo.os,"Advanced Server, " ); if ( osvi.dwMajorVersion <= 4 ) { char temp[256]; sprintf(temp,"version %d.%d %s (Build %d)\n", osvi.dwMajorVersion, osvi.dwMinorVersion, osvi.szCSDVersion, osvi.dwBuildNumber & 0xFFFF); strcat(sysinfo.os,temp); } else { char temp[256]; sprintf(temp,"%s (Build %d)\n", osvi.szCSDVersion, osvi.dwBuildNumber & 0xFFFF); strcat(sysinfo.os,temp); } 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; }
/* ** Updates the current disk free space value. ** */ void CMeasureDiskSpace::UpdateValue() { if (!m_Drive.empty()) { const WCHAR* drive = m_Drive.c_str(); UINT type = GetDriveType(drive); if (m_Type) { switch (type) { case DRIVE_UNKNOWN: case DRIVE_NO_ROOT_DIR: m_Value = DRIVETYPE_REMOVED; m_DriveInfo = L"Removed"; break; case DRIVE_REMOVABLE: m_Value = DRIVETYPE_REMOVABLE; m_DriveInfo = L"Removable"; break; case DRIVE_FIXED: m_Value = DRIVETYPE_FIXED; m_DriveInfo = L"Fixed"; break; case DRIVE_REMOTE: m_Value = DRIVETYPE_NETWORK; m_DriveInfo = L"Network"; break; case DRIVE_CDROM: m_Value = DRIVETYPE_CDROM; m_DriveInfo = L"CDRom"; break; case DRIVE_RAMDISK: m_Value = DRIVETYPE_RAM; m_DriveInfo = L"Ram"; break; default: m_Value = DRIVETYPE_ERROR; m_DriveInfo = L"Error"; break; } } else { BOOL sizeResult = FALSE; ULONGLONG i64TotalBytes, i64FreeBytes; if (type != DRIVE_NO_ROOT_DIR) { if (type != DRIVE_CDROM && (!m_IgnoreRemovable || type != DRIVE_REMOVABLE)) // Ignore CD-ROMS and removable drives { UINT oldMode = SetErrorMode(0); SetErrorMode(oldMode | SEM_FAILCRITICALERRORS); // Prevent the system from displaying message box if (!m_DiskQuota) { sizeResult = GetDiskFreeSpaceEx(drive, NULL, (PULARGE_INTEGER)&i64TotalBytes, (PULARGE_INTEGER)&i64FreeBytes); } else { sizeResult = GetDiskFreeSpaceEx(drive, (PULARGE_INTEGER)&i64FreeBytes, (PULARGE_INTEGER)&i64TotalBytes, NULL); } SetErrorMode(oldMode); // Reset } } if (sizeResult) { m_Value = (double)(__int64)((m_Total) ? i64TotalBytes : i64FreeBytes); if (i64TotalBytes != m_OldTotalBytes) { // Total size was changed, so set new max value. m_MaxValue = (double)(__int64)i64TotalBytes; m_OldTotalBytes = i64TotalBytes; } } else { m_Value = 0.0; m_MaxValue = 0.0; m_OldTotalBytes = 0; } if (m_Label) { BOOL labelResult = FALSE; WCHAR volumeName[MAX_PATH + 1]; if (type != DRIVE_NO_ROOT_DIR) { if (!m_IgnoreRemovable || type != DRIVE_REMOVABLE) // Ignore removable drives { UINT oldMode = SetErrorMode(0); SetErrorMode(oldMode | SEM_FAILCRITICALERRORS); // Prevent the system from displaying message box labelResult = GetVolumeInformation(drive, volumeName, MAX_PATH + 1, NULL, NULL, NULL, NULL, 0); SetErrorMode(oldMode); // Reset } } m_DriveInfo = (labelResult) ? volumeName : L""; } else if (!m_DriveInfo.empty()) { m_DriveInfo.clear(); } } } }
void WCMD_directory (void) { char path[MAX_PATH], drive[8]; int status, paged_mode; ULARGE_INTEGER avail, total, free; CONSOLE_SCREEN_BUFFER_INFO consoleInfo; byte_total = 0; file_total = dir_total = 0; /* Handle args */ paged_mode = (strstr(quals, "/P") != NULL); recurse = (strstr(quals, "/S") != NULL); wide = (strstr(quals, "/W") != NULL); bare = (strstr(quals, "/B") != NULL); /* Handle conflicting args and initialization */ if (bare) wide = FALSE; if (wide) { if (GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &consoleInfo)) max_width = consoleInfo.dwSize.X; else max_width = 80; } if (paged_mode) { WCMD_enter_paged_mode(); } if (param1[0] == '\0') strcpy (param1, "."); status = GetFullPathName (param1, sizeof(path), path, NULL); if (!status) { WCMD_print_error(); if (paged_mode) WCMD_leave_paged_mode(); return; } lstrcpyn (drive, path, 3); if (!bare) { status = WCMD_volume (0, drive); if (!status) { if (paged_mode) WCMD_leave_paged_mode(); return; } } WCMD_list_directory (path, 0); lstrcpyn (drive, path, 4); GetDiskFreeSpaceEx (drive, &avail, &total, &free); if (!bare) { if (recurse) { WCMD_output ("\n\n Total files listed:\n%8d files%25s bytes\n", file_total, WCMD_filesize64 (byte_total)); WCMD_output ("%8d directories %18s bytes free\n\n", dir_total, WCMD_filesize64 (free.QuadPart)); } else { WCMD_output (" %18s bytes free\n\n", WCMD_filesize64 (free.QuadPart)); } } if (paged_mode) WCMD_leave_paged_mode(); }
void CSysInfo::GetDiskInfo (void) { // 드라이브명을 가지고 옴 int curdrive; char path[ _MAX_PATH ]; int iDriveCNT = 0; /* Save current drive. */ curdrive = _getdrive (); char cInstallDrv = curdrive + 'A' - 1; _chdrive (curdrive); path[ 0 ] = '\0'; _getdcwd (curdrive, path, _MAX_PATH); m_mapDisc[ "Current Folder" ] = path; typedef BOOL (*FN_GetDiskFreeSpaceEx) (LPSTR, PULARGE_INTEGER, PULARGE_INTEGER, PULARGE_INTEGER); FN_GetDiskFreeSpaceEx pGetDiskFreeSpaceEx = (FN_GetDiskFreeSpaceEx)GetProcAddress( GetModuleHandle("kernel32.dll"), "GetDiskFreeSpaceExA"); ULARGE_INTEGER i64FreeBytesToCaller; ULARGE_INTEGER i64TotalBytes; ULARGE_INTEGER i64FreeBytes; DWORD dwMB = 1024 * 1024; int iFreeMSize; int iTotalSize; iFreeMSize = 0; iTotalSize = 0; char szDrive[ 8 ]; sprintf ( szDrive, "%c:", cInstallDrv); if (pGetDiskFreeSpaceEx) { BOOL fResult = GetDiskFreeSpaceEx (szDrive, (PULARGE_INTEGER)&i64FreeBytesToCaller, (PULARGE_INTEGER)&i64TotalBytes, (PULARGE_INTEGER)&i64FreeBytes ); if(fResult) { iFreeMSize = (int)(i64FreeBytesToCaller.QuadPart / (1024 * 1024)); iTotalSize = (int)(i64TotalBytes.QuadPart / (1024 * 1024)); } } else { DWORD dwSectPerClust; DWORD dwBytesPerSect; DWORD dwFreeClusters; DWORD dwTotalClusters; BOOL fResult = GetDiskFreeSpace (szDrive, &dwSectPerClust, &dwBytesPerSect, &dwFreeClusters, &dwTotalClusters); if(fResult) { iFreeMSize = (int)(( dwFreeClusters * dwSectPerClust * dwBytesPerSect ) / (1024 * 1024)); iTotalSize = (int)(( dwTotalClusters * dwSectPerClust * dwBytesPerSect ) / (1024 * 1024)); } } char szSize[ 16 ]; char szKey[ 32 ]; sprintf (szSize, "%dMB", iFreeMSize); sprintf (szKey, "Free Space of %c:", cInstallDrv); m_mapDisc[ szKey ] = szSize; sprintf (szSize, "%dMB", iTotalSize); sprintf (szKey, "Total Space of %c:", cInstallDrv); m_mapDisc[ szKey ] = szSize; }
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; }
static PyObject * netuse_usage_report_orig(PyObject *self, PyObject *args) { char * servername = NULL; PyObject *retvalue = NULL; DWORD bitmasks; char chdrive = '@'; char drivepath[] = { 'A', ':', '\\', 0 }; char drivename[] = { 'A', ':', 0 }; ULARGE_INTEGER lFreeBytesAvailable; ULARGE_INTEGER lTotalNumberOfBytes; /* ULARGE_INTEGER lTotalNumberOfFreeBytes; */ char szRemoteName[MAX_PATH]; DWORD dwResult, cchBuff = MAX_PATH; DWORD serverlen = 0; if (! PyArg_ParseTuple(args, "|s", &servername)) { return NULL; } if (servername) serverlen = strlen(servername); bitmasks = GetLogicalDrives(); if (bitmasks == 0) { PyErr_Format(PyExc_RuntimeError, "A system error has occurred in GetLogicalDrives: %ld", GetLastError() ); return NULL; } retvalue = PyList_New(0); if (retvalue == NULL) return NULL; while (bitmasks) { ++ chdrive; drivepath[0] = chdrive; drivename[0] = chdrive; if ((bitmasks & 1L) == 0) { bitmasks >>= 1; continue; } bitmasks >>= 1; switch (GetDriveType(drivepath)) { case DRIVE_REMOTE: break; case DRIVE_FIXED: continue; default: continue; } /* If the network connection was made using the Microsoft LAN * Manager network, and the calling application is running in a * different logon session than the application that made the * connection, a call to the WNetGetConnection function for the * associated local device will fail. The function fails with * ERROR_NOT_CONNECTED or ERROR_CONNECTION_UNAVAIL. This is * because a connection made using Microsoft LAN Manager is * visible only to applications running in the same logon session * as the application that made the connection. (To prevent the * call to WNetGetConnection from failing it is not sufficient for * the application to be running in the user account that created * the connection.) * * Refer to http://msdn.microsoft.com/en-us/library/windows/desktop/aa385453(v=vs.85).aspx * */ dwResult = WNetGetConnection(drivename, szRemoteName, &cchBuff ); if (dwResult == NO_ERROR || dwResult == ERROR_CONNECTION_UNAVAIL \ || dwResult == ERROR_NOT_CONNECTED) { if (serverlen) { if ((cchBuff < serverlen + 3) || (strncmp(servername, szRemoteName+2, serverlen) != 0) || (szRemoteName[serverlen + 2] != '\\') ) continue; } } else { PyErr_Format(PyExc_RuntimeError, "A system error has occurred in WNetGetConnection: %ld", GetLastError() ); Py_XDECREF(retvalue); return NULL; } switch (check_duplicate_shared_folder(retvalue, szRemoteName)) { case -1: Py_XDECREF(retvalue); return NULL; case 1: continue; default: break; } if (GetDiskFreeSpaceEx(drivepath, &lFreeBytesAvailable, &lTotalNumberOfBytes, NULL )) { PyObject *pobj = Py_BuildValue("ssLL", drivename, szRemoteName, lFreeBytesAvailable, lTotalNumberOfBytes ); if (PyList_Append(retvalue, pobj) == -1) { Py_XDECREF(retvalue); return NULL; } } else if (dwResult == ERROR_CONNECTION_UNAVAIL || dwResult == ERROR_NOT_CONNECTED) { PyObject *pobj = Py_BuildValue("ssLL", drivename, szRemoteName, 0L, 0L ); if (PyList_Append(retvalue, pobj) == -1) { Py_XDECREF(retvalue); return NULL; } } else { PyErr_Format(PyExc_RuntimeError, "A system error has occurred in GetDiskFreeSpaceEx(%s): %ld", drivepath, GetLastError() ); Py_XDECREF(retvalue); return NULL; } }
double hb_fsDiskSpace( const char * pszPath, HB_USHORT uiType ) { char szPathBuf[ 2 ]; double dSpace = 0.0; if( uiType > HB_DISK_TOTAL ) uiType = HB_DISK_AVAIL; if( ! pszPath ) { szPathBuf[ 0 ] = HB_OS_PATH_DELIM_CHR; szPathBuf[ 1 ] = '\0'; pszPath = szPathBuf; } #if defined( HB_OS_WIN ) { LPCTSTR lpPath; LPTSTR lpFree; lpPath = HB_FSNAMECONV( pszPath, &lpFree ); { UINT uiErrMode = SetErrorMode( SEM_FAILCRITICALERRORS ); HB_BOOL fResult; #if ! defined( HB_OS_WIN_CE ) && ! defined( HB_OS_WIN_64 ) /* NOTE: We need to call this function dynamically to maintain support Win95 first edition. It was introduced in Win95B (aka OSR2) [vszakats] */ typedef BOOL ( WINAPI * P_GDFSE )( LPCTSTR, PULARGE_INTEGER, PULARGE_INTEGER, PULARGE_INTEGER ); static P_GDFSE s_pGetDiskFreeSpaceEx = NULL; static HB_BOOL s_fInit = HB_FALSE; if( ! s_fInit ) { HMODULE hModule = GetModuleHandle( HB_WINAPI_KERNEL32_DLL() ); if( hModule ) s_pGetDiskFreeSpaceEx = ( P_GDFSE ) HB_WINAPI_GETPROCADDRESST( hModule, "GetDiskFreeSpaceEx" ); s_fInit = HB_TRUE; } if( ! s_pGetDiskFreeSpaceEx ) { DWORD dwSectorsPerCluster; DWORD dwBytesPerSector; DWORD dwNumberOfFreeClusters; DWORD dwTotalNumberOfClusters; fResult = GetDiskFreeSpace( lpPath, &dwSectorsPerCluster, &dwBytesPerSector, &dwNumberOfFreeClusters, &dwTotalNumberOfClusters ) ? HB_TRUE : HB_FALSE; hb_fsSetIOError( fResult, 0 ); if( fResult ) { switch( uiType ) { case HB_DISK_AVAIL: case HB_DISK_FREE: dSpace = ( double ) dwNumberOfFreeClusters * ( double ) dwSectorsPerCluster * ( double ) dwBytesPerSector; break; case HB_DISK_USED: case HB_DISK_TOTAL: dSpace = ( double ) dwTotalNumberOfClusters * ( double ) dwSectorsPerCluster * ( double ) dwBytesPerSector; if( uiType == HB_DISK_USED ) dSpace -= ( double ) dwNumberOfFreeClusters * ( double ) dwSectorsPerCluster * ( double ) dwBytesPerSector; break; } } } else #endif { #if defined( _MSC_VER ) || defined( __LCC__ ) || \ ( defined( __GNUC__ ) && ! defined( __RSXNT__ ) ) # define HB_GET_LARGE_UINT( v ) ( ( double ) (v).LowPart + \ ( double ) (v).HighPart * \ ( ( ( double ) 0xFFFFFFFF ) + 1 ) ) #else /* NOTE: Borland doesn't seem to deal with the un-named struct that is part of ULARGE_INTEGER [pt] */ # define HB_GET_LARGE_UINT( v ) ( ( double ) (v).u.LowPart + \ ( double ) (v).u.HighPart * \ ( ( ( double ) 0xFFFFFFFF ) + 1 ) ) #endif ULARGE_INTEGER i64FreeBytesToCaller, i64TotalBytes, i64FreeBytes; #if ! defined( HB_OS_WIN_CE ) && ! defined( HB_OS_WIN_64 ) fResult = s_pGetDiskFreeSpaceEx( lpPath, ( PULARGE_INTEGER ) &i64FreeBytesToCaller, ( PULARGE_INTEGER ) &i64TotalBytes, ( PULARGE_INTEGER ) &i64FreeBytes ); #else fResult = GetDiskFreeSpaceEx( lpPath, ( PULARGE_INTEGER ) &i64FreeBytesToCaller, ( PULARGE_INTEGER ) &i64TotalBytes, ( PULARGE_INTEGER ) &i64FreeBytes ); #endif hb_fsSetIOError( fResult, 0 ); if( fResult ) { switch( uiType ) { case HB_DISK_AVAIL: dSpace = HB_GET_LARGE_UINT( i64FreeBytesToCaller ); break; case HB_DISK_FREE: dSpace = HB_GET_LARGE_UINT( i64FreeBytes ); break; case HB_DISK_TOTAL: dSpace = HB_GET_LARGE_UINT( i64TotalBytes ); break; case HB_DISK_USED: dSpace = HB_GET_LARGE_UINT( i64TotalBytes ) - HB_GET_LARGE_UINT( i64FreeBytes ); break; } } } SetErrorMode( uiErrMode ); } if( lpFree ) hb_xfree( lpFree ); } #elif defined( HB_OS_DOS ) || defined( HB_OS_OS2 ) { HB_USHORT uiDrive; uiDrive = pszPath == NULL || pszPath[ 0 ] == 0 || pszPath[ 1 ] != HB_OS_DRIVE_DELIM_CHR ? 0 : ( pszPath[ 0 ] >= 'A' && pszPath[ 0 ] <= 'Z' ? pszPath[ 0 ] - 'A' + 1 : ( pszPath[ 0 ] >= 'a' && pszPath[ 0 ] <= 'z' ? pszPath[ 0 ] - 'a' + 1 : 0 ) ); #if defined( HB_OS_DOS ) for( ;; ) { union REGS regs; regs.HB_XREGS.dx = uiDrive; regs.h.ah = 0x36; HB_DOS_INT86( 0x21, ®s, ®s ); if( regs.HB_XREGS.ax != 0xFFFF ) { HB_USHORT uiClusterTotal = regs.HB_XREGS.dx; HB_USHORT uiClusterFree = regs.HB_XREGS.bx; HB_USHORT uiSecPerCluster = regs.HB_XREGS.ax; HB_USHORT uiSectorSize = regs.HB_XREGS.cx; switch( uiType ) { case HB_DISK_AVAIL: case HB_DISK_FREE: dSpace = ( double ) uiClusterFree * ( double ) uiSecPerCluster * ( double ) uiSectorSize; break; case HB_DISK_USED: case HB_DISK_TOTAL: dSpace = ( double ) uiClusterTotal * ( double ) uiSecPerCluster * ( double ) uiSectorSize; if( uiType == HB_DISK_USED ) dSpace -= ( double ) uiClusterFree * ( double ) uiSecPerCluster * ( double ) uiSectorSize; break; } } else { if( hb_errRT_BASE_Ext1( EG_OPEN, 2018, NULL, NULL, 0, ( EF_CANDEFAULT | EF_CANRETRY ), HB_ERR_ARGS_BASEPARAMS ) == E_RETRY ) continue; } break; } #else /* HB_OS_OS2 */ { struct _FSALLOCATE fsa; APIRET rc; /* Query level 1 info from filesystem */ while( ( rc = DosQueryFSInfo( uiDrive, 1, &fsa, sizeof( fsa ) ) ) != NO_ERROR ) { if( hb_errRT_BASE_Ext1( EG_OPEN, 2018, NULL, NULL, 0, ( EF_CANDEFAULT | EF_CANRETRY ), HB_ERR_ARGS_BASEPARAMS ) != E_RETRY ) break; } hb_fsSetError( ( HB_ERRCODE ) rc ); if( rc == NO_ERROR ) { switch( uiType ) { case HB_DISK_AVAIL: case HB_DISK_FREE: dSpace = ( double ) fsa.cUnitAvail * ( double ) fsa.cSectorUnit * ( double ) fsa.cbSector; break; case HB_DISK_USED: case HB_DISK_TOTAL: dSpace = ( double ) fsa.cUnit * ( double ) fsa.cSectorUnit * ( double ) fsa.cbSector; if( uiType == HB_DISK_USED ) dSpace -= ( double ) fsa.cUnitAvail * ( double ) fsa.cSectorUnit * ( double ) fsa.cbSector; break; } } } #endif } #elif defined( HB_OS_UNIX ) && \ !( defined( __WATCOMC__ ) || defined( __CEGCC__ ) || defined( HB_OS_SYMBIAN ) ) { #if defined( HB_OS_DARWIN ) || defined( HB_OS_ANDROID ) || \ defined( HB_OS_VXWORKS ) struct statfs sf; #else struct statvfs sf; #endif char * pszFree; pszPath = hb_fsNameConv( pszPath, &pszFree ); #if defined( HB_OS_DARWIN ) || defined( HB_OS_ANDROID ) || \ defined( HB_OS_VXWORKS ) if( statfs( pszPath, &sf ) == 0 ) #else if( statvfs( pszPath, &sf ) == 0 ) #endif { switch( uiType ) { case HB_DISK_AVAIL: dSpace = ( double ) sf.f_bavail * ( double ) sf.f_bsize; break; case HB_DISK_FREE: dSpace = ( double ) sf.f_bfree * ( double ) sf.f_bsize; break; case HB_DISK_USED: dSpace = ( double ) ( sf.f_blocks - sf.f_bfree ) * ( double ) sf.f_bsize; break; case HB_DISK_TOTAL: dSpace = ( double ) sf.f_blocks * ( double ) sf.f_bsize; break; } hb_fsSetIOError( HB_TRUE, 0 ); } else hb_fsSetIOError( HB_FALSE, 0 ); if( pszFree ) hb_xfree( pszFree ); } #else { int iTODO; HB_SYMBOL_UNUSED( uiType ); } #endif return dSpace; }
bool GetDirverInfo(Json::Value *root) { DWORD lInfoSize = GetLogicalDriveStrings(0, NULL); CHAR *szLogicalDriveStrings=new char[(lInfoSize+1)]; PCHAR szDrive=NULL; ZeroMemory(szLogicalDriveStrings,lInfoSize+1); GetLogicalDriveStrings(lInfoSize,szLogicalDriveStrings); szDrive = (PCHAR)szLogicalDriveStrings; do { Json::Value dir; Json::Value data; Json::Value attr; UINT uDriveType; DWORD dwVolumeSerialNumber; DWORD dwMaximumComponentLength; DWORD dwFileSystemFlags; CHAR szFileSystemNameBuffer[BUFSIZE]; CHAR szDirveName[MAX_PATH]; ULARGE_INTEGER nTotalBytes, nTotalFreeBytes, nTotalAvailable; attr["path"]=Json::Value(szDrive); char vol_type[256]; ZeroMemory(vol_type,256); uDriveType = GetDriveType(szDrive); switch(uDriveType) { case DRIVE_UNKNOWN: sprintf_s(vol_type,256,"磁盘类型:外星设备\r\n"); break; case DRIVE_NO_ROOT_DIR: sprintf_s(vol_type,256,"磁盘类型:非根目录\r\n"); break; case DRIVE_REMOVABLE: sprintf_s(vol_type,256,"磁盘类型:可移动磁盘\r\n"); break; case DRIVE_FIXED: sprintf_s(vol_type,256,"磁盘类型:硬盘\r\n"); break; case DRIVE_REMOTE: sprintf_s(vol_type,256,"磁盘类型:远程驱动器\r\n"); break; case DRIVE_CDROM: sprintf_s(vol_type,256,"磁盘类型:光盘\r\n"); break; case DRIVE_RAMDISK: sprintf_s(vol_type,256,"磁盘类型:内存盘\r\n"); break; default: break; } if(uDriveType == DRIVE_FIXED) { char attr_title[1024]; char total_size[512]; char fee_size[256]; if(GetDiskFreeSpaceEx(szDrive, &nTotalAvailable, &nTotalBytes, &nTotalFreeBytes)) { ZeroMemory(total_size,512); ZeroMemory(fee_size,256); ZeroMemory(attr_title,1024); sprintf_s(total_size,512,"总大小:%ld MB\r\n",nTotalBytes.QuadPart/1024/1024); sprintf_s(fee_size,256,"可用空间:%ld MB\r\n",nTotalFreeBytes.QuadPart/1024/1024); sprintf_s(attr_title,1024,"%s%s%s",total_size,fee_size,vol_type); attr["title"]=Json::Value(attr_title); } } if (!GetVolumeInformation(szDrive,szDirveName,MAX_PATH,&dwVolumeSerialNumber,&dwMaximumComponentLength, &dwFileSystemFlags,szFileSystemNameBuffer,BUFSIZE)) { data["title"]=Json::Value(szDrive); attr["title"]=Json::Value("设备未就绪"); dir["data"]=data; dir["attr"]=attr; dir["state"]=Json::Value(""); root->append(dir); szDrive += (lstrlen(szDrive)+1); continue; } if(0!=lstrlen(szDirveName)) { data["title"]=Json::Value(szDirveName); } else { data["title"]=Json::Value(szDrive); } szDrive += (lstrlen(szDrive)+1); dir["data"]=data; dir["attr"]=attr; dir["state"]=Json::Value("closed"); root->append(dir); } while(*szDrive!='\x00'); delete []szLogicalDriveStrings; return true; }
void CReplayFrame::CreateReplayFrame(void) { CString path = "", filename = "", text = "", fcra_seen = ""; FILE *fp = NULL; int i = 0; time_t ltime = 0; tm now_time = {0}; char now_time_str[100] = {0}; ULARGE_INTEGER free_bytes_for_user_on_disk = {0}, total_bytes_on_disk = {0}, free_bytes_total_on_disk = {0}; int e = SUCCESS; // Sanity check: Enough disk-space for replay frame? GetDiskFreeSpaceEx( _startup_path, // Directory on disk of interest &free_bytes_for_user_on_disk, &total_bytes_on_disk, &free_bytes_total_on_disk); if (free_bytes_for_user_on_disk.QuadPart < FREE_SPACE_NEEDED_FOR_REPLAYFRAME) { MessageBox(NULL, "Not enough disk space to create replay-frame.", "ERROR", 0); return; } // Get current time time(<ime); localtime_s(&now_time, <ime); strftime(now_time_str, 100, "%Y-%m-%d %H:%M:%S", &now_time); // Create replay/session dir if it does not exist path.Format("%s\\replay\\session_%lu\\", _startup_path, theApp._session_id); if (GetFileAttributes(path.GetString()) == INVALID_FILE_ATTRIBUTES) SHCreateDirectoryEx(NULL, path.GetString(), NULL); // Get exclusive access to CScraper and CSymbols variables // (Wait for scrape/symbol cycle to finish before saving frame) EnterCriticalSection(&p_heartbeat_thread->cs_update_in_progress); // Create bitmap file path.Format("%s\\replay\\session_%lu\\frame%03d.bmp", _startup_path, theApp._session_id, _next_replay_frame); CreateBMPFile(path.GetString(), p_scraper->entire_window_cur()); // Create HTML file path.Format("%s\\replay\\session_%lu\\frame%03d.htm", _startup_path, theApp._session_id, _next_replay_frame); if (fopen_s(&fp, path.GetString(), "w")==0) { fprintf(fp, p_scraper->title()); fprintf(fp, "\n"); fprintf(fp, "<html>\n"); fprintf(fp, "<style>\n"); fprintf(fp, "td {text-align:right;}\n"); fprintf(fp, "</style>\n"); fprintf(fp, "<body>\n"); fprintf(fp, "<font face=courier>\n"); fprintf(fp, "<img src=\"frame%03d.bmp\">\n", _next_replay_frame); fprintf(fp, "<br>\n"); fprintf(fp, "<a href=\"frame%03d.htm\">PREV</a>\n", _next_replay_frame-1 >= 0 ? _next_replay_frame-1 : prefs.replay_max_frames()); fprintf(fp, "<a href=\"frame%03d.htm\">NEXT</a>\n", _next_replay_frame+1 < prefs.replay_max_frames() ? _next_replay_frame+1 : 0); fprintf(fp, " [%lu.%03d] [%s]<br>\n", theApp._session_id, _next_replay_frame, now_time_str); fprintf(fp, "<br>\n"); fprintf(fp, "<table>\n"); fprintf(fp, "<tr>\n"); fprintf(fp, "<td>\n"); // Table for: SFABD, hand, bet, balance, name fprintf(fp, "<table border=4 cellpadding=1 cellspacing=1>\n"); fprintf(fp, "<tr>\n"); fprintf(fp, "<th>#</th>\n"); fprintf(fp, "<th>SFABDP</th>\n"); //seated, friend, active, button, dealt, playing fprintf(fp, "<th>hand</th>\n"); fprintf(fp, "<th>bet</th>\n"); fprintf(fp, "<th>balance</th>\n"); fprintf(fp, "<th>name</th>\n"); fprintf(fp, "</tr>\n"); for (i=0; i<p_tablemap->s$items()->num_chairs; i++) { fprintf(fp, "<tr>\n"); fprintf(fp, "<td>%d</td>", i); // # text.Format("%s%s%s%s%s%s", (int) (p_symbols->sym()->playersseatedbits) & (1<<i) ? "s" : "-", p_symbols->sym()->userchair == i ? "f" : "-", (int) (p_symbols->sym()->playersactivebits) & (1<<i) ? "a" : "-", p_symbols->sym()->dealerchair== i ? "b" : "-", (int) (p_symbols->sym()->playersdealtbits) & (1<<i) ? "d" : "-", (int) (p_symbols->sym()->playersplayingbits) & (1<<i) ? "p" : "-"); fprintf(fp, "<td>%s</td>", text.GetString()); // SFABDP fprintf(fp, "<td>%s%s</td>", GetCardHtml(p_scraper->card_player(i, 0)), GetCardHtml(p_scraper->card_player(i, 1)) ); // hand fprintf(fp, "<td>%11.2f</td>", p_scraper->player_bet(i)); // bet fprintf(fp, "<td>%11.2f</td>", p_scraper->player_balance(i)); // balance fprintf(fp, "<td>%-15s</td>\n", p_scraper->player_name(i).GetString()); // name fprintf(fp, "</tr>\n"); } fprintf(fp, "</table>\n"); fprintf(fp, "</td>\n"); // Table for: FCRA fprintf(fp, "<td>\n"); fprintf(fp, "<table align=center border=4 cellpadding=1 cellspacing=1>\n"); fprintf(fp, "<tr><th>FCRA</th></tr>\n"); fprintf(fp, "<tr>\n"); int sym_myturnbits = (int) p_symbols->sym()->myturnbits; fcra_seen.Format("%s%s%s%s", sym_myturnbits&0x1 ? "F" : ".", sym_myturnbits&0x2 ? "C" : ".", sym_myturnbits&0x4 ? "R" : ".", sym_myturnbits&0x8 ? "A" : "."); fprintf(fp, "<td>%s</td>\n", fcra_seen.GetString()); fprintf(fp, "</tr>\n"); fprintf(fp, "</table>\n"); // Table for: sb, bb, BB fprintf(fp, "<table align=center border=4 cellpadding=1 cellspacing=1>\n"); fprintf(fp, "<tr><th>sb</th><td>%11.2f</td></tr>\n", p_symbols->sym()->sblind); fprintf(fp, "<tr><th>bb</th><td>%11.2f</td></tr>\n", p_symbols->sym()->bblind); fprintf(fp, "<tr><th>BB</th><td>%11.2f</td></tr>\n", p_symbols->bigbet()); fprintf(fp, "</table>\n"); // Table for: common cards fprintf(fp, "<table align=center border=4 cellpadding=1 cellspacing=1>\n"); fprintf(fp, "<tr><th>commoncard</th></tr>\n"); fprintf(fp, "<tr>\n"); fprintf(fp, "<td>%s%s%s%s%s</td>\n", GetCardHtml(p_scraper->card_common(0)), GetCardHtml(p_scraper->card_common(1)), GetCardHtml(p_scraper->card_common(2)), GetCardHtml(p_scraper->card_common(3)), GetCardHtml(p_scraper->card_common(4)) ); fprintf(fp, "</tr>\n"); fprintf(fp, "</table>\n"); // Table for: pots fprintf(fp, "<table align=center border=4 cellpadding=1 cellspacing=1>\n"); fprintf(fp, "<tr><th>#</th><th>pot</th></tr>\n"); fprintf(fp, "<tr>\n"); fprintf(fp, "<td>0</td><td>%11.2f</td>\n", p_scraper->pot(0)); fprintf(fp, "</tr>\n"); for (i=1; i<=9; i++) { if (p_scraper->pot(i)) { fprintf(fp, "<tr>\n"); fprintf(fp, "<td>%d</td><td>%11.2f</td>\n", i, p_scraper->pot(i)); fprintf(fp, "</tr>\n"); } else { i = 11; } } fprintf(fp, "</table>\n"); fprintf(fp, "</td>\n"); fprintf(fp, "</tr>\n"); fprintf(fp, "</table>\n"); fprintf(fp, "</body></html>\n"); fclose(fp); } LeaveCriticalSection(&p_heartbeat_thread->cs_update_in_progress); }
// 서버접속처리 void CConnectDlg::OnButtonConnect() { // TODO: Add your control notification handler code here UpdateData(TRUE); CString ip; if(m_nClient == 0){ // 클라이언트 if(m_strServerName == ""){ MessageBox("서버이름을 확인하세요!"); GetDlgItem(IDC_EDIT_SERVERNAME)->SetFocus(); return; } m_ipAddressServerIP.GetWindowText(ip); if(ip == "0.0.0.0"){ MessageBox("서버IP 를 확인하세요!"); GetDlgItem(IDC_IPADDRESS_SERVERIP)->SetFocus(); return; } } // 서버라도 이부분을 체크 if(m_strUserID == ""){ MessageBox("사용자 아이디를 확인하세요!"); GetDlgItem(IDC_EDIT_USERID)->SetFocus(); return; } // 소켓연결(접속처리) ((CMainFrame *)AfxGetMainWnd())->m_myIOCPSocket.m_strUserID = m_strUserID; ((CMainFrame *)AfxGetMainWnd())->m_myIOCPSocket.m_bIsClient = m_nClient; // 클라이언트인지 서버인지 ((CMainFrame *)AfxGetMainWnd())->m_myIOCPSocket.m_strSevrIP = ip; ((CMainFrame *)AfxGetMainWnd())->m_myIOCPSocket.m_bViewFolder = m_bViewFolder; ((CMainFrame *)AfxGetMainWnd())->m_myIOCPSocket.InitSock(); if(((CMainFrame *)AfxGetMainWnd())->m_myIOCPSocket.m_nErrorCode != 0){ // 접속실패시 AfxMessageBox("접속에 실패했습니다\n다시 접속하십시요!"); return; } // 접속할때 환경설정값을 넣어준다 CMainFrame *pMain = (CMainFrame *)AfxGetMainWnd(); pMain->m_cPreferencesValue.DirectoryLoadFile(&(pMain->m_cPreferencesValue.m_strFolderTemp), &(pMain->m_cPreferencesValue.m_strFolderInComing), &(pMain->m_cPreferencesValue.m_strFolderShare)); pMain->m_cPreferencesValue.DirectoryLoadFile(&(pMain->m_cPreferencesValue.m_strFolderTemp), &(pMain->m_cPreferencesValue.m_strFolderInComing), &(pMain->m_cPreferencesValue.m_strFolderShare)); pMain->m_cPreferencesValue.DisplayLoadFile(&(pMain->m_cPreferencesValue.m_bDeleteComplete), &(pMain->m_cPreferencesValue.m_nPopupTime), &(pMain->m_cPreferencesValue.m_bPopupConnect), &(pMain->m_cPreferencesValue.m_bPopupDisconnect), &(pMain->m_cPreferencesValue.m_bPopupCompleteDownload)); // 쓰레드에서 이폴더값을 접근을 못해서 여기서 값을넣어준다 pMain->m_myIOCPSocket.m_strFolderInComing = pMain->m_cPreferencesValue.m_strFolderInComing; pMain->m_myIOCPSocket.m_strFolderTemp = pMain->m_cPreferencesValue.m_strFolderTemp; pMain->m_myIOCPSocket.m_strFolderShare = pMain->m_cPreferencesValue.m_strFolderShare; // 하드의 용량을 알아내서 status 바에 넣는다 CString strUNC; pMain->m_cPreferencesValue.DirectoryLoadFile(&pMain->m_cPreferencesValue.m_strFolderTemp, &pMain->m_cPreferencesValue.m_strFolderInComing, &pMain->m_cPreferencesValue.m_strFolderShare); strUNC.Format(pMain->m_cPreferencesValue.m_strFolderInComing.Left(1)); strUNC = strUNC + ":\\"; ULARGE_INTEGER ulAvailable, ulTotal, ulFree; GetDiskFreeSpaceEx((LPCTSTR)strUNC, &ulAvailable, &ulTotal, &ulFree); double nFree, nTotal; if(ulAvailable.QuadPart){ nFree = ulAvailable.LowPart+(double)ulAvailable.HighPart*(double)4294967296; nTotal = ulTotal.LowPart+(double)ulTotal.HighPart*(double)4294967296; } CString strFree; strFree.Format("%f", nFree); int cnt = strFree.Find(".", 0); strFree = strFree.Mid(0, cnt - 7); // 8은 기가바이트로 나타낼경우 소수점이상의 수치에서 9자리가 기가바이트(12.34 GB) strFree.Format("(%s:)%s.%s GB Free", strUNC.Left(1), strFree.Left(strFree.GetLength() - 2), strFree.Right(2)); pMain->m_wndStatusBar.SetPaneText(1, strFree); // status 바, upload, download CString strStatus; pMain->m_cPreferencesValue.ConnectLoadFile(&pMain->m_cPreferencesValue.m_nDownloadSpeed, &pMain->m_cPreferencesValue.m_nUploadSpeed); strStatus.Format("%d개 - %d kB/s", 0, pMain->m_cPreferencesValue.m_nUploadSpeed); pMain->m_wndStatusBar.SetPaneText(2, strStatus); strStatus.Format("%d개 - %d kB/s", 0, pMain->m_cPreferencesValue.m_nDownloadSpeed); pMain->m_wndStatusBar.SetPaneText(3, strStatus); EndDialog(IDYES); }
//---------------------------------------------------------------------- // // WMain // // Engine. Just get command line switches and fire off a format. This // could also be done in a GUI like Explorer does when you select a // drive and run a check on it. // // We do this in UNICODE because the chkdsk command expects PWCHAR // arguments. // //---------------------------------------------------------------------- int _tmain(int argc, TCHAR *argv[]) { int badArg; DWORD media = FMIFS_HARDDISK; DWORD driveType; TCHAR fileSystem[1024]; TCHAR volumeName[1024]; TCHAR input[1024]; DWORD serialNumber; DWORD flags, maxComponent; ULARGE_INTEGER freeBytesAvailableToCaller, totalNumberOfBytes, totalNumberOfFreeBytes; #ifndef UNICODE WCHAR RootDirectoryW[MAX_PATH], FileSystemW[MAX_PATH], LabelW[MAX_PATH]; #endif TCHAR szMsg[RC_STRING_MAX_SIZE]; // // Get function pointers // if( !LoadFMIFSEntryPoints()) { LoadStringAndOem( GetModuleHandle(NULL), STRING_FMIFS_FAIL, (LPTSTR) szMsg,RC_STRING_MAX_SIZE); _tprintf("%s", szMsg); return -1; } // // Parse command line // if( (badArg = ParseCommandLine( argc, argv ))) { LoadStringAndOem( GetModuleHandle(NULL), STRING_UNKNOW_ARG, (LPTSTR) szMsg,RC_STRING_MAX_SIZE); _tprintf(szMsg, argv[badArg] ); Usage(argv[0]); return -1; } // // Get the drive's format // if( !Drive ) { LoadStringAndOem( GetModuleHandle(NULL), STRING_DRIVE_PARM, (LPTSTR) szMsg,RC_STRING_MAX_SIZE); _tprintf(szMsg); Usage( argv[0] ); return -1; } else { _tcscpy( RootDirectory, Drive ); } RootDirectory[2] = _T('\\'); RootDirectory[3] = _T('\0'); // // See if the drive is removable or not // driveType = GetDriveType( RootDirectory ); switch (driveType) { case DRIVE_UNKNOWN : LoadStringAndOem( GetModuleHandle(NULL), STRING_ERROR_DRIVE_TYPE, (LPTSTR) szMsg,RC_STRING_MAX_SIZE); PrintWin32Error( szMsg, GetLastError()); return -1; case DRIVE_REMOTE: case DRIVE_CDROM: LoadStringAndOem( GetModuleHandle(NULL), STRING_NO_SUPPORT, (LPTSTR) szMsg, RC_STRING_MAX_SIZE); _tprintf(szMsg); return -1; case DRIVE_NO_ROOT_DIR: LoadString( GetModuleHandle(NULL), STRING_NO_VOLUME, (LPTSTR) szMsg,RC_STRING_MAX_SIZE); PrintWin32Error( szMsg, GetLastError()); return -1; case DRIVE_REMOVABLE: LoadStringAndOem( GetModuleHandle(NULL), STRING_INSERT_DISK, (LPTSTR) szMsg,RC_STRING_MAX_SIZE); _tprintf(szMsg, RootDirectory[0] ); _fgetts( input, sizeof(input)/2, stdin ); media = FMIFS_FLOPPY; break; case DRIVE_FIXED: case DRIVE_RAMDISK: media = FMIFS_HARDDISK; break; } // Reject attempts to format the system drive { TCHAR path[MAX_PATH + 1]; UINT rc; rc = GetWindowsDirectory(path, MAX_PATH); if (rc == 0 || rc > MAX_PATH) // todo: Report "Unable to query system directory" return -1; if (_totlower(path[0]) == _totlower(Drive[0])) { // todo: report "Cannot format system drive" LoadStringAndOem( GetModuleHandle(NULL), STRING_NO_SUPPORT, (LPTSTR) szMsg, RC_STRING_MAX_SIZE); _tprintf(szMsg); return -1; } } // // Determine the drive's file system format // if( !GetVolumeInformation( RootDirectory, volumeName, sizeof(volumeName)/2, &serialNumber, &maxComponent, &flags, fileSystem, sizeof(fileSystem)/2)) { LoadStringAndOem( GetModuleHandle(NULL), STRING_NO_VOLUME, (LPTSTR) szMsg,RC_STRING_MAX_SIZE); PrintWin32Error( szMsg, GetLastError()); return -1; } if( !GetDiskFreeSpaceEx( RootDirectory, &freeBytesAvailableToCaller, &totalNumberOfBytes, &totalNumberOfFreeBytes )) { LoadStringAndOem( GetModuleHandle(NULL), STRING_NO_VOLUME_SIZE, (LPTSTR) szMsg,RC_STRING_MAX_SIZE); PrintWin32Error( szMsg, GetLastError()); return -1; } LoadStringAndOem( GetModuleHandle(NULL), STRING_FILESYSTEM, (LPTSTR) szMsg,RC_STRING_MAX_SIZE); _tprintf(szMsg, fileSystem ); // // Make sure they want to do this // if( driveType == DRIVE_FIXED ) { if( volumeName[0] ) { while(1 ) { LoadStringAndOem( GetModuleHandle(NULL), STRING_LABEL_NAME_EDIT, (LPTSTR) szMsg,RC_STRING_MAX_SIZE); _tprintf(szMsg, RootDirectory[0] ); _fgetts( input, sizeof(input)/2, stdin ); input[ _tcslen( input ) - 1] = 0; if( !_tcsicmp( input, volumeName )) { break; } LoadStringAndOem( GetModuleHandle(NULL), STRING_ERROR_LABEL, (LPTSTR) szMsg,RC_STRING_MAX_SIZE); _tprintf("%s", szMsg); } } LoadStringAndOem( GetModuleHandle(NULL), STRING_YN_FORMAT, (LPTSTR) szMsg,RC_STRING_MAX_SIZE); _tprintf(szMsg, RootDirectory[0] ); LoadStringAndOem( GetModuleHandle(NULL), STRING_YES_NO_FAQ, (LPTSTR) szMsg,RC_STRING_MAX_SIZE); while( 1 ) { _fgetts( input, sizeof(input)/2, stdin ); if(_strnicmp(&input[0],&szMsg[0],1) == 0) break; if(_strnicmp(&input[0],&szMsg[1],1) == 0) { _tprintf(_T("\n")); return 0; } } } // // Tell the user we're doing a long format if appropriate // if( !QuickFormat ) { LoadString( GetModuleHandle(NULL), STRING_VERIFYING, (LPTSTR) szMsg,RC_STRING_MAX_SIZE); if( totalNumberOfBytes.QuadPart > 1024*1024*10 ) { _tprintf(_T("%s %luM\n"),szMsg, (DWORD) (totalNumberOfBytes.QuadPart/(1024*1024))); } else { _tprintf(_T("%s %.1fM\n"),szMsg, ((float)(LONGLONG)totalNumberOfBytes.QuadPart)/(float)(1024.0*1024.0)); } } else { LoadStringAndOem( GetModuleHandle(NULL), STRING_FAST_FMT, (LPTSTR) szMsg,RC_STRING_MAX_SIZE); if( totalNumberOfBytes.QuadPart > 1024*1024*10 ) { _tprintf(_T("%s %luM\n"),szMsg, (DWORD) (totalNumberOfBytes.QuadPart/(1024*1024))); } else { _tprintf(_T("%s %.2fM\n"),szMsg, ((float)(LONGLONG)totalNumberOfBytes.QuadPart)/(float)(1024.0*1024.0)); } LoadStringAndOem( GetModuleHandle(NULL), STRING_CREATE_FSYS, (LPTSTR) szMsg,RC_STRING_MAX_SIZE); _tprintf("%s", szMsg); } // // Format away! // #ifndef UNICODE MultiByteToWideChar(CP_ACP, 0, RootDirectory, -1, RootDirectoryW, MAX_PATH); MultiByteToWideChar(CP_ACP, 0, FileSystem, -1, FileSystemW, MAX_PATH); MultiByteToWideChar(CP_ACP, 0, Label, -1, LabelW, MAX_PATH); FormatEx( RootDirectoryW, media, FileSystemW, LabelW, QuickFormat, ClusterSize, FormatExCallback ); #else FormatEx( RootDirectory, media, FileSystem, Label, QuickFormat, ClusterSize, FormatExCallback ); #endif if( Error ) return -1; LoadStringAndOem( GetModuleHandle(NULL), STRING_FMT_COMPLETE, (LPTSTR) szMsg,RC_STRING_MAX_SIZE); _tprintf("%s", szMsg); // // Enable compression if desired // if( CompressDrive ) { #ifndef UNICODE MultiByteToWideChar(CP_ACP, 0, RootDirectory, -1, RootDirectoryW, MAX_PATH); if( !EnableVolumeCompression( RootDirectoryW, TRUE )) { #else if( !EnableVolumeCompression( RootDirectory, TRUE )) { #endif LoadStringAndOem( GetModuleHandle(NULL), STRING_VOL_COMPRESS, (LPTSTR) szMsg,RC_STRING_MAX_SIZE); _tprintf("%s", szMsg); } } // // Get the label if we don't have it // if( !GotALabel ) { LoadString( GetModuleHandle(NULL), STRING_ENTER_LABEL, (LPTSTR) szMsg,RC_STRING_MAX_SIZE); _tprintf("%s", szMsg); _fgetts( input, sizeof(LabelString)/2, stdin ); input[ _tcslen(input)-1] = 0; if( !SetVolumeLabel( RootDirectory, input )) { LoadStringAndOem( GetModuleHandle(NULL), STRING_NO_LABEL, (LPTSTR) szMsg,RC_STRING_MAX_SIZE); PrintWin32Error(szMsg, GetLastError()); return -1; } } if( !GetVolumeInformation( RootDirectory, volumeName, sizeof(volumeName)/2, &serialNumber, &maxComponent, &flags, fileSystem, sizeof(fileSystem)/2)) { LoadStringAndOem( GetModuleHandle(NULL), STRING_NO_VOLUME, (LPTSTR) szMsg,RC_STRING_MAX_SIZE); PrintWin32Error( szMsg, GetLastError()); return -1; } // // Print out some stuff including the formatted size // if( !GetDiskFreeSpaceEx( RootDirectory, &freeBytesAvailableToCaller, &totalNumberOfBytes, &totalNumberOfFreeBytes )) { LoadStringAndOem( GetModuleHandle(NULL), STRING_NO_VOLUME_SIZE, (LPTSTR) szMsg,RC_STRING_MAX_SIZE); PrintWin32Error(szMsg, GetLastError()); return -1; } LoadStringAndOem( GetModuleHandle(NULL), STRING_FREE_SPACE, (LPTSTR) szMsg,RC_STRING_MAX_SIZE); _tprintf(szMsg, totalNumberOfBytes.QuadPart, totalNumberOfFreeBytes.QuadPart ); // // Get the drive's serial number // if( !GetVolumeInformation( RootDirectory, volumeName, sizeof(volumeName)/2, &serialNumber, &maxComponent, &flags, fileSystem, sizeof(fileSystem)/2)) { LoadStringAndOem( GetModuleHandle(NULL), STRING_NO_VOLUME, (LPTSTR) szMsg,RC_STRING_MAX_SIZE); PrintWin32Error( szMsg, GetLastError()); return -1; } LoadStringAndOem( GetModuleHandle(NULL), STRING_SERIAL_NUMBER, (LPTSTR) szMsg,RC_STRING_MAX_SIZE); _tprintf(szMsg, (unsigned int)(serialNumber >> 16), (unsigned int)(serialNumber & 0xFFFF) ); return 0; }
/* ** 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 = parser.ReadBool(section, L"Type", false); m_Total = parser.ReadBool(section, L"Total", false); m_Label = parser.ReadBool(section, L"Label", false); m_IgnoreRemovable = parser.ReadBool(section, L"IgnoreRemovable", true); m_DiskQuota = parser.ReadBool(section, L"DiskQuota", true); // 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; } } }
bool CSysInfo::GetDiskSpace(const CStdString drive,int& iTotal, int& iTotalFree, int& iTotalUsed, int& iPercentFree, int& iPercentUsed) { bool bRet= false; ULARGE_INTEGER ULTotal= { { 0 } }; ULARGE_INTEGER ULTotalFree= { { 0 } }; if( !drive.IsEmpty() && !drive.Equals("*") ) { #ifdef _WIN32 UINT uidriveType = GetDriveType(( drive + ":\\" )); if(uidriveType != DRIVE_UNKNOWN && uidriveType != DRIVE_NO_ROOT_DIR) #endif bRet= ( 0 != GetDiskFreeSpaceEx( ( drive + ":\\" ), NULL, &ULTotal, &ULTotalFree) ); } else { ULARGE_INTEGER ULTotalTmp= { { 0 } }; ULARGE_INTEGER ULTotalFreeTmp= { { 0 } }; #ifdef _WIN32 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 static const char *drv_letter[] = { "C:\\", "E:\\", "F:\\", "G:\\", "X:\\", "Y:\\", "Z:\\", NULL }; for( int i = 0; drv_letter[i]; i++) { if( GetDiskFreeSpaceEx( drv_letter[i], 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; iPercentUsed = (int)( 100.0f * ( ULTotal.QuadPart - ULTotalFree.QuadPart ) / ULTotal.QuadPart + 0.5f ); iPercentFree = 100 - iPercentUsed; } return bRet; }
/* ** Updates the current disk free space value. ** */ void MeasureDiskSpace::UpdateValue() { if (!m_Drive.empty()) { const WCHAR* drive = m_Drive.c_str(); UINT type = GetDriveType(drive); if (m_Type) { switch (type) { case DRIVE_UNKNOWN: case DRIVE_NO_ROOT_DIR: m_Value = DRIVETYPE_REMOVED; m_StringValue = L"Removed"; break; case DRIVE_REMOVABLE: m_Value = DRIVETYPE_REMOVABLE; m_StringValue = L"Removable"; break; case DRIVE_FIXED: m_Value = DRIVETYPE_FIXED; m_StringValue = L"Fixed"; break; case DRIVE_REMOTE: m_Value = DRIVETYPE_NETWORK; m_StringValue = L"Network"; break; case DRIVE_CDROM: m_Value = DRIVETYPE_CDROM; m_StringValue = L"CDRom"; break; case DRIVE_RAMDISK: m_Value = DRIVETYPE_RAM; m_StringValue = L"Ram"; break; default: m_Value = DRIVETYPE_ERROR; m_StringValue = L"Error"; break; } } else { BOOL sizeResult = FALSE; ULONGLONG i64TotalBytes, i64FreeBytes; if (type != DRIVE_NO_ROOT_DIR && type != DRIVE_CDROM && (!m_IgnoreRemovable || type != DRIVE_REMOVABLE)) // Ignore CD-ROMS and removable drives { if (!m_DiskQuota) { sizeResult = GetDiskFreeSpaceEx(drive, nullptr, (PULARGE_INTEGER)&i64TotalBytes, (PULARGE_INTEGER)&i64FreeBytes); } else { sizeResult = GetDiskFreeSpaceEx(drive, (PULARGE_INTEGER)&i64FreeBytes, (PULARGE_INTEGER)&i64TotalBytes, nullptr); } } if (sizeResult) { m_Value = (double)(__int64)((m_Total) ? i64TotalBytes : i64FreeBytes); if (i64TotalBytes != m_OldTotalBytes) { // Total size was changed, so set new max value. m_MaxValue = (double)(__int64)i64TotalBytes; m_OldTotalBytes = i64TotalBytes; } } else { m_Value = 0.0; m_MaxValue = 0.0; m_OldTotalBytes = 0; } if (m_Label) { BOOL labelResult = FALSE; WCHAR volumeName[MAX_PATH + 1]; if (type != DRIVE_NO_ROOT_DIR && (!m_IgnoreRemovable || type != DRIVE_REMOVABLE)) // Ignore removable drives { labelResult = GetVolumeInformation(drive, volumeName, MAX_PATH + 1, nullptr, nullptr, nullptr, nullptr, 0); } m_StringValue = (labelResult) ? volumeName : L""; } else if (!m_StringValue.empty()) { m_StringValue.clear(); } } } }
/* ** Read the options specified in the ini file. ** */ void CMeasureDiskSpace::ReadOptions(CConfigParser& parser, const WCHAR* section) { double oldMaxValue = m_MaxValue; CMeasure::ReadOptions(parser, section); m_Drive = parser.ReadString(section, L"Drive", L"C:\\"); if (m_Drive.empty()) { Log(LOG_WARNING, L"FreeDiskSpace: Drive= empty"); m_Value = 0.0; m_MaxValue = 0.0; m_OldTotalBytes = 0; m_DriveInfo.clear(); } else if (!CSystem::IsPathSeparator(m_Drive[m_Drive.length() - 1])) // E.g. "C:" { m_Drive += L'\\'; // A trailing backslash is required. } 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 { UINT oldMode = SetErrorMode(0); SetErrorMode(oldMode | SEM_FAILCRITICALERRORS); // Prevent the system from displaying message box result = GetDiskFreeSpaceEx(drive, NULL, (PULARGE_INTEGER)&i64TotalBytes, NULL); SetErrorMode(oldMode); // Reset } } 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; } } }
// 初始化文件树和列表 void HsLoadFileTreeList(CFileDlg *cFleDlg) { WCHAR* pDrive = NULL; HTREEITEM hRoot; // 树的根节点的句柄 HTREEITEM hDriverItem; // 可表示任一磁盘节点的句柄 HTREEITEM hFolderItem; // 可表示任一目录节点的句柄 HIMAGELIST hImageListLarge = NULL; HIMAGELIST hImageListSmall = NULL; Shell_GetImageLists(&hImageListLarge, &hImageListSmall); ListView_SetImageList(cFleDlg->m_fileList.m_hWnd, hImageListLarge, LVSIL_NORMAL); ListView_SetImageList(cFleDlg->m_fileList.m_hWnd, hImageListSmall, LVSIL_SMALL); HsInitDriveList(&cFleDlg->m_fileList); cFleDlg->m_fileList.DeleteAllItems(); cFleDlg->m_dirTree.DeleteAllItems(); LPITEMIDLIST ppidl = {0}; SHGetSpecialFolderLocation(NULL,CSIDL_DRIVES,&ppidl); //SHGetPathFromIDList(ppidl,TempPath); SHFILEINFO sfi; SHGetFileInfoW ( (LPCWSTR)ppidl, 0, &sfi, sizeof(SHFILEINFO), SHGFI_SYSICONINDEX | SHGFI_PIDL ); hRoot = cFleDlg->m_dirTree.InsertItem(_T("计算机"),sfi.iIcon,sfi.iIcon,0,0); GetLogicalDriveStrings(sizeof(DriveString), DriveString); pDrive = DriveString; CString DriveName; WCHAR FileSystem[MAX_PATH]; unsigned __int64 HDAmount = 0; unsigned __int64 HDFreeSpace = 0; unsigned long AmntMB = 0; // 总大小 unsigned long FreeMB = 0; // 剩余空间 cFleDlg->m_dirTree.Expand(hRoot,TVE_EXPAND); for (int i = 0; *pDrive != '\0'; i++, pDrive += lstrlen(pDrive) + 1) { // 得到磁盘相关信息 memset(FileSystem, 0, sizeof(FileSystem)); // 得到文件系统信息及大小 GetVolumeInformation(pDrive, NULL, 0, NULL, NULL, NULL, FileSystem, MAX_PATH); int nFileSystemLen = lstrlen(FileSystem) + 1; if (GetDiskFreeSpaceEx(pDrive, (PULARGE_INTEGER)&HDFreeSpace, (PULARGE_INTEGER)&HDAmount, NULL)) { AmntMB = (ULONG)(HDAmount / 1024 / 1024); FreeMB = (ULONG)(HDFreeSpace / 1024 / 1024); } else { AmntMB = 0; FreeMB = 0; } //获得磁盘类别 SHFILEINFO sfi; SHGetFileInfo(pDrive, FILE_ATTRIBUTE_NORMAL, &sfi,sizeof(SHFILEINFO), SHGFI_TYPENAME | SHGFI_USEFILEATTRIBUTES); DriveName = sfi.szTypeName; DriveName += L" ("; DriveName += pDrive; DriveName.Delete(DriveName.GetLength()-1); DriveName += L")"; int icon = GetIconIndex(pDrive,GetFileAttributes(pDrive)); int nItem = cFleDlg->m_fileList.InsertItem(i, DriveName, icon); //插入列表框 cFleDlg->m_fileList.SetItemData(nItem, (DWORD_PTR)pDrive); hDriverItem = cFleDlg->m_dirTree.InsertItem(DriveName,icon,icon,hRoot,0); //插入树形列表 cFleDlg->m_dirTree.SetItemData(hDriverItem, (DWORD_PTR)pDrive); cFleDlg->m_dirTree.Expand(hRoot,TVE_EXPAND); cFleDlg->m_fileList.SetItemText(nItem, 1, sfi.szTypeName); //插入磁盘类别 CString str; str.Format(L"%10.1f GB", (float)AmntMB / 1024); cFleDlg->m_fileList.SetItemText(nItem, 2, str); str.Format(L"%10.1f GB", (float)FreeMB / 1024); cFleDlg->m_fileList.SetItemText(nItem, 3, str); } // 重置本地当前路径 cFleDlg->m_filePath.ResetContent(); cFleDlg->m_filePath.SetWindowTextW(L"计算机"); }
BOOL CALLBACK dialogproc(HWND h,UINT m,WPARAM w,LPARAM l) { switch (m) { case WM_TIMER: { // update the recording/playback counter wchar_t text[30]=L""; if (rchan) // recording wsprintf(text,L"%I64d",BASS_ChannelGetPosition(rchan,BASS_POS_BYTE)); else if (chan) { if (BASS_ChannelIsActive(chan)) // playing wsprintf(text,L"%I64d / %I64d",BASS_ChannelGetPosition(chan,BASS_POS_BYTE),BASS_ChannelGetLength(chan,BASS_POS_BYTE)); else wsprintf(text,L"%I64d",BASS_ChannelGetLength(chan,BASS_POS_BYTE)); } MESS(20,WM_SETTEXT,0,text); { // display free disk space ULARGE_INTEGER space; if (GetDiskFreeSpaceEx(NULL,&space,NULL,NULL)) { wsprintf(text,L"%I64d",space.QuadPart); MESS(21,WM_SETTEXT,0,text); } } } break; case WM_COMMAND: switch (LOWORD(w)) { case IDOK: case IDCANCEL: EndDialog(h,LOWORD(w)); break; case 10: if (!rchan) StartRecording(); else StopRecording(); break; case 11: BASS_ChannelPlay(chan,TRUE); // play the recorded data break; } break; case WM_INITDIALOG: win=h; // setup recording device (using default device) if (!BASS_RecordInit(-1)) { Error(L"Can't initialize recording device"); EndDialog(h,0); return 0; } { // go full screen SHINITDLGINFO shidi; shidi.dwMask = SHIDIM_FLAGS; shidi.dwFlags = SHIDIF_DONEBUTTON|SHIDIF_SIZEDLGFULLSCREEN|SHIDIF_EMPTYMENU|SHIDIF_SIPDOWN; shidi.hDlg = h; SHInitDialog(&shidi); } SetTimer(h,1,200,0); // timer to update the position display return 1; case WM_DESTROY: // release all BASS stuff BASS_RecordFree(); BASS_Free(); break; } return 0; }
void CReplayFrame::CreateReplayFrame(void) { FILE *fp = NULL; int i = 0; time_t ltime = 0; tm now_time = {0}; char now_time_str[100] = {0}; ULARGE_INTEGER free_bytes_for_user_on_disk = {0}, total_bytes_on_disk = {0}, free_bytes_total_on_disk = {0}; int e = SUCCESS; // Sanity check: Enough disk-space for replay frame? GetDiskFreeSpaceEx( p_filenames->OpenHoldemDirectory(), // Directory on disk of interest &free_bytes_for_user_on_disk, &total_bytes_on_disk, &free_bytes_total_on_disk); if (free_bytes_for_user_on_disk.QuadPart < FREE_SPACE_NEEDED_FOR_REPLAYFRAME) { write_log(prefs.debug_replayframes(), "[CReplayFrame] Not enough disk-space\n"); OH_MessageBox_Error_Warning("Not enough disk space to create replay-frame.", "ERROR"); return; } // Get current time time(<ime); localtime_s(&now_time, <ime); strftime(now_time_str, 100, "%Y-%m-%d %H:%M:%S", &now_time); // Get exclusive access to CScraper and CSymbols variables // (Wait for scrape/symbol cycle to finish before saving frame) EnterCriticalSection(&p_heartbeat_thread->cs_update_in_progress); CreateBitMapFile(); // Create HTML file CString path = p_filenames->ReplayHTMLFilename(_next_replay_frame); if (fopen_s(&fp, path.GetString(), "w")==0) { write_log(prefs.debug_replayframes(), "[CReplayFrame] Creating HTML file: $s\n", path); // First line has to be the "title" of the table. // This is no longer valid HTML, but the way Ray.E.Bornert did it // for WinHoldem and WinScrape. fprintf(fp, "%s\n", p_scraper->title()); // HTML header fprintf(fp, "<html>\n"); fprintf(fp, " <head>\n"); fprintf(fp, " <title>%s</title>\n", p_scraper->title()); fprintf(fp, " </head>"); fprintf(fp, "<style>\n"); fprintf(fp, "td {text-align:right;}\n"); fprintf(fp, "</style>\n"); fprintf(fp, "<body>\n"); fprintf(fp, "<font face=courier>\n"); // Bitmap image fprintf(fp, "<img src=\"frame%06d.bmp\">\n", _next_replay_frame); fprintf(fp, "<br>\n"); // Table title fprintf(fp, "[%s]", p_scraper->title()); fprintf(fp, "<br>\n"); // Session, frame number and time fprintf(fp, " [Session %lu]", p_sessioncounter->session_id()); fprintf(fp, " [Frame: %06d]", _next_replay_frame); fprintf(fp, " [%s]<br>\n", now_time_str); fprintf(fp, "<br>\n"); // Links forwards and backwards to the next frames fprintf(fp, "%s", LPCSTR(GetLinksToPrevAndNextFile())); fprintf(fp, "<br>\n"); fprintf(fp, "<br>\n"); // Header of main table for smaller data tables fprintf(fp, "<table>\n"); fprintf(fp, "<tr>\n"); fprintf(fp, "<td>\n"); // Data tables fprintf(fp, "%s", LPCSTR(GetPlayerInfoAsHTML())); fprintf(fp, "/<td>\n"); fprintf(fp, "<td>\n"); fprintf(fp, "%s", LPCSTR(GetButtonStatesAsHTML())); fprintf(fp, "%s", LPCSTR(GetBlindInfoAsHTML())); fprintf(fp, "%s", LPCSTR(GetCommonCardsAsHTML())); fprintf(fp, "%s", LPCSTR(GetPotsAsHTML())); fprintf(fp, "</td>\n"); // Footer of main table fprintf(fp, "</tr>\n"); fprintf(fp, "</table>\n"); // End of HTML fprintf(fp, "</body></html>\n"); fclose(fp); } LeaveCriticalSection(&p_heartbeat_thread->cs_update_in_progress); }
Int64 GetFreeDisk(const char *Name) { #if defined(TARGET_POSIX) char Root[NM]; GetPathRoot(Name,Root); ULARGE_INTEGER uiTotalSize,uiTotalFree,uiUserFree; uiUserFree.u.LowPart=uiUserFree.u.HighPart=0; if ( GetDiskFreeSpaceEx( Root, &uiUserFree, &uiTotalSize, &uiTotalFree ) ) { return(int32to64(uiUserFree.u.HighPart,uiUserFree.u.LowPart)); } return 0; //#ifdef _WIN_32 #elif defined(_WIN_32) char Root[NM]; GetPathRoot(Name,Root); typedef BOOL (WINAPI *GETDISKFREESPACEEX)( LPCTSTR,PULARGE_INTEGER,PULARGE_INTEGER,PULARGE_INTEGER ); static GETDISKFREESPACEEX pGetDiskFreeSpaceEx=NULL; if (pGetDiskFreeSpaceEx==NULL) { HMODULE hKernel=GetModuleHandle("kernel32.dll"); if (hKernel!=NULL) pGetDiskFreeSpaceEx=(GETDISKFREESPACEEX)GetProcAddress(hKernel,"GetDiskFreeSpaceExA"); } if (pGetDiskFreeSpaceEx!=NULL) { GetFilePath(Name,Root); ULARGE_INTEGER uiTotalSize,uiTotalFree,uiUserFree; uiUserFree.u.LowPart=uiUserFree.u.HighPart=0; if (pGetDiskFreeSpaceEx(*Root ? Root:NULL,&uiUserFree,&uiTotalSize,&uiTotalFree) && uiUserFree.u.HighPart<=uiTotalFree.u.HighPart) return(int32to64(uiUserFree.u.HighPart,uiUserFree.u.LowPart)); } DWORD SectorsPerCluster,BytesPerSector,FreeClusters,TotalClusters; if (!GetDiskFreeSpace(*Root ? Root:NULL,&SectorsPerCluster,&BytesPerSector,&FreeClusters,&TotalClusters)) return(1457664); Int64 FreeSize=SectorsPerCluster*BytesPerSector; FreeSize=FreeSize*FreeClusters; return(FreeSize); #elif defined(_BEOS) char Root[NM]; GetFilePath(Name,Root); dev_t Dev=dev_for_path(*Root ? Root:"."); if (Dev<0) return(1457664); fs_info Info; if (fs_stat_dev(Dev,&Info)!=0) return(1457664); Int64 FreeSize=Info.block_size; FreeSize=FreeSize*Info.free_blocks; return(FreeSize); #elif defined(_UNIX) return(1457664); #elif defined(_EMX) int Drive=(!isalpha(Name[0]) || Name[1]!=':') ? 0:toupper(Name[0])-'A'+1; if (_osmode == OS2_MODE) { FSALLOCATE fsa; if (DosQueryFSInfo(Drive,1,&fsa,sizeof(fsa))!=0) return(1457664); Int64 FreeSize=fsa.cSectorUnit*fsa.cbSector; FreeSize=FreeSize*fsa.cUnitAvail; return(FreeSize); } else { union REGS regs,outregs; memset(®s,0,sizeof(regs)); regs.h.ah=0x36; regs.h.dl=Drive; _int86 (0x21,®s,&outregs); if (outregs.x.ax==0xffff) return(1457664); Int64 FreeSize=outregs.x.ax*outregs.x.cx; FreeSize=FreeSize*outregs.x.bx; return(FreeSize); } #else #define DISABLEAUTODETECT return(1457664); #endif }
BOOL CAboutDlg::OnInitDialog() { CDialog::OnInitDialog(); HICON hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); SetIcon(hIcon, TRUE); // Set big icon SetIcon(hIcon, FALSE); // Set small icon CenterWindow(); m_Address.SetURL ( _T("mailto:[email protected]") ); m_Address.SetLinkCursor ( AfxGetApp()->LoadCursor ( IDC_HAND ) ); m_Address.SetToolTip( _T("发邮件至:[email protected]") ); m_Address.SetUnderline(); m_Address.SetItalic(); m_OK.SetIcon ( IDI_OPEN ); m_OK.AddToolTip ( _T("确定") ); m_OK.SetBtnCursor(IDC_HAND); m_OK.SetActiveFgColor(RGB(0,0,255)); m_More.SetIcon ( IDI_MORE ); m_More.AddToolTip ( _T("更多的...") ); m_More.SetBtnCursor(IDC_HAND); m_More.SetActiveFgColor(RGB(0,0,255)); CString str; // fill memory info MEMORYSTATUS MemStat; MemStat.dwLength = sizeof(MEMORYSTATUS); GlobalMemoryStatus(&MemStat); // Total Physical mem str.Format( _T("%lu KB"), MemStat.dwTotalPhys / 1024L); SetDlgItemText(IDC_PHYSICAL_MEM, str); // Free Physical mem str.Format( _T("%lu KB"), MemStat.dwAvailPhys / 1024L); SetDlgItemText(IDC_AVAIL_MEM, str); // Free Virtual mem str.Format( _T("%lu KB"), MemStat.dwAvailVirtual / 1024L); SetDlgItemText(IDC_AVAIL_VIRTUAL_MEM, str); // fill CPU info SYSTEM_INFO SysInfo; GetSystemInfo(&SysInfo); switch (SysInfo.dwProcessorType) { case PROCESSOR_INTEL_486: str = _T("Intel 80486"); break; case PROCESSOR_INTEL_PENTIUM: str = _T("Intel Pentium"); break; default: str = _T(""); break; } SetDlgItemText(IDC_CPU, str); // fill OS info OSVERSIONINFO OsInfo; OsInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); if (GetVersionEx(&OsInfo)) { // platform switch (OsInfo.dwPlatformId) { case VER_PLATFORM_WIN32_WINDOWS: str = _T("Windows 95/98"); break; case VER_PLATFORM_WIN32_NT: str = _T("Windows NT"); break; default: str = _T(""); break; } SetDlgItemText(IDC_OS, str); // version and language TCHAR szVer[512]= _T("不明"); GetWindowsVersion((LPSTR)szVer); str.Format(_T("%ld.%ld, %s"), OsInfo.dwMajorVersion, OsInfo.dwMinorVersion, szVer); SetDlgItemText(IDC_VERSION, str); } // fill disk information TCHAR szWindowsPath[_MAX_PATH]; GetWindowsDirectory(szWindowsPath, _MAX_PATH); ULARGE_INTEGER TotalNumberOfBytes, TotalNumberOfFreeBytes; GetDiskFreeSpaceEx((LPSTR)szWindowsPath, NULL, &TotalNumberOfBytes, &TotalNumberOfFreeBytes); // total space str.Format(_T("%lu KB"), TotalNumberOfBytes.QuadPart / 1024L); SetDlgItemText(IDC_TOTAL_SPACE, str); // free space str.Format(_T("%lu KB"), TotalNumberOfFreeBytes.QuadPart / 1024L); SetDlgItemText(IDC_FREE_SPACE, str); m_Max=0; CRect rc; GetWindowRect(&rc); rc.top+=LENGTHES/2; rc.bottom -= LENGTHES/2; MoveWindow(&rc); TCHAR *pArrCredit = { _T("黑白棋\t|" "1.6版||" "作者\r|上海财经大学98信息系|" "蔡莹||" // this is a quoted bitmap resource "声明\r" "|本软件属于自由免费软件" "|您可以任意拷贝" "|如有任何意见或建议" "|请给我发邮件" "|E-mail: [email protected]" "|您的意见对我很重要!" "|||||")}; // TODO: Add extra initialization here m_DyStatic.SubclassDlgItem(IDD_ABOUTDLG1,this); m_DyStatic.SetCredits(pArrCredit,'|'); m_DyStatic.SetSpeed(g_nStrollSpeed);//you can change it in the regedit m_DyStatic.SetColor(BACKGROUND_COLOR, RGB(0,255,200)); m_DyStatic.SetTransparent(); m_DyStatic.SetGradient(GRADIENT_RIGHT_DARK); m_DyStatic.StartScrolling(); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE }
static BOOL OnSelChange(HWND hwndDlg, PVIRTMEM pVirtMem) { TCHAR szBuffer[64]; MEMORYSTATUSEX MemoryStatus; ULARGE_INTEGER FreeDiskSpace; UINT /*i,*/ FreeMemMb /*, PageFileSizeMb*/; INT Index; Index = (INT)SendDlgItemMessage(hwndDlg, IDC_PAGEFILELIST, LB_GETCURSEL, 0, 0); if (Index >= 0 && Index < pVirtMem->Count) { /* Set drive letter */ SetDlgItemText(hwndDlg, IDC_DRIVE, pVirtMem->Pagefile[Index].szDrive); /* Set available disk space */ if (GetDiskFreeSpaceEx(pVirtMem->Pagefile[Index].szDrive, NULL, NULL, &FreeDiskSpace)) { pVirtMem->Pagefile[Index].FreeSize = (UINT)(FreeDiskSpace.QuadPart / (1024 * 1024)); _stprintf(szBuffer, _T("%u MB"), pVirtMem->Pagefile[Index].FreeSize); SetDlgItemText(hwndDlg, IDC_SPACEAVAIL, szBuffer); } if (pVirtMem->Pagefile[Index].NewMinSize == -1 && pVirtMem->Pagefile[Index].NewMaxSize == -1) { /* No pagefile */ EnableWindow(GetDlgItem(pVirtMem->hSelf, IDC_MAXSIZE), FALSE); EnableWindow(GetDlgItem(pVirtMem->hSelf, IDC_INITIALSIZE), FALSE); CheckDlgButton(pVirtMem->hSelf, IDC_NOPAGEFILE, BST_CHECKED); } else if (pVirtMem->Pagefile[Index].NewMinSize == 0 && pVirtMem->Pagefile[Index].NewMaxSize == 0) { /* System managed size*/ EnableWindow(GetDlgItem(pVirtMem->hSelf, IDC_MAXSIZE), FALSE); EnableWindow(GetDlgItem(pVirtMem->hSelf, IDC_INITIALSIZE), FALSE); CheckDlgButton(pVirtMem->hSelf, IDC_SYSMANSIZE, BST_CHECKED); } else { /* Custom size */ /* Enable and fill the custom values */ EnableWindow(GetDlgItem(pVirtMem->hSelf, IDC_MAXSIZE), TRUE); EnableWindow(GetDlgItem(pVirtMem->hSelf, IDC_INITIALSIZE), TRUE); SetDlgItemInt(pVirtMem->hSelf, IDC_INITIALSIZE, pVirtMem->Pagefile[Index].NewMinSize, FALSE); SetDlgItemInt(pVirtMem->hSelf, IDC_MAXSIZE, pVirtMem->Pagefile[Index].NewMaxSize, FALSE); CheckDlgButton(pVirtMem->hSelf, IDC_CUSTOM, BST_CHECKED); } /* Set minimum pagefile size */ SetDlgItemText(hwndDlg, IDC_MINIMUM, _T("16 MB")); /* Set recommended pagefile size */ MemoryStatus.dwLength = sizeof(MEMORYSTATUSEX); if (GlobalMemoryStatusEx(&MemoryStatus)) { FreeMemMb = (UINT)(MemoryStatus.ullTotalPhys / (1024 * 1024)); _stprintf(szBuffer, _T("%u MB"), FreeMemMb + (FreeMemMb / 2)); SetDlgItemText(hwndDlg, IDC_RECOMMENDED, szBuffer); } /* Set current pagefile size */ #if 0 PageFileSizeMb = 0; for (i = 0; i < 26; i++) { PageFileSizeMb += pVirtMem->Pagefile[i].InitialSize; } _stprintf(szBuffer, _T("%u MB"), PageFileSizeMb); SetDlgItemText(hwndDlg, IDC_CURRENT, szBuffer); #endif } return TRUE; }
void CReplayFrame::CreateReplayFrame(void){ FILE *fp = NULL; ULARGE_INTEGER free_bytes_for_user_on_disk = {0}, total_bytes_on_disk = {0}, free_bytes_total_on_disk = {0}; // Sanity check: Enough disk-space for replay frame? GetDiskFreeSpaceEx( p_filenames->OpenHoldemDirectory(), // Directory on disk of interest &free_bytes_for_user_on_disk, &total_bytes_on_disk, &free_bytes_total_on_disk); if (free_bytes_for_user_on_disk.QuadPart < FREE_SPACE_NEEDED_FOR_REPLAYFRAME) { write_log(preferences.debug_replayframes(), "[CReplayFrame] Not enough disk-space\n"); OH_MessageBox_Error_Warning("Not enough disk space to create replay-frame."); return; } // Get exclusive access to CScraper and CSymbols variables // (Wait for scrape/symbol cycle to finish before saving frame) EnterCriticalSection(&p_heartbeat_thread->cs_update_in_progress); CString next_frame; next_frame.Format("[%06d]", _next_replay_frame); // Replay-frame should always be mentioned in the log for easy reference write_log(k_always_log_basic_information, "[CReplayFrame] Shooting frame %s\n", next_frame); CreateBitMapFile(); // Create HTML file CString path = p_filenames->ReplayHTMLFilename(_next_replay_frame); if (fopen_s(&fp, path.GetString(), "w")==0) { write_log(preferences.debug_replayframes(), "[CReplayFrame] Creating HTML file: %s\n", path); // First line has to be the "title" of the table. // This is no longer valid HTML, but the way Ray.E.Bornert did it // for WinHoldem and WinScrape. fprintf(fp, "%s\n", LPCSTR(p_table_state->TableTitle()->Title())); fprintf(fp, "<br>\n"); // HTML header fprintf(fp, "<html>\n"); fprintf(fp, " <head>\n"); fprintf(fp, " <title>%s</title>\n", LPCSTR(p_table_state->TableTitle()->Title())); fprintf(fp, " </head>"); fprintf(fp, "<style>\n"); fprintf(fp, "td {text-align:right;}\n"); fprintf(fp, "</style>\n"); fprintf(fp, "<body>\n"); fprintf(fp, "<font face=courier>\n"); // Bitmap image fprintf(fp, "<img src=\"frame%06d.bmp\">\n", _next_replay_frame); fprintf(fp, "<br>\n"); // Title, data, frame-number, OH-version fprintf(fp, "%s", LPCSTR(GeneralInfo())); // Links forwards and backwards to the next frames fprintf(fp, "%s", LPCSTR(GetLinksToPrevAndNextFile())); fprintf(fp, "<br>\n"); fprintf(fp, "<br>\n"); // Header of main table for smaller data tables fprintf(fp, "<table>\n"); fprintf(fp, "<tr>\n"); fprintf(fp, "<td>\n"); // Data tables fprintf(fp, "%s", LPCSTR(GetPlayerInfoAsHTML())); fprintf(fp, "/<td>\n"); fprintf(fp, "<td>\n"); fprintf(fp, "%s", LPCSTR(GetButtonStatesAsHTML())); fprintf(fp, "%s", LPCSTR(GetBlindInfoAsHTML())); fprintf(fp, "%s", LPCSTR(GetCommonCardsAsHTML())); fprintf(fp, "%s", LPCSTR(GetPotsAsHTML())); fprintf(fp, "</td>\n"); // Footer of main table fprintf(fp, "</tr>\n"); fprintf(fp, "</table>\n"); // End of HTML fprintf(fp, "</body></html>\n"); fclose(fp); } LeaveCriticalSection(&p_heartbeat_thread->cs_update_in_progress); }
void Button_Stats(void) { short clicked_button; char buffer[37]; dword color_usage[256]; unsigned long long freeRam; qword mem_size = 0; int y; #if defined (__MINT__) _DISKINFO drvInfo; unsigned long STRAM=0,TTRAM=0; char helpBuf[64]={0}; #endif Open_window(310,174,"Statistics"); // Dessin de la fenetre ou va s'afficher le texte Window_display_frame_in(8,17,294,132); Block(Window_pos_X+(Menu_factor_X*9), Window_pos_Y+(Menu_factor_Y*18), Menu_factor_X*292,Menu_factor_Y*130,MC_Black); Window_set_normal_button(120,153,70,14,"OK",0,1,KEY_ESC); // 1 y=19; // row for first line Print_in_window(10,y,"Program version:",STATS_TITLE_COLOR,MC_Black); sprintf(buffer,"%s.%s",Program_version, SVN_revision); Print_in_window(146,y,buffer,STATS_DATA_COLOR,MC_Black); y+=16; Print_in_window(10,y,"Build options:",STATS_TITLE_COLOR,MC_Black); Print_in_window(146,y,TrueType_is_supported()?"TTF fonts":"no TTF fonts",STATS_DATA_COLOR,MC_Black); y+=8; Print_in_window(10,y,"Lua version:",STATS_TITLE_COLOR,MC_Black); Print_in_window_limited(146,y,Lua_version(),10,STATS_DATA_COLOR,MC_Black); y+=16; Print_in_window(10,y,"Free memory: ",STATS_TITLE_COLOR,MC_Black); y+=8; #if defined (__MINT__) // Display free TT/ST RAM freeRam=0; Atari_Memory_free(&STRAM,&TTRAM); freeRam=STRAM+TTRAM; buffer[0]='\0'; if(STRAM > (100*1024*1024)) sprintf(helpBuf,"ST:%u Mb ",(unsigned int)(STRAM/(1024*1024))); else if(freeRam > 100*1024) sprintf(helpBuf,"ST:%u Kb ",(unsigned int)(STRAM/1024)); else sprintf(helpBuf,"ST:%u b ",(unsigned int)STRAM); strncat(buffer,helpBuf,sizeof(char)*37); if(TTRAM > (100ULL*1024*1024*1024)) sprintf(helpBuf,"TT:%u Gb",(unsigned int)(TTRAM/(1024*1024*1024))); else if(TTRAM > (100*1024*1024)) sprintf(helpBuf,"TT:%u Mb",(unsigned int)(TTRAM/(1024*1024))); else if(freeRam > 100*1024) sprintf(helpBuf,"TT:%u Kb",(unsigned int)(TTRAM/1024)); else sprintf(helpBuf,"TT:%u b",(unsigned int)TTRAM); strncat(buffer,helpBuf,sizeof(char)*37); if(freeRam > (100ULL*1024*1024*1024)) sprintf(helpBuf,"(%u Gb)",(unsigned int)(freeRam/(1024*1024*1024))); else if(freeRam > (100*1024*1024)) sprintf(helpBuf,"(%u Mb)",(unsigned int)(freeRam/(1024*1024))); else if(freeRam > 100*1024) sprintf(helpBuf,"(%u Kb)",(unsigned int)(freeRam/1024)); else sprintf(helpBuf,"(%u b)",(unsigned int)freeRam); strncat(buffer,helpBuf,sizeof(char)*37); Print_in_window(18,y,buffer,STATS_DATA_COLOR,MC_Black); #else // Display free RAM (generic) freeRam = Memory_free(); if(freeRam > (100ULL*1024*1024*1024)) sprintf(buffer,"%u Gigabytes",(unsigned int)(freeRam/(1024*1024*1024))); else if(freeRam > (100*1024*1024)) sprintf(buffer,"%u Megabytes",(unsigned int)(freeRam/(1024*1024))); else if(freeRam > 100*1024) sprintf(buffer,"%u Kilobytes",(unsigned int)(freeRam/1024)); else sprintf(buffer,"%u bytes",(unsigned int)freeRam); Print_in_window(114,y,buffer,STATS_DATA_COLOR,MC_Black); #endif y+=8; // Used memory Print_in_window(10,y,"Used memory pages: ",STATS_TITLE_COLOR,MC_Black); if(Stats_pages_memory > (100LL*1024*1024*1024)) sprintf(buffer,"%ld (%lld Gb)",Stats_pages_number, Stats_pages_memory/(1024*1024*1024)); else if(Stats_pages_memory > (100*1024*1024)) sprintf(buffer,"%ld (%lld Mb)",Stats_pages_number, Stats_pages_memory/(1024*1024)); else sprintf(buffer,"%ld (%lld Kb)",Stats_pages_number, Stats_pages_memory/1024); Print_in_window(162,y,buffer,STATS_DATA_COLOR,MC_Black); y+=8; #if defined(__WIN32__) { ULARGE_INTEGER tailleU; GetDiskFreeSpaceEx(Main_selector.Directory,&tailleU,NULL,NULL); mem_size = tailleU.QuadPart; } #elif defined(__linux__) || defined(__macosx__) || defined(__FreeBSD__) || defined(__SYLLABLE__) || defined(__AROS__) { struct statfs disk_info; statfs(Main_selector.Directory,&disk_info); mem_size=(qword) disk_info.f_bfree * (qword) disk_info.f_bsize; } #elif defined(__HAIKU__) mem_size = haiku_get_free_space(Main_selector.Directory); #elif defined (__MINT__) mem_size=0; Dfree(&drvInfo,0); //number of free clusters*sectors per cluster*bytes per sector; // reports current drive mem_size=drvInfo.b_free*drvInfo.b_clsiz*drvInfo.b_secsiz; #else #define NODISKSPACESUPPORT // Free disk space is only for shows. Other platforms can display 0. #warning "Missing code for your platform !!! Check and correct please :)" mem_size=0; #endif // Display free space if (mem_size != 0) { #if defined(__AROS__) char *colon = strchr(Main_selector.Directory, ':'); int len = strlen(Main_selector.Directory); if (colon) { len = (long)colon - (long)Main_selector.Directory; } if (len > 8) len = 8; sprintf(buffer,"Free space on %.*s:",len,Main_selector.Directory); #else sprintf(buffer,"Free space on %c:",Main_selector.Directory[0]); #endif Print_in_window(10,y,buffer,STATS_TITLE_COLOR,MC_Black); if(mem_size > (100ULL*1024*1024*1024)) sprintf(buffer,"%u Gigabytes",(unsigned int)(mem_size/(1024*1024*1024))); else if(mem_size > (100*1024*1024)) sprintf(buffer,"%u Megabytes",(unsigned int)(mem_size/(1024*1024))); else if(mem_size > (100*1024)) sprintf(buffer,"%u Kilobytes",(unsigned int)(mem_size/1024)); else sprintf(buffer,"%u bytes",(unsigned int)mem_size); #if defined(__AROS__) Print_in_window(192,y,buffer,STATS_DATA_COLOR,MC_Black); #else Print_in_window(146,y,buffer,STATS_DATA_COLOR,MC_Black); #endif } else { #ifndef NODISKSPACESUPPORT Print_in_window(10,y,"Disk full!",STATS_TITLE_COLOR,MC_Black); #endif #undef NODISKSPACESUPPORT } y+=16; // Affichage des informations sur l'image Print_in_window(10,y,"Picture info.:",STATS_TITLE_COLOR,MC_Black); y+=8; // Affichage des dimensions de l'image Print_in_window(18,y,"Dimensions :",STATS_TITLE_COLOR,MC_Black); sprintf(buffer,"%dx%d",Main_image_width,Main_image_height); Print_in_window(122,y,buffer,STATS_DATA_COLOR,MC_Black); y+=8; // Affichage du nombre de couleur utilisé Print_in_window(18,y,"Colors used:",STATS_TITLE_COLOR,MC_Black); memset(color_usage,0,sizeof(color_usage)); sprintf(buffer,"%d",Count_used_colors(color_usage)); Print_in_window(122,y,buffer,STATS_DATA_COLOR,MC_Black); y+=16; // Affichage des dimensions de l'écran Print_in_window(10,y,"Resolution:",STATS_TITLE_COLOR,MC_Black); sprintf(buffer,"%dx%d",Screen_width,Screen_height); Print_in_window(106,y,buffer,STATS_DATA_COLOR,MC_Black); Update_rect(Window_pos_X,Window_pos_Y,Menu_factor_X*310,Menu_factor_Y*174); Display_cursor(); do { clicked_button=Window_clicked_button(); if (Is_shortcut(Key,0x200+BUTTON_HELP)) clicked_button=1; } while ( (clicked_button!=1) && (Key!=SDLK_RETURN) ); if(Key==SDLK_RETURN)Key=0; Close_window(); Unselect_button(BUTTON_HELP); Display_cursor(); }
int main( int argc, char *argv[] ) { #if defined(WIN32) && defined(_DEBUG) int tmpFlag = _CrtSetDbgFlag( _CRTDBG_REPORT_FLAG ); tmpFlag |= _CRTDBG_LEAK_CHECK_DF; _CrtSetDbgFlag( tmpFlag ); #endif InitModuleObjects(); addAbortHandler(ControlHandler); EnableSEHtoExceptionMapping(); dummyProc(); #ifndef __64BIT__ Thread::setDefaultStackSize(0x10000); // NB under windows requires linker setting (/stack:) #endif #ifdef _WIN32 Owned<CReleaseMutex> globalNamedMutex; #endif if (globals) globals->Release(); { Owned<IFile> iFile = createIFile("thor.xml"); globals = iFile->exists() ? createPTree(*iFile, ipt_caseInsensitive) : createPTree("Thor", ipt_caseInsensitive); } unsigned multiThorMemoryThreshold = 0; try { if (argc==1) { usage(); return 1; } cmdArgs = argv+1; mergeCmdParams(globals); cmdArgs = argv+1; const char *master = globals->queryProp("@MASTER"); if (!master) usage(); const char *slave = globals->queryProp("@SLAVE"); if (slave) { slfEp.set(slave); localHostToNIC(slfEp); } else slfEp.setLocalHost(0); if (globals->hasProp("@SLAVENUM")) mySlaveNum = atoi(globals->queryProp("@SLAVENUM")); else mySlaveNum = slfEp.port; // shouldn't happen, provided by script setMachinePortBase(slfEp.port); slfEp.port = getMachinePortBase(); startSlaveLog(); startMPServer(getFixedPort(TPORT_mp)); #ifdef USE_MP_LOG startLogMsgParentReceiver(); LOG(MCdebugProgress, thorJob, "MPServer started on port %d", getFixedPort(TPORT_mp)); #endif SocketEndpoint masterEp(master); localHostToNIC(masterEp); setMasterPortBase(masterEp.port); markNodeCentral(masterEp); if (RegisterSelf(masterEp)) { #define ISDALICLIENT // JCSMORE plugins *can* access dali - though I think we should probably prohibit somehow. #ifdef ISDALICLIENT const char *daliServers = globals->queryProp("@DALISERVERS"); if (!daliServers) { LOG(MCerror, thorJob, "No Dali server list specified\n"); return 1; } Owned<IGroup> serverGroup = createIGroup(daliServers, DALI_SERVER_PORT); unsigned retry = 0; loop { try { LOG(MCdebugProgress, thorJob, "calling initClientProcess"); initClientProcess(serverGroup,DCR_ThorSlave, getFixedPort(TPORT_mp)); break; } catch (IJSOCK_Exception *e) { if ((e->errorCode()!=JSOCKERR_port_in_use)) throw; FLLOG(MCexception(e), thorJob, e,"InitClientProcess"); if (retry++>10) throw; e->Release(); LOG(MCdebugProgress, thorJob, "Retrying"); Sleep(retry*2000); } } setPasswordsFromSDS(); #endif StringBuffer thorPath; globals->getProp("@thorPath", thorPath); recursiveCreateDirectory(thorPath.str()); int err = _chdir(thorPath.str()); if (err) { IException *e = MakeErrnoException(-1, "Failed to change dir to '%s'",thorPath.str()); FLLOG(MCexception(e), thorJob, e); throw e; } // Initialization from globals setIORetryCount(globals->getPropInt("Debug/@ioRetries")); // default == 0 == off StringBuffer str; if (globals->getProp("@externalProgDir", str.clear())) _mkdir(str.str()); else globals->setProp("@externalProgDir", thorPath); const char * overrideBaseDirectory = globals->queryProp("@thorDataDirectory"); const char * overrideReplicateDirectory = globals->queryProp("@thorReplicateDirectory"); StringBuffer datadir; StringBuffer repdir; if (getConfigurationDirectory(globals->queryPropTree("Directories"),"data","thor",globals->queryProp("@name"),datadir)) overrideBaseDirectory = datadir.str(); if (getConfigurationDirectory(globals->queryPropTree("Directories"),"mirror","thor",globals->queryProp("@name"),repdir)) overrideReplicateDirectory = repdir.str(); if (overrideBaseDirectory&&*overrideBaseDirectory) setBaseDirectory(overrideBaseDirectory, false); if (overrideReplicateDirectory&&*overrideBaseDirectory) setBaseDirectory(overrideReplicateDirectory, true); StringBuffer tempdirstr; const char *tempdir = globals->queryProp("@thorTempDirectory"); if (getConfigurationDirectory(globals->queryPropTree("Directories"),"temp","thor",globals->queryProp("@name"),tempdirstr)) tempdir = tempdirstr.str(); SetTempDir(tempdir,true); useMemoryMappedRead(globals->getPropBool("@useMemoryMappedRead")); LOG(MCdebugProgress, thorJob, "ThorSlave Version LCR - %d.%d started",THOR_VERSION_MAJOR,THOR_VERSION_MINOR); StringBuffer url; LOG(MCdebugProgress, thorJob, "Slave %s - temporary dir set to : %s", slfEp.getUrlStr(url).toCharArray(), queryTempDir()); #ifdef _WIN32 ULARGE_INTEGER userfree; ULARGE_INTEGER total; ULARGE_INTEGER free; if (GetDiskFreeSpaceEx("c:\\",&userfree,&total,&free)&&total.QuadPart) { unsigned pc = (unsigned)(free.QuadPart*100/total.QuadPart); LOG(MCdebugProgress, thorJob, "Total disk space = %"I64F"d k", total.QuadPart/1000); LOG(MCdebugProgress, thorJob, "Free disk space = %"I64F"d k", free.QuadPart/1000); LOG(MCdebugProgress, thorJob, "%d%% disk free\n",pc); } #endif if (getConfigurationDirectory(globals->queryPropTree("Directories"),"query","thor",globals->queryProp("@name"),str.clear())) globals->setProp("@query_so_dir", str.str()); else globals->getProp("@query_so_dir", str.clear()); if (str.length()) { if (globals->getPropBool("Debug/@dllsToSlaves", true)) { StringBuffer uniqSoPath; if (PATHSEPCHAR == str.charAt(str.length()-1)) uniqSoPath.append(str.length()-1, str.str()); else uniqSoPath.append(str); uniqSoPath.append("_").append(getMachinePortBase()); str.swapWith(uniqSoPath); globals->setProp("@query_so_dir", str.str()); } PROGLOG("Using querySo directory: %s", str.str()); recursiveCreateDirectory(str.str()); } multiThorMemoryThreshold = globals->getPropInt("@multiThorMemoryThreshold")*0x100000; if (multiThorMemoryThreshold) { StringBuffer lgname; if (!globals->getProp("@multiThorResourceGroup",lgname)) globals->getProp("@nodeGroup",lgname); if (lgname.length()) { Owned<ILargeMemLimitNotify> notify = createMultiThorResourceMutex(lgname.str()); setMultiThorMemoryNotify(multiThorMemoryThreshold,notify); PROGLOG("Multi-Thor resource limit for %s set to %"I64F"d",lgname.str(),(__int64)multiThorMemoryThreshold); } else multiThorMemoryThreshold = 0; } slaveMain(); } LOG(MCdebugProgress, thorJob, "ThorSlave terminated OK"); } catch (IException *e) { FLLOG(MCexception(e), thorJob, e,"ThorSlave"); e->Release(); } catch (CATCHALL) { FLLOG(MCerror, thorJob, "ThorSlave exiting because of uncaught exception"); } ClearTempDirs(); if (multiThorMemoryThreshold) setMultiThorMemoryNotify(0,NULL); roxiemem::releaseRoxieHeap(); #ifdef ISDALICLIENT closeEnvironment(); closedownClientProcess(); // dali client closedown #endif #ifdef USE_MP_LOG stopLogMsgReceivers(); #endif stopMPServer(); ::Release(globals); releaseAtoms(); // don't know why we can't use a module_exit to destruct these... return 0; }