]> git.lyx.org Git - features.git/blob - development/Win32/packaging/installer/include/dictionaries.nsh
d540f5349a64a2729333d72a503e505738609727
[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 72
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"
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 144 # the file has 144 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    Push $R0
78    inetc::get /RECEIVETIMEOUT=5000 "https://sourceforge.net/projects/lyxwininstaller/files/hunspell/$String" "$INSTDIR\Resources\dicts\$String" /END
79    Pop $R0
80    # if download failed
81    ${if} $R0 != "OK"
82     MessageBox MB_OK|MB_ICONEXCLAMATION "$(HunspellFailed): $R0"
83     Goto abortinstall
84    ${endif}
85   ${endif} # end if $DictCode == $R3
86   
87  ${Next}
88  FileClose $R5
89
90  abortinstall:
91  Delete "$INSTDIR\$String"
92
93 FunctionEnd
94
95 #--------------------------------
96
97 Function DownloadThesaurusDictionaries
98  # Downloads thesaurus dictionaries from a location that is given in the file
99  # $INSTDIR\Resources\ThesaurusDictionaryNames.txt
100  
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
104  
105   FileRead $R5 $String # $String is now the thesaurus name
106   StrCpy $R3 $String 5 3 # $R3 is now the thesaurus language code
107   
108   ${if} $ThesCode == $R3
109    StrCpy $String $String -2 # delete the linebreak characters at the end
110    # Download thesaurus files
111    Push $R0
112    inetc::get /POPUP /RECEIVETIMEOUT=5000 "https://sourceforge.net/projects/lyxwininstaller/files/thesaurus/$String" "$INSTDIR\Resources\thes\$String" /END
113    Pop $R0
114    # if download failed
115    ${if} $R0 != "OK"
116     MessageBox MB_OK|MB_ICONEXCLAMATION "$(ThesaurusFailed): $R0"
117     Goto abortinstall
118    ${endif}
119   ${endif} # end if $ThesCode == $R3
120   
121  ${Next}
122  FileClose $R5
123
124  abortinstall:
125  Delete "$INSTDIR\$String"
126
127 FunctionEnd
128
129 #--------------------------------
130
131 Function InstallHunspellDictionaries
132  # installs the selected hunspell dictionaries except of already existing ones
133
134  ${Do}
135   # take the first code
136   StrCpy $Search ","
137   StrCpy $String $DictCodes
138   Call StrPoint
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"
142    StrCpy $DictCodes ""
143   ${endif}
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
156    ${endif}
157   ${endif}
158  ${LoopUntil} $DictCodes == ""
159  
160 FunctionEnd
161
162 #--------------------------------
163
164 Function InstallThesaurusDictionaries
165  # installs the selected thesaurus dictionaries except of already existing ones
166
167  ${Do}
168   # take the first code
169   StrCpy $Search ","
170   StrCpy $String $ThesCodes
171   Call StrPoint
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"
175    StrCpy $ThesCodes ""
176   ${endif}
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
189    ${endif}
190   ${endif}
191  ${LoopUntil} $ThesCodes == ""
192  
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"
201  ${endif}
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"
207  ${endif}
208  RMDir "$INSTDIR\Resources\backup"
209  
210 FunctionEnd
211