Skip to content

Commit 0124ea6

Browse files
committed
Installer
1 parent 8c3a69d commit 0124ea6

File tree

3 files changed

+121
-0
lines changed

3 files changed

+121
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/.vs
22
/packages
3+
/Releases
34
.user
45
bin/
56
obj/

Installer/KeyLayoutAutoSwitch.nsi

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
Unicode true
2+
SetCompressor lzma
3+
4+
!include "MUI2.nsh"
5+
!include "DotNetChecker.nsh"
6+
!include "nsProcess.nsh"
7+
8+
!define INSTALL_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\KeyLayoutAutoSwitch.exe"
9+
!define HOMEPAGE "https://github.com/AlexVallat/KeyLayoutAutoSwitch"
10+
!define EXE_FILENAME "KeyLayoutAutoSwitch.exe"
11+
!define SOURCE_PATH "..\KeyLayoutAutoSwitch\bin\Release"
12+
!define UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\KeyLayoutAutoSwitch"
13+
14+
Name "KeyLayoutAutoSwitch"
15+
OutFile "../Releases/KeyLayoutAutoSwitch-Install.exe"
16+
InstallDir "$PROGRAMFILES64\KeyLayoutAutoSwitch"
17+
InstallDirRegKey HKLM "${INSTALL_DIR_REGKEY}" ""
18+
19+
!insertmacro MUI_PAGE_DIRECTORY
20+
!define MUI_COMPONENTSPAGE_NODESC
21+
!insertmacro MUI_PAGE_COMPONENTS
22+
!insertmacro MUI_PAGE_INSTFILES
23+
!define MUI_FINISHPAGE_RUN "$INSTDIR\${EXE_FILENAME}"
24+
!define MUI_FINISHPAGE_RUN_TEXT "Configure KeyLayoutAutoSwitch now"
25+
!define MUI_FINISHPAGE_LINK "http://keylayoutautoswitch.byalexv.co.uk"
26+
!define MUI_FINISHPAGE_LINK_LOCATION "http://keylayoutautoswitch.byalexv.co.uk"
27+
!insertmacro MUI_PAGE_FINISH
28+
29+
Section "KeyLayoutAutoSwitch Program Files" SecCore
30+
SectionIn RO
31+
SetOutPath "$INSTDIR"
32+
!insertmacro CheckNetFramework 461
33+
34+
File "${SOURCE_PATH}\${EXE_FILENAME}"
35+
File "${SOURCE_PATH}\CommandLine.dll"
36+
File "${SOURCE_PATH}\ObjectListView.dll"
37+
SectionEnd
38+
39+
Section "Add icon to Start Menu"
40+
CreateShortCut "$SMPROGRAMS\KeyLayoutAutoSwitch.lnk" "$INSTDIR\${EXE_FILENAME}"
41+
SectionEnd
42+
Section "Start with Windows"
43+
CreateShortCut "$SMSTARTUP\KeyLayoutAutoSwitch.lnk" "$INSTDIR\${EXE_FILENAME}" "--minimized"
44+
SectionEnd
45+
46+
!macro Language Culture
47+
Section "-Lang-${Culture}"
48+
SetOutPath "$INSTDIR\${Culture}"
49+
File "${SOURCE_PATH}\${Culture}\KeyLayoutAutoSwitch.resources.dll"
50+
SetOutPath "$INSTDIR"
51+
SectionEnd
52+
Section "-un.Lang-${Culture}"
53+
Delete "$INSTDIR\${Culture}\KeyLayoutAutoSwitch.resources.dll"
54+
RMDir "$INSTDIR\${Culture}"
55+
SectionEnd
56+
!macroend
57+
58+
#!insertmacro Language "qps-ploc"
59+
60+
Section -Post
61+
WriteUninstaller "$INSTDIR\uninstall.exe"
62+
WriteRegStr HKLM "${INSTALL_DIR_REGKEY}" "" "$INSTDIR\${EXE_FILENAME}"
63+
64+
WriteRegStr HKLM "${UNINST_KEY}" "DisplayName" "$(^Name)"
65+
WriteRegStr HKLM "${UNINST_KEY}" "UninstallString" "$INSTDIR\uninstall.exe"
66+
WriteRegStr HKLM "${UNINST_KEY}" "DisplayIcon" "$INSTDIR\${EXE_FILENAME}"
67+
WriteRegStr HKLM "${UNINST_KEY}" "Publisher" "Alex Vallat"
68+
WriteRegStr HKLM "${UNINST_KEY}" "HelpLink" "${HOMEPAGE}"
69+
WriteRegDword HKLM "${UNINST_KEY}" "NoModify" "1"
70+
WriteRegDword HKLM "${UNINST_KEY}" "NoRepair" "1"
71+
72+
SectionGetSize ${SecCore} $0
73+
IntFmt $0 "0x%08X" $0
74+
WriteRegDWORD HKLM "${UNINST_KEY}" "EstimatedSize" "$0"
75+
SectionEnd
76+
77+
# Uninstall
78+
79+
!insertmacro MUI_UNPAGE_COMPONENTS
80+
!insertmacro MUI_UNPAGE_INSTFILES
81+
82+
Section "un.KeyLayoutAutoSwitch Program Files"
83+
SectionIn RO
84+
85+
${nsProcess::FindProcess} "${EXE_FILENAME}" $R0
86+
StrCmp $R0 0 0 endclose
87+
DetailPrint "Closing KeyLayoutAutoSwitch..."
88+
${nsProcess::CloseProcess} "${EXE_FILENAME}" $R0
89+
# Try a few times to wait for it to close
90+
${nsProcess::FindProcess} "${EXE_FILENAME}" $R0
91+
StrCmp $R0 0 0 endclose
92+
${nsProcess::FindProcess} "${EXE_FILENAME}" $R0
93+
StrCmp $R0 0 0 endclose
94+
${nsProcess::FindProcess} "${EXE_FILENAME}" $R0
95+
StrCmp $R0 0 0 endclose
96+
DetailPrint "Unable to close KeyLayoutAutoSwitch"
97+
endclose:
98+
${nsProcess::Unload}
99+
100+
Delete "$SMPROGRAMS\KeyLayoutAutoSwitch.lnk"
101+
Delete "$SMSTARTUP\KeyLayoutAutoSwitch.lnk"
102+
103+
Delete "$INSTDIR\${EXE_FILENAME}"
104+
Delete "$INSTDIR\CommandLine.dll"
105+
Delete "$INSTDIR\ObjectListView.dll"
106+
107+
Delete "$INSTDIR\uninstall.exe"
108+
RMDir "$INSTDIR"
109+
110+
DeleteRegKey HKLM "${UNINST_KEY}"
111+
SectionEnd
112+
113+
Section /o "un.Remove all settings"
114+
RMDir /r "$APPDATA\KeyLayoutAutoSwitch"
115+
116+
DeleteRegKey HKLM "${INSTALL_DIR_REGKEY}"
117+
SectionEnd
118+
119+
!insertmacro MUI_LANGUAGE "English"

KeyLayoutAutoSwitch.sln

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KeyLayoutAutoSwitch", "KeyL
77
EndProject
88
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{28B63DFE-1829-4DD9-9941-86222A09576B}"
99
ProjectSection(SolutionItems) = preProject
10+
Installer\KeyLayoutAutoSwitch.nsi = Installer\KeyLayoutAutoSwitch.nsi
1011
README.md = README.md
1112
EndProjectSection
1213
EndProject

0 commit comments

Comments
 (0)