How do I check if there is a directory, if there is a request to report a new directory? I am using innosetup to create an installer

Asked

Viewed 787 times

4

I need to check the folder C: SISAUTO, C: BASESISAUTO. If folders exist, create a new one for example C: SISAUTO2, C: BASESISAUTO2

Follows code.

; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

#define MyAppName "SISAUTO - SISTEMA DE AUTOMAÇÃO COMERCIAL"
#define MyAppVersion "7.0.23"
#define MyAppPublisher "SUPPORT INFORMÁTICA"
#define MyAppURL "http://www.support-br.com.br"
#define MyAppExeName "MyProg.exe"

[Setup]
; NOTE: The value of AppId uniquely identifies this application.
; Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{0D0A707B-5DF4-4AF9-BC4C-133886E5E379}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
CreateAppDir=no
OutputDir=C:\Users\SERVER\Desktop\Arquivos para Executavel\Output
OutputBaseFilename=INSTALADOR_SISAUTO_2017
SetupIconFile=C:\Users\SERVER\Desktop\Arquivos para Executavel\SISAUTO\install.ico
Compression=lzma
SolidCompression=yes

DisableWelcomePage=no
DisableDirPage=yes
DisableProgramGroupPage=yes
DisableReadyMemo=yes
DisableReadyPage=yes
DisableStartupPrompt=yes
DisableFinishedPage=no

[Languages]
Name: brazilianportuguese; MessagesFile: compiler:Languages\BrazilianPortuguese.isl

[Tasks]
Name: desktopicon; Description: Create a &desktop icon; GroupDescription: Additional icons:

[Dirs]
Name: C:\SISAUTO
Name: C:\BASESISAUTO
Name: C:\BASESISAUTO\GERNFE2
Name: C:\BASESISAUTO\BASE1
Name: C:\notas
Name: C:\ACBrMonitorPLUS
Name: C:\Unimake
Name: C:\Unimake\UniNFe
Name: C:\Unimake\UniDANFE

[Files]

Source: C:\Users\SERVER\Desktop\Arquivos para Executavel\BASESISAUTO\GERNFE2\*; DestDir: C:\BASESISAUTO\GERNFE2; Flags: recursesubdirs onlyifdoesntexist confirmoverwrite; Tasks: 
Source: C:\Users\SERVER\Desktop\Arquivos para Executavel\BASESISAUTO\BASE1\*; DestDir: C:\BASESISAUTO\BASE1; Flags: recursesubdirs onlyifdoesntexist confirmoverwrite
Source: C:\Users\SERVER\Desktop\Arquivos para Executavel\SISAUTO\*; DestDir: C:\SISAUTO; Flags: recursesubdirs onlyifdoesntexist confirmoverwrite
Source: C:\Users\SERVER\Desktop\Arquivos para Executavel\ACBrMonitorPLUS\*; DestDir: C:\ACBrMonitorPLUS; Flags: recursesubdirs onlyifdoesntexist confirmoverwrite; Tasks: ; Languages: 
Source: C:\Users\SERVER\Desktop\Arquivos para Executavel\UniNFe\*; DestDir: C:\Unimake\UniNFe; Flags: recursesubdirs onlyifdoesntexist confirmoverwrite
Source: C:\Users\SERVER\Desktop\Arquivos para Executavel\UniDANFE\*; DestDir: C:\Unimake\UniDANFE; Flags: recursesubdirs onlyifdoesntexist confirmoverwrite

[Icons]
Name: {userdesktop}\SISAUTO; Filename: C:\SISAUTO\sisauto.exe; Tasks: desktopicon
Name: {userdesktop}\GERNFE2; Filename: C:\BASESISAUTO\GERNFE2\gernfe2.exe; Tasks: desktopicon
Name: {userdesktop}\ACBrMonitorPLUS; Filename: C:\ACBrMonitorPLUS\ACBrMonitor.exe; Tasks: desktopicon
Name: {userdesktop}\UNINFE; Filename: C:\Unimake\UniNFe\uninfe.exe; Tasks: desktopicon
Name: {userdesktop}\UNIDANFE; Filename: C:\Unimake\UniDANFE\unidanfe.exe; Tasks: desktopicon

Name: {commonstartup}\GERNFE2; Filename: C:\BASESISAUTO\GERNFE2\gernfe2.exe
Name: {commonstartup}\ACBrMonitorPLUS; Filename: C:\ACBrMonitorPLUS\ACBrMonitor.exe
Name: {commonstartup}\UniNFe; Filename: C:\Unimake\UniNFe\uninfe.exe

[_ISTool]
UseAbsolutePaths=true
; NOTE: Don't use "Flags: ignoreversion" on any shared system files

[Run]
Filename: C:\SISAUTO\InstalaDLL2.exe
Filename: C:\ACBrMonitorPLUS\ACBrMonitor.exe; Flags: nowait runminimized hidewizard runhidden
Filename: C:\Unimake\UniNFe\uninfe.exe; Flags: nowait runminimized hidewizard runhidden
  • In this tool you can program in pascal to test directories/files easily.

2 answers

5

Simple. You will put a [Code] tag. Then create a validation process. Now create a method to be launched before installation: Beforeinstall. Inside Beforeinstall Voce will call your validation methods.

Follow the example:

[Files]

Source: {#MyAppDirOut}\Exemplo.exe; DestDir: {#MyAppDirIns}; BeforeInstall: onBeforeInstall;

[Code]

procedure Validar();
begin
  if (DirExists('C:\SISAUTO')) then
    CreateDir('C:\SISAUTO2');
end;

procedure onBeforeInstall();
begin
  Validar;
end;

The methods you need are the DirExists and CreateDir. To work with pascal code in Inno setup, just put the tag [Code].

The previous answer from the colleague, works, but only in Delphi, and I find it interesting you edit your question too, why she is focused on the Inno setup.

2

You can use Directoryexists and Forcedirectories from System.Sysutils to solve your problem. For example:

if (DirectoryExists(C:\SISAUTO)) then
   ForceDirectories(C:\SISAUTO2);

I hope it helps. Hugs!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.