]> git.lyx.org Git - lyx.git/blob - development/Win32/packaging/installer/include/thesaurus.nsh
9f9a4643a63b17c4ba3a34bd067891fac75e7cd3
[lyx.git] / development / Win32 / packaging / installer / include / thesaurus.nsh
1 # download dictionaries
2
3 Function DownloadHunspellDictionary
4  # Downloads hunspell dictionaries from a location that is given in the file
5  # $INSTDIR\Resources\HunspellDictionaryNames.txt
6  
7  # read out the locations from the file 
8  FileOpen $R5 "$INSTDIR\Resources\HunspellDictionaryNames.txt" r
9  ${For} $5 1 132       # the file has 132 lines
10  
11   FileRead $R5 $String # $String is now the dictionary name
12   StrCpy $R3 $String -6 # $R3 is now the dictionary language code
13   
14   ${if} $DictCode == $R3
15    StrCpy $String $String -2 # delete the linebreak characters at the end
16    # Download hunspell dictionaries,
17    # if first download repository is not available try the other ones listed in "DictionaryMirrors.txt"
18    FileOpen $R4 "$INSTDIR\Resources\DictionaryMirrors.txt" r
19    
20    ${For} $4 1 8
21     FileRead $R4 $Search # $Search is now the mirror
22     StrCpy $Search $Search -2 # delete the linebreak characters at the end
23     Push $R0
24     InetLoad::load /TIMEOUT=5000 "http://$Search.dl.sourceforge.net/project/lyxwininstaller/hunspell/$String" "$INSTDIR\Resources\dicts\$String" /END
25     Pop $R0
26     ${if} $R0 == "OK"
27      ${ExitFor}
28     ${endif}
29    ${Next}
30    
31    FileClose $R4
32    # if download failed
33    ${if} $R0 != "OK"
34     MessageBox MB_OK|MB_ICONEXCLAMATION "$(HunspellFailed)"
35     Goto abortinstall
36    ${endif}
37   ${endif} # end if $DictCode == $R3
38   
39  ${Next}
40  FileClose $R5
41
42   abortinstall:
43   Delete "$INSTDIR\$String"
44
45 FunctionEnd
46
47 #--------------------------------
48
49 Function DownloadThesaurusDictionary
50  # Downloads thesaurus dictionaries from a location that is given in the file
51  # $INSTDIR\Resources\ThesaurusDictionaryNames.txt
52  
53  # read out the locations from the file 
54  FileOpen $R5 "$INSTDIR\Resources\ThesaurusDictionaryNames.txt" r
55  ${For} $5 1 44          # the file has 44 lines
56  
57   FileRead $R5 $String   # $String is now the dictionary name
58   StrCpy $R3 $String 5 3 # $R3 is now the dictionary language code
59   
60   ${if} $ThesCode == $R3
61    StrCpy $String $String -2 # delete the linebreak characters at the end
62    # Download thesaurus dictionaries,
63    # if first download repository is not available try the other ones listed in "DictionaryMirrors.txt"
64    FileOpen $R4 "$INSTDIR\Resources\DictionaryMirrors.txt" r
65    
66    ${For} $4 1 8
67     FileRead $R4 $Search # $Search is now the mirror
68     StrCpy $Search $Search -2 # delete the linebreak characters at the end
69     Push $R0
70     InetLoad::load /TIMEOUT=5000 "http://$Search.dl.sourceforge.net/project/lyxwininstaller/thesaurus/$String" "$INSTDIR\Resources\thes\$String" /END
71     Pop $R0
72     ${if} $R0 == "OK"
73      ${ExitFor}
74     ${endif}
75    ${Next}
76    
77    FileClose $R4
78    # if download failed
79    ${if} $R0 != "OK"
80     MessageBox MB_OK|MB_ICONEXCLAMATION "$(ThesaurusFailed)"
81     Goto abortinstall
82    ${endif}
83   ${endif} # end if $ThesCode == $R3
84   
85  ${Next}
86  FileClose $R5
87
88   abortinstall:
89   Delete "$INSTDIR\$String"
90
91 FunctionEnd
92
93 #--------------------------------
94
95 Function InstallHunspellDictionary
96  # install the selected hunspell dictionaries except of already existing ones
97
98  # download the dictionaries
99  ${Do}
100   # take the first code
101   StrCpy $Search ","
102   StrCpy $String $DictCodes
103   Call StrPoint
104   ${if} $Pointer != "-1"
105    StrCpy $DictCode $DictCodes $Pointer
106    # remove the taken code from the list
107    IntOp $Pointer $Pointer + 1
108    StrCpy $DictCodes $DictCodes "" $Pointer
109   ${endif}
110   # don't dowload existing ones thus check if $DictCode is in $FoundDict
111   StrCpy $String $FoundDict
112   StrCpy $Search $DictCode
113   Call StrPoint # function from LyXUtils.nsh
114   ${if} $Pointer == "-1"
115    Call DownloadHunspellDictionary
116   ${endif}
117  ${LoopUntil} $DictCodes == ""
118  
119 FunctionEnd
120
121 #--------------------------------
122
123 Function InstallThesaurusDictionary
124  # install the selected thesaurus dictionaries except of already existing ones
125
126  # download the dictionaries
127  ${Do}
128   # all codes have 5 characters
129   StrCpy $ThesCode $ThesCodes 5 # take the first code
130   StrCpy $ThesCodes $ThesCodes "" 5 # remove the taken code from the list
131   # don't dowload existing ones thus check if $ThesCode is in $FoundThes
132   StrCpy $String $FoundThes
133   StrCpy $Search $ThesCode
134   Call StrPoint # function from LyXUtils.nsh
135   ${if} $Pointer == "-1"
136    Call DownloadThesaurusDictionary
137   ${endif}
138  ${LoopUntil} $ThesCodes == ""
139  
140  # some dictionaries of language variants are identic
141  # therefore copy and rename an existing dictionary
142  CreateDirectory "$INSTDIR\Resources\backup"
143  ${if} ${FileExists} "$INSTDIR\Resources\thes\th_de_DE_v2.dat"
144   CopyFiles "$INSTDIR\Resources\thes\th_de_DE_v2.*" "$INSTDIR\Resources\backup"
145   Rename "$INSTDIR\Resources\backup\th_de_DE_v2.dat" "$INSTDIR\Resources\backup\th_de_AT_v2.dat"
146   Rename "$INSTDIR\Resources\backup\th_de_DE_v2.idx" "$INSTDIR\Resources\backup\th_de_AT_v2.idx"
147   CopyFiles "$INSTDIR\Resources\backup\th_de_AT_v2.*" "$INSTDIR\Resources\thes"
148  ${endif}
149  ${if} ${FileExists} "$INSTDIR\Resources\thes\th_en_US_v2.dat"
150   CopyFiles "$INSTDIR\Resources\thes\th_en_US_v2.*" "$INSTDIR\Resources\backup"
151   Rename "$INSTDIR\Resources\backup\th_en_US_v2.dat" "$INSTDIR\Resources\backup\th_en_AU_v2.dat"
152   Rename "$INSTDIR\Resources\backup\th_en_US_v2.idx" "$INSTDIR\Resources\backup\th_en_AU_v2.idx"
153   CopyFiles "$INSTDIR\Resources\backup\th_en_AU_v2.*" "$INSTDIR\Resources\thes"
154  ${endif}
155  RMDir "$INSTDIR\Resources\backup"
156  
157 FunctionEnd