excluded python helpers from frames view
[idea/community.git] / python / edu / build / idea.nsi
1 !verbose 2
2
3 !include "paths.nsi"
4 !include "strings.nsi"
5 !include "Registry.nsi"
6 !include "version.nsi"
7 !include x64.nsh
8
9 ; Product with version (IntelliJ IDEA #xxxx).
10
11 ; Used in registry to put each build info into the separate subkey
12 ; Add&Remove programs doesn't understand subkeys in the Uninstall key,
13 ; thus ${PRODUCT_WITH_VER} is used for uninstall registry information
14 !define PRODUCT_REG_VER "${MUI_PRODUCT}\${VER_BUILD}"
15
16 !define INSTALL_OPTION_ELEMENTS 7
17 !define PYTHON_VERSIONS 4
18 Name "${MUI_PRODUCT}"
19 SetCompressor lzma
20 ; http://nsis.sourceforge.net/Shortcuts_removal_fails_on_Windows_Vista
21 RequestExecutionLevel user
22
23 ;------------------------------------------------------------------------------
24 ; include "Modern User Interface"
25 ;------------------------------------------------------------------------------
26 !include "MUI2.nsh"
27 !include "FileFunc.nsh"
28 !include "TextFunc.nsh"
29 !include UAC.nsh
30 !include "InstallOptions.nsh"
31 !include StrFunc.nsh
32 !include LogicLib.nsh
33
34 ${UnStrStr}
35 ${UnStrLoc}
36 ${UnStrRep}
37 ${StrRep}
38 ${StrTok}
39
40 ReserveFile "desktop.ini"
41 ReserveFile "DeleteSettings.ini"
42 ReserveFile '${NSISDIR}\Plugins\InstallOptions.dll'
43 !insertmacro MUI_RESERVEFILE_LANGDLL
44
45 !define MUI_ICON "${IMAGES_LOCATION}\${PRODUCT_ICON_FILE}"
46 !define MUI_UNICON "${IMAGES_LOCATION}\${PRODUCT_UNINST_ICON_FILE}"
47
48 !define MUI_HEADERIMAGE
49 !define MUI_HEADERIMAGE_BITMAP "${IMAGES_LOCATION}\${PRODUCT_HEADER_FILE}"
50 !define MUI_WELCOMEFINISHPAGE_BITMAP "${IMAGES_LOCATION}\${PRODUCT_LOGO_FILE}"
51
52 ;------------------------------------------------------------------------------
53 ; on GUI initialization installer checks whether IDEA is already installed
54 ;------------------------------------------------------------------------------
55
56 !define MUI_CUSTOMFUNCTION_GUIINIT GUIInit
57
58 Var baseRegKey
59 Var IS_UPGRADE_60
60
61 !define MUI_LANGDLL_REGISTRY_ROOT "HKCU" 
62 !define MUI_LANGDLL_REGISTRY_KEY "Software\JetBrains\${MUI_PRODUCT}\${VER_BUILD}\" 
63 !define MUI_LANGDLL_REGISTRY_VALUENAME "Installer Language"
64
65 ;check if the window is win7 or newer
66 !macro INST_UNINST_SWITCH un
67   Function ${un}winVersion
68     ;The platform is returned into $0, minor version into $1.
69     ;Windows 7 is equals values of 6 as platform and 1 as minor version.
70     ;Windows 8 is equals values of 6 as platform and 2 as minor version.
71     nsisos::osversion
72     ${If} $0 == "6"
73       ${AndIf} $1 >= "1"
74       StrCpy $0 "1"
75     ${else}
76       StrCpy $0 "0"
77     ${EndIf}
78   FunctionEnd
79
80   Function ${un}compareFileInstallationTime
81     StrCpy $9 ""
82   get_first_file:
83     Pop $7
84     IfFileExists "$7" get_next_file 0
85       StrCmp $7 "Complete" complete get_first_file
86   get_next_file:
87     Pop $8
88     StrCmp $8 "Complete" 0 +2
89       ; check if there is only one property file
90       StrCmp $9 "no changes" complete different
91     IfFileExists "$8" 0 get_next_file
92     ClearErrors
93     ${GetTime} "$7" "M" $0 $1 $2 $3 $4 $5 $6
94     ${GetTime} "$8" "M" $R0 $R1 $R2 $R3 $R4 $R5 $R6
95     StrCmp $0 $R0 0 different
96       StrCmp $1 $R1 0 different
97         StrCmp $2 $R2 0 different
98           StrCmp $4 $R4 0 different
99             StrCmp $5 $R5 0 different
100               StrCmp $6 $R6 0 different
101                 StrCpy $9 "no changes"
102                 Goto get_next_file
103   different:
104     StrCpy $9 "Modified"
105   complete:
106 FunctionEnd
107
108 Function ${un}SplitStr
109 Exch $0 ; str
110 Push $1 ; inQ
111 Push $3 ; idx
112 Push $4 ; tmp
113 StrCpy $1 0
114 StrCpy $3 0
115 loop:
116     StrCpy $4 $0 1 $3
117     ${If} $4 == '"'
118         ${If} $1 <> 0
119             StrCpy $0 $0 "" 1
120             IntOp $3 $3 - 1
121         ${EndIf}
122         IntOp $1 $1 !
123     ${EndIf}
124     ${If} $4 == '' ; The end?
125         StrCpy $1 0
126         StrCpy $4 ','
127     ${EndIf}
128     ${If} $4 == ','
129     ${AndIf} $1 = 0
130         StrCpy $4 $0 $3
131         StrCpy $1 $4 "" -1
132         ${IfThen} $1 == '"' ${|} StrCpy $4 $4 -1 ${|}
133         killspace:
134             IntOp $3 $3 + 1
135             StrCpy $0 $0 "" $3
136             StrCpy $1 $0 1
137             StrCpy $3 0
138             StrCmp $1 ',' killspace
139         Push $0 ; Remaining
140         Exch 4
141         Pop $0
142         StrCmp $4 "" 0 moreleft
143             Pop $4
144             Pop $3
145             Pop $1
146             Return
147         moreleft:
148         Exch $4
149         Exch 2
150         Pop $1
151         Pop $3
152         Return
153     ${EndIf}
154     IntOp $3 $3 + 1
155     Goto loop
156 FunctionEnd
157
158 !macroend
159 !insertmacro INST_UNINST_SWITCH ""
160 !insertmacro INST_UNINST_SWITCH "un."
161
162 Function InstDirState
163         !define InstDirState `!insertmacro InstDirStateCall`
164
165         !macro InstDirStateCall _PATH _RESULT
166                 Push `${_PATH}`
167                 Call InstDirState
168                 Pop ${_RESULT}
169         !macroend
170
171         Exch $0
172         Push $1
173         ClearErrors
174
175         FindFirst $1 $0 '$0\*.*'
176         IfErrors 0 +3
177         StrCpy $0 -1
178         goto end
179         StrCmp $0 '.' 0 +4
180         FindNext $1 $0
181         StrCmp $0 '..' 0 +2
182         FindNext $1 $0
183         FindClose $1
184         IfErrors 0 +3
185         StrCpy $0 0
186         goto end
187         StrCpy $0 1
188
189         end:
190         Pop $1
191         Exch $0
192 FunctionEnd
193
194 Function SplitFirstStrPart
195   Exch $R0
196   Exch
197   Exch $R1
198   Push $R2
199   Push $R3
200   StrCpy $R3 $R1
201   StrLen $R1 $R0
202   IntOp $R1 $R1 + 1
203   loop:
204     IntOp $R1 $R1 - 1
205     StrCpy $R2 $R0 1 -$R1
206     StrCmp $R1 0 exit0
207     StrCmp $R2 $R3 exit1 loop
208   exit0:
209   StrCpy $R1 ""
210   Goto exit2
211   exit1:
212     IntOp $R1 $R1 - 1
213     StrCmp $R1 0 0 +3
214      StrCpy $R2 ""
215      Goto +2
216     StrCpy $R2 $R0 "" -$R1
217     IntOp $R1 $R1 + 1
218     StrCpy $R0 $R0 -$R1
219     StrCpy $R1 $R2
220   exit2:
221   Pop $R3
222   Pop $R2
223   Exch $R1 ;rest
224   Exch
225   Exch $R0 ;first
226 FunctionEnd
227
228 Function VersionSplit
229     !define VersionSplit `!insertmacro VersionSplitCall`
230
231     !macro VersionSplitCall _FULL _PRODUCT _BRANCH _BUILD
232         Push `${_FULL}`
233         Call VersionSplit
234         Pop ${_PRODUCT}
235         Pop ${_BRANCH}
236         Pop ${_BUILD}
237     !macroend
238
239     Pop $R0
240     Push "-"
241     Push $R0
242     Call SplitFirstStrPart
243     Pop $R0
244     Pop $R1
245     Push "."
246     Push $R1
247     Call SplitFirstStrPart
248     Push $R0
249 FunctionEnd
250
251 Function OnDirectoryPageLeave
252     StrCpy $IS_UPGRADE_60 "0"
253     ${InstDirState} "$INSTDIR" $R0
254     IntCmp $R0 1 check_build skip_abort skip_abort
255 check_build:
256     FileOpen $R1 "$INSTDIR\build.txt" "r"
257     IfErrors do_abort
258     FileRead $R1 $R2
259     FileClose $R1
260     IfErrors do_abort
261     ${VersionSplit} ${MIN_UPGRADE_BUILD} $R3 $R4 $R5
262     ${VersionSplit} ${MAX_UPGRADE_BUILD} $R6 $R7 $R8
263     ${VersionSplit} $R2 $R9 $R2 $R0
264     StrCmp $R9 $R3 0 do_abort
265     IntCmp $R2 $R4 0 do_abort
266     IntCmp $R0 $R5 do_accept do_abort
267
268     StrCmp $R9 $R6 0 do_abort
269     IntCmp $R2 $R7 0 0 do_abort
270     IntCmp $R0 $R8 do_abort do_accept do_abort
271
272 do_accept:
273     StrCpy $IS_UPGRADE_60 "1"
274     FileClose $R1
275     Goto skip_abort
276
277 do_abort:
278   ;check
279   ; - if there are no files into $INSTDIR (recursively) just excepted property files
280   ; - if property files have the same installation time.
281   StrCpy $9 "$INSTDIR"
282   Call instDirEmpty
283   StrCmp $9 "not empty" abort 0
284   Push "Complete"
285   Push "$INSTDIR\bin\${PRODUCT_EXE_FILE}.vmoptions"
286   Push "$INSTDIR\bin\idea.properties"
287   ${StrRep} $0 ${PRODUCT_EXE_FILE} ".exe" "64.exe.vmoptions"
288   Push "$INSTDIR\bin\$0"
289   Call compareFileInstallationTime
290   StrCmp $9 "Modified" abort skip_abort
291 abort:
292   MessageBox MB_OK|MB_ICONEXCLAMATION "$(empty_or_upgrade_folder)"
293   Abort
294 skip_abort:
295 FunctionEnd
296
297
298 ;check if there are no files into $INSTDIR recursively just except property files.
299 Function instDirEmpty
300   Push $0
301   Push $1
302   Push $2
303   ClearErrors
304   FindFirst $1 $2 "$9\*.*"
305 nextElemement:
306   ;is the element a folder?
307   StrCmp $2 "." getNextElement
308   StrCmp $2 ".." getNextElement
309   IfFileExists "$9\$2\*.*" 0 nextFile
310     Push $9
311     StrCpy "$9" "$9\$2"
312     Call instDirEmpty
313     StrCmp $9 "not empty" done 0
314     Pop $9
315     Goto getNextElement
316 nextFile:
317   ;is it the file property?
318   ${If} $2 != "idea.properties"
319     ${AndIf} $2 != "${PRODUCT_EXE_FILE}.vmoptions"
320       ${StrRep} $0 ${PRODUCT_EXE_FILE} ".exe" "64.exe.vmoptions"
321       ${AndIf} $2 != $0
322         StrCpy $9 "not empty"
323         Goto done
324   ${EndIf}
325 getNextElement:
326   FindNext $1 $2
327   IfErrors 0 nextElemement
328 done:
329   FindClose $1
330   Pop $2
331   Pop $1
332   Pop $0
333 FunctionEnd
334
335
336 ;------------------------------------------------------------------------------
337 ; Variables
338 ;------------------------------------------------------------------------------
339   Var STARTMENU_FOLDER
340   Var config_path
341   Var system_path
342
343 ;------------------------------------------------------------------------------
344 ; configuration
345 ;------------------------------------------------------------------------------
346
347 !insertmacro MUI_PAGE_WELCOME
348
349 Page custom uninstallOldVersionDialog
350 Var productDir
351 Var control_fields
352 Var max_fields
353
354 !ifdef LICENSE_FILE
355 !insertmacro MUI_PAGE_LICENSE "$(myLicenseData)"
356 !endif
357
358 !define MUI_PAGE_CUSTOMFUNCTION_LEAVE OnDirectoryPageLeave
359 !insertmacro MUI_PAGE_DIRECTORY
360
361 Page custom ConfirmDesktopShortcut
362   !define MUI_STARTMENUPAGE_NODISABLE
363   !define MUI_STARTMENUPAGE_DEFAULTFOLDER "JetBrains"
364
365 !insertmacro MUI_PAGE_STARTMENU Application $STARTMENU_FOLDER
366 !define MUI_ABORTWARNING
367 !insertmacro MUI_PAGE_INSTFILES
368 !define MUI_FINISHPAGE_RUN_NOTCHECKED
369 !define MUI_FINISHPAGE_RUN
370 !define MUI_FINISHPAGE_RUN_FUNCTION PageFinishRun
371 !insertmacro MUI_PAGE_FINISH
372
373 !define MUI_UNINSTALLER
374 ;!insertmacro MUI_UNPAGE_CONFIRM
375 UninstPage custom un.ConfirmDeleteSettings
376 !insertmacro MUI_UNPAGE_INSTFILES
377
378 OutFile "${OUT_DIR}\${OUT_FILE}.exe"
379
380 InstallDir "$PROGRAMFILES\${MANUFACTURER}\${PRODUCT_WITH_VER}"
381 !define MUI_BRANDINGTEXT " "
382 BrandingText " "
383
384 Function PageFinishRun
385 !insertmacro UAC_AsUser_ExecShell "" "$INSTDIR\bin\${PRODUCT_EXE_FILE}" "" "" ""
386 FunctionEnd
387
388 ;------------------------------------------------------------------------------
389 ; languages
390 ;------------------------------------------------------------------------------
391 !insertmacro MUI_LANGUAGE "English"
392 ;!insertmacro MUI_LANGUAGE "Japanese"
393 !include "idea_en.nsi"
394 ;!include "idea_jp.nsi"
395
396 !ifdef LICENSE_FILE
397 LicenseLangString myLicenseData ${LANG_ENGLISH} "${LICENSE_FILE}.txt"
398 LicenseLangString myLicenseData ${LANG_JAPANESE} "${LICENSE_FILE}.txt"
399 !endif
400
401 Function .onInit
402   StrCpy $baseRegKey "HKCU"
403   IfSilent UAC_Done
404 UAC_Elevate:
405     !insertmacro UAC_RunElevated
406     StrCmp 1223 $0 UAC_ElevationAborted ; UAC dialog aborted by user? - continue install under user
407     StrCmp 0 $0 0 UAC_Err ; Error?
408     StrCmp 1 $1 0 UAC_Success ;Are we the real deal or just the wrapper?
409     Quit
410 UAC_Err:
411     Abort
412 UAC_ElevationAborted:
413     StrCpy $INSTDIR "$APPDATA\${MANUFACTURER}\${PRODUCT_WITH_VER}"
414     goto UAC_Done
415 UAC_Success:
416     StrCmp 1 $3 UAC_Admin ;Admin?
417     StrCmp 3 $1 0 UAC_ElevationAborted ;Try again?
418     goto UAC_Elevate
419 UAC_Admin:
420     StrCpy $INSTDIR "$PROGRAMFILES\${MANUFACTURER}\${PRODUCT_WITH_VER}"
421     SetShellVarContext all
422     StrCpy $baseRegKey "HKLM"
423 UAC_Done:       
424 ;  !insertmacro MUI_LANGDLL_DISPLAY
425 FunctionEnd
426
427 Function checkVersion
428   StrCpy $2 ""
429   StrCpy $1 "Software\${MANUFACTURER}\${PRODUCT_REG_VER}"
430 ;  ${If} $0 == "HKLM"
431 ;    StrCpy $1 "Software\${MANUFACTURER}\${PRODUCT_REG_VER}"
432 ;    Push $0
433 ;    call winVersion
434 ;    ${If} $0 == "1"
435 ;      StrCpy $1 "Software\Wow6432Node\${MANUFACTURER}\${PRODUCT_REG_VER}"
436 ;    ${Else}
437 ;      StrCpy $1 "Software\${MANUFACTURER}\${PRODUCT_REG_VER}"
438 ;    ${EndIf}
439 ;    Pop $0
440 ;  ${EndIf}
441   Call OMReadRegStr
442   IfFileExists $3\bin\${PRODUCT_EXE_FILE} check_version
443   Goto Done
444 check_version:
445   StrCpy $2 "Build"
446   Call OMReadRegStr
447   StrCmp $3 "" Done
448   IntCmpU $3 ${VER_BUILD} ask_Install_Over Done ask_Install_Over
449 ask_Install_Over:
450   MessageBox MB_YESNO|MB_ICONQUESTION "$(current_version_already_installed)" IDYES continue IDNO exit_installer
451 exit_installer:
452   Abort
453 continue:
454   StrCpy $0 "complete"
455 Done:
456 FunctionEnd
457
458
459 Function searchCurrentVersion
460   ; search current version of IDEA
461   StrCpy $0 "HKCU"
462   Call checkVersion
463   StrCmp $0 "complete" Done
464   StrCpy $0 "HKLM"
465   Call checkVersion
466 Done:  
467 FunctionEnd
468
469
470 Function uninstallOldVersion
471   ;check if the uninstalled application is running
472 remove_previous_installation:
473   ;prepare a copy of launcher
474   CopyFiles "$3\bin\${PRODUCT_EXE_FILE}" "$3\bin\${PRODUCT_EXE_FILE}_copy"
475   ClearErrors
476   ;copy launcher to itself
477   CopyFiles "$3\bin\${PRODUCT_EXE_FILE}_copy" "$3\bin\${PRODUCT_EXE_FILE}"
478   Delete "$3\bin\${PRODUCT_EXE_FILE}_copy"
479   IfErrors 0 +3
480   MessageBox MB_OKCANCEL|MB_ICONQUESTION|MB_TOPMOST "$(application_running)" IDOK remove_previous_installation IDCANCEL complete
481   goto complete
482   ; uninstallation mode
483   !insertmacro INSTALLOPTIONS_READ $9 "UninstallOldVersions.ini" "Field 2" "State"
484   ${If} $9 == "1"
485     ExecWait '"$3\bin\Uninstall.exe" /S'
486   ${else}
487     ExecWait '"$3\bin\Uninstall.exe" _?=$3\bin'
488   ${EndIf}
489   IfFileExists $3\bin\${PRODUCT_EXE_FILE} 0 uninstall
490   goto complete
491 uninstall:
492   ;previous installation has been removed
493   ;customer decided to keep properties?
494   IfFileExists $3\bin\idea.properties saveProperties fullRemove
495 saveProperties:
496   Delete "$3\bin\Uninstall.exe"
497   Goto complete
498 fullRemove:
499   RmDir /r "$3"
500 complete:
501 FunctionEnd
502
503
504 Function checkProductVersion
505 ;$8 - count of already added fields to the dialog
506 ;$3 - an old version which will be checked if the one should be added too
507 StrCpy $7 $control_fields
508 StrCpy $6 ""
509 loop:
510   IntOp $7 $7 + 1
511   ${If} $8 >= $7
512         !insertmacro INSTALLOPTIONS_READ $6 "UninstallOldVersions.ini" "Field $7" "Text"
513         ${If} $6 == $3
514                 ;found the same value in list of installations
515                 StrCpy $6 "duplicated"
516                 Goto finish
517         ${EndIf}
518     Goto loop
519   ${EndIf}
520 finish:
521 FunctionEnd
522
523
524 Function uninstallOldVersionDialog
525   StrCpy $control_fields 2
526   StrCpy $max_fields 13
527   StrCpy $0 "HKLM"
528   StrCpy $4 0
529   ReserveFile "UninstallOldVersions.ini"
530   !insertmacro INSTALLOPTIONS_EXTRACT "UninstallOldVersions.ini"
531   StrCpy $8 $control_fields
532
533 get_installation_info:
534   StrCpy $1 "Software\${MANUFACTURER}\${MUI_PRODUCT}"
535   StrCpy $5 "\bin\${PRODUCT_EXE_FILE}"
536   StrCpy $2 ""
537   Call getInstallationPath
538   StrCmp $3 "complete" next_registry_root
539   ;check if the old installation could be uninstalled
540   IfFileExists $3\bin\Uninstall.exe uninstall_dialog get_next_key
541 uninstall_dialog:
542   Call checkProductVersion
543   ${If} $6 != "duplicated"
544     IntOp $8 $8 + 1
545     !insertmacro INSTALLOPTIONS_WRITE "UninstallOldVersions.ini" "Field $8" "Text" "$3"
546     StrCmp $8 $max_fields complete
547   ${EndIf}
548 get_next_key:
549   IntOp $4 $4 + 1 ;to check next record from registry
550   goto get_installation_info
551
552 next_registry_root:
553 ${If} $0 == "HKLM"
554   StrCpy $0 "HKCU"
555   StrCpy $4 0
556   Goto get_installation_info
557 ${EndIf}
558 complete:
559 !insertmacro INSTALLOPTIONS_WRITE "UninstallOldVersions.ini" "Settings" "NumFields" "$8"
560 ${If} $8 > $control_fields
561   ;$2 used in prompt text
562   StrCpy $2 "s"
563   StrCpy $7 $control_fields
564   IntOp $7 $7 + 1
565   StrCmp $8 $7 0 +2
566     StrCpy $2 ""
567   !insertmacro MUI_HEADER_TEXT "$(uninstall_previous_installations_title)" "$(uninstall_previous_installations)"
568   !insertmacro INSTALLOPTIONS_WRITE "UninstallOldVersions.ini" "Field 1" "Text" "$(uninstall_previous_installations_prompt)"
569   !insertmacro INSTALLOPTIONS_WRITE "UninstallOldVersions.ini" "Field 3" "Flags" "FOCUS"
570   !insertmacro INSTALLOPTIONS_DISPLAY "UninstallOldVersions.ini"
571   ;uninstall chosen installation(s)
572
573   ;no disabled controls. StrCmp $2 "OK" loop finish
574 loop:
575   !insertmacro INSTALLOPTIONS_READ $0 "UninstallOldVersions.ini" "Field $8" "State"
576   !insertmacro INSTALLOPTIONS_READ $3 "UninstallOldVersions.ini" "Field $8" "Text"
577   ${If} $0 == "1"
578     Call uninstallOldVersion
579     ${EndIf}
580     IntOp $8 $8 - 1
581     StrCmp $8 $control_fields finish loop
582   ${EndIf}
583 finish:
584 FunctionEnd
585
586
587 Function getInstallationPath
588   Push $1
589   Push $2
590   Push $5
591 loop:
592   Call OMEnumRegKey
593   StrCmp $3 "" 0 getPath
594   StrCpy $3 "complete"
595   goto done
596 getPath:
597   Push $1
598   StrCpy $1 "$1\$3"
599   Call OMReadRegStr
600   Pop $1
601   IfFileExists $3$5 done 0 
602   IntOp $4 $4 + 1
603   goto loop
604 done:
605   Pop $5
606   Pop $2
607   Pop $1
608 FunctionEnd
609
610
611 Function GUIInit
612   Push $0
613   Push $1
614   Push $2
615   Push $3
616   Push $4
617   Push $5
618
619 ; is the current version of IDEA installed?
620   Call searchCurrentVersion
621
622 ; search old versions of IDEA
623   StrCpy $4 0
624   StrCpy $0 "HKCU"
625   StrCpy $1 "Software\${MANUFACTURER}\${MUI_PRODUCT}"
626   StrCpy $5 "\bin\${PRODUCT_EXE_FILE}"
627   StrCpy $2 ""
628   Call getInstallationPath
629   StrCmp $3 "complete" all_users
630   IfFileExists $3\bin\${PRODUCT_EXE_FILE} old_version_located all_users
631 all_users:
632   StrCpy $4 0
633   StrCpy $0 "HKLM"
634   Call getInstallationPath
635   StrCmp $3 "complete" success
636   IfFileExists $3\bin\${PRODUCT_EXE_FILE} 0 success
637 old_version_located:
638 ;  MessageBox MB_YESNO|MB_ICONQUESTION "$(previous_installations)" IDYES uninstall IDNO success
639 ;uninstall:
640 ;  Call uninstallOldVersions
641
642 success:
643   IntCmp ${SHOULD_SET_DEFAULT_INSTDIR} 0 end_enum_versions_hklm
644   StrCpy $3 "0"        # latest build number
645   StrCpy $0 "0"        # registry key index
646
647 enum_versions_hkcu:
648   EnumRegKey $1 "HKCU" "Software\${MANUFACTURER}\${MUI_PRODUCT}" $0
649   StrCmp $1 "" end_enum_versions_hkcu
650   IntCmp $1 $3 continue_enum_versions_hkcu continue_enum_versions_hkcu
651   StrCpy $3 $1
652   ReadRegStr $INSTDIR "HKCU" "Software\${MANUFACTURER}\${MUI_PRODUCT}\$3" ""
653   
654 continue_enum_versions_hkcu:
655   IntOp $0 $0 + 1
656   Goto enum_versions_hkcu
657   
658 end_enum_versions_hkcu:  
659
660   StrCpy $0 "0"        # registry key index
661
662 enum_versions_hklm:
663   EnumRegKey $1 "HKLM" "Software\${MANUFACTURER}\${MUI_PRODUCT}" $0
664   StrCmp $1 "" end_enum_versions_hklm
665   IntCmp $1 $3 continue_enum_versions_hklm continue_enum_versions_hklm
666   StrCpy $3 $1
667   ReadRegStr $INSTDIR "HKLM" "Software\${MANUFACTURER}\${MUI_PRODUCT}\$3" ""
668   
669 continue_enum_versions_hklm:
670   IntOp $0 $0 + 1
671   Goto enum_versions_hklm
672   
673 end_enum_versions_hklm:
674
675   StrCmp $INSTDIR "" 0 skip_default_instdir
676   StrCpy $INSTDIR "$PROGRAMFILES\${MANUFACTURER}\${MUI_PRODUCT} ${MUI_VERSION_MAJOR}.${MUI_VERSION_MINOR}"
677 skip_default_instdir:
678
679   Pop $5
680   Pop $4
681   Pop $3
682   Pop $2
683   Pop $1
684   Pop $0
685   !insertmacro INSTALLOPTIONS_EXTRACT "Desktop.ini"
686
687 FunctionEnd
688
689 Function ProductRegistration
690   StrCmp "${PRODUCT_WITH_VER}" "${MUI_PRODUCT} ${VER_BUILD}" eapInfo releaseInfo
691 eapInfo:
692   StrCpy $3 "${PRODUCT_WITH_VER}(EAP)"
693   goto createRegistration
694 releaseInfo:
695   StrCpy $3 "${PRODUCT_WITH_VER}"
696 createRegistration:
697   StrCpy $0 "HKCR"
698   StrCpy $1 "Applications\${PRODUCT_EXE_FILE}\shell\open"
699   StrCpy $2 "FriendlyAppName"
700   call OMWriteRegStr
701   StrCpy $1 "Applications\${PRODUCT_EXE_FILE}\shell\open\command"
702   StrCpy $2 ""
703   StrCpy $3 '$INSTDIR\bin\${PRODUCT_EXE_FILE} "%1"'
704   call OMWriteRegStr
705 FunctionEnd
706
707 Function ProductAssociation
708  ; back up old value of an association
709  ReadRegStr $1 HKCR $R4 ""
710   StrCmp $1 "" skip_backup
711     StrCmp $1 ${PRODUCT_PATHS_SELECTOR} skip_backup
712     WriteRegStr HKCR $R4 "backup_val" $1
713 skip_backup:
714   WriteRegStr HKCR $R4 "" "${PRODUCT_PATHS_SELECTOR}"
715   ReadRegStr $0 HKCR ${PRODUCT_PATHS_SELECTOR} ""
716   StrCmp $0 "" 0 command_exists
717         WriteRegStr HKCR ${PRODUCT_PATHS_SELECTOR} "" "${PRODUCT_FULL_NAME}"
718         WriteRegStr HKCR "${PRODUCT_PATHS_SELECTOR}\shell" "" "open"
719         WriteRegStr HKCR "${PRODUCT_PATHS_SELECTOR}\DefaultIcon" "" "$INSTDIR\bin\${PRODUCT_EXE_FILE},0"
720 command_exists:
721   WriteRegStr HKCR "${PRODUCT_PATHS_SELECTOR}\shell\open\command" "" \
722     '$INSTDIR\bin\${PRODUCT_EXE_FILE} "%1"'
723 FunctionEnd
724
725 Function getPythonInfo
726   ClearErrors
727   FileOpen $3 $Temp\python.txt r
728   IfErrors cantOpenFile ;file can not be open.
729   ${If} ${RunningX64}
730     goto getPythonInfo
731   ${Else}
732     FileRead $3 $4
733     FileRead $3 $4
734   ${EndIf}
735   ;get python2 info
736 getPythonInfo:
737   FileRead $3 $4
738   ${StrTok} $0 $4 " " "1" "1"
739   ${StrTok} $1 $4 " " "2" "1"
740   ;get python3 info
741   FileRead $3 $4
742   ${StrTok} $R0 $4 " " "1" "1"
743   ${StrTok} $R1 $4 " " "2" "1"
744   goto done
745 cantOpenFile:
746   MessageBox MB_OK|MB_ICONEXCLAMATION "python.txt is not exist. Python will not be downloaded."
747   StrCpy $0 "Error"
748 done:
749 FunctionEnd
750
751 Function searchPython
752   ;$R2 - version of python
753   ReadRegStr $1 "HKCU" "Software\Python\PythonCore\$R2\InstallPath" ""
754   StrCmp $1 "" installationForAllUsers
755   goto verifyPythonLauncher
756 installationForAllUsers:
757   ReadRegStr $1 "HKLM" "Software\Python\PythonCore\$R2\InstallPath" ""
758   StrCmp $1 "" pythonAbsent
759 verifyPythonLauncher:
760   IfFileExists $1python.exe pythonExists pythonAbsent
761 pythonAbsent:  
762   StrCpy $R2 "Absent"
763   goto done
764 pythonExists:  
765   StrCpy $R2 "Exists"   
766 done:  
767 FunctionEnd
768
769 ;------------------------------------------------------------------------------
770 ; Installer sections
771 ;------------------------------------------------------------------------------
772 Section "IDEA Files" CopyIdeaFiles
773   ${LineSum} "$TEMP\python.txt" $R0
774   IfErrors cantOpenFile
775   StrCmp $R0 ${PYTHON_VERSIONS} getPythonInfo ;info about 2 and 3 version of python
776 cantOpenFile:  
777   MessageBox MB_OK|MB_ICONEXCLAMATION "python.txt is invalid. Python will not be downloaded."
778   goto skip_python_download
779 getPythonInfo:  
780   Call getPythonInfo
781   StrCmp $0 "Error" skip_python_download
782   !insertmacro INSTALLOPTIONS_READ $R2 "Desktop.ini" "Field 4" "State"
783   StrCmp $R2 1 "" python3
784   StrCpy $R2 $0
785   StrCpy $R3 $1
786   goto check_python
787 python3:  
788   !insertmacro INSTALLOPTIONS_READ $R2 "Desktop.ini" "Field 5" "State"
789   StrCmp $R2 1 "" skip_python_download
790   StrCpy $R2 $R0
791   StrCpy $R3 $R1
792 check_python:  
793   ReadRegStr $1 "HKCU" "Software\Python\PythonCore\$R2\InstallPath" ""
794   StrCmp $1 "" installation_for_all_users
795   goto verefy_python_launcher
796 installation_for_all_users:
797   ReadRegStr $1 "HKLM" "Software\Python\PythonCore\$R2\InstallPath" ""
798   StrCmp $1 "" get_python
799 verefy_python_launcher:
800   IfFileExists $1python.exe python_exists get_python
801 get_python:
802   CreateDirectory "$INSTDIR\python"
803   inetc::get "$R3" "$INSTDIR\python\python_$R2.msi"
804   Pop $0
805   ${If} $0 == "OK" 
806     ExecCmd::exec 'msiexec /i "$INSTDIR\python\python_$R2.msi" /quiet /qn /norestart'
807   ${Else}
808     MessageBox MB_OK|MB_ICONEXCLAMATION "The download is failed"
809   ${EndIf}
810 python_exists:  
811 skip_python_download:  
812 ; create shortcuts
813   !insertmacro INSTALLOPTIONS_READ $R2 "Desktop.ini" "Field 1" "State"
814   StrCmp $R2 1 "" skip_desktop_shortcut
815   CreateShortCut "$DESKTOP\${PRODUCT_FULL_NAME_WITH_VER}.lnk" \
816                  "$INSTDIR\bin\${PRODUCT_EXE_FILE}" "" "" "" SW_SHOWNORMAL
817
818 skip_desktop_shortcut:
819   ; OS is not win7
820   Call winVersion
821   ${If} $0 == "0" 
822     !insertmacro INSTALLOPTIONS_READ $R2 "Desktop.ini" "Field 2" "State"
823     StrCmp $R2 1 "" skip_quicklaunch_shortcut
824     CreateShortCut "$QUICKLAUNCH\${PRODUCT_FULL_NAME_WITH_VER}.lnk" \
825                    "$INSTDIR\bin\${PRODUCT_EXE_FILE}" "" "" "" SW_SHOWNORMAL
826   ${EndIf}      
827 skip_quicklaunch_shortcut:
828
829   !insertmacro INSTALLOPTIONS_READ $R1 "Desktop.ini" "Settings" "NumFields"
830   IntCmp $R1 ${INSTALL_OPTION_ELEMENTS} do_association done do_association
831 do_association:
832   StrCpy $R2 ${INSTALL_OPTION_ELEMENTS}  
833 get_user_choice:
834   !insertmacro INSTALLOPTIONS_READ $R3 "Desktop.ini" "Field $R2" "State"
835   StrCmp $R3 1 "" next_association
836   !insertmacro INSTALLOPTIONS_READ $R4 "Desktop.ini" "Field $R2" "Text"
837   call ProductAssociation
838 next_association:  
839   IntOp $R2 $R2 + 1
840   IntCmp $R1 $R2 get_user_choice done get_user_choice
841
842 done:
843   ;registration application to be presented in Open With list
844   call ProductRegistration
845   ;reset icon cache
846   System::Call 'shell32.dll::SHChangeNotify(i, i, i, i) v (0x08000000, 0, 0, 0)'
847 !insertmacro MUI_STARTMENU_WRITE_BEGIN Application
848 ; $STARTMENU_FOLDER stores name of IDEA folder in Start Menu,
849 ; save it name in the "MenuFolder" RegValue
850   CreateDirectory "$SMPROGRAMS\$STARTMENU_FOLDER"
851
852   CreateShortCut "$SMPROGRAMS\$STARTMENU_FOLDER\${PRODUCT_FULL_NAME_WITH_VER}.lnk" \
853                  "$INSTDIR\bin\${PRODUCT_EXE_FILE}" "" "" "" SW_SHOWNORMAL
854 ;  CreateShortCut "$SMPROGRAMS\$STARTMENU_FOLDER\Uninstall ${PRODUCT_FULL_NAME_WITH_VER}.lnk" \
855 ;                 "$INSTDIR\bin\Uninstall.exe"
856   StrCpy $0 $baseRegKey
857   StrCpy $1 "Software\${MANUFACTURER}\${PRODUCT_REG_VER}"
858   StrCpy $2 "MenuFolder"
859   StrCpy $3 "$STARTMENU_FOLDER"
860   Call OMWriteRegStr
861 !insertmacro MUI_STARTMENU_WRITE_END
862
863   StrCmp ${IPR} "false" skip_ipr
864
865   ; back up old value of .ipr
866 !define Index "Line${__LINE__}"
867   ReadRegStr $1 HKCR ".ipr" ""
868   StrCmp $1 "" "${Index}-NoBackup"
869     StrCmp $1 "IntelliJIdeaProjectFile" "${Index}-NoBackup"
870     WriteRegStr HKCR ".ipr" "backup_val" $1
871 "${Index}-NoBackup:"
872   WriteRegStr HKCR ".ipr" "" "IntelliJIdeaProjectFile"
873   ReadRegStr $0 HKCR "IntelliJIdeaProjectFile" ""
874   StrCmp $0 "" 0 "${Index}-Skip"
875         WriteRegStr HKCR "IntelliJIdeaProjectFile" "" "IntelliJ IDEA Project File"
876         WriteRegStr HKCR "IntelliJIdeaProjectFile\shell" "" "open"
877 "${Index}-Skip:"
878   WriteRegStr HKCR "IntelliJIdeaProjectFile\DefaultIcon" "" "$INSTDIR\bin\${PRODUCT_EXE_FILE},0"
879   WriteRegStr HKCR "IntelliJIdeaProjectFile\shell\open\command" "" \
880     '$INSTDIR\bin\${PRODUCT_EXE_FILE} "%1"'
881 !undef Index
882
883 skip_ipr:
884
885 ; readonly section
886   SectionIn RO
887 !include "idea_win.nsh"
888
889   IntCmp $IS_UPGRADE_60 1 skip_properties
890   SetOutPath $INSTDIR\bin
891   File "${PRODUCT_PROPERTIES_FILE}"
892   File "${PRODUCT_VM_OPTIONS_FILE}"
893 skip_properties:
894
895   StrCpy $0 $baseRegKey
896   StrCpy $1 "Software\${MANUFACTURER}\${PRODUCT_REG_VER}"
897   StrCpy $2 ""
898   StrCpy $3 "$INSTDIR"
899   Call OMWriteRegStr
900   StrCpy $2 "Build"
901   StrCpy $3 ${VER_BUILD}
902   Call OMWriteRegStr
903
904 ; write uninstaller & add it to add/remove programs in control panel
905   WriteUninstaller "$INSTDIR\bin\Uninstall.exe"
906   WriteRegStr SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_WITH_VER}" \
907             "DisplayName" "${PRODUCT_FULL_NAME_WITH_VER}"
908   WriteRegStr SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_WITH_VER}" \
909               "UninstallString" "$INSTDIR\bin\Uninstall.exe"
910   WriteRegStr SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_WITH_VER}" \
911               "InstallLocation" "$INSTDIR"
912   WriteRegStr SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_WITH_VER}" \
913               "DisplayIcon" "$INSTDIR\bin\${PRODUCT_EXE_FILE}"
914   WriteRegStr SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_WITH_VER}" \
915               "DisplayVersion" "${VER_BUILD}"
916   WriteRegStr SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_WITH_VER}" \
917               "Publisher" "JetBrains s.r.o."
918   WriteRegStr SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_WITH_VER}" \
919               "URLInfoAbout" "https://www.jetbrains.com/products"
920   WriteRegStr SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_WITH_VER}" \
921               "InstallType" "$baseRegKey"
922   WriteRegDWORD SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_WITH_VER}" \
923               "NoModify" 1
924   WriteRegDWORD SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_WITH_VER}" \
925               "NoRepair" 1
926
927   ExecWait "$INSTDIR\jre\jre\bin\javaw.exe -Xshare:dump"
928   SetOutPath $INSTDIR\bin
929   ; set the current time for installation files under $INSTDIR\bin
930   ExecCmd::exec 'copy "$INSTDIR\bin\*.*s" +,,'
931   call winVersion
932   ${If} $0 == "1"  
933     ;ExecCmd::exec 'icacls "$INSTDIR" /grant %username%:F /T >"$INSTDIR"\installation_log.txt 2>"$INSTDIR"\installation_error.txt'
934     AccessControl::GrantOnFile \
935       "$INSTDIR" "(S-1-5-32-545)" "GenericRead + GenericExecute"
936   ${EndIf}
937 SectionEnd
938
939 ;------------------------------------------------------------------------------
940 ; Descriptions of sections
941 ;------------------------------------------------------------------------------
942 ; LangString DESC_CopyRuntime ${LANG_ENGLISH} "${MUI_PRODUCT} files"
943
944 ;------------------------------------------------------------------------------
945 ; custom install pages
946 ;------------------------------------------------------------------------------
947 Function updatePythonControls
948   !insertmacro INSTALLOPTIONS_WRITE "Desktop.ini" $R4 "Text" "Python $R2 (installed)"
949   !insertmacro INSTALLOPTIONS_WRITE "Desktop.ini" $R4 "Flags" "DISABLED"
950   !insertmacro INSTALLOPTIONS_WRITE "Desktop.ini" $R4 "Type" "checkbox"
951   !insertmacro INSTALLOPTIONS_WRITE "Desktop.ini" $R4 "State" "0"
952   !insertmacro INSTALLOPTIONS_WRITE "Desktop.ini" $R5 "Type" "checkbox"
953   !insertmacro INSTALLOPTIONS_WRITE "Desktop.ini" $R5 "State" "0"
954 FunctionEnd
955
956 Function ConfirmDesktopShortcut
957   !insertmacro MUI_HEADER_TEXT "$(installation_options)" "$(installation_options_prompt)"
958   !insertmacro INSTALLOPTIONS_WRITE "Desktop.ini" "Field 1" "Text" "$(create_desktop_shortcut)"
959   call winVersion
960   ${If} $0 == "1"
961     !insertmacro INSTALLOPTIONS_WRITE "Desktop.ini" "Field 2" "Type" "Label"    
962     !insertmacro INSTALLOPTIONS_WRITE "Desktop.ini" "Field 2" "Text" ""
963   ${Else}
964     !insertmacro INSTALLOPTIONS_WRITE "Desktop.ini" "Field 2" "Text" "$(create_quick_launch_shortcut)"
965   ${EndIf}
966   IfFileExists "$TEMP\python.txt" deletePythonFileInfo getPythonFileInfo
967 deletePythonFileInfo:  
968   Delete "$TEMP\python.txt"
969 getPythonFileInfo:
970   inetc::get "https://www.jetbrains.com/updates/python.txt" "$TEMP\python.txt"
971   ${LineSum} "$TEMP\python.txt" $R0
972   IfErrors cantOpenFile
973   StrCmp $R0 ${PYTHON_VERSIONS} getPythonInfo
974 cantOpenFile:  
975   MessageBox MB_OK|MB_ICONEXCLAMATION "python.txt is not exist. Python will not be downloaded."
976 removePythonChoice:
977   !insertmacro INSTALLOPTIONS_WRITE "Desktop.ini" "Field 4" "Flags" "DISABLED"
978   !insertmacro INSTALLOPTIONS_WRITE "Desktop.ini" "Field 5" "Flags" "DISABLED" 
979   goto association
980 getPythonInfo:  
981   Call getPythonInfo
982   StrCmp $0 "Error" removePythonChoice
983   ;check if pythons are already installed
984   StrCpy $R2 $0
985   Call searchPython
986   !insertmacro INSTALLOPTIONS_WRITE "Desktop.ini" "Field 4" "Text" "Python $0"
987   StrCmp $R2 "Absent" checkPython3
988   StrCpy $R2 $0
989   StrCpy $R4 "Field 4"
990   StrCpy $R5 "Field 5"
991   Call updatePythonControls
992 checkPython3:
993   StrCpy $R2 $R0
994   Call searchPython
995   !insertmacro INSTALLOPTIONS_WRITE "Desktop.ini" "Field 5" "Text" "Python $R0"
996   StrCmp $R2 "Absent" association
997   StrCpy $R2 $R0
998   StrCpy $R4 "Field 5"
999   StrCpy $R5 "Field 4"
1000   Call updatePythonControls
1001 association:
1002   StrCmp "${ASSOCIATION}" "NoAssociation" skip_association
1003   StrCpy $R0 6
1004   push "${ASSOCIATION}"
1005 loop:
1006   call SplitStr
1007   Pop $0
1008   StrCmp $0 "" done
1009   IntOp $R0 $R0 + 1
1010   !insertmacro INSTALLOPTIONS_WRITE "Desktop.ini" "Field $R0" "Text" "$0"
1011   goto loop
1012 skip_association:
1013   StrCpy $R0 2
1014   call winVersion
1015   ${If} $0 == "1"
1016   IntOp $R0 $R0 - 1
1017   ${EndIf}
1018 done:
1019   !insertmacro INSTALLOPTIONS_WRITE "Desktop.ini" "Settings" "NumFields" "$R0"
1020   !insertmacro INSTALLOPTIONS_DISPLAY "Desktop.ini"
1021 FunctionEnd
1022
1023
1024 ;------------------------------------------------------------------------------
1025 ; custom uninstall functions
1026 ;------------------------------------------------------------------------------
1027
1028 Function un.onInit
1029   StrCpy $baseRegKey "HKCU"
1030   ;admin perm. is required to uninstall?
1031   ${UnStrStr} $R0 $INSTDIR $PROGRAMFILES
1032   StrCmp $R0 $INSTDIR requred_admin_perm UAC_Done
1033
1034 requred_admin_perm:
1035   ;the user has admin rights?
1036   UserInfo::GetAccountType
1037   Pop $R2
1038   StrCmp $R2 "Admin" UAC_Admin uninstall_location
1039
1040 uninstall_location:
1041   ;check if the uninstallation is running from the product location
1042   IfFileExists $APPDATA\${PRODUCT_PATHS_SELECTOR}_${VER_BUILD}_Uninstall.exe UAC_Elevate copy_uninstall
1043
1044 copy_uninstall:
1045   ;do copy for unistall.exe
1046   CopyFiles "$OUTDIR\Uninstall.exe" "$APPDATA\${PRODUCT_PATHS_SELECTOR}_${VER_BUILD}_Uninstall.exe"
1047   ExecWait '"$APPDATA\${PRODUCT_PATHS_SELECTOR}_${VER_BUILD}_Uninstall.exe" _?=$INSTDIR'
1048   Delete "$APPDATA\${PRODUCT_PATHS_SELECTOR}_${VER_BUILD}_Uninstall.exe"
1049   Quit
1050
1051 UAC_Elevate:
1052   !insertmacro UAC_RunElevated
1053   StrCmp 1223 $0 UAC_ElevationAborted ; UAC dialog aborted by user? - continue install under user
1054   StrCmp 0 $0 0 UAC_Err ; Error?
1055   StrCmp 1 $1 0 UAC_Success ;Are we the real deal or just the wrapper?
1056   Quit
1057 UAC_ElevationAborted:
1058 UAC_Err:
1059   Abort
1060 UAC_Success:
1061   StrCmp 1 $3 UAC_Admin ;Admin?
1062   StrCmp 3 $1 0 UAC_ElevationAborted ;Try again?
1063   goto UAC_Elevate
1064 UAC_Admin:
1065   SetShellVarContext all
1066   StrCpy $baseRegKey "HKLM"
1067 UAC_Done:
1068   !insertmacro MUI_UNGETLANGUAGE
1069   !insertmacro INSTALLOPTIONS_EXTRACT "DeleteSettings.ini"
1070 FunctionEnd
1071
1072 Function un.ReturnBackupRegValue
1073   ;replace Default str with the backup value (if there is the one) and then delete backup
1074   ; $1 - key (for example ".java")
1075   ; $2 - name (for example "backup_val")
1076   Push $0
1077   ReadRegStr $0 HKCR $1 $2
1078   StrCmp $0 "" "noBackup"
1079     WriteRegStr HKCR $1 "" $0
1080     DeleteRegValue HKCR $1 $2
1081 noBackup:  
1082   Pop $0
1083 FunctionEnd
1084
1085 ;------------------------------------------------------------------------------
1086 ; custom uninstall pages
1087 ;------------------------------------------------------------------------------
1088
1089 Function un.ConfirmDeleteSettings
1090   !insertmacro MUI_HEADER_TEXT "$(uninstall_options)" "$(uninstall_options_prompt)"
1091   !insertmacro INSTALLOPTIONS_WRITE "DeleteSettings.ini" "Field 1" "Text" "$(prompt_delete_settings)"
1092   !insertmacro INSTALLOPTIONS_WRITE "DeleteSettings.ini" "Field 2" "Text" $INSTDIR
1093   !insertmacro INSTALLOPTIONS_WRITE "DeleteSettings.ini" "Field 3" "Text" "$(text_delete_settings)"
1094   !insertmacro INSTALLOPTIONS_WRITE "DeleteSettings.ini" "Field 4" "Text" "$(confirm_delete_caches)"
1095   !insertmacro INSTALLOPTIONS_WRITE "DeleteSettings.ini" "Field 5" "Text" "$(confirm_delete_settings)"
1096   !insertmacro INSTALLOPTIONS_DISPLAY "DeleteSettings.ini"
1097 FunctionEnd
1098
1099
1100 Function un.PrepareCustomPath
1101   ;Input:
1102   ;$0 - name of variable
1103   ;$1 - value of the variable
1104   ;$2 - line from the property file
1105   push $3
1106   push $5
1107   ${UnStrLoc} $3 $2 $0 ">"
1108   StrCmp $3 "" not_found
1109   StrLen $5 $0
1110   IntOp $3 $3 + $5
1111   StrCpy $2 $2 "" $3
1112   IfFileExists "$1$2\\*.*" not_found
1113   StrCpy $2 $1$2
1114   goto complete
1115 not_found:
1116   StrCpy $0 ""
1117 complete:
1118   pop $5
1119   pop $3
1120 FunctionEnd
1121
1122
1123 Function un.getCustomPath
1124   push $0
1125   push $1
1126   StrCpy $0 "${user.home}/"
1127   StrCpy $1 "$PROFILE/"
1128   Call un.PrepareCustomPath
1129   StrCmp $0 "" check_idea_var
1130   goto complete
1131 check_idea_var:
1132   StrCpy $0 "${idea.home}/"
1133   StrCpy $1 "$INSTDIR/"
1134   Call un.PrepareCustomPath
1135   StrCmp $2 "" +1 +2
1136   StrCpy $2 ""
1137 complete:
1138   pop $1
1139   pop $0
1140 FunctionEnd
1141
1142
1143 Function un.getPath
1144 ; The function read lines from idea.properties and search the substring and prepare the path to settings or caches.
1145   ClearErrors
1146   FileOpen $3 $INSTDIR\bin\idea.properties r
1147   IfErrors complete ;file can not be open. not sure if a message should be displayed in this case.
1148   StrLen $5 $1
1149 read_line:
1150   FileRead $3 $4
1151   StrCmp $4 "" complete
1152   ${UnStrLoc} $6 $4 $1 ">"
1153   StrCmp $6 "" read_line ; there is no substring in a string from the file. go for next one.
1154   IntOp $6 $6 + $5
1155   ${unStrStr} $7 $4 "#" ;check if the property has been customized
1156   StrCmp $7 "" custom
1157   StrCpy $2 "$PROFILE/${PRODUCT_SETTINGS_DIR}/$0" ;no. use the default value.
1158   goto complete
1159 custom:
1160   StrCpy $2 $4 "" $6
1161   Call un.getCustomPath
1162 complete:
1163   FileClose $3
1164   ${UnStrRep} $2 $2 "/" "\"
1165 FunctionEnd
1166
1167
1168 Section "Uninstall"
1169   StrCpy $productDir $INSTDIR
1170   StrCpy $baseRegKey "HKCU"
1171   ; Uninstaller is in the \bin directory, we need upper level dir
1172   StrCpy $INSTDIR $INSTDIR\..
1173
1174   !insertmacro INSTALLOPTIONS_READ $R2 "DeleteSettings.ini" "Field 4" "State"
1175   DetailPrint "Data: $DOCUMENTS\..\${PRODUCT_SETTINGS_DIR}\"
1176   StrCmp $R2 1 "" skip_delete_caches
1177    ;find the path to caches (system) folder
1178    StrCpy $0 "system"
1179    StrCpy $1 "idea.system.path="
1180    Call un.getPath
1181    StrCmp $2 "" skip_delete_caches
1182    StrCpy $system_path $2
1183    RmDir /r "$system_path"
1184    RmDir "$system_path\\.." ; remove parent of system dir if the dir is empty
1185 ;   RmDir /r $DOCUMENTS\..\${PRODUCT_SETTINGS_DIR}\system
1186 skip_delete_caches:
1187
1188   !insertmacro INSTALLOPTIONS_READ $R3 "DeleteSettings.ini" "Field 5" "State"
1189   StrCmp $R3 1 "" skip_delete_settings
1190     ;find the path to settings (config) folder
1191     StrCpy $0 "config"
1192     StrCpy $1 "idea.config.path="
1193     Call un.getPath
1194     StrCmp $2 "" skip_delete_settings
1195     StrCpy $config_path $2
1196     RmDir /r "$config_path"
1197 ;    RmDir /r $DOCUMENTS\..\${PRODUCT_SETTINGS_DIR}\config
1198   Delete "$INSTDIR\bin\${PRODUCT_VM_OPTIONS_NAME}"
1199   Delete "$INSTDIR\bin\idea.properties"
1200   StrCmp $R2 1 "" skip_delete_settings
1201   RmDir "$config_path\\.." ; remove parent of config dir if the dir is empty
1202 ;    RmDir $DOCUMENTS\..\${PRODUCT_SETTINGS_DIR}
1203 skip_delete_settings:
1204
1205 ; Delete uninstaller itself
1206   Delete "$INSTDIR\bin\Uninstall.exe"
1207   Delete "$INSTDIR\jre\jre\bin\client\classes.jsa"
1208
1209   Push "Complete"
1210   Push "$INSTDIR\bin\${PRODUCT_EXE_FILE}.vmoptions"
1211   Push "$INSTDIR\bin\idea.properties"
1212   ${UnStrRep} $0 ${PRODUCT_EXE_FILE} ".exe" "64.exe.vmoptions"
1213   Push "$INSTDIR\bin\$0"
1214   Call un.compareFileInstallationTime
1215   ${If} $9 != "Modified"
1216     RMDir /r "$INSTDIR"
1217   ${Else}
1218     !include "unidea_win.nsh"
1219     RMDir "$INSTDIR"
1220   ${EndIf}
1221
1222   ReadRegStr $R9 HKCU "Software\${MANUFACTURER}\${PRODUCT_REG_VER}" "MenuFolder"
1223   StrCmp $R9 "" "" clear_shortcuts
1224   ReadRegStr $R9 HKLM "Software\${MANUFACTURER}\${PRODUCT_REG_VER}" "MenuFolder"
1225   StrCmp $R9 "" clear_Registry
1226   StrCpy $5 "Software\${MANUFACTURER}"
1227 ;  call un.winVersion
1228 ; ${If} $0 == "1"
1229 ;    StrCpy $5 "Software\Wow6432Node\${MANUFACTURER}"
1230 ; ${EndIf}
1231 clear_shortcuts:
1232   ;the user has the admin rights
1233 ;  UserInfo::GetAccountType
1234 ;  Pop $R2
1235   IfFileExists "$DESKTOP\${PRODUCT_FULL_NAME_WITH_VER}.lnk" keep_current_user
1236   SetShellVarContext all
1237 keep_current_user:
1238   DetailPrint "Start Menu: $SMPROGRAMS\$R9\${PRODUCT_FULL_NAME_WITH_VER}"
1239  
1240   Delete "$SMPROGRAMS\$R9\${PRODUCT_FULL_NAME_WITH_VER}.lnk"
1241 ;  Delete "$SMPROGRAMS\$R9\Uninstall ${PRODUCT_FULL_NAME_WITH_VER}.lnk"
1242 ; Delete only if empty (last IDEA version is uninstalled)
1243   RMDir  "$SMPROGRAMS\$R9"
1244
1245   Delete "$DESKTOP\${PRODUCT_FULL_NAME_WITH_VER}.lnk"
1246   Delete "$QUICKLAUNCH\${PRODUCT_FULL_NAME_WITH_VER}.lnk"
1247
1248 clear_Registry:
1249   StrCpy $5 "Software\${MANUFACTURER}"
1250  call un.winVersion
1251  ${If} $0 == "1"
1252     StrCpy $5 "Software\Wow6432Node\${MANUFACTURER}"
1253  ${EndIf}
1254
1255   StrCpy $0 $baseRegKey
1256   StrCpy $1 "$5\${PRODUCT_REG_VER}"
1257   StrCpy $2 "MenuFolder"
1258   Call un.OMDeleteRegValue
1259
1260   StrCmp "${ASSOCIATION}" "NoAssociation" finish_uninstall
1261   push "${ASSOCIATION}"
1262 loop:
1263   call un.SplitStr
1264   Pop $0
1265   StrCmp $0 "" finish_uninstall
1266   StrCpy $1 $0
1267   StrCpy $2 "backup_val"
1268   Call un.ReturnBackupRegValue
1269   goto loop
1270 finish_uninstall:
1271   StrCpy $0 $baseRegKey
1272   StrCpy $1 "$5\${PRODUCT_REG_VER}"
1273   StrCpy $2 "Build"
1274   Call un.OMReadRegStr
1275
1276   StrCpy $1 "$5\${PRODUCT_REG_VER}"
1277   Call un.OMDeleteRegKey
1278
1279   StrCpy $1 "$5\${MUI_PRODUCT}"
1280   Call un.OMDeleteRegKeyIfEmpty
1281
1282   StrCpy $1 "$5"
1283   Call un.OMDeleteRegKeyIfEmpty
1284
1285   StrCpy $0 "HKCR"
1286   StrCpy $1 "Applications\${PRODUCT_EXE_FILE}"
1287   StrCpy $2 ""
1288   Call un.OMDeleteRegKey
1289   StrCpy $0 "HKCR"
1290   StrCpy $1 "${PRODUCT_PATHS_SELECTOR}"
1291   StrCpy $2 ""
1292   Call un.OMDeleteRegKey
1293
1294   StrCpy $0 "HKCR"
1295   StrCpy $1 "IntelliJIdeaProjectFile\DefaultIcon"
1296   StrCpy $2 ""
1297   call un.OMReadRegStr
1298   StrCmp $3 "$productDir\${PRODUCT_EXE_FILE},0" remove_IntelliJIdeaProjectFile done
1299 remove_IntelliJIdeaProjectFile:
1300   StrCpy $1 "IntelliJIdeaProjectFile"
1301   Call un.OMDeleteRegKey
1302 done:
1303   DeleteRegKey SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_WITH_VER}"
1304
1305 ; UNCOMMENT THIS IN RELEASE BUILD
1306 ; ExecShell "" "https://www.jetbrains.com/idea/uninstall/"
1307
1308 SectionEnd