Alloc
Новичок
Приветствую!
Помогите поправить скрип, таким образом, что бы он выдавал ПРАВИЛЬНЫЙ размер дисков. Потому что система показывает мне одно а программа немного другое.
И дело тут как я заметил в версии компилятора, т.е. я компилирую на ANSI а скрипт написан для UNICODE. В UNICODE такой проблемы нет. Буду вам очень благодарен за помощь.
Собственно вот сам скрипт:
Помогите поправить скрип, таким образом, что бы он выдавал ПРАВИЛЬНЫЙ размер дисков. Потому что система показывает мне одно а программа немного другое.
И дело тут как я заметил в версии компилятора, т.е. я компилирую на ANSI а скрипт написан для UNICODE. В UNICODE такой проблемы нет. Буду вам очень благодарен за помощь.
Собственно вот сам скрипт:
Код:
[Setup]
AppName=My Program
AppVerName=My Program v.1.2
DefaultDirName={pf}\My Program
;BitmapResource=Drive:img_small.bmp
[CustomMessages]
rus.DiskName=Имя
rus.DiskFileSystem=Файловая система
rus.DiskTotal=Ёмкость
rus.DiskFree=Свободно
rus.DiskType=Тип
eng.DiskName=Name
eng.DiskFileSystem=File System
eng.DiskTotal=Capacity
eng.DiskFree=Free Space
eng.DiskType=Type
[Code]
#ifdef UNICODE
#define A "W"
#else
#define A "A"
#endif
const
#ifndef NeedHDD
DRIVE_NO_ROOT_DIR = 1;
DRIVE_REMOVABLE = 2;
DRIVE_FIXED = 3;
#endif
MAX_PATH = 260;
SHGFI_ICON = $100;
SHGFI_SMALLICON = $1;
SHGFI_DISPLAYNAME = $200;
SHGFI_TYPENAME = $400;
type
_SHFILEINFO = record
hIcon: HICON;
iIcon: Integer;
dwAttributes: DWORD;
szDisplayName: array [0..MAX_PATH-1] of Char;
szTypeName: array [0..79] of Char;
end;
_ULARGE_INTEGER = record
LowPart: DWORD;
HighPart: DWORD;
end;
DriveInfo = record
DriveName: String;
DriveFileSystemName: String;
DriveSize: Extended;
DriveFreeSize: array [0..1] of Extended;
DriveType: String;
DriveIcon: _SHFILEINFO;
end;
function SHGetFileInfo(pszPath: String; dwFileAttributes: DWORD; var psfi: _SHFILEINFO; cbFileInfo, uFlags: UINT): DWORD; external 'SHGetFileInfo{#A}@shell32.dll stdcall';
function StrFormatByteSize64(qdw: Currency; var pszBuf: Char; cchBuf: UINT): PAnsiChar; external 'StrFormatByteSize64A@shlwapi.dll stdcall';
function GetVolumeInformationLp(lpRootPathName, lpVolumeNameBuffer: String; nVolumeNameSize, lpVolumeSerialNumber: DWORD; var lpMaximumComponentLength, lpFileSystemFlags: DWORD; lpFileSystemNameBuffer: String; nFileSystemNameSize: DWORD): BOOL; external 'GetVolumeInformation{#A}@kernel32.dll stdcall';
function GetDriveTypeLp(lpRootPathName: String): UINT; external 'GetDriveType{#A}@kernel32.dll stdcall';
function GetDiskFreeSpaceEx(lpDirectoryName: String; var lpFreeBytesAvailableToCaller, lpTotalNumberOfBytes, lpTotalNumberOfFreeBytes: _ULARGE_INTEGER): BOOL; external 'GetDiskFreeSpaceEx{#A}@kernel32.dll stdcall';
function BytesToSize(Bytes: Extended): String;
var
pszBuf: array [0..15] of Char;
begin
try
Result := StrFormatByteSize64(Abs(Bytes div 1E4), pszBuf[0], SizeOf(pszBuf));
except end;
end;
function CharArrayToString(cArray: array of Char): String;
begin
Result := '';
while cArray[Length(Result)] <> #0 do Insert(cArray[Length(Result)], Result, Length(Result)+1);
end;
function Size64(QuadPart: _ULARGE_INTEGER): Extended;
begin
Result := $7FFFFFFF;
Result := ((QuadPart.HighPart + integer(QuadPart.LowPart < 0))*Result + QuadPart.HighPart + integer(QuadPart.LowPart < 0))*2 + QuadPart.LowPart;
end;
procedure GetDrivesInfo(var DriveArray: array of DriveInfo);
var
i, e: Integer;
iIcon: WORD;
UndefDriveLetter: String;
DriveType: UINT;
DrivePath: String;
VolumeName, FileSystemName: String;
ComponentLength, SerialNumber, FileSystemFlags: DWORD;
FreeBytesAvailableToCaller, TotalNumberOfBytes, TotalNumberOfFreeBytes: _ULARGE_INTEGER;
begin
for i := 67 to 90 do // Loop from C..Z to determine available drives
begin
UndefDriveLetter := Chr(i) + ':\';
DriveType := GetDriveTypeLp(UndefDriveLetter);
case DriveType of
DRIVE_REMOVABLE, DRIVE_FIXED: begin
VolumeName := StringOfChar(#32, MAX_PATH);
FileSystemName := StringOfChar(#32, MAX_PATH);
GetVolumeInformationLp(UndefDriveLetter, VolumeName, MAX_PATH, SerialNumber, ComponentLength, FileSystemFlags, FileSystemName, MAX_PATH);
GetDiskFreeSpaceEx(UndefDriveLetter, FreeBytesAvailableToCaller, TotalNumberOfBytes, TotalNumberOfFreeBytes);
SetArrayLength(DriveArray, GetArrayLength(DriveArray)+1);
e := GetArrayLength(DriveArray)-1;
SHGetFileInfo(UndefDriveLetter, FILE_ATTRIBUTE_DIRECTORY, DriveArray[e].DriveIcon, sizeof(DriveArray[e].DriveIcon), SHGFI_ICON or SHGFI_SMALLICON or SHGFI_TYPENAME or SHGFI_DISPLAYNAME);
DriveArray[e].DriveName := CharArrayToString(DriveArray[e].DriveIcon.szDisplayName);
DriveArray[e].DriveFileSystemName := FileSystemName;
DriveArray[e].DriveSize := Size64(TotalNumberOfBytes);
DriveArray[e].DriveFreeSize[0] := Size64(TotalNumberOfFreeBytes);
if DriveArray[e].DriveSize > 0 then DriveArray[e].DriveFreeSize[1] := DriveArray[e].DriveFreeSize[0]*100/DriveArray[e].DriveSize;
DriveArray[e].DriveType := CharArrayToString(DriveArray[e].DriveIcon.szTypeName);
end;
DRIVE_NO_ROOT_DIR: Continue;
end;
end;
end;
procedure DriveListViewOnClick(Sender: TObject);
begin
if Assigned(TListView(Sender).Selected) then
WizardForm.DirEdit.Text := AddBackSlash(Copy(TListView(Sender).Selected.Caption, Pos('(', TListView(Sender).Selected.Caption)+1, 2)) + Copy(WizardForm.DirEdit.Text, 4, Length(WizardForm.DirEdit.Text));
end;
procedure DriveListViewColumnClick(Sender: TObject; Column: TListColumn);
begin
TListView(Sender).Tag := Column.Index;
with TListView(Sender) do
begin
if DesignInfo = 0 then DesignInfo := 1 else DesignInfo := -DesignInfo;
AlphaSort;
end;
end;
procedure DriveListViewOnCompare(Sender: TObject; Item1, Item2: TListItem; Data: Integer; var Compare: Integer);
begin
with TListView(Sender) do
begin
if Tag = 0 then
Compare := DesignInfo*CompareText(Item1.Caption, Item2.Caption)
else
Compare := DesignInfo*CompareText(Item1.SubItems[Tag-1], Item2.SubItems[Tag-1]);
end;
end;
procedure GetDiskInfo;
var
ReadyArray: array of DriveInfo;
DriveListView: TListView;
NewColumn: TListColumn;
ListItem: TListItem;
ImgList: TImageList;
i, e: Integer;
ico: TIcon;
begin
GetDrivesInfo(ReadyArray);
e := GetArrayLength(ReadyArray)-1;
DriveListView := TListView.Create(nil);
with DriveListView do
begin
Parent := WizardForm.SelectDirPage;
ViewStyle := vsReport;
ReadOnly := True;
//SetBounds(WizardForm.DirEdit.Left, WizardForm.DirEdit.Top + ScaleY(40), WizardForm.DirEdit.Width, ScaleY(200));
SetBounds(WizardForm.DirEdit.Left, WizardForm.DirEdit.Top + ScaleY(30), WizardForm.DirEdit.Width+85, ScaleY(99));
OnClick := @DriveListViewOnClick;
OnColumnClick := @DriveListViewColumnClick;
OnCompare := @DriveListViewOnCompare;
ImgList := TImageList.Create(DriveListView);
ImgList.BkColor := Color;
for i := 0 to e do
begin
ico := TIcon.Create;
ico.Handle := ReadyArray[i].DriveIcon.hIcon;
ImgList.AddIcon(ico);
ico.Free;
end;
SmallImages := ImgList;
NewColumn := Columns.Add;
NewColumn.Caption := ExpandConstant('{cm:DiskName}');
NewColumn.Width := ScaleX(130);
NewColumn := Columns.Add;
NewColumn.Caption := ExpandConstant('{cm:DiskFileSystem}');
NewColumn.Width := ScaleX(105);
NewColumn := Columns.Add;
NewColumn.Caption := ExpandConstant('{cm:DiskTotal}');
NewColumn.Width := ScaleX(60);
NewColumn := Columns.Add;
NewColumn.Caption := ExpandConstant('{cm:DiskFree}');
NewColumn.Width := ScaleX(90);
NewColumn := Columns.Add;
NewColumn.Caption := ExpandConstant('{cm:DiskType}');
NewColumn.Width := ScaleX(100);
for i := 0 to e do
begin
ListItem := Items.Add;
with ListItem do
begin
Caption := ReadyArray[i].DriveName;
SubItems.Add(ReadyArray[i].DriveFileSystemName);
SubItems.Add(BytesToSize(ReadyArray[i].DriveSize));
SubItems.Add(Format('%s (%d%%)', [BytesToSize(ReadyArray[i].DriveFreeSize[0]), Round(ReadyArray[i].DriveFreeSize[1])]));
SubItems.Add(ReadyArray[i].DriveType);
ImageIndex := i;
end;
end;
end;
end;
Последнее редактирование: