Go Back   FileForums > Game Backup > PC Games > PC Games - CD/DVD Conversions > Conversion Tutorials

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #9  
Old 07-05-2018, 18:55
Cesar82's Avatar
Cesar82 Cesar82 is offline
Registered User
 
Join Date: May 2011
Location: Brazil
Posts: 1,080
Thanks: 1,843
Thanked 2,315 Times in 790 Posts
Cesar82 is on a distinguished road
Possible solution.

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;

Last edited by Cesar82; 07-05-2018 at 20:06. Reason: Added alternative mode using JRD! script file returning value to string
Reply With Quote
The Following User Says Thank You to Cesar82 For This Useful Post:
JRD! (12-05-2018)
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
BlackBox v2 y_thelastknight Conversion Tutorials 567 11-03-2025 07:16
INNO TROUBLESHOOT - Tutorials and Answers about INNO Setup REV0 Conversion Tutorials 129 21-05-2021 05:51
Inno Setup: Additional Libraries altef_4 Conversion Tutorials 50 21-10-2020 09:59
Useful Dll for Inno Setup users peterf1999 Conversion Tutorials 88 01-12-2017 16:00
INNO TUTORIAL - Using Unicode and ANSI Versions of INNO Setup REV0 Conversion Tutorials 51 26-03-2015 06:57



All times are GMT -7. The time now is 23:00.


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