Inno Setup: How to let Folder.CopyHere finish copying before moving to the next folder?

SlowLearner

This is a continuation from an earlier question: here. TLama provided a solution where a function requires: - an Archive parameter to be the name of an existing archive file - a Folder parameter can be the name of a file or folder

Call is like this:

CopyToArchive('C:\ExistingArchive.zip', 'C:\FolderToCopy\');

Procedure Runs...

procedure CopyToArchive(const Archive, Content: string);
var
  Shell: Variant;
  Folder: Variant;
begin
  Shell := CreateOleObject('Shell.Application');
  Folder := Shell.NameSpace(Archive);
  Folder.CopyHere(Content);
end;

It is a brilliant solution but behaves slightly differently than the VBScript in the previous question. Specifically, this solution is unable to copy my files in 1 go. I get an invalid file name error which does not occur with the VBScript - I've no idea why. I found that I can work around the issue by modifying the code like this:

// ----------------------------------------------------------------------------
procedure CopyToArchive(); //(const Archive, Content: string);
var
  Shell: Variant;
  Folder: Variant;
  Archive, Content: string;
begin
 Shell := CreateOleObject('Shell.Application');
  Archive := ExpandConstant('{code:GetDataDir_S|0}') + '\myZipFile.zip';
  Folder := Shell.NameSpace(Archive);

  Content := ExpandConstant('{code:GetDataDir_S|0}\Temp\Folder1\');
  Folder.CopyHere(Content, $0100);
    sleep(1100) 
  Content := ExpandConstant('{code:GetDataDir_S|0}\Temp\Folder2\');
  Folder.CopyHere(Content, $0100); 
    sleep(1100)
  Content := ExpandConstant('{code:GetDataDir_S|0}\Temp\Folder3\');
  Folder.CopyHere(Content, $0100); 
    sleep(1100)
  Content := ExpandConstant('{code:GetDataDir_S|0}\Temp\File1.abc');
  Folder.CopyHere(Content, $0100); 
    sleep(1100)
  Content := ExpandConstant('{code:GetDataDir_S|0}\Temp\File2.abc');
  Folder.CopyHere(Content, $0100); 
    sleep(1100)
  Content := ExpandConstant('{code:GetDataDir_S|0}\Temp\File3.abc');
  Folder.CopyHere(Content, $0100);
    sleep(1100)

end;

But, as you can see that is a LOT of waiting. I get file permission errors if I reduce the Sleep time so I am pretty confident that I need to provide time for the files to finish transferring before starting the next operation.

In VBScript the solution was to check the file size and only move on when it stopped growing. The code that I pulled together for Inno Setup is: Var max0, max1: integer; Begin // Initialise FileSizeCounters max0 := 1 max1 := 0

    // Replace each Sleep(1100) line with the following:
    while  max0 > max1 do begin
    FileSize( Archive, max0 );
        sleep(500)
    FileSize( Archive, max1 );
    log(max1)
    end;

But it does not seem to work - still crashes. To stop crashing I need to increase the sleep time to at least 1100 ms and event then it still crashes on some test runs. Is there are better way to write this?

SlowLearner

Solution was to leave as many files in the zip container as possible. Then selectively copy remaining files using the solution provided earlier by TLama. This makes the overall process significantly faster and significantly more robust than my initial attempt which was to fill an empty zip container.

I did find that operating with the zip container is a bit temperamental and it seems to work best when I perform the following steps on my original zip file:

  • extract to a folder
  • open the zip file
  • select all & delete
  • drag & drop files that dont change

Install via Inno then use the no notification, annoying, asynch, script with a dose of sleep to copy remaining files that have been modified during install.

Hope this helps someone :-)

Big thanks to TLama

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to delete a nonempty folder in inno setup

From Dev

Inno Setup - How to set permissions of installation folder

From Dev

How to test if FileExists in folder where Inno Setup is running?

From Dev

How to disable OK button in "Browse For Folder" dialog in Inno Setup

From Dev

How to delete folder and files in the destination that are missing in the source (before copying)?

From Dev

Inno Setup: pack folder with all subfolders

From Dev

Inno Setup: Delete folder with Task function

From Dev

Inno Setup - Get a path to parent folder

From Dev

Creating shortcut in startup folder using Inno setup

From Dev

Inno Setup shortcuts for folder are not opening in Windows 10

From Dev

How to use javascript promises that waits for jquery ajax to finish before moving onto next promise?

From Dev

C++ Finish Current task before moving on to the next

From Dev

How to setup an upload folder in openshift?

From Dev

Inno Setup: Get 'Don't create a start menu folder' option

From Dev

Inno Setup CreateInputDirPage but don't check for folder existence

From Dev

Empty game folder stays after uninstallation - Inno Setup

From Dev

Inno-setup pack all files in a folder exept for 1 file

From Dev

Avoiding "Failed to expand shell folder constant userdocs" errors in Inno Setup

From Dev

Inno Setup: copy folder, subfolders and files recursively in Code section

From Dev

Inno Setup [UninstallDelete] delete all except one folder

From Dev

Inno-setup pack all files in a folder exept for 1 file

From Dev

Inno Setup: Get 'Don't create a start menu folder' option

From Dev

Empty game folder stays after uninstallation - Inno Setup

From Dev

Checking existence of a file in Inno Setup Internal Temporary folder

From Dev

Inno Setup Finding folder and using multiple choice of directories

From Dev

Inno Setup: Disable finish page

From Dev

How can I check a file has been copied fully to a folder before moving it using python

From Dev

Copying hidden files in Inno Setup

From Dev

Moving file from folder to folder

Related Related

  1. 1

    How to delete a nonempty folder in inno setup

  2. 2

    Inno Setup - How to set permissions of installation folder

  3. 3

    How to test if FileExists in folder where Inno Setup is running?

  4. 4

    How to disable OK button in "Browse For Folder" dialog in Inno Setup

  5. 5

    How to delete folder and files in the destination that are missing in the source (before copying)?

  6. 6

    Inno Setup: pack folder with all subfolders

  7. 7

    Inno Setup: Delete folder with Task function

  8. 8

    Inno Setup - Get a path to parent folder

  9. 9

    Creating shortcut in startup folder using Inno setup

  10. 10

    Inno Setup shortcuts for folder are not opening in Windows 10

  11. 11

    How to use javascript promises that waits for jquery ajax to finish before moving onto next promise?

  12. 12

    C++ Finish Current task before moving on to the next

  13. 13

    How to setup an upload folder in openshift?

  14. 14

    Inno Setup: Get 'Don't create a start menu folder' option

  15. 15

    Inno Setup CreateInputDirPage but don't check for folder existence

  16. 16

    Empty game folder stays after uninstallation - Inno Setup

  17. 17

    Inno-setup pack all files in a folder exept for 1 file

  18. 18

    Avoiding "Failed to expand shell folder constant userdocs" errors in Inno Setup

  19. 19

    Inno Setup: copy folder, subfolders and files recursively in Code section

  20. 20

    Inno Setup [UninstallDelete] delete all except one folder

  21. 21

    Inno-setup pack all files in a folder exept for 1 file

  22. 22

    Inno Setup: Get 'Don't create a start menu folder' option

  23. 23

    Empty game folder stays after uninstallation - Inno Setup

  24. 24

    Checking existence of a file in Inno Setup Internal Temporary folder

  25. 25

    Inno Setup Finding folder and using multiple choice of directories

  26. 26

    Inno Setup: Disable finish page

  27. 27

    How can I check a file has been copied fully to a folder before moving it using python

  28. 28

    Copying hidden files in Inno Setup

  29. 29

    Moving file from folder to folder

HotTag

Archive