0

I am working on an app that requires a large hierarchy of configuration files. I am trying to use InnoSetup to build the installer. Rather than putting each config file and its path into the .iss file, I put the entire hierarchy into a .zip file. The app needs to be installed into 'Program Files (x86), and the config files hierarchy needs to be in a folder in the same location as the executable. My installer successfully puts the 'config.zip' file in 'Program Files (x86) with the app's executable, but I can't extract the folders and files from the archive. I considered using a self-extracting archive, but the required script for IExpress would just be too unmanageable. I don't want to include any third-party extraction programs, or rely on finding them on the customer's computer. And I don't want to rely on the customer using file explorer to extract the folder.

I am using the following code to extract the archive contents, but it is not working. Nothing is getting extracted.

[Run]
; Unzip the Configuration folder
Filename: "powershell"; Parameters: "-WindowStyle Hidden -Command ""Expand-Archive -Force '{app}\Configuration.zip'"""; Flags: runascurrentuser; Description: "Install Configuration folder hierarchy"

I assume this is a 'permissions' problem, but I can't find the necessary settings to overcome the issue. Here is the whole .iss file:

; Dummy

[Setup]
WizardStyle=modern
SetupLogging=yes
AppName=Dummy
AppVersion=1.0
VersionInfoVersion=1.0
DefaultDirName={commonpf}\Dummy
DefaultGroupName=Dummy
;SourceDir="Dummy"
; If you set 'SourceDir', you must force 'OutputDir' to be where you want it.
;OutputDir="Setup"
OutputBaseFilename={#SetupSetting("AppName")}_Setup

; Files section (i.e. the .exe file)
[Files]
Source: "Dummy.exe"; DestDir: "{app}"
Source: "Configuration.zip"; DestDir: "{app}"

; Icons section - Defines shortcuts to be created.
[Icons]
Name: "{commondesktop}\Dummy"; Filename: "{app}\Dummy.exe"; Tasks: "desktopicons"; Comment: "Dummy Application."
Name: "{commondesktop}\Uninstall Dummy"; Filename: "{uninstallexe}"; Tasks: "desktopicons"; 
Name: "{group}\Dummy"; Filename: "{app}\Dummy.exe"; Comment: "Dummy Application."
Name: "{group}\Uninstall Dummy"; Filename: "{uninstallexe}";

; Tasks section - Defines user-customizable tasks
[Tasks]
Name: "desktopicons"; Description: "Create desktop icons"

; Run section
[Run]
; Unzip the Configuration folder
;Filename: "powershell"; Parameters: "-WindowStyle Hidden -Command ""Expand-Archive -Force 'Configuration.zip'"""; Flags: runhidden; Description: "Install Configuration folder hierarchy"
Filename: "powershell"; Parameters: "-WindowStyle Hidden -Command ""Expand-Archive -Force '{app}\Configuration.zip'"""; Flags: runascurrentuser; Description: "Install Configuration folder hierarchy"

; UninstallDelete section - Clean-up the Configurations folder
[UninstallDelete]
Type: filesandordirs; Name: "{app}\Configuration"
;Type: dirifempty; Name: "{app}"

; End of Script

Additional information: After running the installer, if I run the PowerShell command from a batch file in the folder where the .zip file was installed, I get this:

C:\Program Files (x86)\Dummy>powershell -command "Expand-Archive -Force 'Configuration.zip'"
   New-Item : Access to the path 'Configuration' is denied.
   At
   C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\Microsoft.PowerShell.Archive\Microsoft.PowerShell.Archive.psm1:393 char:25
      + ...             New-Item -Path $resolvedDestinationPath -ItemType Directo ...
      +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         + CategoryInfo          : PermissionDenied: (C:\Program File...y\Configuration:String) [New-Item], UnauthorizedAccessException
         + FullyQualifiedErrorId : CreateDirectoryUnauthorizedAccessError,Microsoft.PowerShell.Commands.NewItemCommand
JNygrenLT
  • 173
  • 12
  • 1
    Your example has a dependency that `Expand-Archive` is an available PowerShell cmdlet, which may be an unwarranted assumption. But with that said, why include an archive? Why not just include your directory full of files in the `[Files]` section and let Inno Setup extract them? – Bill_Stewart Mar 16 '21 at 13:59
  • What does it mean *"I can't extract"*? Do you get any errors? Or what happens? + *"but the required script for IExpress would just be too unmanageable"* What does IExpress have to do with this? What/How is it *"unmanageable"*? – Martin Prikryl Mar 16 '21 at 14:25
  • I guess the problem is that you do not set the target directory in your `Expand-Archive` command. – Martin Prikryl Mar 16 '21 at 14:26
  • @Bill_Stewart Running the PowerShell line from a batch file, and in a different location works fine, so Expand-Archive is available. Can Inno-Setup install a folder full of files? I'm not aware of that, I'll look into it – JNygrenLT Mar 16 '21 at 16:20
  • @MartinPrikryl The IExpress statement was in reference to creating a Self-Extracting archive. The Expand-Archive target directory defaults to the current directory. When I run my installer, it seems to run just fine, but when it completes, there is no 'Configuration' folder extracted from the .zip. – JNygrenLT Mar 16 '21 at 16:24
  • "Can Inno Setup install a folder full of files?" Yes. Just use `*` wildcard, as in: `Source: D:\SourceFiles\*"; DestDir: "{app}"; Flags: recursesubdirs` (or something similar). – Bill_Stewart Mar 16 '21 at 17:01

1 Answers1

0

You don't need a compressed folder. Inno-Setup can handle all of this for you. (Thank you @Bill_Stewart!)

This eliminates the need for the PowerShell call in the [Run] section.

[Files]
Source: "Dummy.exe"; DestDir: "{app}"
Source: "Configuration\*"; DestDir: "{app}\Configuration"; Flags: recursesubdirs createallsubdirs
JNygrenLT
  • 173
  • 12
  • Would be nice, if you let @Bill post his answer on his own. Though this is duplicate anyway. – Martin Prikryl Mar 16 '21 at 18:27
  • If Bill had posted his response as an 'answer', I would have accepted and upvoted it! Credit where credit is due. Since the question had no answers, I thought this would be better than leaving it unanswered. @Martin_Prikryl It would have been nice if the duplicate question had been found by any of my searches on the topic, or if someone has simply pointed it out in a comment to my question. Thanks. – JNygrenLT Mar 18 '21 at 12:32