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 144 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 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"
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 144 # the file has 144 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
78 inetc::get /RECEIVETIMEOUT=5000 "https://sourceforge.net/projects/lyxwininstaller/files/hunspell/$String" "$INSTDIR\Resources\dicts\$String" /END
82 MessageBox MB_OK|MB_ICONEXCLAMATION "$(HunspellFailed): $R0"
85 ${endif} # end if $DictCode == $R3
91 Delete "$INSTDIR\$String"
95 #--------------------------------
97 Function DownloadThesaurusDictionaries
98 # Downloads thesaurus dictionaries from a location that is given in the file
99 # $INSTDIR\Resources\ThesaurusDictionaryNames.txt
101 # read out the locations from the file
102 FileOpen $R5 "$INSTDIR\Resources\ThesaurusDictionaryNames.txt" r
103 ${For} $5 1 56 # the file has 56 lines
105 FileRead $R5 $String # $String is now the thesaurus name
106 StrCpy $R3 $String 5 3 # $R3 is now the thesaurus language code
108 ${if} $ThesCode == $R3
109 StrCpy $String $String -2 # delete the linebreak characters at the end
110 # Download thesaurus files
112 inetc::get /POPUP /RECEIVETIMEOUT=5000 "https://sourceforge.net/projects/lyxwininstaller/files/thesaurus/$String" "$INSTDIR\Resources\thes\$String" /END
116 MessageBox MB_OK|MB_ICONEXCLAMATION "$(ThesaurusFailed): $R0"
119 ${endif} # end if $ThesCode == $R3
125 Delete "$INSTDIR\$String"
129 #--------------------------------
131 Function InstallHunspellDictionaries
132 # installs the selected hunspell dictionaries except of already existing ones
135 # take the first code
137 StrCpy $String $DictCodes
139 # we always have a "," for each code, so in case in case something
140 # went wrong, empty the code list to exit the loop
141 ${if} $Pointer == "-1"
144 ${if} $Pointer != "-1"
145 StrCpy $DictCode $DictCodes $Pointer
146 # remove the taken code from the list
147 IntOp $Pointer $Pointer + 1
148 StrCpy $DictCodes $DictCodes "" $Pointer
149 # don't dowload existing ones thus check if $DictCode is in $FoundDict
150 StrCpy $String $FoundDict
151 StrCpy $Search $DictCode
152 Call StrPoint # function from LyXUtils.nsh
153 ${if} $Pointer == "-1"
154 # download the dictionaries
155 Call DownloadHunspellDictionaries
158 ${LoopUntil} $DictCodes == ""
162 #--------------------------------
164 Function InstallThesaurusDictionaries
165 # installs the selected thesaurus dictionaries except of already existing ones
168 # take the first code
170 StrCpy $String $ThesCodes
172 # we always have a "," for each code, so in case in case something
173 # went wrong, empty the code list to exit the loop
174 ${if} $Pointer == "-1"
177 ${if} $Pointer != "-1"
178 StrCpy $ThesCode $ThesCodes $Pointer
179 # remove the taken code from the list
180 IntOp $Pointer $Pointer + 1
181 StrCpy $ThesCodes $ThesCodes "" $Pointer
182 # don't dowload existing ones thus check if $ThesCode is in $FoundThes
183 StrCpy $String $FoundThes
184 StrCpy $Search $ThesCode
185 Call StrPoint # function from LyXUtils.nsh
186 ${if} $Pointer == "-1"
187 # download the dictionaries
188 Call DownloadThesaurusDictionaries
191 ${LoopUntil} $ThesCodes == ""
193 # some dictionaries of language variants are identic
194 # therefore copy and rename an existing dictionary
195 CreateDirectory "$INSTDIR\Resources\backup"
196 ${if} ${FileExists} "$INSTDIR\Resources\thes\th_de_DE_v2.dat"
197 CopyFiles "$INSTDIR\Resources\thes\th_de_DE_v2.*" "$INSTDIR\Resources\backup"
198 Rename "$INSTDIR\Resources\backup\th_de_DE_v2.dat" "$INSTDIR\Resources\backup\th_de_AT_v2.dat"
199 Rename "$INSTDIR\Resources\backup\th_de_DE_v2.idx" "$INSTDIR\Resources\backup\th_de_AT_v2.idx"
200 CopyFiles "$INSTDIR\Resources\backup\th_de_AT_v2.*" "$INSTDIR\Resources\thes"
202 ${if} ${FileExists} "$INSTDIR\Resources\thes\th_en_US_v2.dat"
203 CopyFiles "$INSTDIR\Resources\thes\th_en_US_v2.*" "$INSTDIR\Resources\backup"
204 Rename "$INSTDIR\Resources\backup\th_en_US_v2.dat" "$INSTDIR\Resources\backup\th_en_AU_v2.dat"
205 Rename "$INSTDIR\Resources\backup\th_en_US_v2.idx" "$INSTDIR\Resources\backup\th_en_AU_v2.idx"
206 CopyFiles "$INSTDIR\Resources\backup\th_en_AU_v2.*" "$INSTDIR\Resources\thes"
208 RMDir "$INSTDIR\Resources\backup"