okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Windows uninstaller: remove the app's own folders (control, host, node, harness) recursively; files the app wrote there while it ran (Python bytecode caches under control) are not in the installer's file list, so those folders and the program folder stayed behind after use (found on strix with a standard user after the process fix); test4b9e05a2a

main
40.0 KiB1145 linesraw
1Unicode true
2ManifestDPIAware true
3; Add in `dpiAwareness` `PerMonitorV2` to manifest for Windows 10 1607+ (note this should not affect lower versions since they should be able to ignore this and pick up `dpiAware` `true` set by `ManifestDPIAware true`)
4; Currently undocumented on NSIS's website but is in the Docs folder of source tree, see
5; https://github.com/kichik/nsis/blob/5fc0b87b819a9eec006df4967d08e522ddd651c9/Docs/src/attributes.but#L286-L300
6; https://github.com/tauri-apps/tauri/pull/10106
7ManifestDPIAwareness PerMonitorV2
8
9!if "{{compression}}" == "none"
10  SetCompress off
11!else
12  ; Set the compression algorithm. We default to LZMA.
13  SetCompressor /SOLID "{{compression}}"
14!endif
15
16; Keep above !include to stay ahead of any plugin command
17; see https://github.com/tauri-apps/tauri/pull/15422#discussion_r3289239624
18{{#if signed_plugins_path}}
19!addplugindir "{{signed_plugins_path}}"
20{{/if}}
21
22!include MUI2.nsh
23!include FileFunc.nsh
24!include x64.nsh
25!include WordFunc.nsh
26!include "utils.nsh"
27!include "FileAssociation.nsh"
28!include "Win\COM.nsh"
29!include "Win\Propkey.nsh"
30!include "Win\RestartManager.nsh"
31!include "StrFunc.nsh"
32${StrCase}
33${StrLoc}
34
35{{#if installer_hooks}}
36!include "{{installer_hooks}}"
37{{/if}}
38
39!define WEBVIEW2APPGUID "{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}"
40
41!define MANUFACTURER "{{manufacturer}}"
42!define PRODUCTNAME "{{product_name}}"
43!define VERSION "{{version}}"
44!define VERSIONWITHBUILD "{{version_with_build}}"
45!define HOMEPAGE "{{homepage}}"
46!define INSTALLMODE "{{install_mode}}"
47!define LICENSE "{{license}}"
48!define INSTALLERICON "{{installer_icon}}"
49!define SIDEBARIMAGE "{{sidebar_image}}"
50!define HEADERIMAGE "{{header_image}}"
51!define UNINSTALLERICON "{{uninstaller_icon}}"
52!define UNINSTALLERHEADERIMAGE "{{uninstaller_header_image}}"
53!define MAINBINARYNAME "{{main_binary_name}}"
54!define MAINBINARYSRCPATH "{{main_binary_path}}"
55!define BUNDLEID "{{bundle_id}}"
56!define COPYRIGHT "{{copyright}}"
57!define OUTFILE "{{out_file}}"
58!define ARCH "{{arch}}"
59!define ADDITIONALPLUGINSPATH "{{additional_plugins_path}}"
60!define ALLOWDOWNGRADES "{{allow_downgrades}}"
61!define DISPLAYLANGUAGESELECTOR "{{display_language_selector}}"
62!define INSTALLWEBVIEW2MODE "{{install_webview2_mode}}"
63!define WEBVIEW2INSTALLERARGS "{{webview2_installer_args}}"
64!define WEBVIEW2BOOTSTRAPPERPATH "{{webview2_bootstrapper_path}}"
65!define WEBVIEW2INSTALLERPATH "{{webview2_installer_path}}"
66!define MINIMUMWEBVIEW2VERSION "{{minimum_webview2_version}}"
67!define UNINSTKEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCTNAME}"
68!define MANUKEY "Software\${MANUFACTURER}"
69!define MANUPRODUCTKEY "${MANUKEY}\${PRODUCTNAME}"
70!define UNINSTALLERSIGNCOMMAND "{{uninstaller_sign_cmd}}"
71!define ESTIMATEDSIZE "{{estimated_size}}"
72!define STARTMENUFOLDER "{{start_menu_folder}}"
73
74Var PassiveMode
75Var UpdateMode
76Var NoShortcutMode
77Var WixMode
78Var OldMainBinaryName
79
80Name "${PRODUCTNAME}"
81BrandingText "${COPYRIGHT}"
82OutFile "${OUTFILE}"
83
84; We don't actually use this value as default install path,
85; it's just for nsis to append the product name folder in the directory selector
86; https://nsis.sourceforge.io/Reference/InstallDir
87!define PLACEHOLDER_INSTALL_DIR "placeholder\${PRODUCTNAME}"
88InstallDir "${PLACEHOLDER_INSTALL_DIR}"
89
90VIProductVersion "${VERSIONWITHBUILD}"
91VIAddVersionKey "ProductName" "${PRODUCTNAME}"
92VIAddVersionKey "FileDescription" "${PRODUCTNAME}"
93VIAddVersionKey "LegalCopyright" "${COPYRIGHT}"
94VIAddVersionKey "FileVersion" "${VERSION}"
95VIAddVersionKey "ProductVersion" "${VERSION}"
96
97# additional plugins
98!addplugindir "${ADDITIONALPLUGINSPATH}"
99
100; Uninstaller signing command
101!if "${UNINSTALLERSIGNCOMMAND}" != ""
102  !uninstfinalize '${UNINSTALLERSIGNCOMMAND}'
103!endif
104
105; Handle install mode, `perUser`, `perMachine` or `both`
106!if "${INSTALLMODE}" == "perMachine"
107  RequestExecutionLevel admin
108!endif
109
110!if "${INSTALLMODE}" == "currentUser"
111  RequestExecutionLevel user
112!endif
113
114!if "${INSTALLMODE}" == "both"
115  !define MULTIUSER_MUI
116  !define MULTIUSER_INSTALLMODE_INSTDIR "${PRODUCTNAME}"
117  !define MULTIUSER_INSTALLMODE_COMMANDLINE
118  !if "${ARCH}" == "x64"
119    !define MULTIUSER_USE_PROGRAMFILES64
120  !else if "${ARCH}" == "arm64"
121    !define MULTIUSER_USE_PROGRAMFILES64
122  !endif
123  !define MULTIUSER_INSTALLMODE_DEFAULT_REGISTRY_KEY "${UNINSTKEY}"
124  !define MULTIUSER_INSTALLMODE_DEFAULT_REGISTRY_VALUENAME "CurrentUser"
125  !define MULTIUSER_INSTALLMODEPAGE_SHOWUSERNAME
126  !define MULTIUSER_INSTALLMODE_FUNCTION RestorePreviousInstallLocation
127  !define MULTIUSER_EXECUTIONLEVEL Highest
128  !include MultiUser.nsh
129!endif
130
131; Installer icon
132!if "${INSTALLERICON}" != ""
133  !define MUI_ICON "${INSTALLERICON}"
134!endif
135
136; Installer sidebar image
137!if "${SIDEBARIMAGE}" != ""
138  !define MUI_WELCOMEFINISHPAGE_BITMAP "${SIDEBARIMAGE}"
139!endif
140
141; Enable header images for installer and uninstaller pages when either image is configured.
142!if "${HEADERIMAGE}" != ""
143  !define MUI_HEADERIMAGE
144!else if "${UNINSTALLERHEADERIMAGE}" != ""
145  !define MUI_HEADERIMAGE
146!endif
147
148; Installer header image
149!if "${HEADERIMAGE}" != ""
150  !define MUI_HEADERIMAGE_BITMAP "${HEADERIMAGE}"
151!endif
152
153; Uninstaller header image
154!if "${UNINSTALLERHEADERIMAGE}" != ""
155  !define MUI_HEADERIMAGE_UNBITMAP "${UNINSTALLERHEADERIMAGE}"
156!endif
157
158; Uninstaller icon
159!if "${UNINSTALLERICON}" != ""
160  !define MUI_UNICON "${UNINSTALLERICON}"
161!else if "${INSTALLERICON}" != ""
162  ; Tauri leaves the uninstaller icon empty unless asked; use the Strata icon so the uninstaller is not the NSIS default
163  !define MUI_UNICON "${INSTALLERICON}"
164!endif
165
166; Define registry key to store installer language
167!define MUI_LANGDLL_REGISTRY_ROOT "HKCU"
168!define MUI_LANGDLL_REGISTRY_KEY "${MANUPRODUCTKEY}"
169!define MUI_LANGDLL_REGISTRY_VALUENAME "Installer Language"
170
171; Strata's look and words: the app's light surface and ink, short copy. The install folder page is shown on a first or manual install (#3186 #3190: C: can be short on space) and
172; skipped in an update (passive), which goes on into the folder the earlier install wrote to the registry.
173!define MUI_BGCOLOR "F9FAFB"
174!define MUI_TEXTCOLOR "171B1E"
175!define MUI_INSTFILESPAGE_PROGRESSBAR "smooth"
176!define MUI_WELCOMEPAGE_TITLE "State of the art. At home."
177!define MUI_WELCOMEPAGE_TEXT "Strata runs AI on your own computer.$\r$\n$\r$\nThis takes about a minute and needs no administrator. You choose your first model inside Strata."
178!define MUI_FINISHPAGE_TITLE "Strata is ready."
179!define MUI_FINISHPAGE_TEXT "Open it to pick your first model. Strata downloads it for you and gets it ready."
180!define MUI_FINISHPAGE_RUN_TEXT "Open Strata"
181!define MUI_PAGE_HEADER_TEXT "Installing Strata"
182!define MUI_PAGE_HEADER_SUBTEXT "Copying the app. You can keep working meanwhile."
183BrandingText "Strata"
184ShowInstDetails nevershow
185
186; Installer pages, must be ordered as they appear
187; 1. Welcome Page
188!define MUI_PAGE_CUSTOMFUNCTION_PRE SkipIfPassive
189!insertmacro MUI_PAGE_WELCOME
190
191; 2. License Page (if defined)
192!if "${LICENSE}" != ""
193  !define MUI_PAGE_CUSTOMFUNCTION_PRE SkipIfPassive
194  !insertmacro MUI_PAGE_LICENSE "${LICENSE}"
195!endif
196
197; 3. Install mode (if it is set to `both`)
198!if "${INSTALLMODE}" == "both"
199  !define MUI_PAGE_CUSTOMFUNCTION_PRE SkipIfPassive
200  !insertmacro MULTIUSER_PAGE_INSTALLMODE
201!endif
202
203; 4. Custom page to ask user if he wants to reinstall/uninstall
204;    only if a previous installation was detected
205Var ReinstallPageCheck
206; 1 when this installer was started on an installed copy of the SAME version and the person chose Uninstall: after it ran the
207; uninstaller this installer ends. (Stock Tauri goes on to the install pages, so Uninstall reinstalled Strata at once; tester report 2026-10-17.)
208Var UninstallOnly
209Page custom PageReinstall PageLeaveReinstall
210Function PageReinstall
211  ; Uninstall previous WiX installation if exists.
212  ;
213  ; A WiX installer stores the installation info in registry
214  ; using a UUID and so we have to loop through all keys under
215  ; `HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall`
216  ; and check if `DisplayName` and `Publisher` keys match ${PRODUCTNAME} and ${MANUFACTURER}
217  ;
218  ; This has a potential issue that there maybe another installation that matches
219  ; our ${PRODUCTNAME} and ${MANUFACTURER} but wasn't installed by our WiX installer,
220  ; however, this should be fine since the user will have to confirm the uninstallation
221  ; and they can chose to abort it if doesn't make sense.
222  StrCpy $0 0
223  wix_loop:
224    EnumRegKey $1 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" $0
225    StrCmp $1 "" wix_loop_done ; Exit loop if there is no more keys to loop on
226    IntOp $0 $0 + 1
227    ReadRegStr $R0 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$1" "DisplayName"
228    ReadRegStr $R1 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$1" "Publisher"
229    StrCmp "$R0$R1" "${PRODUCTNAME}${MANUFACTURER}" 0 wix_loop
230    ReadRegStr $R0 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$1" "UninstallString"
231    ${StrCase} $R1 $R0 "L"
232    ${StrLoc} $R0 $R1 "msiexec" ">"
233    StrCmp $R0 0 0 wix_loop_done
234    StrCpy $WixMode 1
235    StrCpy $R6 "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$1"
236    Goto compare_version
237  wix_loop_done:
238
239  ; Check if there is an existing installation, if not, abort the reinstall page
240  ReadRegStr $R0 SHCTX "${UNINSTKEY}" ""
241  ReadRegStr $R1 SHCTX "${UNINSTKEY}" "UninstallString"
242  ${IfThen} "$R0$R1" == "" ${|} Abort ${|}
243
244  ; Compare this installar version with the existing installation
245  ; and modify the messages presented to the user accordingly
246  compare_version:
247  StrCpy $R4 "$(older)"
248  ${If} $WixMode = 1
249    ReadRegStr $R0 HKLM "$R6" "DisplayVersion"
250  ${Else}
251    ReadRegStr $R0 SHCTX "${UNINSTKEY}" "DisplayVersion"
252  ${EndIf}
253  ${IfThen} $R0 == "" ${|} StrCpy $R4 "$(unknown)" ${|}
254
255  nsis_tauri_utils::SemverCompare "${VERSION}" $R0
256  Pop $R0
257  ; Reinstalling the same version
258  ${If} $R0 = 0
259    StrCpy $R1 "$(alreadyInstalledLong)"
260    StrCpy $R2 "$(addOrReinstall)"
261    StrCpy $R3 "$(uninstallApp)"
262    !insertmacro MUI_HEADER_TEXT "$(alreadyInstalled)" "$(chooseMaintenanceOption)"
263  ; Upgrading
264  ${ElseIf} $R0 = 1
265    StrCpy $R1 "$(olderOrUnknownVersionInstalled)"
266    StrCpy $R2 "$(uninstallBeforeInstalling)"
267    StrCpy $R3 "$(dontUninstall)"
268    !insertmacro MUI_HEADER_TEXT "$(alreadyInstalled)" "$(choowHowToInstall)"
269  ; Downgrading
270  ${ElseIf} $R0 = -1
271    StrCpy $R1 "$(newerVersionInstalled)"
272    StrCpy $R2 "$(uninstallBeforeInstalling)"
273    !if "${ALLOWDOWNGRADES}" == "true"
274      StrCpy $R3 "$(dontUninstall)"
275    !else
276      StrCpy $R3 "$(dontUninstallDowngrade)"
277    !endif
278    !insertmacro MUI_HEADER_TEXT "$(alreadyInstalled)" "$(choowHowToInstall)"
279  ${Else}
280    Abort
281  ${EndIf}
282
283  ; Skip showing the page if passive
284  ;
285  ; Note that we don't call this earlier at the beginning
286  ; of this function because we need to populate some variables
287  ; related to current installed version if detected and whether
288  ; we are downgrading or not.
289  ${If} $PassiveMode = 1
290    Call PageLeaveReinstall
291  ${Else}
292    nsDialogs::Create 1018
293    Pop $R4
294    ${IfThen} $(^RTL) = 1 ${|} nsDialogs::SetRTL $(^RTL) ${|}
295
296    ${NSD_CreateLabel} 0 0 100% 24u $R1
297    Pop $R1
298
299    ${NSD_CreateRadioButton} 30u 50u -30u 8u $R2
300    Pop $R2
301    ${NSD_OnClick} $R2 PageReinstallUpdateSelection
302
303    ${NSD_CreateRadioButton} 30u 70u -30u 8u $R3
304    Pop $R3
305    ; Disable this radio button if downgrading and downgrades are disabled
306    !if "${ALLOWDOWNGRADES}" == "false"
307      ${IfThen} $R0 = -1 ${|} EnableWindow $R3 0 ${|}
308    !endif
309    ${NSD_OnClick} $R3 PageReinstallUpdateSelection
310
311    ; Check the first radio button if this the first time
312    ; we enter this page or if the second button wasn't
313    ; selected the last time we were on this page
314    ${If} $ReinstallPageCheck <> 2
315      SendMessage $R2 ${BM_SETCHECK} ${BST_CHECKED} 0
316    ${Else}
317      SendMessage $R3 ${BM_SETCHECK} ${BST_CHECKED} 0
318    ${EndIf}
319
320    ${NSD_SetFocus} $R2
321    nsDialogs::Show
322  ${EndIf}
323FunctionEnd
324Function PageReinstallUpdateSelection
325  ${NSD_GetState} $R2 $R1
326  ${If} $R1 == ${BST_CHECKED}
327    StrCpy $ReinstallPageCheck 1
328  ${Else}
329    StrCpy $ReinstallPageCheck 2
330  ${EndIf}
331FunctionEnd
332Function PageLeaveReinstall
333  ${NSD_GetState} $R2 $R1
334
335  ; If migrating from Wix, always uninstall
336  ${If} $WixMode = 1
337    Goto reinst_uninstall
338  ${EndIf}
339
340  ; In update mode, always proceeds without uninstalling
341  ${If} $UpdateMode = 1
342    Goto reinst_done
343  ${EndIf}
344
345  ; $R0 holds whether same(0)/upgrading(1)/downgrading(-1) version
346  ; $R1 holds the radio buttons state:
347  ;   1 => first choice was selected
348  ;   0 => second choice was selected
349  ${If} $R0 = 0 ; Same version, proceed
350    ${If} $R1 = 1              ; User chose to add/reinstall
351      Goto reinst_done
352    ${Else}                    ; User chose to uninstall
353      StrCpy $UninstallOnly 1
354      Goto reinst_uninstall
355    ${EndIf}
356  ${ElseIf} $R0 = 1 ; Upgrading
357    ${If} $R1 = 1              ; User chose to uninstall
358      Goto reinst_uninstall
359    ${Else}
360      Goto reinst_done         ; User chose NOT to uninstall
361    ${EndIf}
362  ${ElseIf} $R0 = -1 ; Downgrading
363    ${If} $R1 = 1              ; User chose to uninstall
364      Goto reinst_uninstall
365    ${Else}
366      Goto reinst_done         ; User chose NOT to uninstall
367    ${EndIf}
368  ${EndIf}
369
370  reinst_uninstall:
371    HideWindow
372    ClearErrors
373
374    ${If} $WixMode = 1
375      ReadRegStr $R1 HKLM "$R6" "UninstallString"
376      ExecWait '$R1' $0
377    ${Else}
378      ReadRegStr $4 SHCTX "${MANUPRODUCTKEY}" ""
379      ReadRegStr $R1 SHCTX "${UNINSTKEY}" "UninstallString"
380      ${IfThen} $UpdateMode = 1 ${|} StrCpy $R1 "$R1 /UPDATE" ${|} ; append /UPDATE
381      ${IfThen} $PassiveMode = 1 ${|} StrCpy $R1 "$R1 /P" ${|} ; append /P
382      StrCpy $R1 "$R1 _?=$4" ; append uninstall directory
383      ExecWait '$R1' $0
384    ${EndIf}
385
386    BringToFront
387
388    ${IfThen} ${Errors} ${|} StrCpy $0 2 ${|} ; ExecWait failed, set fake exit code
389
390    ${If} $0 <> 0
391    ${OrIf} ${FileExists} "$INSTDIR\${MAINBINARYNAME}.exe"
392      ; User cancelled wix uninstaller? return to select un/reinstall page
393      ${If} $WixMode = 1
394      ${AndIf} $0 = 1602
395        Abort
396      ${EndIf}
397
398      ; User cancelled NSIS uninstaller? return to select un/reinstall page
399      ${If} $0 = 1
400        Abort
401      ${EndIf}
402
403      ; Other errors? show generic error message and return to select un/reinstall page
404      MessageBox MB_ICONEXCLAMATION "$(unableToUninstall)"
405      Abort
406    ${EndIf}
407
408    ; The NSIS uninstaller was run in place (`_?=`), so it cannot delete itself
409    ; and the install directory, clean them up here once the uninstall succeeded
410    ; https://nsis.sourceforge.io/Docs/Chapter3.html#:~:text=path%20contains%20spaces.-,3.2.3%20Examples,-installer.exe%20/NCRC
411    ${If} $WixMode = 0
412    ${AndIf} $4 != ""
413      Delete "$4\uninstall.exe"
414      RMDir "$4"
415    ${EndIf}
416
417    ; Uninstall means uninstall: do not go on to the install pages.
418    ${If} $UninstallOnly = 1
419      MessageBox MB_OK|MB_ICONINFORMATION "Strata was uninstalled."
420      Quit
421    ${EndIf}
422  reinst_done:
423FunctionEnd
424
425; 5. Choose install directory page. The app is installed for this user only (no administrator), so the folder must be one the
426; user can write to: another drive (D:\Strata) or a folder in the profile, not Program Files. An update (passive: the app's own
427; updater) and a silent install skip it and keep the earlier folder (RestorePreviousInstallLocation).
428!ifdef MUI_PAGE_HEADER_TEXT
429  !undef MUI_PAGE_HEADER_TEXT
430!endif
431!ifdef MUI_PAGE_HEADER_SUBTEXT
432  !undef MUI_PAGE_HEADER_SUBTEXT
433!endif
434!define MUI_PAGE_HEADER_TEXT "Choose where to install Strata"
435!define MUI_PAGE_HEADER_SUBTEXT "Pick another drive if C: is short on space."
436!define MUI_DIRECTORYPAGE_TEXT_TOP "Strata is installed into this folder, for your user only (no administrator needed). Models and chats are stored separately, in the data folder you choose inside Strata."
437!define MUI_PAGE_CUSTOMFUNCTION_PRE SkipIfPassive
438!insertmacro MUI_PAGE_DIRECTORY
439
440; 6. Start menu shortcut page
441Var AppStartMenuFolder
442!if "${STARTMENUFOLDER}" != ""
443  !define MUI_PAGE_CUSTOMFUNCTION_PRE SkipIfPassive
444  !define MUI_STARTMENUPAGE_DEFAULTFOLDER "${STARTMENUFOLDER}"
445!else
446  !define MUI_PAGE_CUSTOMFUNCTION_PRE Skip
447!endif
448!insertmacro MUI_PAGE_STARTMENU Application $AppStartMenuFolder
449
450; 7. Installation page (a page macro uses up the header texts, so they are set again here)
451!ifdef MUI_PAGE_HEADER_TEXT
452  !undef MUI_PAGE_HEADER_TEXT
453!endif
454!ifdef MUI_PAGE_HEADER_SUBTEXT
455  !undef MUI_PAGE_HEADER_SUBTEXT
456!endif
457!define MUI_PAGE_HEADER_TEXT "Installing Strata"
458!define MUI_PAGE_HEADER_SUBTEXT "Copying the app. You can keep working meanwhile."
459!insertmacro MUI_PAGE_INSTFILES
460
461; 8. Finish page
462;
463; Don't auto jump to finish page after installation page,
464; because the installation page has useful info that can be used debug any issues with the installer.
465; (no NOAUTOCLOSE: welcome, progress, finish)
466; Use show readme button in the finish page as a button create a desktop shortcut
467!define MUI_FINISHPAGE_SHOWREADME
468!define MUI_FINISHPAGE_SHOWREADME_TEXT "$(createDesktop)"
469!define MUI_FINISHPAGE_SHOWREADME_FUNCTION CreateOrUpdateDesktopShortcut
470; Show run app after installation.
471!define MUI_FINISHPAGE_RUN
472!define MUI_FINISHPAGE_RUN_FUNCTION RunMainBinary
473!define MUI_PAGE_CUSTOMFUNCTION_PRE SkipIfPassive
474!insertmacro MUI_PAGE_FINISH
475
476Function RunMainBinary
477  nsis_tauri_utils::RunAsUser "$INSTDIR\${MAINBINARYNAME}.exe" ""
478FunctionEnd
479
480; Uninstaller Pages
481; 1. Confirm uninstall page
482Var DeleteAppDataCheckbox
483Var DeleteAppDataCheckboxState
484!define MUI_PAGE_CUSTOMFUNCTION_PRE un.SkipIfPassive
485!insertmacro MUI_UNPAGE_CONFIRM
486
487; 2. "Also remove my Strata data": unticked by default, and it says exactly what it deletes. Skipped when updating or in passive mode
488;    (an update never deletes anything). Model folders the person chose themselves are never touched.
489UninstPage custom un.DataPage un.DataPageLeave
490Function un.DataPage
491  ${If} $PassiveMode = 1
492  ${OrIf} $UpdateMode = 1
493    Abort
494  ${EndIf}
495  !insertmacro MUI_HEADER_TEXT "Remove your Strata data too?" "Your models, chats and settings stay on this PC unless you tick the box."
496  nsDialogs::Create 1018
497  Pop $0
498  ${IfThen} $(^RTL) = 1 ${|} nsDialogs::SetRTL $(^RTL) ${|}
499  ${NSD_CreateCheckBox} 0 0 100% 12u "Also remove my Strata data (models, chats, settings)"
500  Pop $DeleteAppDataCheckbox
501  ${NSD_CreateLabel} 12u 18u -12u 96u "If you tick it, these folders are deleted, and nothing else:$\r$\n$\r$\n$LOCALAPPDATA\Strata   (engine, installed copy, tunings)$\r$\n$APPDATA\Strata   (settings)$\r$\n$PROFILE\.strata   (your chats, app settings)$\r$\n$DOCUMENTS\Strata\Models   (models Strata downloaded into its own folder)$\r$\n$\r$\nA model folder you chose yourself is never deleted."
502  Pop $0
503  ${NSD_SetFocus} $DeleteAppDataCheckbox
504  nsDialogs::Show
505FunctionEnd
506Function un.DataPageLeave
507  ${NSD_GetState} $DeleteAppDataCheckbox $DeleteAppDataCheckboxState
508FunctionEnd
509
510; 3. Uninstalling Page
511!insertmacro MUI_UNPAGE_INSTFILES
512
513;Languages
514{{#each languages}}
515!insertmacro MUI_LANGUAGE "{{this}}"
516{{/each}}
517!insertmacro MUI_RESERVEFILE_LANGDLL
518{{#each language_files}}
519  !include "{{this}}"
520{{/each}}
521
522Function .onInit
523  ${GetOptions} $CMDLINE "/P" $PassiveMode
524  ${IfNot} ${Errors}
525    StrCpy $PassiveMode 1
526  ${EndIf}
527
528  ${GetOptions} $CMDLINE "/NS" $NoShortcutMode
529  ${IfNot} ${Errors}
530    StrCpy $NoShortcutMode 1
531  ${EndIf}
532
533  ${GetOptions} $CMDLINE "/UPDATE" $UpdateMode
534  ${IfNot} ${Errors}
535    StrCpy $UpdateMode 1
536  ${EndIf}
537
538  !if "${DISPLAYLANGUAGESELECTOR}" == "true"
539    !insertmacro MUI_LANGDLL_DISPLAY
540  !endif
541
542  !insertmacro SetContext
543
544  ${If} $INSTDIR == "${PLACEHOLDER_INSTALL_DIR}"
545    ; Set default install location
546    !if "${INSTALLMODE}" == "perMachine"
547      ${If} ${RunningX64}
548        !if "${ARCH}" == "x64"
549          StrCpy $INSTDIR "$PROGRAMFILES64\${PRODUCTNAME}"
550        !else if "${ARCH}" == "arm64"
551          StrCpy $INSTDIR "$PROGRAMFILES64\${PRODUCTNAME}"
552        !else
553          StrCpy $INSTDIR "$PROGRAMFILES\${PRODUCTNAME}"
554        !endif
555      ${Else}
556        StrCpy $INSTDIR "$PROGRAMFILES\${PRODUCTNAME}"
557      ${EndIf}
558    !else if "${INSTALLMODE}" == "currentUser"
559      StrCpy $INSTDIR "$LOCALAPPDATA\Programs\${PRODUCTNAME}"
560    !endif
561
562    Call RestorePreviousInstallLocation
563  ${EndIf}
564
565
566  !if "${INSTALLMODE}" == "both"
567    !insertmacro MULTIUSER_INIT
568  !endif
569
570  ; Abort downgrades if they are disabled, in the modes that skip the reinstall page choice:
571  ; silent, passive and update
572  !if "${ALLOWDOWNGRADES}" == "false"
573  ${If} ${Silent}
574  ${OrIf} $PassiveMode = 1
575  ${OrIf} $UpdateMode = 1
576    ReadRegStr $R0 SHCTX "${UNINSTKEY}" "DisplayVersion"
577    nsis_tauri_utils::SemverCompare "${VERSION}" $R0
578    Pop $R0
579    ; If downgrading
580    ${If} $R0 = -1
581      ${If} ${Silent}
582        System::Call 'kernel32::AttachConsole(i -1)i.r0'
583        ${If} $0 <> 0
584          System::Call 'kernel32::GetStdHandle(i -11)i.r0'
585          System::call 'kernel32::SetConsoleTextAttribute(i r0, i 0x0004)' ; set red color
586          FileWrite $0 "$(silentDowngrades)"
587        ${EndIf}
588      ${Else}
589        MessageBox MB_ICONSTOP "$(silentDowngrades)"
590      ${EndIf}
591      Abort
592    ${EndIf}
593  ${EndIf}
594  !endif
595FunctionEnd
596
597Section WebView2
598  ; Check if Webview2 is already installed and skip this section
599  ${If} ${RunningX64}
600    ReadRegStr $4 HKLM "SOFTWARE\WOW6432Node\Microsoft\EdgeUpdate\Clients\${WEBVIEW2APPGUID}" "pv"
601  ${Else}
602    ReadRegStr $4 HKLM "SOFTWARE\Microsoft\EdgeUpdate\Clients\${WEBVIEW2APPGUID}" "pv"
603  ${EndIf}
604  ${If} $4 == ""
605    ReadRegStr $4 HKCU "SOFTWARE\Microsoft\EdgeUpdate\Clients\${WEBVIEW2APPGUID}" "pv"
606  ${EndIf}
607
608  ${If} $4 == ""
609    ; Webview2 installation
610    ;
611    ; Skip if updating
612    ${If} $UpdateMode <> 1
613      !if "${INSTALLWEBVIEW2MODE}" == "downloadBootstrapper"
614        Delete "$TEMP\MicrosoftEdgeWebview2Setup.exe"
615        DetailPrint "$(webview2Downloading)"
616        NSISdl::download "https://go.microsoft.com/fwlink/p/?LinkId=2124703" "$TEMP\MicrosoftEdgeWebview2Setup.exe"
617        Pop $0
618        ${If} $0 == "success"
619          DetailPrint "$(webview2DownloadSuccess)"
620        ${Else}
621          DetailPrint "$(webview2DownloadError)"
622          Abort "$(webview2AbortError)"
623        ${EndIf}
624        StrCpy $6 "$TEMP\MicrosoftEdgeWebview2Setup.exe"
625        Goto install_webview2
626      !endif
627
628      !if "${INSTALLWEBVIEW2MODE}" == "embedBootstrapper"
629        Delete "$TEMP\MicrosoftEdgeWebview2Setup.exe"
630        File "/oname=$TEMP\MicrosoftEdgeWebview2Setup.exe" "${WEBVIEW2BOOTSTRAPPERPATH}"
631        DetailPrint "$(installingWebview2)"
632        StrCpy $6 "$TEMP\MicrosoftEdgeWebview2Setup.exe"
633        Goto install_webview2
634      !endif
635
636      !if "${INSTALLWEBVIEW2MODE}" == "offlineInstaller"
637        Delete "$TEMP\MicrosoftEdgeWebView2RuntimeInstaller.exe"
638        File "/oname=$TEMP\MicrosoftEdgeWebView2RuntimeInstaller.exe" "${WEBVIEW2INSTALLERPATH}"
639        DetailPrint "$(installingWebview2)"
640        StrCpy $6 "$TEMP\MicrosoftEdgeWebView2RuntimeInstaller.exe"
641        Goto install_webview2
642      !endif
643
644      Goto webview2_done
645
646      install_webview2:
647        DetailPrint "$(installingWebview2)"
648        ; $6 holds the path to the webview2 installer
649        ExecWait "$6 ${WEBVIEW2INSTALLERARGS} /install" $1
650        ${If} $1 = 0
651          DetailPrint "$(webview2InstallSuccess)"
652        ${Else}
653          DetailPrint "$(webview2InstallError)"
654          Abort "$(webview2AbortError)"
655        ${EndIf}
656      webview2_done:
657    ${EndIf}
658  ${Else}
659    !if "${MINIMUMWEBVIEW2VERSION}" != ""
660      ${VersionCompare} "${MINIMUMWEBVIEW2VERSION}" "$4" $R0
661      ${If} $R0 = 1
662        update_webview:
663          DetailPrint "$(installingWebview2)"
664          ${If} ${RunningX64}
665            ReadRegStr $R1 HKLM "SOFTWARE\WOW6432Node\Microsoft\EdgeUpdate" "path"
666          ${Else}
667            ReadRegStr $R1 HKLM "SOFTWARE\Microsoft\EdgeUpdate" "path"
668          ${EndIf}
669          ${If} $R1 == ""
670            ReadRegStr $R1 HKCU "SOFTWARE\Microsoft\EdgeUpdate" "path"
671          ${EndIf}
672          ${If} $R1 != ""
673            ; Chromium updater docs: https://source.chromium.org/chromium/chromium/src/+/main:docs/updater/user_manual.md
674            ; Modified from "HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft EdgeWebView\ModifyPath"
675            ExecWait `"$R1" /install appguid=${WEBVIEW2APPGUID}&needsadmin=true` $1
676            ${If} $1 = 0
677              DetailPrint "$(webview2InstallSuccess)"
678            ${Else}
679              MessageBox MB_ICONEXCLAMATION|MB_ABORTRETRYIGNORE "$(webview2InstallError)" IDIGNORE ignore IDRETRY update_webview
680              Quit
681              ignore:
682            ${EndIf}
683          ${EndIf}
684      ${EndIf}
685    !endif
686  ${EndIf}
687SectionEnd
688
689; STRATA-MIGRATE-BEGIN
690; An earlier build installed the app into %LOCALAPPDATA%\Strata, the folder that also holds the user's data (components, install,
691; procs, runtime, time-skip). Remove only the app files that build put there; everything else stays.
692!macro StrataMigrateOldInstall OLDDIR NEWDIR
693  StrCmp "${OLDDIR}" "${NEWDIR}" +8
694  IfFileExists "${OLDDIR}\strata-desktop.exe" 0 +7
695    Delete "${OLDDIR}\strata-desktop.exe"
696    Delete "${OLDDIR}\uninstall.exe"
697    RMDir /r "${OLDDIR}\host"
698    RMDir /r "${OLDDIR}\node"
699    RMDir /r "${OLDDIR}\control"
700    RMDir "${OLDDIR}"
701!macroend
702; STRATA-MIGRATE-END
703
704; STRATA-STOP-BEGIN
705; Stop what Strata itself started from the install folder (the app, its host, the node runtime, the engine) before files are removed:
706; a running copy keeps its files open, so the folder stayed behind after use. Only processes whose image path is inside INSTDIR are
707; stopped; this uninstaller's own process and any program elsewhere are left alone.
708!macro StrataStopOwnProcesses INSTALLDIR
709  System::Call 'kernel32::SetEnvironmentVariableW(w "STRATA_INSTDIR", w "${INSTALLDIR}")'
710  System::Call 'kernel32::GetCurrentProcessId()i.r9'
711  System::Call 'kernel32::SetEnvironmentVariableW(w "STRATA_SELFPID", w "$9")'
712  ; the installer is a 32-bit program, so plain powershell.exe is the 32-bit one, which cannot read the image path of a 64-bit process: use the 64-bit one
713  StrCpy $8 "$WINDIR\Sysnative\WindowsPowerShell\v1.0\powershell.exe"
714  IfFileExists $8 +2 0
715    StrCpy $8 "powershell.exe"
716  nsExec::Exec '"$8" -NoProfile -NonInteractive -ExecutionPolicy Bypass -Command "$$d = [IO.Path]::GetFullPath($$env:STRATA_INSTDIR).TrimEnd([char]92) + [char]92; $$ids = @(); $$ids += Get-Process -ErrorAction SilentlyContinue | Where-Object { $$_.Path -and [IO.Path]::GetFullPath($$_.Path).StartsWith($$d, [StringComparison]::OrdinalIgnoreCase) } | ForEach-Object { $$_.Id }; try { $$ids += Get-CimInstance Win32_Process -ErrorAction Stop | Where-Object { $$_.ExecutablePath -and [IO.Path]::GetFullPath($$_.ExecutablePath).StartsWith($$d, [StringComparison]::OrdinalIgnoreCase) } | ForEach-Object { $$_.ProcessId } } catch {}; $$ids | Sort-Object -Unique | Where-Object { $$_ -ne [int]$$env:STRATA_SELFPID } | ForEach-Object { Stop-Process -Id $$_ -Force -ErrorAction SilentlyContinue }; Start-Sleep -Milliseconds 1500"'
717  Pop $9
718!macroend
719; STRATA-STOP-END
720
721; STRATA-CLEAN-BEGIN
722; The app writes into its own folders while it runs (Python bytecode caches under control\, for one), and the file-by-file delete below does not know them,
723; so those folders stayed behind with a few dozen files. These four folders hold only what the installer put there and what the app made there;
724; user data is never in them (it lives in the data folder), and the install folder itself is still removed with a plain RMDir.
725!macro StrataRemoveAppFolders INSTALLDIR
726  RMDir /r "${INSTALLDIR}\control"
727  RMDir /r "${INSTALLDIR}\host"
728  RMDir /r "${INSTALLDIR}\node"
729  RMDir /r "${INSTALLDIR}\harness"
730!macroend
731; STRATA-CLEAN-END
732
733Section Install
734  SetOutPath $INSTDIR
735
736  !ifmacrodef NSIS_HOOK_PREINSTALL
737    !insertmacro NSIS_HOOK_PREINSTALL
738  !endif
739
740  !insertmacro StrataMigrateOldInstall "$LOCALAPPDATA\${PRODUCTNAME}" "$INSTDIR"
741
742  !insertmacro CheckIfAppIsRunning "$INSTDIR\${MAINBINARYNAME}.exe" "${PRODUCTNAME}"
743
744  ; Copy main executable
745  File "${MAINBINARYSRCPATH}"
746
747  ; Copy resources
748  {{#each resources_dirs}}
749    CreateDirectory "$INSTDIR\\{{this}}"
750  {{/each}}
751  {{#each resources}}
752    File /a "/oname={{this.[1]}}" "{{no-escape @key}}"
753  {{/each}}
754
755  ; Copy external binaries
756  {{#each binaries}}
757    File /a "/oname={{this}}" "{{no-escape @key}}"
758  {{/each}}
759
760  ; Create file associations
761  {{#each file_associations as |association| ~}}
762    {{#each association.ext as |ext| ~}}
763       !insertmacro APP_ASSOCIATE "{{ext}}" "{{or association.name ext}}" "{{association-description association.description ext}}" "$INSTDIR\${MAINBINARYNAME}.exe,0" "Open with ${PRODUCTNAME}" "$INSTDIR\${MAINBINARYNAME}.exe $\"%1$\""
764    {{/each}}
765  {{/each}}
766
767  ; Register deep links
768  {{#each deep_link_protocols as |protocol| ~}}
769    WriteRegStr SHCTX "Software\Classes\\{{protocol}}" "URL Protocol" ""
770    WriteRegStr SHCTX "Software\Classes\\{{protocol}}" "" "URL:${BUNDLEID} protocol"
771    WriteRegStr SHCTX "Software\Classes\\{{protocol}}\DefaultIcon" "" "$\"$INSTDIR\${MAINBINARYNAME}.exe$\",0"
772    WriteRegStr SHCTX "Software\Classes\\{{protocol}}\shell\open\command" "" "$\"$INSTDIR\${MAINBINARYNAME}.exe$\" $\"%1$\""
773  {{/each}}
774
775  ; Create uninstaller
776  WriteUninstaller "$INSTDIR\uninstall.exe"
777
778  ; Save $INSTDIR in registry for future installations
779  WriteRegStr SHCTX "${MANUPRODUCTKEY}" "" $INSTDIR
780
781  !if "${INSTALLMODE}" == "both"
782    ; Save install mode to be selected by default for the next installation such as updating
783    ; or when uninstalling
784    WriteRegStr SHCTX "${UNINSTKEY}" $MultiUser.InstallMode 1
785  !endif
786
787  ; Remove old main binary if it doesn't match new main binary name
788  ReadRegStr $OldMainBinaryName SHCTX "${UNINSTKEY}" "MainBinaryName"
789  ${If} $OldMainBinaryName != ""
790  ${AndIf} $OldMainBinaryName != "${MAINBINARYNAME}.exe"
791    Delete "$INSTDIR\$OldMainBinaryName"
792  ${EndIf}
793
794  ; Save current MAINBINARYNAME for future updates
795  WriteRegStr SHCTX "${UNINSTKEY}" "MainBinaryName" "${MAINBINARYNAME}.exe"
796
797  ; Registry information for add/remove programs
798  WriteRegStr SHCTX "${UNINSTKEY}" "DisplayName" "${PRODUCTNAME}"
799  WriteRegStr SHCTX "${UNINSTKEY}" "DisplayIcon" "$\"$INSTDIR\${MAINBINARYNAME}.exe$\""
800  WriteRegStr SHCTX "${UNINSTKEY}" "DisplayVersion" "${VERSION}"
801  WriteRegStr SHCTX "${UNINSTKEY}" "Publisher" "${MANUFACTURER}"
802  WriteRegStr SHCTX "${UNINSTKEY}" "InstallLocation" "$\"$INSTDIR$\""
803  WriteRegStr SHCTX "${UNINSTKEY}" "UninstallString" "$\"$INSTDIR\uninstall.exe$\""
804  WriteRegDWORD SHCTX "${UNINSTKEY}" "NoModify" "1"
805  WriteRegDWORD SHCTX "${UNINSTKEY}" "NoRepair" "1"
806
807  ${GetSize} "$INSTDIR" "/M=uninstall.exe /S=0K /G=0" $0 $1 $2
808  IntOp $0 $0 + ${ESTIMATEDSIZE}
809  IntFmt $0 "0x%08X" $0
810  WriteRegDWORD SHCTX "${UNINSTKEY}" "EstimatedSize" "$0"
811
812  !if "${HOMEPAGE}" != ""
813    WriteRegStr SHCTX "${UNINSTKEY}" "URLInfoAbout" "${HOMEPAGE}"
814    WriteRegStr SHCTX "${UNINSTKEY}" "URLUpdateInfo" "${HOMEPAGE}"
815    WriteRegStr SHCTX "${UNINSTKEY}" "HelpLink" "${HOMEPAGE}"
816  !endif
817
818  ; Create start menu shortcut
819  !insertmacro MUI_STARTMENU_WRITE_BEGIN Application
820    Call CreateOrUpdateStartMenuShortcut
821  !insertmacro MUI_STARTMENU_WRITE_END
822
823  ; Create desktop shortcut for silent and passive installers
824  ; because finish page will be skipped
825  ${If} $PassiveMode = 1
826  ${OrIf} ${Silent}
827    Call CreateOrUpdateDesktopShortcut
828  ${EndIf}
829
830  !ifmacrodef NSIS_HOOK_POSTINSTALL
831    !insertmacro NSIS_HOOK_POSTINSTALL
832  !endif
833
834  ; Auto close this page for passive mode
835  ${If} $PassiveMode = 1
836    SetAutoClose true
837  ${EndIf}
838SectionEnd
839
840Function .onInstSuccess
841  ; Check for `/R` flag only in silent and passive installers because
842  ; GUI installer has a toggle for the user to (re)start the app
843  ${If} $PassiveMode = 1
844  ${OrIf} ${Silent}
845    ${GetOptions} $CMDLINE "/R" $R0
846    ${IfNot} ${Errors}
847      ${GetOptions} $CMDLINE "/ARGS" $R0
848      nsis_tauri_utils::RunAsUser "$INSTDIR\${MAINBINARYNAME}.exe" "$R0"
849    ${EndIf}
850  ${EndIf}
851FunctionEnd
852
853Function un.onInit
854  !insertmacro SetContext
855
856  !if "${INSTALLMODE}" == "both"
857    !insertmacro MULTIUSER_UNINIT
858  !endif
859
860  !insertmacro MUI_UNGETLANGUAGE
861
862  ${GetOptions} $CMDLINE "/P" $PassiveMode
863  ${IfNot} ${Errors}
864    StrCpy $PassiveMode 1
865  ${EndIf}
866
867  ${GetOptions} $CMDLINE "/UPDATE" $UpdateMode
868  ${IfNot} ${Errors}
869    StrCpy $UpdateMode 1
870  ${EndIf}
871FunctionEnd
872
873Section Uninstall
874
875  !ifmacrodef NSIS_HOOK_PREUNINSTALL
876    !insertmacro NSIS_HOOK_PREUNINSTALL
877  !endif
878
879  !insertmacro StrataStopOwnProcesses "$INSTDIR"
880  !insertmacro CheckIfAppIsRunning "$INSTDIR\${MAINBINARYNAME}.exe" "${PRODUCTNAME}"
881
882  ; Delete the app directory and its content from disk
883  ; Copy main executable
884  Delete "$INSTDIR\${MAINBINARYNAME}.exe"
885
886  ; Delete resources
887  {{#each resources}}
888    Delete "$INSTDIR\\{{this.[1]}}"
889  {{/each}}
890
891  ; Delete external binaries
892  {{#each binaries}}
893    Delete "$INSTDIR\\{{this}}"
894  {{/each}}
895
896  ; Delete app associations
897  {{#each file_associations as |association| ~}}
898    {{#each association.ext as |ext| ~}}
899      !insertmacro APP_UNASSOCIATE "{{ext}}" "{{or association.name ext}}"
900    {{/each}}
901  {{/each}}
902
903  ; Delete deep links
904  {{#each deep_link_protocols as |protocol| ~}}
905    ReadRegStr $R7 SHCTX "Software\Classes\\{{protocol}}\shell\open\command" ""
906    ${If} $R7 == "$\"$INSTDIR\${MAINBINARYNAME}.exe$\" $\"%1$\""
907      DeleteRegKey SHCTX "Software\Classes\\{{protocol}}"
908    ${EndIf}
909  {{/each}}
910
911
912  !insertmacro StrataRemoveAppFolders "$INSTDIR"
913
914  ; Delete uninstaller
915  Delete "$INSTDIR\uninstall.exe"
916
917  {{#each resources_ancestors}}
918  RMDir /REBOOTOK "$INSTDIR\\{{this}}"
919  {{/each}}
920  RMDir "$INSTDIR"
921
922  ; Remove shortcuts if not updating
923  ${If} $UpdateMode <> 1
924    !insertmacro DeleteAppUserModelId
925
926    ; Remove start menu shortcut
927    !insertmacro MUI_STARTMENU_GETFOLDER Application $AppStartMenuFolder
928    !insertmacro IsShortcutTarget "$SMPROGRAMS\$AppStartMenuFolder\${PRODUCTNAME}.lnk" "$INSTDIR\${MAINBINARYNAME}.exe"
929    Pop $0
930    ${If} $0 = 1
931      !insertmacro UnpinShortcut "$SMPROGRAMS\$AppStartMenuFolder\${PRODUCTNAME}.lnk"
932      Delete "$SMPROGRAMS\$AppStartMenuFolder\${PRODUCTNAME}.lnk"
933      RMDir "$SMPROGRAMS\$AppStartMenuFolder"
934    ${EndIf}
935    !insertmacro IsShortcutTarget "$SMPROGRAMS\${PRODUCTNAME}.lnk" "$INSTDIR\${MAINBINARYNAME}.exe"
936    Pop $0
937    ${If} $0 = 1
938      !insertmacro UnpinShortcut "$SMPROGRAMS\${PRODUCTNAME}.lnk"
939      Delete "$SMPROGRAMS\${PRODUCTNAME}.lnk"
940    ${EndIf}
941
942    ; Remove desktop shortcuts
943    !insertmacro IsShortcutTarget "$DESKTOP\${PRODUCTNAME}.lnk" "$INSTDIR\${MAINBINARYNAME}.exe"
944    Pop $0
945    ${If} $0 = 1
946      !insertmacro UnpinShortcut "$DESKTOP\${PRODUCTNAME}.lnk"
947      Delete "$DESKTOP\${PRODUCTNAME}.lnk"
948    ${EndIf}
949  ${EndIf}
950
951  ; Remove registry information for add/remove programs
952  !if "${INSTALLMODE}" == "both"
953    DeleteRegKey SHCTX "${UNINSTKEY}"
954  !else if "${INSTALLMODE}" == "perMachine"
955    DeleteRegKey HKLM "${UNINSTKEY}"
956  !else
957    DeleteRegKey HKCU "${UNINSTKEY}"
958  !endif
959
960  ; Removes the Autostart entry for ${PRODUCTNAME} from the HKCU Run key if it exists.
961  ; This ensures the program does not launch automatically after uninstallation if it exists.
962  ; If it doesn't exist, it does nothing.
963  ; We do this when not updating (to preserve the registry value on updates)
964  ${If} $UpdateMode <> 1
965    DeleteRegValue HKCU "Software\Microsoft\Windows\CurrentVersion\Run" "${PRODUCTNAME}"
966  ${EndIf}
967
968  ; Delete app data if the checkbox is selected
969  ; and if not updating
970  ${If} $DeleteAppDataCheckboxState = 1
971  ${AndIf} $UpdateMode <> 1
972    ; Clear the install location $INSTDIR from registry
973    DeleteRegKey SHCTX "${MANUPRODUCTKEY}"
974    DeleteRegKey /ifempty SHCTX "${MANUKEY}"
975
976    ; Clear the install language from registry
977    DeleteRegValue HKCU "${MANUPRODUCTKEY}" "Installer Language"
978    DeleteRegKey /ifempty HKCU "${MANUPRODUCTKEY}"
979    DeleteRegKey /ifempty HKCU "${MANUKEY}"
980
981    SetShellVarContext current
982    RmDir /r "$APPDATA\${BUNDLEID}"
983    RmDir /r "$LOCALAPPDATA\${BUNDLEID}"
984
985    ; Strata's own data, for a fresh start: the folders listed on the page, nothing else. Each path is checked first.
986    ${If} "$LOCALAPPDATA" != ""
987      RmDir /r "$LOCALAPPDATA\Strata"
988    ${EndIf}
989    ${If} "$APPDATA" != ""
990      RmDir /r "$APPDATA\Strata"
991    ${EndIf}
992    ${If} "$PROFILE" != ""
993      RmDir /r "$PROFILE\.strata"
994    ${EndIf}
995    ${If} "$DOCUMENTS" != ""
996      RmDir /r "$DOCUMENTS\Strata\Models"
997      RmDir "$DOCUMENTS\Strata"          ; only if it is empty now
998    ${EndIf}
999  ${EndIf}
1000
1001  !ifmacrodef NSIS_HOOK_POSTUNINSTALL
1002    !insertmacro NSIS_HOOK_POSTUNINSTALL
1003  !endif
1004
1005  ; Auto close if passive mode or updating
1006  ${If} $PassiveMode = 1
1007  ${OrIf} $UpdateMode = 1
1008    SetAutoClose true
1009  ${EndIf}
1010SectionEnd
1011
1012; StrIsUnder: Push path, Push folder, Call StrIsUnder, Pop result ("1" when path is the folder or inside it; case-insensitive,
1013; whole path segments only).
1014Function StrIsUnder
1015  Exch $1                  ; folder
1016  Exch
1017  Exch $0                  ; path
1018  Push $2
1019  Push $3
1020  StrCpy $R9 0
1021  StrCmp $1 "" under_done 0
1022  StrLen $2 $1
1023  StrCpy $3 $0 $2
1024  StrCmp $3 $1 0 under_done
1025  StrCpy $3 $0 1 $2
1026  StrCmp $3 "" under_yes 0
1027  StrCmp $3 "\" under_yes under_done
1028  under_yes:
1029    StrCpy $R9 1
1030  under_done:
1031  Pop $3
1032  Pop $2
1033  Pop $0
1034  Pop $1
1035  Push $R9
1036FunctionEnd
1037
1038; Strata: the install folder remembered in the registry is only reused when it is a real place for an app. A location under the
1039; temp folders (a test install, a build machine's scratch run) is ignored and the default per-user folder is used instead.
1040Function RestorePreviousInstallLocation
1041  ReadRegStr $4 SHCTX "${MANUPRODUCTKEY}" ""
1042  StrCmp $4 "" restore_done 0
1043  ; %LOCALAPPDATA%\Strata holds the user's engines, model configs and tuning: never an app folder
1044  StrCmp $4 "$LOCALAPPDATA\${PRODUCTNAME}" restore_done 0
1045  Push $4
1046  Push "$LOCALAPPDATA\Temp"
1047  Call StrIsUnder
1048  Pop $5
1049  StrCmp $5 1 restore_done 0
1050  Push $4
1051  Push "$TEMP"
1052  Call StrIsUnder
1053  Pop $5
1054  StrCmp $5 1 restore_done 0
1055  ReadEnvStr $6 TMP
1056  Push $4
1057  Push $6
1058  Call StrIsUnder
1059  Pop $5
1060  StrCmp $5 1 restore_done 0
1061  ReadEnvStr $6 TEMP
1062  Push $4
1063  Push $6
1064  Call StrIsUnder
1065  Pop $5
1066  StrCmp $5 1 restore_done 0
1067  StrCpy $INSTDIR $4
1068  restore_done:
1069FunctionEnd
1070
1071Function Skip
1072  Abort
1073FunctionEnd
1074
1075Function SkipIfPassive
1076  ${IfThen} $PassiveMode = 1  ${|} Abort ${|}
1077FunctionEnd
1078Function un.SkipIfPassive
1079  ${IfThen} $PassiveMode = 1  ${|} Abort ${|}
1080FunctionEnd
1081
1082Function CreateOrUpdateStartMenuShortcut
1083  ; We used to use product name as MAINBINARYNAME
1084  ; migrate old shortcuts to target the new MAINBINARYNAME
1085  StrCpy $R0 0
1086
1087  !insertmacro IsShortcutTarget "$SMPROGRAMS\$AppStartMenuFolder\${PRODUCTNAME}.lnk" "$INSTDIR\$OldMainBinaryName"
1088  Pop $0
1089  ${If} $0 = 1
1090    !insertmacro SetShortcutTarget "$SMPROGRAMS\$AppStartMenuFolder\${PRODUCTNAME}.lnk" "$INSTDIR\${MAINBINARYNAME}.exe"
1091    StrCpy $R0 1
1092  ${EndIf}
1093
1094  !insertmacro IsShortcutTarget "$SMPROGRAMS\${PRODUCTNAME}.lnk" "$INSTDIR\$OldMainBinaryName"
1095  Pop $0
1096  ${If} $0 = 1
1097    !insertmacro SetShortcutTarget "$SMPROGRAMS\${PRODUCTNAME}.lnk" "$INSTDIR\${MAINBINARYNAME}.exe"
1098    StrCpy $R0 1
1099  ${EndIf}
1100
1101  ${If} $R0 = 1
1102    Return
1103  ${EndIf}
1104
1105  ; Skip creating shortcut if in update mode or no shortcut mode
1106  ; but always create if migrating from wix
1107  ${If} $WixMode = 0
1108    ${If} $UpdateMode = 1
1109    ${OrIf} $NoShortcutMode = 1
1110      Return
1111    ${EndIf}
1112  ${EndIf}
1113
1114  !if "${STARTMENUFOLDER}" != ""
1115    CreateDirectory "$SMPROGRAMS\$AppStartMenuFolder"
1116    CreateShortcut "$SMPROGRAMS\$AppStartMenuFolder\${PRODUCTNAME}.lnk" "$INSTDIR\${MAINBINARYNAME}.exe" "" "$INSTDIR\${MAINBINARYNAME}.exe" 0
1117    !insertmacro SetLnkAppUserModelId "$SMPROGRAMS\$AppStartMenuFolder\${PRODUCTNAME}.lnk"
1118  !else
1119    CreateShortcut "$SMPROGRAMS\${PRODUCTNAME}.lnk" "$INSTDIR\${MAINBINARYNAME}.exe" "" "$INSTDIR\${MAINBINARYNAME}.exe" 0
1120    !insertmacro SetLnkAppUserModelId "$SMPROGRAMS\${PRODUCTNAME}.lnk"
1121  !endif
1122FunctionEnd
1123
1124Function CreateOrUpdateDesktopShortcut
1125  ; We used to use product name as MAINBINARYNAME
1126  ; migrate old shortcuts to target the new MAINBINARYNAME
1127  !insertmacro IsShortcutTarget "$DESKTOP\${PRODUCTNAME}.lnk" "$INSTDIR\$OldMainBinaryName"
1128  Pop $0
1129  ${If} $0 = 1
1130    !insertmacro SetShortcutTarget "$DESKTOP\${PRODUCTNAME}.lnk" "$INSTDIR\${MAINBINARYNAME}.exe"
1131    Return
1132  ${EndIf}
1133
1134  ; Skip creating shortcut if in update mode or no shortcut mode
1135  ; but always create if migrating from wix
1136  ${If} $WixMode = 0
1137    ${If} $UpdateMode = 1
1138    ${OrIf} $NoShortcutMode = 1
1139      Return
1140    ${EndIf}
1141  ${EndIf}
1142
1143  CreateShortcut "$DESKTOP\${PRODUCTNAME}.lnk" "$INSTDIR\${MAINBINARYNAME}.exe" "" "$INSTDIR\${MAINBINARYNAME}.exe" 0
1144  !insertmacro SetLnkAppUserModelId "$DESKTOP\${PRODUCTNAME}.lnk"
1145FunctionEnd