1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * OpenOffice.org - a multi-platform office productivity suite
6 * The Contents of this file are made available subject to
7 * the terms of GNU Lesser General Public License Version 3.
10 * GNU Lesser General Public License Version 3
11 * =============================================
12 * Copyright 2005 by Sun Microsystems, Inc.
13 * 901 San Antonio Road, Palo Alto, CA 94303, USA
15 * This library is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU Lesser General Public
17 * License version 2.1, as published by the Free Software Foundation.
19 * This library is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * Lesser General Public License for more details.
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
29 ************************************************************************/
33 #define WIN32_LEAN_AND_MEAN
34 #define _WIN32_WINNT 0x0500
46 #include <systools/win32/uwinapi.h>
59 string
GetMsiProperty(MSIHANDLE handle
, const string
& sProperty
)
62 TCHAR szDummy
[1] = TEXT("");
65 if (MsiGetProperty(handle
, sProperty
.c_str(), szDummy
, &nChars
) == ERROR_MORE_DATA
)
67 DWORD nBytes
= ++nChars
* sizeof(TCHAR
);
68 LPTSTR buffer
= reinterpret_cast<LPTSTR
>(_alloca(nBytes
));
69 ZeroMemory( buffer
, nBytes
);
70 MsiGetProperty(handle
, sProperty
.c_str(), buffer
, &nChars
);
76 inline bool IsSetMsiProperty(MSIHANDLE handle
, const string
& sProperty
)
78 return (GetMsiProperty(handle
, sProperty
).length() > 0);
81 inline void UnsetMsiProperty(MSIHANDLE handle
, const string
& sProperty
)
83 MsiSetProperty(handle
, sProperty
.c_str(), NULL
);
86 inline void SetMsiProperty(MSIHANDLE handle
, const string
& sProperty
, const string
&)
88 MsiSetProperty(handle
, sProperty
.c_str(), TEXT("1"));
91 static const int MAXLINE
= 1024*64;
94 void generateIndex(const char *inputFile
, const char *outputFile
)
97 ifstream
in(inputFile
);
98 char inputBuffer
[MAXLINE
];
99 map
<string
, size_t> entries
;
100 map
<string
,size_t>::iterator
ret(entries
.begin());
103 in
.getline(inputBuffer
, MAXLINE
);
104 const string
encoding(inputBuffer
);
105 size_t currentOffset(encoding
.size()+1);
108 // Extract the next word, but not the entry count
109 in
.getline(inputBuffer
, MAXLINE
, '|');
113 string
word(inputBuffer
);
114 ret
= entries
.insert(ret
, pair
<string
, size_t>(word
, currentOffset
));
115 currentOffset
+= word
.size() + 1;
116 // Next is the entry count
117 in
.getline(inputBuffer
, MAXLINE
);
123 currentOffset
+= strlen(inputBuffer
)+1;
124 int entryCount(strtol(inputBuffer
, NULL
, 10));
125 for (int i(0); i
< entryCount
; ++i
)
127 in
.getline(inputBuffer
, MAXLINE
);
128 currentOffset
+= strlen(inputBuffer
)+1;
133 // Use binary mode to prevent any translation of LF to CRLF on Windows
134 ofstream
outputStream(outputFile
, ios_base::binary
| ios_base::trunc
|ios_base::out
);
135 if (!outputStream
.is_open())
137 //cerr << "Unable to open output file " << outputFile << endl;
141 cerr
<< "Doing it now" << outputFile
<< endl
;
142 outputStream
<< encoding
<< '\n' << entries
.size() << '\n';
144 for (map
<string
, size_t>::const_iterator
ii(entries
.begin());
149 outputStream
<< ii
->first
<< '|' << ii
->second
<< '\n';
151 outputStream
.close();
154 void generateIndex(const string
&datFile
)
156 string
idxFile(datFile
.substr(0, datFile
.size()-3)+"idx");
157 generateIndex(datFile
.c_str(), idxFile
.c_str());
159 void createIndexesForThesaurusFiles(const string
& sOfficeInstallPath
)
161 vector
<string
> thesaurusPaths
;
163 string sExtensionsPath
= sOfficeInstallPath
+ "\\share\\extensions\\";
165 string dictionariesWildcard
= sExtensionsPath
+ "dict-*";
167 struct _finddatai64_t dictFind
;
168 long h
= _findfirsti64(dictionariesWildcard
.c_str(),&dictFind
);
173 if (dictFind
.attrib
& _A_SUBDIR
)
175 struct _finddatai64_t datFind
;
176 // Find any .dat files in the subdirectory
177 string dictPath
= sExtensionsPath
+ dictFind
.name
+ "\\";
178 string datWildCard
= dictPath
+ "*.dat";
179 long h2
= _findfirsti64(datWildCard
.c_str(), &datFind
);
184 thesaurusPaths
.push_back(dictPath
+ datFind
.name
);
186 } while (_findnexti64(h2
,&datFind
) == 0);
190 } while (_findnexti64(h
,&dictFind
) == 0);
192 for (vector
<string
>::const_iterator
ii(thesaurusPaths
.begin());
193 ii
!= thesaurusPaths
.end();
204 // Creates the thesaurus .idx files for all installed .dat
206 extern "C" UINT __stdcall
CreateIndexes( MSIHANDLE handle
)
209 string sOfficeInstallPath
= GetMsiProperty(handle
, TEXT("INSTALLLOCATION"));
210 createIndexesForThesaurusFiles(sOfficeInstallPath
);
211 return ERROR_SUCCESS
;
214 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */