; ImajViewer Setup Script
; Inno Setup 6

#define MyAppName "ImajViewer"
#define MyAppVersion "1.1.0"
#define MyAppPublisher "imajviewer"
#define MyAppURL "https://git.softmediadesign.com/git_alhan/imajviewer"
#define MyAppExeName "imajviewer.exe"

[Setup]
AppId={{B8F4A3D2-1C5E-4A7B-9D0F-6E2C8A1B3D5F}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
DefaultDirName={autopf}\{#MyAppName}
DefaultGroupName={#MyAppName}
DisableProgramGroupPage=yes
OutputDir=..\dist
OutputBaseFilename=imajviewer_setup_{#MyAppVersion}
Compression=lzma
SolidCompression=yes
WizardStyle=modern
PrivilegesRequired=admin
ArchitecturesInstallIn64BitMode=x64compatible
SetupIconFile=..\windows\runner\resources\app_icon.ico

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

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

[Files]
Source: "..\build\windows\x64\runner\Release\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs

[Icons]
Name: "{group}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
Name: "{group}\{cm:UninstallProgram,{#MyAppName}}"; Filename: "{uninstallexe}"
Name: "{autodesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon

[Run]
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#MyAppName}}"; Flags: nowait postinstall skipifsilent

[Registry]
; Register as default image viewer
Root: HKCR; Subkey: ".png\OpenWithProgids\ImajViewer"; ValueType: string; ValueData: ""; Flags: uninsdeletevalue
Root: HKCR; Subkey: ".jpg\OpenWithProgids\ImajViewer"; ValueType: string; ValueData: ""; Flags: uninsdeletevalue
Root: HKCR; Subkey: ".jpeg\OpenWithProgids\ImajViewer"; ValueType: string; ValueData: ""; Flags: uninsdeletevalue
Root: HKCR; Subkey: ".webp\OpenWithProgids\ImajViewer"; ValueType: string; ValueData: ""; Flags: uninsdeletevalue
Root: HKCR; Subkey: ".bmp\OpenWithProgids\ImajViewer"; ValueType: string; ValueData: ""; Flags: uninsdeletevalue
Root: HKCR; Subkey: ".gif\OpenWithProgids\ImajViewer"; ValueType: string; ValueData: ""; Flags: uninsdeletevalue

[Code]
procedure CurStepChanged(CurStep: TSetupStep);
begin
  if CurStep = ssPostInstall then
  begin
    // Register application path for OpenWith
    RegWriteStringValue(HKEY_CLASSES_ROOT, 'Applications\imajviewer.exe\shell\open\command', '', ExpandConstant('"{app}\imajviewer.exe" "%1"'));
    RegWriteStringValue(HKEY_CURRENT_USER, 'Software\RegisteredApplications', 'ImajViewer', ExpandConstant('Software\ImajViewer\Capabilities'));
  end;
end;
