rtoss

Subversion Repositories:
Compare Path: Rev
With Path: Rev
/volumes/ @ 206  →  /volumes/ @ 207
/volumes/volumes-classic.c
@@ -1,36 +1,49 @@
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdio.h>
#include <stdint.h>
//#include <stdint.h>
#include <string.h>
#include <locale.h>
 
WCHAR *fdigitsW(uint64_t integer);
WCHAR *ComputerUnits(uint64_t integer, int maxdiv);
#ifdef _MSC_VER
#if _MSC_VER < 1200
// VC++ < 6.0 doesn't support i64 to double (VC5 untested)
typedef __int64 uint64_t;
#else
typedef unsigned __int64 uint64_t;
#endif
#endif
#ifndef INVALID_FILE_ATTRIBUTES
#define INVALID_FILE_ATTRIBUTES ((DWORD)-1)
#endif
 
char *fdigitsA(uint64_t integer);
char *ComputerUnits(uint64_t integer, int maxdiv);
void DrawGauge(int length, int percent, int isempty);
int IsTargetDrive(int DriveType, int flgNoRemoveable, int flgIsRealFloppy);
void ShowVolume(WCHAR* VolumeName, int flgShowDevName, int flgVerbose, int flgUnit, int flgGauge, int flgNoRemoveable);
void ShowVolume(char* VolumeName, int flgShowDevName, int flgVerbose, int flgUnit, int flgGauge, int flgNoRemoveable);
 
#define MAX_PLACES 64
WCHAR *fdigitsW(uint64_t integer) {
static WCHAR fdigits[MAX_PLACES + (MAX_PLACES / 3) + 1];
WCHAR digits[MAX_PLACES + 1];
WCHAR *dgt = digits, *fdgt = fdigits;
char *fdigitsA(uint64_t integer) {
static char fdigits[MAX_PLACES + (MAX_PLACES / 3) + 1];
char digits[MAX_PLACES + 1];
char *dgt = digits, *fdgt = fdigits;
int places;
 
places = swprintf(digits, L"%I64u", integer); /* convert integer to string */
places = sprintf(digits, "%I64u", integer); /* convert integer to string */
/* places = digits in string */
while (*fdgt++ = *dgt++) /* while there are more digits*/
if (--places) /* if places-1 > 0 */
if ( !(places % 3) ) /* if places is multiple of 3 */
*fdgt++ = L','; /* insert a comma here */
*fdgt++ = ','; /* insert a comma here */
 
return fdigits;
}
 
WCHAR *ComputerUnits(uint64_t integer, int maxdiv) {
static WCHAR fdigits[MAX_PLACES + (MAX_PLACES / 3) + 1];
WCHAR *units[] = {L"B",L"KB",L"MB",L"GB",L"TB",L"PB",L"EB", NULL};
WCHAR tmp[16] = {0};
char *ComputerUnits(uint64_t integer, int maxdiv) {
static char fdigits[MAX_PLACES + (MAX_PLACES / 3) + 1];
char *units[] = {"B","KB","MB","GB","TB","PB","EB", NULL};
char tmp[16] = {0};
int count = 0;
double smallfloat;
uint64_t smallint;
@@ -42,11 +55,11 @@
}
 
if(count) {
swprintf(tmp, L"%.3f", smallfloat-smallint);
sprintf(tmp, "%.3f", smallfloat-smallint);
tmp[4] = 0; // truncate
}
 
swprintf(fdigits, L"%s%s %s", fdigitsW(smallint), tmp+1, units[count]); /* convert integer to string */
sprintf(fdigits, "%s%s %s", fdigitsA(smallint), tmp+1, units[count]); /* convert integer to string */
 
return fdigits;
}
@@ -83,12 +96,12 @@
return ret;
}
 
