; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Input configuration for the Inno Setup Compiler
; Copyright (c) 2004-2005 Christian Stimming <stimming@tuhh.de>
;
; Inno Setup Compiler: See http://www.jrsoftware.org/isdl.php
; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

[Setup]
; Using the name here directly because we want it capitalized
AppName=GnuCash
AppVerName=GnuCash @VERSION@
AppPublisher=GnuCash Development Team
AppPublisherURL=http://www.gnucash.org
AppSupportURL=http://www.gnucash.org
AppUpdatesURL=http://www.gnucash.org
DefaultDirName={pf}\@PACKAGE@
DefaultGroupName=GnuCash
LicenseFile=@prefix@\..\dist\share\@PACKAGE@\doc\COPYING
Compression=lzma
OutputDir=.
OutputBaseFilename=@PACKAGE@-@VERSION@-setup
UninstallFilesDir={app}\uninstall\@PACKAGE@
InfoAfterFile=@prefix@\..\dist\share\@PACKAGE@\doc\README

[Types]
Name: "full"; Description: "{cm:FullInstall}"
Name: "custom"; Description: "{cm:CustomInstall}"; Flags: iscustom

[Components]
Name: "main"; Description: "{cm:MainFiles}"; Types: full custom; Flags: fixed
;Name: "translations"; Description: "{cm:TranslFiles}"; Types: full
;Name: "templates"; Description: "{cm:TemplFiles}"; Types: full

[Tasks]
Name: desktopicon; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"
Name: menuicon; Description: "{cm:CreateMenuLink}"; GroupDescription: "{cm:AdditionalIcons}"

[Icons]
Name: "{group}\GnuCash"; Filename: "{app}\bin\gnucash.bat"; WorkingDir: "{app}\bin"; Comment: "GnuCash Free Finance Manager"; IconFilename: "{app}\share\gnucash\pixmaps\gnucash-icon.ico"; Tasks: menuicon
Name: "{group}\Uninstall GnuCash"; Filename: "{uninstallexe}"; Tasks: menuicon
Name: "{userdesktop}\GnuCash"; Filename: "{app}\bin\gnucash.bat"; WorkingDir: "{app}\bin"; Comment: "GnuCash Free Finance Manager"; IconFilename: "{app}\share\gnucash\pixmaps\gnucash-icon.ico"; Tasks: desktopicon

[Run]
Filename: "{app}\bin\gnucash.bat"; Description: "{cm:RunPrg}"; WorkingDir: "{app}\bin"; Flags: postinstall skipifsilent
Filename: "{app}\bin\guile.bat"; Parameters: "-c ""(use-modules (ice-9 slib)) (require 'printf)"""; Flags: runhidden

; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Here we configure the included files and the place of their
; installation
; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
[Files]
; The main executables and DLLs
Source: "@prefix@\..\dist\bin\*"; DestDir: "{app}\bin"; Flags: recursesubdirs; Components: main; AfterInstall: MyAfterInstallConfig()
; Note: The above AfterInstall function will create the 
; gnucash.bat file on-the-fly by the Pascal script below.

Source: "@prefix@\..\dist\etc\*"; DestDir: "{app}\etc"; Flags: recursesubdirs; Components: main
Source: "@prefix@\..\dist\lib\*"; DestDir: "{app}\lib"; Flags: recursesubdirs; Components: main
Source: "@prefix@\..\dist\libexec\*"; DestDir: "{app}\libexec"; Flags: recursesubdirs; Components: main
Source: "@prefix@\..\dist\share\*"; DestDir: "{app}\share"; Flags: recursesubdirs; Components: main

;; The translations (no idea why mingw installs them in prefix/lib/locale)
;Source: "@prefix@\..\dist\lib\locale\*"; DestDir: "{app}\lib\locale"; Flags: recursesubdirs; Components: translations
;
;; The account templates
;Source: "@prefix@\..\dist\share\gnucash\accounts\*"; DestDir: "{app}\share\gnucash\accounts"; Flags: recursesubdirs; Components: templates

; And all the documentation
Source: "@prefix@\..\dist\share\@PACKAGE@\doc\README"; DestDir: "{app}\doc\@PACKAGE@"; Components: main
Source: "@prefix@\..\dist\share\@PACKAGE@\doc\COPYING"; DestDir: "{app}\doc\@PACKAGE@"; Flags: ignoreversion; Components: main
Source: "@prefix@\..\dist\share\@PACKAGE@\doc\AUTHORS"; DestDir: "{app}\doc\@PACKAGE@"; Components: main
Source: "@prefix@\..\dist\share\@PACKAGE@\doc\ChangeLog"; DestDir: "{app}\doc\@PACKAGE@"; Components: main


; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Define the registry keys Setup should create (HKCU = HKEY_CURRENT_USER)
; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
[Registry]
Root: HKCU; Subkey: "Software\GnuCash"; ValueType: none; Flags: uninsdeletekeyifempty
Root: HKCU; Subkey: "Software\GnuCash\Paths"; ValueType: none; Flags: uninsdeletekeyifempty
Root: HKCU; Subkey: "Software\GnuCash\Paths"; ValueType: string; ValueName: "prefix"; ValueData: "{app}"; Flags: uninsdeletevalue
Root: HKCU; Subkey: "Software\GnuCash\Paths"; ValueType: string; ValueName: "libdir"; ValueData: "{app}\lib"; Flags: uninsdeletevalue
Root: HKCU; Subkey: "Software\GnuCash\Paths"; ValueType: string; ValueName: "pkglibdir"; ValueData: "{app}\lib\@PACKAGE@"; Flags: uninsdeletevalue
Root: HKCU; Subkey: "Software\GnuCash\Paths"; ValueType: string; ValueName: "sysconfdir"; ValueData: "{app}\etc"; Flags: uninsdeletevalue
Root: HKCU; Subkey: "Software\GnuCash\Paths"; ValueType: string; ValueName: "localedir"; ValueData: "{app}\share\locale"; Flags: uninsdeletevalue

; Additionally, we have to install the paths for gwenhywfar
Root: HKCU; Subkey: "Software\Gwenhywfar"; ValueType: none; Flags: uninsdeletekeyifempty
Root: HKCU; Subkey: "Software\Gwenhywfar\Paths"; ValueType: none; Flags: uninsdeletekeyifempty
Root: HKCU; Subkey: "Software\Gwenhywfar\Paths"; ValueType: string; ValueName: "prefix"; ValueData: "{app}"; Flags: uninsdeletevalue
Root: HKCU; Subkey: "Software\Gwenhywfar\Paths"; ValueType: string; ValueName: "libdir"; ValueData: "{app}\lib"; Flags: uninsdeletevalue
Root: HKCU; Subkey: "Software\Gwenhywfar\Paths"; ValueType: string; ValueName: "plugindir"; ValueData: "{app}\lib\gwenhywfar\plugins\38"; Flags: uninsdeletevalue
Root: HKCU; Subkey: "Software\Gwenhywfar\Paths"; ValueType: string; ValueName: "sysconfdir"; ValueData: "{app}\etc"; Flags: uninsdeletevalue
Root: HKCU; Subkey: "Software\Gwenhywfar\Paths"; ValueType: string; ValueName: "localedir"; ValueData: "{app}\share\locale"; Flags: uninsdeletevalue

; And we also need some registry keys for aqbanking
Root: HKCU; Subkey: "Software\Aqbanking"; ValueType: none; Flags: uninsdeletekeyifempty
Root: HKCU; Subkey: "Software\Aqbanking\Paths"; ValueType: none; Flags: uninsdeletekeyifempty
Root: HKCU; Subkey: "Software\Aqbanking\Paths"; ValueType: string; ValueName: "providerdir"; ValueData: "{app}\lib\aqbanking\plugins\16\providers"; Flags: uninsdeletevalue
Root: HKCU; Subkey: "Software\Aqbanking\Paths"; ValueType: string; ValueName: "bankinfodir"; ValueData: "{app}\lib\aqbanking\plugins\16\bankinfo"; Flags: uninsdeletevalue
Root: HKCU; Subkey: "Software\Aqbanking\Paths"; ValueType: string; ValueName: "importerdir"; ValueData: "{app}\lib\aqbanking\plugins\16\imexporters"; Flags: uninsdeletevalue
Root: HKCU; Subkey: "Software\Aqbanking\Paths"; ValueType: string; ValueName: "pkgdatadir"; ValueData: "{app}\share\aqbanking"; Flags: uninsdeletevalue
Root: HKCU; Subkey: "Software\Aqbanking\Paths"; ValueType: string; ValueName: "sysconfdir"; ValueData: "{app}\etc"; Flags: uninsdeletevalue

; And even one for aqhbci
Root: HKCU; Subkey: "Software\AqHbci"; ValueType: none; Flags: uninsdeletekeyifempty
Root: HKCU; Subkey: "Software\AqHbci\Paths"; ValueType: none; Flags: uninsdeletekeyifempty
Root: HKCU; Subkey: "Software\AqHbci\Paths"; ValueType: string; ValueName: "xmldatadir"; ValueData: "{app}\share\aqhbci\xml"; Flags: uninsdeletevalue

