sobota, 7 kwietnia 2018

class with disk information, wchar_t use (C++ Builder)


CLASS:

#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
#include <vcl.h>
#define length_bufor 255
class Disc
{
private:
DWORD sectors;
DWORD serial;
DWORD free_cl;
DWORD bytes_in_sector;
DWORD number_claster;
DWORD total_free_bytes;
wchar_t *changeDWORD(unsigned int value)
{
size_t i,j,width;
j=0;
wchar_t temp_buff1[50];
static wchar_t temp_buff2[75];
width=wcslen(temp_buff1);
swprintf(temp_buff1,sizeof(temp_buff1),L"%1u",value);
for(i=0;i<width;i++)
{
;
if(i&&((width-i)%3)==0)
{
;
temp_buff2[i+j]=' ';j++;
}
temp_buff2[i+j]=temp_buff1[i];
}
temp_buff2[i+j]=temp_buff1[i];

return temp_buff2;

}
wchar_t temp_Str[40];
UnicodeString Volumen;
UnicodeString BytSectors;
UnicodeString Serial;
UnicodeString temp_Path;
UnicodeString Sectors;
UnicodeString Claster;
UnicodeString FreeB;
public:
Disc(UnicodeString discPath)
{

UnicodeString vol;
vol.SetLength(length_bufor);
temp_Path=discPath;
if(GetVolumeInformation(temp_Path.w_str(),vol.w_str(),vol.Length(),&serial,
NULL,NULL,NULL,NULL))
{
_itow(serial,temp_Str,20);
Volumen=vol;
Serial=temp_Str;
GetDiskFreeSpace(temp_Path.w_str(),&sectors,&bytes_in_sector,&free_cl,&number_claster);
total_free_bytes=bytes_in_sector*sectors*number_claster;
Sectors=changeDWORD(sectors);
BytSectors=changeDWORD(bytes_in_sector);
Claster=changeDWORD(number_claster);
FreeB=changeDWORD(total_free_bytes);


}
else
{
ShowMessage("Disc is protected");
Application->Terminate();
}


}
UnicodeString give_Volumen()
{
return Volumen;
}
UnicodeString give_Serial()
{
return Serial;
}
UnicodeString give_Sectors()
{
return Sectors;
}
UnicodeString give_byte_in_Sector()
{
return BytSectors;
}
UnicodeString give_Claster()
{
return Claster;
}
UnicodeString give_free_Bytes()
{
return FreeB;
}

};

EXAMPLE:

void __fastcall TForm1::Button2Click(TObject *Sender)
{
  Disc my_D("C:\\");
  ListBox1->Items->Add(my_D.give_Volumen());
  ListBox1->Items->Add(my_D.give_Serial());
  ListBox1->Items->Add(my_D.give_Claster());
  ListBox1->Items->Add(my_D.give_Sectors());
  ListBox1->Items->Add(my_D.give_byte_in_Sector());
  ListBox1->Items->Add(my_D.give_free_Bytes());
}

Brak komentarzy:

Prześlij komentarz