-
Notifications
You must be signed in to change notification settings - Fork 0
/
windows-installer.sh
executable file
·302 lines (240 loc) · 7.48 KB
/
windows-installer.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
here=`pwd`
echo $here
# done: fix the file associations not getting added
# done: fix the program not appearing in the search menu
# todo: fix the program's icon not being shown in the search menu
command="iscc"
iscc_exists=0
if where "$command" > /dev/null 2>&1; then
iscc_exists=1
else
echo "Warning: Could not find iscc, please install Inno Setup Compiler"
echo " or if you have it installed already, add it to PATH"
fi
buildPath="$here/build"
iconPath="$here/assets/icon.png"
pythonEntryPath="$here/main.py"
installerPath="$here/installer"
installerOutPath="$installerPath/inno.iss"
shouldBuildExe=0
shouldBuildInstaller=0
extensions=("jpg" "gif" "webp" "png" "mp4" "mkv" "avi" )
source_dirs=("assets" "ffmpeg")
appName="Foto Folio"
appVersion="1.0"
appPublisher="Arthur378"
appUrl="https://github.com/Arthur378"
appExeName="Foto Folio.exe"
appAssocName="$appName File"
# this should probably be more dynamic
exeSource="../build/Foto Folio.exe"
add_source_dir() {
number=$1
dir_name=$2
outputfile=$3
echo "adding" $dir_name "source directory in app's installation folder"
mkdir_section=$(cat <<EOF
Name: "{app}\\$dir_name"
EOF
)
echo "$mkdir_section" >> $outputfile
}
add_source_def() {
number=$1
dir_name=$2
outputfile=$3
echo "adding source definition for" $dir_name
dirdef_section=$(cat <<EOF
Source: "../$dir_name/*"; DestDir: "{app}\\$dir_name"; Flags: ignoreversion recursesubdirs createallsubdirs
EOF
)
echo "$dirdef_section" >> $outputfile
}
write_assoc_def() {
number=$1
extension=$2
outputfile=$3
echo "writing definition section for" $extension
assoc_def=$(cat <<EOF
;
#define MyAppAssocExt$number "$extension"
#define MyAppAssocKey$number StringChange(MyAppAssocName, " ", "") + MyAppAssocExt$number
EOF
)
echo "$assoc_def" >> $outputfile
}
write_assoc_reg() {
number=$1
extension=$2
outputfile=$3
echo "writing registry section for" $extension
assoc_reg=$(cat <<EOF
;
Root: HKA; Subkey: "Software\Classes\{#MyAppAssocExt$number}\OpenWithProgids"; ValueType: string; ValueName: "{#MyAppAssocKey$number}"; ValueData: ""; Flags: uninsdeletevalue
Root: HKA; Subkey: "Software\Classes\{#MyAppAssocKey$number}"; ValueType: string; ValueName: ""; ValueData: "{#MyAppAssocName}"; Flags: uninsdeletekey
Root: HKA; Subkey: "Software\Classes\{#MyAppAssocKey$number}\DefaultIcon"; ValueType: string; ValueName: ""; ValueData: "{app}\{#MyAppExeName},0"
Root: HKA; Subkey: "Software\Classes\{#MyAppAssocKey$number}\shell\open\command"; ValueType: string; ValueName: ""; ValueData: """{app}\{#MyAppExeName}"" ""%1"""
Root: HKA; Subkey: "Software\Classes\Applications\{#MyAppExeName}\SupportedTypes"; ValueType: string; ValueName: "{#MyAppAssocExt$number}"; ValueData: ""
EOF
)
echo "$assoc_reg" >> $outputfile
}
write_installer_script()
{
echo Starting to write the inno setup script
echo writing the definition section for inno setup
def_section_text=$(cat <<EOF
#define MyAppName "$appName"
#define MyAppVersion "$appVersion"
#define MyAppPublisher "$appPublisher"
#define MyAppURL "$appUrl"
#define MyAppExeName "$appExeName"
#define MyAppAssocName "$appAssocName"
#define ExeSource "$exeSource"
EOF
)
if [ -e $installerOutPath ]; then
rm $installerOutPath
else
echo
fi
echo "$def_section_text" >> $installerOutPath
echo writing the definition section for program\'s associated extensions
i=0
for item in "${extensions[@]}"; do
write_assoc_def $i ".$item" $installerOutPath
((i++))
done
body_section_text=$(cat <<EOF
;
[Setup]
AppId={{931B78F1-4C54-4E34-883F-1470C64243CB}}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={autopf}\{#MyAppName}
ChangesAssociations=yes
DisableProgramGroupPage=yes
OutputBaseFilename=Foto Folio Setup
Compression=lzma
SolidCompression=yes
WizardStyle=modern
[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"
[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
[Dirs]
EOF
)
echo "$body_section_text" >> $installerOutPath
i=0
for item in "${source_dirs[@]}"; do
add_source_dir $i $item $installerOutPath
((i++))
done
file_section_text=$(cat <<EOF
;
[Files]
Source: "{#ExeSource}" ; DestDir: "{app}"; Flags: ignoreversion
EOF
)
echo "$file_section_text" >> $installerOutPath
i=0
for item in "${source_dirs[@]}"; do
add_source_def $i $item $installerOutPath
((i++))
done
echo "[Registry]" >> $installerOutPath
echo writing the registeration section for program\'s associated extensions
i=0
for item in "${extensions[@]}"; do
write_assoc_reg $i ".$item" $installerOutPath
((i++))
done
final_section_text=$(cat <<EOF
[Icons]
Name: "{autoprograms}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
Name: "{autodesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon
[Run]
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent
EOF
)
echo writing the final section of the inno setup script!
echo "$final_section_text" >> $installerOutPath
}
if [ -e $buildPath ]; then
echo The build folder already exists, re-build the executables?? y/n:
read input
if [ "$input" == "y" ]; then
shouldBuildExe=1
elif [ "$input" == "n" ]; then
echo Ok
else
echo Bad output! 1>&2
exit 1
fi
else
echo The build folder does not exist.
shouldBuildExe=1
fi
if [ -e $installerPath ]; then
echo The installer folder already exists, re-build the Windows Installer?? y/n:
read input
if [ "$input" == "y" ]; then
shouldBuildInstaller=1
elif [ "$input" == "n" ]; then
echo Ok
else
echo Bad output! 1>&2
exit 1
fi
else
echo The installer folder does not exist.
shouldBuildInstaller=1
fi
if [ $shouldBuildExe -eq 1 ]; then
echo "Building the executables ..."
if [ -e $buildPath ]; then
rm -rf $buildPath
echo Deleting $buildPath
else
echo $buildPath does not exist.
fi
mkdir $buildPath
cd $buildPath
echo "I'm in $(pwd)"
pyinstaller $pythonEntryPath --windowed --onefile --icon=$iconPath
rm -rf "$buildPath\build"
rm "$buildPath\main.spec"
# todo: automatically sync the executable name with the script name ( or sth like that )
mv "$buildPath\dist\main.exe" "$buildPath\\$appExeName"
rm -r "$buildPath\dist"
else
echo "The executables are already built."
fi
if [ $shouldBuildInstaller -eq 1 ]; then
echo "Building the Windows Installer ..."
rm -rf $installerPath
mkdir $installerPath
write_installer_script
else
echo "The Windows Installer is already built."
fi
if [ $iscc_exists -eq 0 ]; then
echo Could not find iscc \(Inno Setup Compiler\), I can\'t compile the installer
else
echo Compile the Inno Setup Script file?? y/n:
read input
if [ "$input" == "y" ]; then
iscc $installerOutPath
elif [ "$input" == "n" ]; then
echo Ok
else
echo Bad output! 1>&2
exit 1
fi
fi
echo -e "\nGoodbye!"