; ============================================================================
; smPlayer Windows Installer (Inno Setup 6)
; ----------------------------------------------------------------------------
; 用法：
;   1. 先执行：flutter build windows --release
;   2. 再执行：iscc installer\sm_emby.iss
;   或一键：  powershell -ExecutionPolicy Bypass -File scripts\build-installer.ps1
;
; 命令行可覆盖版本号：iscc /DAppVersion=1.2.3 installer\sm_emby.iss
; ============================================================================

#define AppName        "smPlayer"
#define AppPublisher   "smPlayer"
#define AppExeName     "smplayer.exe"
#define AppId          "{{A8E3F1C2-7D5B-4A6E-9C8D-3F2E1B0A9D7C}"

#ifndef AppVersion
  #define AppVersion "0.0.15"
#endif

#define ProjectRoot    SourcePath + ".."
#define BuildDir       ProjectRoot + "\build\windows\x64\runner\Release"
#define IconFile       ProjectRoot + "\windows\runner\resources\app_icon.ico"
#define OutputDirAbs   ProjectRoot + "\build\installer"

[Setup]
AppId={#AppId}
AppName={#AppName}
AppVersion={#AppVersion}
AppVerName={#AppName} {#AppVersion}
AppPublisher={#AppPublisher}
DefaultDirName={autopf}\{#AppName}
DefaultGroupName={#AppName}
DisableProgramGroupPage=yes
DisableDirPage=no
ArchitecturesInstallIn64BitMode=x64compatible
ArchitecturesAllowed=x64compatible
OutputDir={#OutputDirAbs}
OutputBaseFilename=smplayer-setup-{#AppVersion}-x64
SetupIconFile={#IconFile}
UninstallDisplayIcon={app}\{#AppExeName}
Compression=lzma2/ultra64
SolidCompression=yes
WizardStyle=modern
PrivilegesRequired=admin
PrivilegesRequiredOverridesAllowed=dialog
CloseApplications=force
RestartApplications=no
MinVersion=10.0

[Languages]
; ChineseSimplified.isl 来自 https://github.com/jrsoftware/issrc (Files/Languages/Unofficial)
; 已随仓库提交至 installer/lang/ 以避免依赖系统级 Inno Setup 安装
Name: "chinesesimp"; MessagesFile: "lang\ChineseSimplified.isl"
Name: "english";    MessagesFile: "compiler:Default.isl"

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

[Files]
; 主可执行文件
Source: "{#BuildDir}\{#AppExeName}"; DestDir: "{app}"; Flags: ignoreversion
; 所有 DLL（Flutter 引擎、fvp/MDK、media_kit/mpv、插件等）
Source: "{#BuildDir}\*.dll"; DestDir: "{app}"; Flags: ignoreversion
; native_assets 清单
Source: "{#BuildDir}\native_assets.json"; DestDir: "{app}"; Flags: ignoreversion skipifsourcedoesntexist
; data 目录（flutter_assets + icudtl.dat + app.so）
Source: "{#BuildDir}\data\*"; DestDir: "{app}\data"; Flags: ignoreversion recursesubdirs createallsubdirs

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

[Registry]
; 自定义 URL scheme：smplayer:// → 本程序（Trakt OAuth 回跳 smplayer://oauth-trakt）。
; 安装到 HKLM\Software\Classes，正式安装走管理员权限写入。
; app 已运行时点链接会拉起第二个进程，由 windows/runner/main.cpp 的 SendAppLinkToInstance
; 把深链转发给已存在窗口后立即退出（app_links 官方单实例范式），不会出现孤立的第二实例。
Root: HKLM; Subkey: "Software\Classes\smplayer"; ValueType: string; ValueName: ""; ValueData: "URL:smplayer Protocol"; Flags: uninsdeletekey
Root: HKLM; Subkey: "Software\Classes\smplayer"; ValueType: string; ValueName: "URL Protocol"; ValueData: ""
Root: HKLM; Subkey: "Software\Classes\smplayer\DefaultIcon"; ValueType: string; ValueName: ""; ValueData: "{app}\{#AppExeName},0"
Root: HKLM; Subkey: "Software\Classes\smplayer\shell\open\command"; ValueType: string; ValueName: ""; ValueData: """{app}\{#AppExeName}"" ""%1"""

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

[UninstallDelete]
; 清理用户数据目录（可选；如需保留用户配置可注释掉）
; Type: filesandordirs; Name: "{userappdata}\sm_emby"