; And also a key for ktoblzcheck
Root: HKCU; Subkey: "Software\Ktoblzcheck"; ValueType: none; Flags: uninsdeletekeyifempty
Root: HKCU; Subkey: "Software\Ktoblzcheck\Paths"; ValueType: none; Flags: uninsdeletekeyifempty
Root: HKCU; Subkey: "Software\Ktoblzcheck\Paths"; ValueType: string; ValueName: "datadir"; ValueData: "{app}\share\ktoblzcheck"


; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Delete the created config script on uninstall
; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
[UninstallDelete]
Type: files; Name: "{app}\bin\gnucash.bat"
Type: files; Name: "{app}\bin\guile.bat"
Type: files; Name: "{app}\share\guile\1.6\slibcat"
Type: filesandordirs; Name: "{app}\share\guile"
Type: filesandordirs; Name: "{app}\etc\gconf"
Type: dirifempty; Name: "{app}\etc"

; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; This large section is a Pascal scripting program that will modify
; the gnucash shell script so that it then includes the
; correct values according to our local installation. See
; http://www.remobjects.com/?ps for a syntax reference.
; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
[Code]
function MingwBacksl(const S: String): String;
begin
  { Modify the path name S so that it can be used by MinGW }
  if Length(ExtractFileDrive(S)) = 0 then
    Result := S
  else begin
    Result := '/'+S;
    StringChange(Result, ':\', '\');
  end;
  StringChange(Result, '\', '/');
end;

procedure MyAfterInstallConfig();
var
  FileName, FileString, appdir, libdir, pkglibdir, pkgdatadir: String;
  Res: Boolean;
begin

  { Get the installation-specific paths }
  appdir := ExpandConstant('{app}');
  libdir := appdir + '\lib';
  pkglibdir := libdir + '\gnucash';
  pkgdatadir := appdir + '\share\gnucash';

  { Create the gnucash.bat file; #10 is the linefeed character and #13 CR }
  FileName := appdir + '\bin\gnucash.bat' ;
  FileString := 'set PATH=' + appdir + '\bin;' + libdir + ';' + libdir + '\gnucash;%PATH%'#13#10 ;

  FileString := FileString + 'set GUILE_WARN_DEPRECATED=no'#13#10 ;
  FileString := FileString + 'set GNC_MODULE_PATH=' + pkglibdir + ''#13#10 ;
  FileString := FileString + 'set GUILE_LOAD_PATH=' + pkgdatadir + '\guile-modules;' + pkgdatadir + '\scm;' + appdir + '\share\guile\1.6;%GUILE_LOAD_PATH%'#13#10 ;
  FileString := FileString + 'set LTDL_LIBRARY_PATH=' + libdir + ''#13#10 ;
  FileString := FileString + 'start gnucash-bin'#13#10 ;

  { Save the final file }
  Res := SaveStringToFile(FileName, FileString, False);
  if Res = False then
    MsgBox('Error on saving '+FileName+' for completing the installation', mbInformation, MB_OK);

  FileName := appdir + '\bin\guile.bat' ;
  FileString := 'set GUILE_LOAD_PATH=' + pkgdatadir + '\guile-modules;' + pkgdatadir + '\scm;' + appdir + '\share\guile\1.6;%GUILE_LOAD_PATH%'#13#10 ;
  FileString := FileString + 'start guile.exe %*'#13#10 ;
  Res := SaveStringToFile(FileName, FileString, False);
  if Res = False then
    MsgBox('Error on saving '+FileName+' for completing the installation', mbInformation, MB_OK);

end;


[Languages]
Name: "en"; MessagesFile: "compiler:Default.isl"
Name: "de"; MessagesFile: "compiler:Languages\German.isl"
Name: "fr"; MessagesFile: "compiler:Languages\French.isl"

; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; These are only for improved text messages
; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
[Messages]

[CustomMessages]
; *** "Select Components" wizard page
FullInstall=Full installation
CustomInstall=Custom installation
CreateDesktopIcon=Create a &desktop icon
CreateMenuLink=Create a start menu link
RunPrg=Run GnuCash now
AdditionalIcons=Create these icons:

MainFiles=GnuCash Program
TranslFiles=Translation Files
TemplFiles=Account Template Files

de.FullInstall=Komplett-Installation
de.CustomInstall=Benutzerdefiniert
de.CreateDesktopIcon=Ein Icon auf dem Desktop erstellen
de.CreateMenuLink=Eine Verknüpfung im Startmenü erstellen
de.RunPrg=GnuCash jetzt starten
de.AdditionalIcons=Folgende Icons erstellen:

de.MainFiles=GnuCash Hauptprogramm
de.TranslFiles=Deutsche Übersetzung
de.TemplFiles=Beispiel-Kontenrahmen
