Inno Script: Strange Empty Folder

2019-08-14 16:20发布

问题:

My Inno Script installer makes an empty folder in the C: drive but only on one machine. Every other machine I've tested the script on works without this problem. I've tested on two Windows 7 computers, an XP computer and a Windows XP virtual computer. For all of these computers the installer doesn't create this empty folder.

However, on my colleague's Windows XP computer the installer behaves as it should except that it also creates an empty directory on the C Drive. Uninstalling does not remove the folder.

I've had a look through my script and looked for things that could possibly be creating the extra folder, but I can't see anything. It's especially hard to solve because I can't seem to replicate the problem.

Does anyone here have an idea of why this could be happening?

#define MyAppName "Program1"
#define MyAppVersion "1.0"
#define MyAppExeName "program1.exe"

[Setup]
AppName=Test
AppVersion=1.0
AppPublisher=Me
AppSupportURL=www.google.com
AppUpdatesURL= www.google.com

DefaultDirName={code:getDirectory}
UsePreviousAppDir=no
DisableDirPage=yes
DefaultGroupName={#MyAppName}
DisableProgramGroupPage=yes
OutputBaseFilename={#MyAppName} {#MyAppVersion} Setup
Compression=lzma
SolidCompression=yes
OutputDir=output
UninstallFilesDir={code:getDirectory}


[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"
Name: "german"; MessagesFile: "compiler:Languages\German.isl"

[Files]
Source: "test.iss"; DestDir: "{code:getDirectory}"; Flags: ignoreversion;

[Code]

var
  InstallTestVersionCheckBox: TNewCheckBox;
  Directory : string;


// ------------------------------
// INSTALL
// ------------------------------ 
procedure InitializeWizard;
var  
  MainPage: TWizardPage;


begin

  MainPage := CreateCustomPage(wpWelcome, 'text', 'text');

  // make the checkbox
  InstallTestVersionCheckBox := TNewCheckBox.Create(MainPage);
  InstallTestVersionCheckBox.Parent := MainPage.Surface;
  InstallTestVersionCheckBox.Caption := 'Test Version';

end;

function InstallTestVersion: Boolean;
begin
  Result := InstallTestVersionCheckBox.Checked;
end;

procedure CurPageChanged(CurPageID: Integer);
begin
  if InstallTestVersion() then
    begin
      // Set the test version directory
      Directory := ExpandConstant('{pf32}\Testversion');
    end
  else
    begin
      // Set the production version directory
      Directory := ExpandConstant('{pf32}\Normal');
    end;
end;

// Returns the correct directory
function getDirectory(Param: String): String;
begin
  Result := Directory;
end;

回答1:

For those who might run into similar problems: Inno setup suddenly created additional empty folders I didn't want to have. Finally I understood the reason: I tried to create a single empty folder within the [Files] section. That was no good idea... So you just create your empty folder with the [Dirs] section to do it the good way.

DO NOT DO THIS:

[Files]
Source: "M:\My_Empty_Folder"; DestDir: "{userdocs}\My_App_Name"; Flags: ignoreversion

THIS IS BETTER:

[Dirs]
Name: "{userdocs}\My_App_Name\My_Empty_Folder"