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

#define FileHandle
#define FileLine
#define MyAppVersion
#sub ProcessFileLine
  #define FileLine = FileRead(FileHandle)
  #define public MyAppVersion = FileLine
  #pragma message "Version: " + MyAppVersion
#endsub
#for {FileHandle = FileOpen("..\..\VERSION"); \
  FileHandle && !FileEof(FileHandle); ""} \
  ProcessFileLine
#if FileHandle
  #expr FileClose(FileHandle)
#endif

#define MyAppName "LPHK"
#define MyAppPublisher "Ella Jameson (nimaid)"
#define MyAppURL "https://github.com/nimaid/LPHK"
#define MyAppExeName "LPHK.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={{A6E030E7-C7D0-4EA7-BBD9-4AD52745451B}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={autopf}\{#MyAppName}
DisableProgramGroupPage=auto
DisableWelcomePage=no
PrivilegesRequired=admin
PrivilegesRequiredOverridesAllowed=dialog
OutputDir=..\..\__setup__
OutputBaseFilename=LPHK_setup_{#MyAppVersion}
SetupIconFile=..\..\resources\LPHK.ico
UninstallDisplayIcon={app}\{#MyAppExeName}
Compression=lzma
SolidCompression=yes
WizardImageFile=..\..\INSTALL\RESOURCES\LPHK-banner.bmp
WizardSmallImageFile=..\..\INSTALL\RESOURCES\LPHK.bmp
WizardStyle=modern

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

[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked

[Files]
Source: "..\..\dist\LPHK\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs
Source: "..\..\user_layouts\examples\*"; DestDir: "{code:GetUserDir}\user_layouts\examples"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "..\..\user_scripts\examples\*"; DestDir: "{code:GetUserDir}\user_scripts\examples"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "..\..\user_sounds\examples\*"; DestDir: "{code:GetUserDir}\user_sounds\examples"; Flags: ignoreversion recursesubdirs createallsubdirs; AfterInstall: SetLphkUserPath
; NOTE: Don't use "Flags: ignoreversion" on any shared system files

[Icons]
Name: "{autoprograms}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
Name: "{autodesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon

[Messages]
WelcomeLabel2=This will install [name/ver] on your computer.%n%nIt is recommended that you close all other applications before continuing.%n%nPlease be advised this program is still in beta. Kindly report any issues on the Discord server or GitHub.

[Code]
var UserDirPage: TInputDirWizardPage;

procedure InitializeWizard();
begin
  UserDirPage := CreateInputDirPage(wpSelectDir,
    'Select User Folder', 'Where should the User Folder be installed?',
    'Setup will install layouts, scripts, sounds, and logs into the following folder.' + #13#10#13#10#13#10 +
    'To continue, click Next. If you would like to select a different folder, click Browse.',
    False, '');
    UserDirPage.Add('');
  UserDirPage.Values[0] := ExpandConstant('{userdocs}\LPHK');
end;
  
function GetUserDir(Param: String): String;
begin
  Result := UserDirPage.Values[0];
end;

procedure SetLphkUserPath();
begin
  SaveStringToFile(ExpandConstant('{app}\USERPATH'), ExpandConstant('{code:GetUserDir}'), False);
end;

[Run]
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: shellexec postinstall skipifsilent

[UninstallDelete]
Type: filesandordirs; Name: "{app}"
Type: files; Name: "{code:GetUserDir}\*.log"
