; Inno Setup script — AyaanScript+ Windows installer
; Bundles the pre-built ayaan.exe + aspkg.exe directly.
; No PowerShell, no rustup, no remote downloads — eliminates the
; "trojan-downloader" heuristic that older builds tripped.
;
; Build:
;   Linux:  iscc.exe installer.iss  (via Wine — see build-windows-installer.sh)
;   Win:    Open in Inno Setup Compiler and click Build.

#define MyAppName      "AyaanScript+"
#define MyAppVersion   "1.36.0"
#define MyAppPublisher "Ayaan"
#define MyAppURL       "https://crates.io/crates/ayaan"
#define MyAppExeName   "ayaan.exe"

[Setup]
AppId={{B5E14C8A-3F2C-4B0A-9F1D-AA12001CDEF1}}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={localappdata}\AyaanScriptPlus
DefaultGroupName=AyaanScript+
DisableProgramGroupPage=yes
OutputDir=.
OutputBaseFilename=AyaanScriptPlus-Setup
Compression=lzma2/ultra
SolidCompression=yes
PrivilegesRequired=lowest
WizardStyle=modern
ArchitecturesInstallIn64BitMode=x64
ArchitecturesAllowed=x64
UninstallDisplayName={#MyAppName} {#MyAppVersion}
UninstallDisplayIcon={app}\{#MyAppExeName}
VersionInfoVersion={#MyAppVersion}
VersionInfoCompany={#MyAppPublisher}
VersionInfoDescription=AyaanScript+ scripting language and ASPKG package manager
VersionInfoProductName={#MyAppName}
VersionInfoProductVersion={#MyAppVersion}

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

[Tasks]
Name: "addtopath"; Description: "Add AyaanScript+ to my PATH"; GroupDescription: "Integration:"; Flags: checkedonce

[Files]
; Pre-built binaries — bundled, not downloaded
Source: "..\target\x86_64-pc-windows-gnu\release\ayaan.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\target\x86_64-pc-windows-gnu\release\aspkg.exe"; DestDir: "{app}"; Flags: ignoreversion
; Demos
Source: "..\demos\*.ayaan"; DestDir: "{app}\demos"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "..\demos\README.md";  DestDir: "{app}\demos"; Flags: ignoreversion skipifsourcedoesntexist

[Icons]
Name: "{group}\{#MyAppName} REPL";       Filename: "{app}\{#MyAppExeName}"
Name: "{group}\Uninstall {#MyAppName}";  Filename: "{uninstallexe}"

[Run]
Filename: "{app}\{#MyAppExeName}"; Description: "Launch AyaanScript+ REPL"; Flags: nowait postinstall skipifsilent

[Registry]
; Extend user PATH so cmd / new shells can find ayaan + aspkg
Root: HKCU; Subkey: "Environment"; ValueType: expandsz; ValueName: "Path"; \
    ValueData: "{olddata};{app}"; \
    Check: NeedsAddPath('{app}'); \
    Tasks: addtopath

[Code]
function NeedsAddPath(Param: string): boolean;
var
  OrigPath: string;
begin
  if not RegQueryStringValue(HKEY_CURRENT_USER, 'Environment', 'Path', OrigPath) then
  begin
    Result := True;
    Exit;
  end;
  Result := Pos(';' + Param + ';', ';' + OrigPath + ';') = 0;
end;
