4 Handling of hunspell / MyThes dictionaries
7 # This script contains the following functions:
9 # - FindDictionaries (finds already installed dictionaries)
11 # - DownloadHunspellDictionaries and DownloadThesaurusDictionaries
12 # (Downloads hunspell / MyThes dictionaries from a location that is
13 # given in the file $INSTDIR\Resources\HunspellDictionaryNames.txt)
15 # - InstallHunspellDictionaries and InstallThesaurusDictionaries
16 # (installs the selected hunspell / MyThes dictionaries except of
17 # already existing ones), uses:
18 # DownloadHunspellDictionaries or DownloadThesaurusDictionaries
20 # ---------------------------------------
22 Function FindDictionaries
23 # finds already installed dictionaries
25 # start with empty strings
29 # read out the possible spell-checker filenames from the file
30 FileOpen $R5 "$INSTDIR\Resources\HunspellDictionaryNames.txt" r
32 # the file has 138 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"
44 # read out the possible thesaurus filenames from the file
45 FileOpen $R5 "$INSTDIR\Resources\ThesaurusDictionaryNames.txt" r
47 # the file has 48 lines, but we only need to check for one of the 2 dictionary 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"
61 # ---------------------------------------
63 Function DownloadHunspellDictionaries
64 # Downloads hunspell dictionaries from a location that is given in the file
65 # $INSTDIR\Resources\HunspellDictionaryNames.txt
67 # read out the locations from the file
68 FileOpen $R5 "$INSTDIR\Resources\HunspellDictionaryNames.txt" r
69 ${For} $5 1 138 # the file has 138 lines
71 FileRead $R5 $String # $String is now the dictionary name
72 StrCpy $R3 $String -6 # $R3 is now the dictionary language code
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
80 ${For} $4 1 8 # we know about 8 mirrors
81 FileRead $R4 $Search # $Search is now the mirror
82 StrCpy $Search $Search -2 # delete the linebreak characters at the end
84 InetLoad::load /TIMEOUT=5000 "http://$Search.dl.sourceforge.net/project/lyxwininstaller/hunspell/$String" "$INSTDIR\Resources\dicts\$String" /END
94 MessageBox MB_OK|MB_ICONEXCLAMATION "$(HunspellFailed)"
97 ${endif} # end if $DictCode == $R3
103 Delete "$INSTDIR\$String"
107 #--------------------------------
109 Function DownloadThesaurusDictionaries
110 # Downloads thesaurus dictionaries from a location that is given in the file
111 # $INSTDIR\Resources\ThesaurusDictionaryNames.txt
113 # read out the locations from the file
114 FileOpen $R5 "$INSTDIR\Resources\ThesaurusDictionaryNames.txt" r
115 ${For} $5 1 48 # the file has 48 lines
117 FileRead $R5 $String # $String is now the dictionary name
118 StrCpy $R3 $String 5 3 # $R3 is now the dictionary language code
120 ${if} $ThesCode == $R3
121 StrCpy $String $String -2 # delete the linebreak characters at the end
122 # Download thesaurus dictionaries,
123 # if first download repository is not available try the other ones listed in "DictionaryMirrors.txt"
124 FileOpen $R4 "$INSTDIR\Resources\DictionaryMirrors.txt" r
127 FileRead $R4 $Search # $Search is now the mirror
128 StrCpy $Search $Search -2 # delete the linebreak characters at the end
130 InetLoad::load /TIMEOUT=5000 "http://$Search.dl.sourceforge.net/project/lyxwininstaller/thesaurus/$String" "$INSTDIR\Resources\thes\$String" /END
140 MessageBox MB_OK|MB_ICONEXCLAMATION "$(ThesaurusFailed)"
143 ${endif} # end if $ThesCode == $R3
149 Delete "$INSTDIR\$String"
153 #--------------------------------
155 Function InstallHunspellDictionaries
156 # installs the selected hunspell dictionaries except of already existing ones
159 # take the first code
161 StrCpy $String $DictCodes
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"
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
182 ${LoopUntil} $DictCodes == ""
186 #--------------------------------
188 Function InstallThesaurusDictionaries
189 # installs the selected thesaurus dictionaries except of already existing ones
192 # take the first code
194 StrCpy $String $ThesCodes
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"
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
215 ${LoopUntil} $ThesCodes == ""
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"
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"
232 RMDir "$INSTDIR\Resources\backup"