void ShowVolume(WCHAR* VolumeName, int flgShowDevName, int flgVerbose, int flgUnit, int flgGauge, int flgRemoveable) {
void ShowVolume(char* VolumeName, int flgShowDevName, int flgVerbose, int flgUnit, int flgGauge, int flgRemoveable) {
DWORD Error = ERROR_SUCCESS;
DWORD CharCount = 0;
WCHAR tmp[MAX_PATH] = L"";
WCHAR DeviceName[MAX_PATH] = L"";
WCHAR* VolumeTypeName = 0;
char tmp[MAX_PATH] = "";
char DeviceName[MAX_PATH] = "";
char* VolumeTypeName = 0;
UINT VolumeType = 0;
size_t Index = 0;
DWORD SectorsPerCluster = 0;
@@ -103,37 +116,37 @@
double den = 0.0f;
double percent = 0.0f;
 
wcscpy(tmp, VolumeName);
strcpy(tmp, VolumeName);
 
VolumeType = GetDriveTypeW(tmp);
VolumeType = GetDriveTypeA(tmp);
switch(VolumeType) {
case 0:
VolumeTypeName = L"(Unknown)";
VolumeTypeName = "(Unknown)";
break;
case 1:
VolumeTypeName = L"(invalid root path)";
VolumeTypeName = "(invalid root path)";
break;
case 2:
VolumeTypeName = L"(Removable)";
VolumeTypeName = "(Removable)";
break;
case 3:
VolumeTypeName = L"(Fixed)";
VolumeTypeName = "(Fixed)";
break;
case 4:
VolumeTypeName = L"(Remote)";
VolumeTypeName = "(Remote)";
break;
case 5:
VolumeTypeName = L"(CD-ROM)";
VolumeTypeName = "(CD-ROM)";
break;
case 6:
VolumeTypeName = L"(RAM Disk)";
VolumeTypeName = "(RAM Disk)";
break;
}
 
if(!flgVerbose && !IsTargetDrive(VolumeType,7,0)) return;
// get free space information
if(IsTargetDrive(VolumeType,flgRemoveable,flgIsRealFloppy)) {
GetDiskFreeSpaceW(tmp, &SectorsPerCluster, &BytesPerSector, &NumberOfFreeClusters, &TotalNumberOfClusters);
GetDiskFreeSpaceA(tmp, &SectorsPerCluster, &BytesPerSector, &NumberOfFreeClusters, &TotalNumberOfClusters);
FreeSize = TotalSize = SectorsPerCluster;
FreeSize *= BytesPerSector;
TotalSize *= BytesPerSector;
@@ -146,34 +159,34 @@
}
 
if(flgVerbose) {
wprintf(L"\nFound a device: %s", DeviceName);
wprintf(L"\nVolume name: %s %s", tmp, VolumeTypeName);
wprintf(L"\nPaths:");
printf("\nFound a device: %s", DeviceName);
printf("\nVolume name: %s %s", tmp, VolumeTypeName);
printf("\nPaths:");
}
else if(flgGauge) {
DrawGauge(36,(int)percent,!IsTargetDrive(VolumeType,flgRemoveable,flgIsRealFloppy)|!TotalSize);
}
 
if (!flgShowDevName)
wprintf(L" %s", tmp);
printf(" %s", tmp);
 
 
if(IsTargetDrive(VolumeType,flgRemoveable,flgIsRealFloppy)) {
// VolumeName is reused here
wcscpy(tmp, ComputerUnits(FreeSize, flgUnit));
strcpy(tmp, ComputerUnits(FreeSize, flgUnit));
 
// DeviceName is reused here
if(TotalSize)
swprintf(DeviceName, L"%.2f", percent);
sprintf(DeviceName, "%.2f", percent);
else
wcscpy(DeviceName, L"--");
strcpy(DeviceName, "--");
 
wprintf(L" (%s / %s) %s%%", tmp, ComputerUnits(TotalSize, flgUnit), DeviceName);
printf(" (%s / %s) %s%%", tmp, ComputerUnits(TotalSize, flgUnit), DeviceName);
}
if(!flgVerbose) {
if(VolumeType != 3) wprintf(L" %s", VolumeTypeName);
if(VolumeType != 3) printf(" %s", VolumeTypeName);
}
wprintf(L"\n");
printf("\n");
}
 
 
@@ -184,7 +197,7 @@
BOOL Found = FALSE;
size_t Index = 0;
BOOL Success = FALSE;
WCHAR VolumeName[MAX_PATH] = L"";
char VolumeName[MAX_PATH] = "";
DWORD dwAttrib = 0;
 
int i = 1;
@@ -235,9 +248,10 @@
if(!flgForceEnum)
flgNonEnum = 1;
// dwAttrib is reused
dwAttrib = MultiByteToWideChar(CP_ACP, 0, argv[i], -1, VolumeName, MAX_PATH);
strcpy(VolumeName, argv[i]);
dwAttrib = strlen(VolumeName);
// workaround on getting free space from \\host\share
if (VolumeName[dwAttrib-2] != L'\\') VolumeName[dwAttrib-1] = L'\\';
if (VolumeName[dwAttrib-2] != '\\') VolumeName[dwAttrib-1] = '\\';
ShowVolume(VolumeName, 0, flgVerbose, flgUnit, flgGauge, flgRemoveable);
} else {
printf("%s is not valid path.\n", argv[i]);
@@ -246,16 +260,14 @@
}
}
 
setlocale(LC_CTYPE, ""); // reset locale
 
if(!flgNonEnum) {
 
wcscpy(VolumeName,L"A:\\");
strcpy(VolumeName,"A:\\");
if(flgRemoveable & 2) i = 0;
else i = 2;
// i is reused here
for (; i< 26 ; i++) {
VolumeName[0] = L'A' + i;
VolumeName[0] = 'A' + i;
ShowVolume(VolumeName, 0, flgVerbose, flgUnit, flgGauge, flgRemoveable);
}