FileForums

FileForums (https://fileforums.com/index.php)
-   Conversion Tutorials (https://fileforums.com/forumdisplay.php?f=55)
-   -   Inno Setup 5.5.1 limitation (https://fileforums.com/showthread.php?t=97697)

JRD! 24-02-2016 02:25

Inno Setup 5.5.1 limitation
 
Hi dudes,

I have a little problem, I want to get the weight of greater than +2Gb file with Inno Setup 5.5.1 ee2, I try many things without success, can someone help me ?

Many thanks!

Example:

Code:


#define FileSize "D:\Game\Grand Theft Auto V\x64q.rpf"

[Setup]
AppName=My Application
AppVersion=1.5
DefaultDirName={pf}\My Application

[_Code]
const
    // Some constants for CreateFile ().
    GENERIC_READ          = $80000000;
    GENERIC_WRITE          = $40000000;
    GENERIC_EXECUTE        = $20000000;
    GENERIC_ALL            = $10000000;
    FILE_SHARE_READ        = 1;
    FILE_SHARE_WRITE      = 2;
    FILE_SHARE_DELETE      = 4;
    CREATE_NEW            = 1;
    CREATE_ALWAYS          = 2;
    OPEN_EXISTING          = 3;
    OPEN_ALWAYS            = 4;
    TRUNCATE_EXISTING      = 5;
    FILE_READ_ATTRIBUTES  = $80;
    FILE_WRITE_ATTRIBUTES  = $100;

    // General Win32.
    INVALID_HANDLE_VALUE  = -1;

function CloseHandle (hHandle: THandle): Boolean;
  external '[email protected] stdcall';

function CreateFile (
    lpFileName            : String;
    dwDesiredAccess        : Cardinal;
    dwShareMode            : Cardinal;
    lpSecurityAttributes  : Cardinal;
    dwCreationDisposition  : Cardinal;
    dwFlagsAndAttributes  : Cardinal;
    hTemplateFile          : Integer
): Integer;
 external '[email protected] stdcall';

function GetFileSize (hFile: THandle; var lpFileSizeHigh: Integer): Integer;
  external '[email protected] stdcall';

function GetTheFileSize (FileName: String): Integer;
var
    hFile:  THandle;
    iSize:  Integer;
    hSize:  Integer;
begin
    hFile := CreateFile (FileName,
        GENERIC_READ,// Desired access.
        FILE_SHARE_READ + FILE_SHARE_WRITE,
        0,                // Security attributes.
        OPEN_EXISTING,
        FILE_ATTRIBUTE_TEMPORARY,
        0);
    if (INVALID_HANDLE_VALUE = hFile) then
    begin
        Result := 0;
        Exit;
    end;
    iSize := GetFileSize (hFile, hSize);
    CloseHandle (hFile);
    Result := iSize;
end;

function InitializeSetup():Boolean;
var
  FileSize: integer;
begin
  FileSize := GetTheFileSize(ExpandConstant('{#FileSize}'));
  MsgBox(IntToStr(FileSize), mbInformation, mb_OK);
  Result := False;
end;


JRD! 24-02-2016 02:35

This example return INVALID_HANDLE_VALUE, how to fix it?

THANKS!

JRD! 24-02-2016 02:39

This fix it but return negative value :confused:

#ifdef UNICODE
external '[email protected] stdcall';
#else
external '[email protected] stdcall';
#endif

JRD! 24-02-2016 07:11

Solved, close this post!

Thanks moderator ;)

lolaya 24-02-2016 07:58

lol :D

julenza 25-04-2018 07:38

you have to write DiskSpanning = yes before setup and the problem will be solved
 
you have to write DiskSpanning = yes before setup and the problem will be solved.

Hi Giuseppe.

Quote:

Originally Posted by JRD! (Post 447551)
Hi dudes,

I have a little problem, I want to get the weight of greater than +2Gb file with Inno Setup 5.5.1 ee2, I try many things without success, can someone help me ?

Many thanks!

Example:

Code:


#define FileSize "D:\Game\Grand Theft Auto V\x64q.rpf"

[Setup]
AppName=My Application
AppVersion=1.5
DefaultDirName={pf}\My Application

[_Code]
const
    // Some constants for CreateFile ().
    GENERIC_READ          = $80000000;
    GENERIC_WRITE          = $40000000;
    GENERIC_EXECUTE        = $20000000;
    GENERIC_ALL            = $10000000;
    FILE_SHARE_READ        = 1;
    FILE_SHARE_WRITE      = 2;
    FILE_SHARE_DELETE      = 4;
    CREATE_NEW            = 1;
    CREATE_ALWAYS          = 2;
    OPEN_EXISTING          = 3;
    OPEN_ALWAYS            = 4;
    TRUNCATE_EXISTING      = 5;
    FILE_READ_ATTRIBUTES  = $80;
    FILE_WRITE_ATTRIBUTES  = $100;

    // General Win32.
    INVALID_HANDLE_VALUE  = -1;

function CloseHandle (hHandle: THandle): Boolean;
  external '[email protected] stdcall';

function CreateFile (
    lpFileName            : String;
    dwDesiredAccess        : Cardinal;
    dwShareMode            : Cardinal;
    lpSecurityAttributes  : Cardinal;
    dwCreationDisposition  : Cardinal;
    dwFlagsAndAttributes  : Cardinal;
    hTemplateFile          : Integer
): Integer;
 external '[email protected] stdcall';

function GetFileSize (hFile: THandle; var lpFileSizeHigh: Integer): Integer;
  external '[email protected] stdcall';

function GetTheFileSize (FileName: String): Integer;
var
    hFile:  THandle;
    iSize:  Integer;
    hSize:  Integer;
begin
    hFile := CreateFile (FileName,
        GENERIC_READ,// Desired access.
        FILE_SHARE_READ + FILE_SHARE_WRITE,
        0,                // Security attributes.
        OPEN_EXISTING,
        FILE_ATTRIBUTE_TEMPORARY,
        0);
    if (INVALID_HANDLE_VALUE = hFile) then
    begin
        Result := 0;
        Exit;
    end;
    iSize := GetFileSize (hFile, hSize);
    CloseHandle (hFile);
    Result := iSize;
end;

function InitializeSetup():Boolean;
var
  FileSize: integer;
begin
  FileSize := GetTheFileSize(ExpandConstant('{#FileSize}'));
  MsgBox(IntToStr(FileSize), mbInformation, mb_OK);
  Result := False;
end;



Siber Pro 26-04-2018 06:34

Answer
 
1 Attachment(s)
Why You Do Not Making Like This?

JRD! 06-05-2018 12:44

Quote:

Originally Posted by julenza (Post 470499)
you have to write DiskSpanning = yes before setup and the problem will be solved.

Hi Giuseppe.

Thank you but it has nothing to do with diskspanning, this is because inno setup 5.5.1 does not integrate the type of variable Int64, so limited to the max value of an integer (2 ^ 32) -1 bytes.
The problem is getting around by reviewing the result in megabytes.

Cesar82 07-05-2018 18:55

Possible solution.
 
1 Attachment(s)
Test this code.
If you need to make a calculation with the value, convert back to an extended type variable using the StrToFloat function.

Code:

#define FileSize "D:\Game\Grand Theft Auto V\x64q.rpf"

[Setup]
AppName=My Application
AppVersion=1.5
DefaultDirName={pf}\My Application

[ code]
const
  KFactor = $400; {1024}

function FormatBytes(const Bytes: Extended): String;
var
  Dms: Array of String;
  Amount: Extended;
  Idx: Byte;
begin
  Dms := ['B', 'KB', 'MB', 'GB', 'TB', 'PB'];
  Amount := Bytes;
  Idx := 0;
  while Amount > (0.9 * KFactor) do
  begin
    Inc(Idx)
    Amount := Amount / KFactor;
  end;
  if Abs(Amount - Trunc(Amount)) < 0.007 {0.07} then
    Result := Format('%.0f %s', [Amount, Dms[Idx]])
  else
    Result := Format('%.2f %s', [Amount, Dms[Idx]]);
end;

function Size64(Hi, Lo: Longint): Extended;
begin
  Result := Lo;
  if Lo < 0 then
    Result := Result + $7FFFFFFF + $7FFFFFFF + 2;
  for Hi := (Hi - 1) downto 0 do
    Result := Result + $7FFFFFFF + $7FFFFFFF + 2;
end;

function GetFileSize(const FileName: String): Extended;
var
  FindRec: TFindRec;
begin
  Result := 0;
  if FindFirst(FileName, FindRec) then
  begin
    try
      if FindRec.Attributes and FILE_ATTRIBUTE_DIRECTORY = 0 then
        Result := Size64(FindRec.SizeHigh, FindRec.SizeLow);
    finally
      FindClose(FindRec);
    end;
  end;
end;

function FloatToByte(const Bytes: Extended): String;
begin
  Result := Format('%.0f', [Bytes])
end;

function InitializeSetup(): Boolean;
var
  FileSize: Extended;
begin
  FileSize := GetFileSize(ExpandConstant('{#FileSize}'));

  MsgBox(FormatBytes(FileSize), mbInformation, mb_OK);
  {or use}
  MsgBox(FloatToByte(FileSize), mbInformation, mb_OK);

  Result := False;
end;


JRD! 12-05-2018 13:34

I had worked around the problem differently, well done for the "Size64" function, I would not have thought of this technique. 2 * (MaxInt +1), Thank you!


All times are GMT -7. The time now is 04:11.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
FileForums @ https://fileforums.com