]> git.lyx.org Git - features.git/blob - development/Win32/packaging/installer/include/dictionaries.nsh
Win installer: updates and fixes
[features.git] / development / Win32 / packaging / installer / include / dictionaries.nsh
1 /*
2 dictionaries.nsh
3
4 Handling of hunspell / MyThes dictionaries
5 */
6
7 # This script contains the following functions:
8 #
9 # - FindDictionaries (finds already installed dictionaries)
10 #
11 # - DownloadHunspellDictionaries and DownloadThesaurusDictionaries
12 #    (Downloads hunspell / MyThes dictionaries from a location that is
13 #     given in the file $INSTDIR\Resources\HunspellDictionaryNames.txt)
14 #
15 # - InstallHunspellDictionaries and InstallThesaurusDictionaries
16 #    (installs the selected hunspell / MyThes dictionaries except of
17 #     already existing ones), uses:
18 #    DownloadHunspellDictionaries or DownloadThesaurusDictionaries
19
20 # ---------------------------------------
21
22 Function FindDictionaries
23   # finds already installed dictionaries
24
25   # start with empty strings
26   StrCpy $FoundDict ""
27   StrCpy $FoundThes ""
28   
29   # read out the possible spell-checker filenames from the file 
30   FileOpen $R5 "$INSTDIR\Resources\HunspellDictionaryNames.txt" r
31   ${for} $5 1 73
32    # the file has 146 lines, but we only need to check for one of the 2 dictionary files per language
33    # therefore check only for every second line
34    FileRead $R5 $String # skip the .aff file
35    FileRead $R5 $String # $String is now the .dic filename
36    StrCpy $String $String -2 # remove the linebreak characters
37    StrCpy $R3 $String -4 # $R3 is now the dictionary language code
38    ${if} ${FileExists} "$INSTDIR\Resources\dicts\$String"
39     StrCpy $FoundDict "$R3 $FoundDict"
40    ${endif}
41   ${next}
42   FileClose $R5
43   
44   # read out the possible thesaurus filenames from the file     
45   FileOpen $R5 "$INSTDIR\Resources\ThesaurusDictionaryNames.txt" r
46   ${for} $5 1 28
47    # the file has 56 lines, but we only need to check for one of the 2 thesaurus files per language
48    # therefore check only for every second line
49    FileRead $R5 $String # $String is now the dictionary name
50    FileRead $R5 $String # $String is now the dictionary name
51    StrCpy $String $String -2 # remove the linebreak characters
52    StrCpy $R3 $String 5 3 # $R3 is now the dictionary language code
53    ${if} ${FileExists} "$INSTDIR\Resources\thes\$String"
54     StrCpy $FoundThes "$R3 $FoundThes"
55    ${endif}
56   ${next}
57   FileClose $R5
58
59 FunctionEnd
60
61 # ---------------------------------------
62
63 Function DownloadHunspellDictionaries
64  # Downloads hunspell dictionaries from a location that is given in the file
65  # $INSTDIR\Resources\HunspellDictionaryNames.txt
66  
67  # read out the locations from the file 
68  FileOpen $R5 "$INSTDIR\Resources\HunspellDictionaryNames.txt" r
69  ${For} $5 1 146 # the file has 146 lines
70  
71   FileRead $R5 $String # $String is now the dictionary name
72   StrCpy $R3 $String -6 # $R3 is now the dictionary language code
73   
74   ${if} $DictCode == $R3
75    StrCpy $String $String -2 # delete the linebreak characters at the end
76    # Download hunspell dictionaries,
77    # if first download repository is not available try the other ones listed in "DictionaryMirrors.txt"
78    FileOpen $R4 "$INSTDIR\Resources\DictionaryMirrors.txt" r
79    
80    ${For} $4 1 24 # there are 24 mirrors in the file
81     FileRead $R4 $Search # $Search is now the mirror
82     StrCpy $Search $Search -2 # delete the linebreak characters at the end
83     Push $R0
84     inetc::get /TIMEOUT=5000 "https://$Search.dl.sourceforge.net/project/lyxwininstaller/hunspell/$String" "$INSTDIR\Resources\dicts\$String" /END
85     Pop $R0
86     ${if} $R0 == "OK"
87      ${ExitFor}
88     ${endif}
89    ${Next}
90    
91    FileClose $R4
92    # if download failed
93    ${if} $R0 != "OK"
94     MessageBox MB_OK|MB_ICONEXCLAMATION "$(HunspellFailed)"
95     Goto abortinstall
96    ${endif}
97   ${endif} # end if $DictCode == $R3
98   
99  ${Next}
100  FileClose $R5
101
102  abortinstall:
103  Delete "$INSTDIR\$String"
104
105 FunctionEnd
106
107 #--------------------------------
108
109 Function DownloadThesaurusDictionaries
110  # Downloads thesaurus dictionaries from a location that is given in the file
111  # $INSTDIR\Resources\ThesaurusDictionaryNames.txt
112  
113  # read out the locations from the file 
114  FileOpen $R5 "$INSTDIR\Resources\ThesaurusDictionaryNames.txt" r
115  ${For} $5 1 56 # the file has 56 lines
116  
117   FileRead $R5 $String # $String is now the thesaurus name
118   StrCpy $R3 $String 5 3 # $R3 is now the thesaurus language code
119   
120   ${if} $ThesCode == $R3
121    StrCpy $String $String -2 # delete the linebreak characters at the end
122    # Download thesaurus files,
123    # if first download repository is not available try the other ones listed in "DictionaryMirrors.txt"
124    FileOpen $R4 "$INSTDIR\Resources\DictionaryMirrors.txt" r
125    
126    ${For} $4 1 24 # there are 24 mirrors in the file
127     FileRead $R4 $Search # $Search is now the mirror
128     StrCpy $Search $Search -2 # delete the linebreak characters at the end
129     Push $R0
130     inetc::get /TIMEOUT=5000 "https://$Search.dl.sourceforge.net/project/lyxwininstaller/thesaurus/$String" "$INSTDIR\Resources\thes\$String" /END
131     Pop $R0
132     ${if} $R0 == "OK"
133      ${ExitFor}
134     ${endif}
135    ${Next}
136    
137    FileClose $R4
138    # if download failed
139    ${if} $R0 != "OK"
140     MessageBox MB_OK|MB_ICONEXCLAMATION "$(ThesaurusFailed)"
141     Goto abortinstall
142    ${endif}
143   ${endif} # end if $ThesCode == $R3
144   
145  ${Next}
146  FileClose $R5
147
148  abortinstall:
149  Delete "$INSTDIR\$String"
150
151 FunctionEnd
152
153 #--------------------------------
154
155 Function InstallHunspellDictionaries
156  # installs the selected hunspell dictionaries except of already existing ones
157
158  ${Do}
159   # take the first code
160   StrCpy $Search ","
161   StrCpy $String $DictCodes
162   Call StrPoint
163   # we always have a "," for each code, so in case in case something
164   # went wrong, empty the code list to exit the loop
165   ${if} $Pointer == "-1"
166    StrCpy $DictCodes ""
167   ${endif}
168   ${if} $Pointer != "-1"
169    StrCpy $DictCode $DictCodes $Pointer
170    # remove the taken code from the list
171    IntOp $Pointer $Pointer + 1
172    StrCpy $DictCodes $DictCodes "" $Pointer
173    # don't dowload existing ones thus check if $DictCode is in $FoundDict
174    StrCpy $String $FoundDict
175    StrCpy $Search $DictCode
176    Call StrPoint # function from LyXUtils.nsh
177    ${if} $Pointer == "-1"
178     # download the dictionaries
179     Call DownloadHunspellDictionaries
180    ${endif}
181   ${endif}
182  ${LoopUntil} $DictCodes == ""
183  
184 FunctionEnd
185
186 #--------------------------------
187
188 Function InstallThesaurusDictionaries
189  # installs the selected thesaurus dictionaries except of already existing ones
190
191  ${Do}
192   # take the first code
193   StrCpy $Search ","
194   StrCpy $String $ThesCodes
195   Call StrPoint
196   # we always have a "," for each code, so in case in case something
197   # went wrong, empty the code list to exit the loop
198   ${if} $Pointer == "-1"
199    StrCpy $ThesCodes ""
200   ${endif}
201   ${if} $Pointer != "-1"
202    StrCpy $ThesCode $ThesCodes $Pointer
203    # remove the taken code from the list
204    IntOp $Pointer $Pointer + 1
205    StrCpy $ThesCodes $ThesCodes "" $Pointer
206    # don't dowload existing ones thus check if $ThesCode is in $FoundThes
207    StrCpy $String $FoundThes
208    StrCpy $Search $ThesCode
209    Call StrPoint # function from LyXUtils.nsh
210    ${if} $Pointer == "-1"
211     # download the dictionaries
212     Call DownloadThesaurusDictionaries
213    ${endif}
214   ${endif}
215  ${LoopUntil} $ThesCodes == ""
216  
217  # some dictionaries of language variants are identic
218  # therefore copy and rename an existing dictionary
219  CreateDirectory "$INSTDIR\Resources\backup"
220  ${if} ${FileExists} "$INSTDIR\Resources\thes\th_de_DE_v2.dat"
221   CopyFiles "$INSTDIR\Resources\thes\th_de_DE_v2.*" "$INSTDIR\Resources\backup"
222   Rename "$INSTDIR\Resources\backup\th_de_DE_v2.dat" "$INSTDIR\Resources\backup\th_de_AT_v2.dat"
223   Rename "$INSTDIR\Resources\backup\th_de_DE_v2.idx" "$INSTDIR\Resources\backup\th_de_AT_v2.idx"
224   CopyFiles "$INSTDIR\Resources\backup\th_de_AT_v2.*" "$INSTDIR\Resources\thes"
225  ${endif}
226  ${if} ${FileExists} "$INSTDIR\Resources\thes\th_en_US_v2.dat"
227   CopyFiles "$INSTDIR\Resources\thes\th_en_US_v2.*" "$INSTDIR\Resources\backup"
228   Rename "$INSTDIR\Resources\backup\th_en_US_v2.dat" "$INSTDIR\Resources\backup\th_en_AU_v2.dat"
229   Rename "$INSTDIR\Resources\backup\th_en_US_v2.idx" "$INSTDIR\Resources\backup\th_en_AU_v2.idx"
230   CopyFiles "$INSTDIR\Resources\backup\th_en_AU_v2.*" "$INSTDIR\Resources\thes"
231  ${endif}
232  RMDir "$INSTDIR\Resources\backup"
233  
234 FunctionEnd
235