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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 27-06-2024, 00:09
Lord.Freddy's Avatar
Lord.Freddy Lord.Freddy is offline
Registered User
 
Join Date: Apr 2022
Location: ...
Posts: 54
Thanks: 222
Thanked 40 Times in 25 Posts
Lord.Freddy is on a distinguished road
Hello, yesterday I attempted to create a function in Inno Setup to gather file names and their respective sizes, but only a few files were returned. I am currently at a standstill and unsure of how to proceed. Does anyone know where i went wrong?
Code:
[Setup]
AppName=FindFiles
AppVerName=FindFiles
CreateAppDir=no
OutputDir=.\OutPut
OutputBaseFilename=FindFiles

[_Code]
type 
  TAutoString = {#defined(UNICODE) ? "Wide" : ""}String;
  TFileList = array of record
    FileName, FileSize: TAutoString;
  end;

var 
  FileList: TFileList;

function Size64(const Hi, Lo: Integer): 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 FloatToStrEx(const value: Extended): TAutoString;
begin
  Result := FloatToStr(value);
  while ((Result[Length(Result)] = '0') or (Result[Length(Result)] = '.')) and (Pos('.', Result) > 0) do
    SetLength(Result, (Length(Result) - 1));
end;

function FindFilesEx(FolderPath: TAutoString; var FilesList, FileSize: array of TAutoString): Integer;
var
  FindRec: TFindRec;
begin
  Result := 0;
  if FindFirst(ExpandConstant(AddBackslash(FolderPath)) + '*', FindRec) then
  begin
    repeat
      if (FindRec.Attributes and FILE_ATTRIBUTE_DIRECTORY = 0) or
         (FindRec.Attributes and FILE_ATTRIBUTE_HIDDEN <> 0) then
      begin
        SetArrayLength(FilesList, Result + 1);
        SetArrayLength(FileSize, Result + 1);
        FilesList[GetArrayLength(FilesList) - 1] := ExpandConstant(AddBackslash(FolderPath)) + FindRec.Name;
        FileSize[GetArrayLength(FileSize) - 1] := FloatToStrEx(Size64(FindRec.SizeHigh, FindRec.SizeLow));
        Result := Result + 1;
      end;
      if FindRec.Attributes and FILE_ATTRIBUTE_DIRECTORY <> 0 then
      begin
        if (FindRec.Name <> '.') and (FindRec.Name <> '..') then
          Result := Result + FindFilesEx(AddBackslash(FolderPath) + FindRec.Name, FilesList, FileSize);
      end;
    until not FindNext(FindRec);
    FindClose(FindRec);
  end;
end;

procedure FindFiles(Dir: TAutoString; var FilesFound: Integer);
var
  TotalFilesFound, Y, S: Integer;
  FilesNameList, FileNameSize: array of TAutoString;
begin
  TotalFilesFound := FindFilesEx(ExpandConstant(Dir), FilesNameList, FileNameSize);
  FilesFound := TotalFilesFound;
  for Y := 0 to totalFilesFound - 1 do
  begin
    SetArrayLength(FileList, GetArrayLength(FileList) + 1);
    S := GetArrayLength(FileList) - 1;
    with FileList[S] do
    begin
      FileList[S].FileName := FilesNameList[Y];
      Delete(FileList[S].FileName, Pos(AddBackslash(Dir), FileList[S].FileName), Length(AddBackslash(Dir)));    
      FileList[S].FileSize := FileNameSize[Y];
    end;      
  end;
end;

function InitializeSetup: Boolean;
var
  TotalFilesFound, I: Integer;
  Dir: TAutoString;
begin
  Dir := ExpandConstant('{src}\..');
  FindFiles(Dir, TotalFilesFound);
  for I := 0 to GetArrayLength(FileList) - 1 do
  begin
    msgbox('FileName: ' + FileList[I].FileName + #13#10 + 'FileSize: ' + FileList[I].FileSize + ' bytes', mbInformation, MB_OK);
  end;
  Result := False;
end;
Update(solution):
I found a solution for the above code, which is as follows.
Code:
[Setup]
AppName=FindFiles
AppVerName=FindFiles
CreateAppDir=no
OutputDir=.\OutPut
OutputBaseFilename=FindFiles

[_Code]
type 
  TAutoString = {#defined(UNICODE) ? "Wide" : ""}String;
  TFileList = array of record
    FileName, FileExt, FileSize, FilePath: TAutoString;
  end;

function Size64(const Hi, Lo: Integer): 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 FloatToStrEx(const value: Extended): TAutoString;
begin
  Result := FloatToStr(value);
  while ((Result[Length(Result)] = '0') or (Result[Length(Result)] = '.')) and (Pos('.', Result) > 0) do
    SetLength(Result, (Length(Result) - 1));
end;

function pFindFiles(const BaseDir, DestDir, FileMask: TAutoString; var OutFileList: TFileList): Integer;
var
  FSR, DSR: TFindRec;
  FindResult: Boolean;
  APath: TAutoString;
  nCount: Integer;
begin
  APath := ExpandConstant(AddBackslash(DestDir));
  FindResult := FindFirst(APath + '*.*', DSR);
  try
    while FindResult do
    begin
      if ((DSR.Attributes and FILE_ATTRIBUTE_DIRECTORY) = FILE_ATTRIBUTE_DIRECTORY) and not ((DSR.Name = '.') or (DSR.Name = '..')) then
      begin
        pFindFiles(BaseDir, APath + DSR.Name, FileMask, OutFileList);
      end;
      FindResult := FindNext(DSR);
    end;

    FindResult := FindFirst(APath + FileMask, FSR);

    while FindResult do
    begin
      if (FSR.Attributes and FILE_ATTRIBUTE_DIRECTORY = 0) then
      begin
        SetArrayLength(OutFileList, GetArrayLength(OutFileList) + 1);
        OutFileList[GetArrayLength(OutFileList) - 1].FileName := FSR.Name;        
        OutFileList[GetArrayLength(OutFileList) - 1].FileExt  := ExtractFileExt(FSR.Name);
        OutFileList[GetArrayLength(OutFileList) - 1].FileSize := FloatToStrEx(Size64(FSR.SizeHigh, FSR.SizeLow));
        OutFileList[GetArrayLength(OutFileList) - 1].FilePath := ExtractFilePath(ExtractRelativePath(AddBackslash(BaseDir), APath + FSR.Name));
        nCount := nCount + 1;
      end;
      FindResult := FindNext(FSR);
    end;
  finally
    FindClose(FSR);
    FindClose(DSR);
  end;
  Result := nCount;
end;

function InitializeSetup: Boolean;
var
  TotalFilesFound, I: Integer;
  Dir: TAutoString;
  FileList: TFileList;
  OutList: TAutoString;
begin
  Dir := ExpandConstant('{src}\..');
  TotalFilesFound := pFindFiles(Dir, Dir, '*.*', FileList);
  for I := 0 to GetArrayLength(FileList) - 1 do
  begin
    OutList := OutList + 'FileName: ' + FileList[I].FileName + #13#10 + 'FileSize: ' + FileList[I].FileSize + ' bytes' + #13#10 + 'FileExt: ' + FileList[I].FileExt + #13#10 + 'FilePath: ' + FileList[I].FilePath + #13#10 + #13#10;
  end;
  msgbox(OutList, mbInformation, MB_OK);
  Result := False;
end;
__________________
¤ Life good be a Dream ¤

Last edited by Lord.Freddy; 27-06-2024 at 07:57.
Reply With Quote
Sponsored Links
Reply

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
INNO TROUBLESHOOT - Tutorials and Answers about INNO Setup REV0 Conversion Tutorials 129 21-05-2021 05:51
INNO TUTORIAL - Using Unicode and ANSI Versions of INNO Setup REV0 Conversion Tutorials 51 26-03-2015 06:57
Frequently Asked Questions Joe Forster/STA PC Games - Frequently Asked Questions 0 29-11-2005 09:48



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


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