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 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"
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 146 # the file has 146 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 inetc::get /TIMEOUT=5000 "https://www.lyx.org/trac/export/HEAD/lyxsvn/dictionaries/trunk/dicts/$String" "$INSTDIR\Resources\dicts\$String" /END
81 MessageBox MB_OK|MB_ICONEXCLAMATION "$(HunspellFailed)"
84 ${endif} # end if $DictCode == $R3
90 Delete "$INSTDIR\$String"
94 #--------------------------------
96 Function DownloadThesaurusDictionaries
97 # Downloads thesaurus dictionaries from a location that is given in the file
98 # $INSTDIR\Resources\ThesaurusDictionaryNames.txt
100 # read out the locations from the file
101 FileOpen $R5 "$INSTDIR\Resources\ThesaurusDictionaryNames.txt" r
102 ${For} $5 1 56 # the file has 56 lines
104 FileRead $R5 $String # $String is now the thesaurus name
105 StrCpy $R3 $String 5 3 # $R3 is now the thesaurus language code
107 ${if} $ThesCode == $R3
108 StrCpy $String $String -2 # delete the linebreak characters at the end
109 # Download thesaurus files
110 inetc::get /TIMEOUT=5000 "https://www.lyx.org/trac/export/HEAD/lyxsvn/dictionaries/trunk/thes/$String" "$INSTDIR\Resources\thes\$String" /END
114 MessageBox MB_OK|MB_ICONEXCLAMATION "$(ThesaurusFailed)"
117 ${endif} # end if $ThesCode == $R3
123 Delete "$INSTDIR\$String"
127 #--------------------------------
129 Function InstallHunspellDictionaries
130 # installs the selected hunspell dictionaries except of already existing ones
133 # take the first code
135 StrCpy $String $DictCodes
137 # we always have a "," for each code, so in case in case something
138 # went wrong, empty the code list to exit the loop
139 ${if} $Pointer == "-1"
142 ${if} $Pointer != "-1"
143 StrCpy $DictCode $DictCodes $Pointer
144 # remove the taken code from the list
145 IntOp $Pointer $Pointer + 1
146 StrCpy $DictCodes $DictCodes "" $Pointer
147 # don't dowload existing ones thus check if $DictCode is in $FoundDict
148 StrCpy $String $FoundDict
149 StrCpy $Search $DictCode
150 Call StrPoint # function from LyXUtils.nsh
151 ${if} $Pointer == "-1"
152 # download the dictionaries
153 Call DownloadHunspellDictionaries
156 ${LoopUntil} $DictCodes == ""
160 #--------------------------------
162 Function InstallThesaurusDictionaries
163 # installs the selected thesaurus dictionaries except of already existing ones
166 # take the first code
168 StrCpy $String $ThesCodes
170 # we always have a "," for each code, so in case in case something
171 # went wrong, empty the code list to exit the loop
172 ${if} $Pointer == "-1"
175 ${if} $Pointer != "-1"
176 StrCpy $ThesCode $ThesCodes $Pointer
177 # remove the taken code from the list
178 IntOp $Pointer $Pointer + 1
179 StrCpy $ThesCodes $ThesCodes "" $Pointer
180 # don't dowload existing ones thus check if $ThesCode is in $FoundThes
181 StrCpy $String $FoundThes
182 StrCpy $Search $ThesCode
183 Call StrPoint # function from LyXUtils.nsh
184 ${if} $Pointer == "-1"
185 # download the dictionaries
186 Call DownloadThesaurusDictionaries
189 ${LoopUntil} $ThesCodes == ""
191 # some dictionaries of language variants are identic
192 # therefore copy and rename an existing dictionary
193 CreateDirectory "$INSTDIR\Resources\backup"
194 ${if} ${FileExists} "$INSTDIR\Resources\thes\th_de_DE_v2.dat"
195 CopyFiles "$INSTDIR\Resources\thes\th_de_DE_v2.*" "$INSTDIR\Resources\backup"
196 Rename "$INSTDIR\Resources\backup\th_de_DE_v2.dat" "$INSTDIR\Resources\backup\th_de_AT_v2.dat"
197 Rename "$INSTDIR\Resources\backup\th_de_DE_v2.idx" "$INSTDIR\Resources\backup\th_de_AT_v2.idx"
198 CopyFiles "$INSTDIR\Resources\backup\th_de_AT_v2.*" "$INSTDIR\Resources\thes"
200 ${if} ${FileExists} "$INSTDIR\Resources\thes\th_en_US_v2.dat"
201 CopyFiles "$INSTDIR\Resources\thes\th_en_US_v2.*" "$INSTDIR\Resources\backup"
202 Rename "$INSTDIR\Resources\backup\th_en_US_v2.dat" "$INSTDIR\Resources\backup\th_en_AU_v2.dat"
203 Rename "$INSTDIR\Resources\backup\th_en_US_v2.idx" "$INSTDIR\Resources\backup\th_en_AU_v2.idx"
204 CopyFiles "$INSTDIR\Resources\backup\th_en_AU_v2.*" "$INSTDIR\Resources\thes"
206 RMDir "$INSTDIR\Resources\backup"