Update ooo320-m1
[ooovba.git] / binfilter / binfilterdetect / source / bindetect.cxx
blobfc4a76ddecebfacd41e944d986ea92e08dfaf8cc
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: bindetect.cxx,v $
10 * $Revision: 1.14 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "bindetect.hxx"
33 #ifndef _COM_SUN_STAR_IO_XINPUTSTREAM_HPP_
34 #include <com/sun/star/io/XInputStream.hpp>
35 #endif
36 #ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_
37 #include <com/sun/star/container/XNameAccess.hpp>
38 #endif
39 #ifndef _COM_SUN_STAR_CONTAINER_XCONTAINERQUERY_HPP_
40 #include <com/sun/star/container/XContainerQuery.hpp>
41 #endif
42 #ifndef _COM_SUN_STAR_CONTAINER_XENUMERATION_HPP_
43 #include <com/sun/star/container/XEnumeration.hpp>
44 #endif
45 #ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HPP_
46 #include <com/sun/star/beans/PropertyValue.hpp>
47 #endif
48 #ifndef _COM_SUN_STAR_BEANS_NAMEDVALUE_HPP_
49 #include <com/sun/star/beans/NamedValue.hpp>
50 #endif
52 #ifndef _URLOBJ_HXX
53 #include <tools/urlobj.hxx>
54 #endif
55 #ifndef INCLUDED_SVTOOLS_PATHOPTIONS_HXX
56 #include <bf_svtools/pathoptions.hxx>
57 #endif
58 #include <rtl/ustring.h>
59 #include <vos/mutex.hxx>
60 #include <sot/storage.hxx>
61 #include <sot/exchange.hxx>
62 #include <comphelper/mediadescriptor.hxx>
63 #include <unotools/ucbstreamhelper.hxx>
64 #include <vcl/svapp.hxx>
65 #ifndef _OSL_MODULE_HXX_
66 #include <osl/module.hxx>
67 #endif
68 #ifndef _OSL_FILE_HXX_
69 #include <osl/file.hxx>
70 #endif
72 #if defined( WNT )
74 // Typen fuer die Funktion der W4W-DLL
75 #include <tools/svwin.h>
76 #endif
78 #ifdef UNX
79 #include <stdlib.h>
80 #endif
82 using namespace ::com::sun::star::registry;
83 using namespace ::com::sun::star::uno;
85 namespace binfilter {
87 struct TypesInfo
89 const char* Type;
90 sal_Int32 Length;
93 // --> OD 2005-08-04 #i47323#, #i51938# - list of file types
94 // the binfilter modul is responsible for
95 // - see /filter/source/config/fragments/filters/
96 static const sal_uInt8 nStreamFileTypeCount = 114;
97 static const sal_uInt8 nFileTypeCount = 29 + nStreamFileTypeCount;
98 static const sal_uInt8 nW4WStartOffset = 5;
99 static const TypesInfo aFileTypeList[ nFileTypeCount ] =
101 RTL_CONSTASCII_STRINGPARAM("writer_StarWriter_10"),
102 RTL_CONSTASCII_STRINGPARAM("writer_StarWriter_20"),
103 RTL_CONSTASCII_STRINGPARAM("writer_StarWriter_DOS"),
104 RTL_CONSTASCII_STRINGPARAM("writer_Lotus_1_2_3_10_DOS_StarWriter"),
105 RTL_CONSTASCII_STRINGPARAM("writer_Lotus_1_2_3_10_WIN_StarWriter"),
106 RTL_CONSTASCII_STRINGPARAM("writer_Ami_Pro_1x_31_W4W"), // 5 , 33
107 RTL_CONSTASCII_STRINGPARAM("writer_CTOS_DEF_W4W"), // 6 , 36
108 RTL_CONSTASCII_STRINGPARAM("writer_Claris_Works_W4W"), // 7 , 57
109 RTL_CONSTASCII_STRINGPARAM("writer_DCA_Revisable_Form_Text_W4W"), // 8 , 15
110 RTL_CONSTASCII_STRINGPARAM("writer_DCA_with_Display_Write_5_W4W"), // 9 , 15
111 RTL_CONSTASCII_STRINGPARAM("writer_DCAFFT_Final_Form_Text_W4W"), //10, 32
112 RTL_CONSTASCII_STRINGPARAM("writer_DEC_DX_W4W"), //11, 30
113 RTL_CONSTASCII_STRINGPARAM("writer_DEC_WPS_PLUS_W4W"), //12, 45
114 RTL_CONSTASCII_STRINGPARAM("writer_DataGeneral_CEO_Write_W4W"), //13, 104
115 RTL_CONSTASCII_STRINGPARAM("writer_DisplayWrite_20_4x_W4W"), //14, 15
116 RTL_CONSTASCII_STRINGPARAM("writer_DisplayWrite_5x_W4W"), //15, 15
117 RTL_CONSTASCII_STRINGPARAM("writer_EBCDIC_W4W"), //16, 02
118 RTL_CONSTASCII_STRINGPARAM("writer_Enable_W4W"), //17, 28
119 RTL_CONSTASCII_STRINGPARAM("writer_Frame_Maker_MIF_30_W4W"), //18, 42
120 RTL_CONSTASCII_STRINGPARAM("writer_Frame_Maker_MIF_40_W4W"), //19, 42
121 RTL_CONSTASCII_STRINGPARAM("writer_Frame_Maker_MIF_50_W4W"), //20, 42
122 RTL_CONSTASCII_STRINGPARAM("writer_Frame_Work_III_W4W"), //21, 29
123 RTL_CONSTASCII_STRINGPARAM("writer_Frame_Work_IV_W4W"), //22, 29
124 RTL_CONSTASCII_STRINGPARAM("writer_HP_AdvanceWrite_Plus_W4W"), //23, 22
125 RTL_CONSTASCII_STRINGPARAM("writer_ICL_Office_Power_6_W4W"), //24, 102
126 RTL_CONSTASCII_STRINGPARAM("writer_ICL_Office_Power_7_W4W"), //25, 102
127 RTL_CONSTASCII_STRINGPARAM("writer_Interleaf_W4W"), //26, 35
128 RTL_CONSTASCII_STRINGPARAM("writer_Interleaf_5_6_W4W"), //27, 46
129 RTL_CONSTASCII_STRINGPARAM("writer_Legacy_Winstar_onGO_W4W"), //28, 37
130 RTL_CONSTASCII_STRINGPARAM("writer_Lotus_Manuscript_W4W"), //29, 24
131 RTL_CONSTASCII_STRINGPARAM("writer_MASS_11_Rel_80_83_W4W"), //30, 31
132 RTL_CONSTASCII_STRINGPARAM("writer_MASS_11_Rel_85_90_W4W"), //31, 31
133 RTL_CONSTASCII_STRINGPARAM("writer_MS_MacWord_30_W4W"), //32, 54
134 RTL_CONSTASCII_STRINGPARAM("writer_MS_MacWord_40_W4W"), //33, 54
135 RTL_CONSTASCII_STRINGPARAM("writer_MS_MacWord_5x_W4W"), //34, 54
136 RTL_CONSTASCII_STRINGPARAM("writer_MS_WinWord_1x_W4W"), //35, 44
137 RTL_CONSTASCII_STRINGPARAM("writer_MS_WinWord_2x_W4W"), //36, 44
138 RTL_CONSTASCII_STRINGPARAM("writer_MS_Word_3x_W4W"), //37, 05
139 RTL_CONSTASCII_STRINGPARAM("writer_MS_Word_4x_W4W"), //38, 05
140 RTL_CONSTASCII_STRINGPARAM("writer_MS_Word_5x_W4W"), //39, 05
141 RTL_CONSTASCII_STRINGPARAM("writer_MS_Word_6x_W4W"), //40, 49
142 RTL_CONSTASCII_STRINGPARAM("writer_MS_Works_20_DOS_W4W"), //41, 39
143 RTL_CONSTASCII_STRINGPARAM("writer_MS_Works_30_Win_W4W"), //42, 39
144 RTL_CONSTASCII_STRINGPARAM("writer_MS_Works_40_Mac_W4W"), //43, 58
145 RTL_CONSTASCII_STRINGPARAM("writer_Mac_Write_4x_50_W4W"), //44, 51
146 RTL_CONSTASCII_STRINGPARAM("writer_Mac_Write_II_W4W"), //45, 52
147 RTL_CONSTASCII_STRINGPARAM("writer_Mac_Write_Pro_W4W"), //46, 56
148 RTL_CONSTASCII_STRINGPARAM("writer_MultiMate_33_W4W"), //47, 10
149 RTL_CONSTASCII_STRINGPARAM("writer_MultiMate_4_W4W"), //48, 10
150 RTL_CONSTASCII_STRINGPARAM("writer_MultiMate_Adv_36_W4W"), //49, 10
151 RTL_CONSTASCII_STRINGPARAM("writer_MultiMate_Adv_II_37_W4W"), //50, 10
152 RTL_CONSTASCII_STRINGPARAM("writer_NAVY_DIF_W4W"), //51, 18
153 RTL_CONSTASCII_STRINGPARAM("writer_OfficeWriter_40_W4W"), //52, 16
154 RTL_CONSTASCII_STRINGPARAM("writer_OfficeWriter_50_W4W"), //53, 16
155 RTL_CONSTASCII_STRINGPARAM("writer_OfficeWriter_6x_W4W"), //54, 16
156 RTL_CONSTASCII_STRINGPARAM("writer_PFS_First_Choice_10_W4W"), //55, 08
157 RTL_CONSTASCII_STRINGPARAM("writer_PFS_First_Choice_20_W4W"), //56, 08
158 RTL_CONSTASCII_STRINGPARAM("writer_PFS_First_Choice_30_W4W"), //57, 08
159 RTL_CONSTASCII_STRINGPARAM("writer_PFS_Write_W4W"), //58, 08
160 RTL_CONSTASCII_STRINGPARAM("writer_Peach_Text_W4W"), //59, 27
161 RTL_CONSTASCII_STRINGPARAM("writer_Professional_Write_10_W4W"), //60, 33
162 RTL_CONSTASCII_STRINGPARAM("writer_Professional_Write_2x_W4W"), //61, 33
163 RTL_CONSTASCII_STRINGPARAM("writer_Professional_Write_Plus_W4W"), //62, 33
164 RTL_CONSTASCII_STRINGPARAM("writer_QA_Write_10_30_W4W"), //63, 23
165 RTL_CONSTASCII_STRINGPARAM("writer_QA_Write_40_W4W"), //64, 23
166 RTL_CONSTASCII_STRINGPARAM("writer_Rapid_File_10_W4W"), //65, 25
167 RTL_CONSTASCII_STRINGPARAM("writer_Rapid_File_12_W4W"), //66, 25
168 RTL_CONSTASCII_STRINGPARAM("writer_Samna_Word_IV_IV_Plus_W4W"), //67, 22
169 RTL_CONSTASCII_STRINGPARAM("writer_Total_Word_W4W"), //68, 14
170 RTL_CONSTASCII_STRINGPARAM("writer_Uniplex_V7_V8_W4W"), //69, 101
171 RTL_CONSTASCII_STRINGPARAM("writer_Uniplex_onGO_W4W"), //70, 101
172 RTL_CONSTASCII_STRINGPARAM("writer_VolksWriter_3_and_4_W4W"), //71, 14
173 RTL_CONSTASCII_STRINGPARAM("writer_VolksWriter_Deluxe_W4W"), //72, 11
174 RTL_CONSTASCII_STRINGPARAM("writer_WITA_W4W"), //73, 34
175 RTL_CONSTASCII_STRINGPARAM("writer_Wang_II_SWP_W4W"), //74, 88
176 RTL_CONSTASCII_STRINGPARAM("writer_Wang_PC_W4W"), //75, 26
177 RTL_CONSTASCII_STRINGPARAM("writer_Wang_WP_Plus_W4W"), //76, 89
178 RTL_CONSTASCII_STRINGPARAM("writer_Win_Write_3x_W4W"), //77, 43
179 RTL_CONSTASCII_STRINGPARAM("writer_WiziWord_30_W4W"), //78, 47
180 RTL_CONSTASCII_STRINGPARAM("writer_WordPerfect_Win_51_52_W4W"), //79, 07
181 RTL_CONSTASCII_STRINGPARAM("writer_WordPerfect_Win_60_W4W"), //80, 48
182 RTL_CONSTASCII_STRINGPARAM("writer_WordPerfect_Win_61_W4W"), //81, 48
183 RTL_CONSTASCII_STRINGPARAM("writer_WordPerfect_Win_70_W4W"), //82, 07
184 RTL_CONSTASCII_STRINGPARAM("writer_WordPerfect_41_W4W"), //83, 06
185 RTL_CONSTASCII_STRINGPARAM("writer_WordPerfect_42_W4W"), //84, 06
186 RTL_CONSTASCII_STRINGPARAM("writer_WordPerfect_50_W4W"), //85, 07
187 RTL_CONSTASCII_STRINGPARAM("writer_WordPerfect_51_W4W"), //86, 07
188 RTL_CONSTASCII_STRINGPARAM("writer_WordPerfect_60_W4W"), //87, 07
189 RTL_CONSTASCII_STRINGPARAM("writer_WordPerfect_61_W4W"), //88, 07
190 RTL_CONSTASCII_STRINGPARAM("writer_WordPerfect_Mac_1_W4W"), //89, 59
191 RTL_CONSTASCII_STRINGPARAM("writer_WordPerfect_Mac_2_W4W"), //90, 60
192 RTL_CONSTASCII_STRINGPARAM("writer_WordPerfect_Mac_3_W4W"), //91, 60
193 RTL_CONSTASCII_STRINGPARAM("writer_WordStar_Win_1x_20_W4W"), //92, 04
194 RTL_CONSTASCII_STRINGPARAM("writer_WordStar_2000_Rel_30_W4W"), //93, 09
195 RTL_CONSTASCII_STRINGPARAM("writer_WordStar_2000_Rel_35_W4W"), //94, 09
196 RTL_CONSTASCII_STRINGPARAM("writer_WordStar_33x_W4W"), //95, 04
197 RTL_CONSTASCII_STRINGPARAM("writer_WordStar_345_W4W"), //96, 04
198 RTL_CONSTASCII_STRINGPARAM("writer_WordStar_40_W4W"), //97, 04
199 RTL_CONSTASCII_STRINGPARAM("writer_WordStar_50_W4W"), //98, 04
200 RTL_CONSTASCII_STRINGPARAM("writer_WordStar_55_W4W"), //99, 04
201 RTL_CONSTASCII_STRINGPARAM("writer_WordStar_60_W4W"), //100, 04
202 RTL_CONSTASCII_STRINGPARAM("writer_WordStar_70_W4W"), //101, 04
203 RTL_CONSTASCII_STRINGPARAM("writer_WriteNow_30_Macintosh_W4W"), //102, 62
204 RTL_CONSTASCII_STRINGPARAM("writer_Writing_Assistant_W4W"), //103, 13
205 RTL_CONSTASCII_STRINGPARAM("writer_XEROX_XIF_50_Illustrator_W4W"), //104, 103
206 RTL_CONSTASCII_STRINGPARAM("writer_XEROX_XIF_50_W4W"), //105, 103
207 RTL_CONSTASCII_STRINGPARAM("writer_XEROX_XIF_60_Color_Bitmap_W4W"), //106, 103
208 RTL_CONSTASCII_STRINGPARAM("writer_XEROX_XIF_60_Res_Graphic_W4W"), //107, 103
209 RTL_CONSTASCII_STRINGPARAM("writer_XyWrite_Win_10_W4W"), //108, 17
210 RTL_CONSTASCII_STRINGPARAM("writer_XyWrite_III_W4W"), //109, 17
211 RTL_CONSTASCII_STRINGPARAM("writer_XyWrite_IIIP_W4W"), //110, 17
212 RTL_CONSTASCII_STRINGPARAM("writer_XyWrite_IV_W4W"), //111, 17
213 RTL_CONSTASCII_STRINGPARAM("writer_XyWrite_Sig_Win_W4W"), //112, 17
214 RTL_CONSTASCII_STRINGPARAM("writer_XyWrite_Signature_W4W"), //113, 17
215 RTL_CONSTASCII_STRINGPARAM("calc_StarCalc_30"),
216 RTL_CONSTASCII_STRINGPARAM("calc_StarCalc_30_VorlageTemplate"),
217 RTL_CONSTASCII_STRINGPARAM("calc_StarCalc_40"),
218 RTL_CONSTASCII_STRINGPARAM("calc_StarCalc_40_VorlageTemplate"),
219 RTL_CONSTASCII_STRINGPARAM("calc_StarCalc_50"),
220 RTL_CONSTASCII_STRINGPARAM("calc_StarCalc_50_VorlageTemplate"),
221 RTL_CONSTASCII_STRINGPARAM("chart_StarChart_30"),
222 RTL_CONSTASCII_STRINGPARAM("chart_StarChart_40"),
223 RTL_CONSTASCII_STRINGPARAM("chart_StarChart_50"),
224 RTL_CONSTASCII_STRINGPARAM("draw_StarDraw_30"),
225 RTL_CONSTASCII_STRINGPARAM("draw_StarDraw_30_Vorlage"),
226 RTL_CONSTASCII_STRINGPARAM("draw_StarDraw_50"),
227 RTL_CONSTASCII_STRINGPARAM("draw_StarDraw_50_Vorlage"),
228 RTL_CONSTASCII_STRINGPARAM("impress_StarImpress_40"),
229 RTL_CONSTASCII_STRINGPARAM("impress_StarImpress_40_Vorlage"),
230 RTL_CONSTASCII_STRINGPARAM("impress_StarImpress_50"),
231 RTL_CONSTASCII_STRINGPARAM("impress_StarImpress_50_Vorlage"),
232 RTL_CONSTASCII_STRINGPARAM("impress_StarImpress_50_packed"),
233 RTL_CONSTASCII_STRINGPARAM("math_StarMath_30"),
234 RTL_CONSTASCII_STRINGPARAM("math_StarMath_40"),
235 RTL_CONSTASCII_STRINGPARAM("math_StarMath_50"),
236 RTL_CONSTASCII_STRINGPARAM("writer_StarWriter_30"),
237 RTL_CONSTASCII_STRINGPARAM("writer_StarWriter_30_VorlageTemplate"),
238 RTL_CONSTASCII_STRINGPARAM("writer_StarWriter_40"),
239 RTL_CONSTASCII_STRINGPARAM("writer_StarWriter_40_VorlageTemplate"),
240 RTL_CONSTASCII_STRINGPARAM("writer_globaldocument_StarWriter_40GlobalDocument"),
241 RTL_CONSTASCII_STRINGPARAM("writer_StarWriter_50"),
242 RTL_CONSTASCII_STRINGPARAM("writer_StarWriter_50_VorlageTemplate"),
243 RTL_CONSTASCII_STRINGPARAM("writer_globaldocument_StarWriter_50GlobalDocument")
245 //list of Word4Word filters the identifiers are returned by AutoDetec
246 static const sal_uInt8 nW4WFilterCount = 109;
247 static const USHORT aW4WIdentifier[nW4WFilterCount] =
249 33 ,//"writer_Ami_Pro_1x_31_W4W"
250 36 ,//"writer_CTOS_DEF_W4W"
251 57 ,//"writer_Claris_Works_W4W"
252 15 ,//"writer_DCA_Revisable_Form_Text_W4W"
253 15 ,//"writer_DCA_with_Display_Write_5_W4W"
254 32 ,//"writer_DCAFFT_Final_Form_Text_W4W"
255 30 ,//"writer_DEC_DX_W4W"
256 45 ,//"writer_DEC_WPS_PLUS_W4W"
257 104 ,//"writer_DataGeneral_CEO_Write_W4W"
258 15 ,//"writer_DisplayWrite_20_4x_W4W"
259 15 ,//"writer_DisplayWrite_5x_W4W"
260 02 ,//"writer_EBCDIC_W4W"
261 28 ,//"writer_Enable_W4W"
262 42 ,//"writer_Frame_Maker_MIF_30_W4W"
263 42 ,//"writer_Frame_Maker_MIF_40_W4W"
264 42 ,//"writer_Frame_Maker_MIF_50_W4W"
265 29 ,//"writer_Frame_Work_III_W4W"
266 29 ,//"writer_Frame_Work_IV_W4W"
267 22 ,//"writer_HP_AdvanceWrite_Plus_W4W"
268 102 ,//"writer_ICL_Office_Power_6_W4W"
269 102 ,//"writer_ICL_Office_Power_7_W4W"
270 35 ,//"writer_Interleaf_W4W"
271 46 ,//"writer_Interleaf_5_6_W4W"
272 37 ,//"writer_Legacy_Winstar_onGO_W4W"
273 24 ,//"writer_Lotus_Manuscript_W4W"
274 31 ,//"writer_MASS_11_Rel_80_83_W4W"
275 31 ,//"writer_MASS_11_Rel_85_90_W4W"
276 54 ,//"writer_MS_MacWord_30_W4W"
277 54 ,//"writer_MS_MacWord_40_W4W"
278 54 ,//"writer_MS_MacWord_5x_W4W"
279 44 ,//"writer_MS_WinWord_1x_W4W"
280 44 ,//"writer_MS_WinWord_2x_W4W"
281 05 ,//"writer_MS_Word_3x_W4W"
282 05 ,//"writer_MS_Word_4x_W4W"
283 05 ,//"writer_MS_Word_5x_W4W"
284 49 ,//"writer_MS_Word_6x_W4W"
285 39 ,//"writer_MS_Works_20_DOS_W4W"
286 39 ,//"writer_MS_Works_30_Win_W4W"
287 58 ,//"writer_MS_Works_40_Mac_W4W"
288 51 ,//"writer_Mac_Write_4x_50_W4W"
289 52 ,//"writer_Mac_Write_II_W4W"
290 56 ,//"writer_Mac_Write_Pro_W4W"
291 10 ,//"writer_MultiMate_33_W4W"
292 10 ,//"writer_MultiMate_4_W4W"
293 10 ,//"writer_MultiMate_Adv_36_W4W"
294 10 ,//"writer_MultiMate_Adv_II_37_W4W"
295 18 ,//"writer_NAVY_DIF_W4W"
296 16 ,//"writer_OfficeWriter_40_W4W"
297 16 ,//"writer_OfficeWriter_50_W4W"
298 16 ,//"writer_OfficeWriter_6x_W4W"
299 8 ,//"writer_PFS_First_Choice_10_W4W"
300 8 ,//"writer_PFS_First_Choice_20_W4W"
301 8 ,//"writer_PFS_First_Choice_30_W4W"
302 8 ,//"writer_PFS_Write_W4W"
303 27 ,//"writer_Peach_Text_W4W"
304 33 ,//"writer_Professional_Write_10_W4W"
305 33 ,//"writer_Professional_Write_2x_W4W"
306 33 ,//"writer_Professional_Write_Plus_W4W"
307 23 ,//"writer_QA_Write_10_30_W4W"
308 23 ,//"writer_QA_Write_40_W4W"
309 25 ,//"writer_Rapid_File_10_W4W"
310 25 ,//"writer_Rapid_File_12_W4W"
311 22 ,//"writer_Samna_Word_IV_IV_Plus_W4W"
312 14 ,//"writer_Total_Word_W4W"
313 101 ,//"writer_Uniplex_V7_V8_W4W"
314 101 ,//"writer_Uniplex_onGO_W4W"
315 14 ,//"writer_VolksWriter_3_and_4_W4W"
316 11 ,//"writer_VolksWriter_Deluxe_W4W"
317 34 ,//"writer_WITA_W4W"
318 88 ,//"writer_Wang_II_SWP_W4W"
319 26 ,//"writer_Wang_PC_W4W"
320 89 ,//"writer_Wang_WP_Plus_W4W"
321 43 ,//"writer_Win_Write_3x_W4W"
322 47 ,//"writer_WiziWord_30_W4W"
323 7 ,//"writer_WordPerfect_Win_51_52_W4W"
324 48 ,//"writer_WordPerfect_Win_60_W4W"
325 48 ,//"writer_WordPerfect_Win_61_W4W"
326 7 ,//"writer_WordPerfect_Win_70_W4W"
327 6 ,//"writer_WordPerfect_41_W4W"
328 6 ,//"writer_WordPerfect_42_W4W"
329 7 ,//"writer_WordPerfect_50_W4W"
330 7 ,//"writer_WordPerfect_51_W4W"
331 7 ,//"writer_WordPerfect_60_W4W"
332 7 ,//"writer_WordPerfect_61_W4W"
333 59 ,//"writer_WordPerfect_Mac_1_W4W"
334 60 ,//"writer_WordPerfect_Mac_2_W4W"
335 60 ,//"writer_WordPerfect_Mac_3_W4W"
336 4 ,//"writer_WordStar_Win_1x_20_W4W"
337 9 ,//"writer_WordStar_2000_Rel_30_W4W"
338 9 ,//"writer_WordStar_2000_Rel_35_W4W"
339 4 ,//"writer_WordStar_33x_W4W"
340 4 ,//"writer_WordStar_345_W4W"
341 4 ,//"writer_WordStar_40_W4W"
342 4 ,//"writer_WordStar_50_W4W"
343 4 ,//"writer_WordStar_55_W4W"
344 4 ,//"writer_WordStar_60_W4W"
345 4 ,//"writer_WordStar_70_W4W"
346 62 ,//"writer_WriteNow_30_Macintosh_W4W"
347 13 ,//"writer_Writing_Assistant_W4W"
348 103,//"writer_XEROX_XIF_50_Illustrator_W4W"
349 103,//"writer_XEROX_XIF_50_W4W"
350 103,//"writer_XEROX_XIF_60_Color_Bitmap_W4W"
351 103,//"writer_XEROX_XIF_60_Res_Graphic_W4W"
352 17 ,//"writer_XyWrite_Win_10_W4W"
353 17 ,//"writer_XyWrite_III_W4W"
354 17 ,//"writer_XyWrite_IIIP_W4W"
355 17 ,//"writer_XyWrite_IV_W4W"
356 17 ,//"writer_XyWrite_Sig_Win_W4W"
357 17 //"writer_XyWrite_Signature_W4W"
360 /*-- 06.03.2006 14:48:00---------------------------------------------------
362 -----------------------------------------------------------------------*/
363 #ifndef WNT
364 //Same as osl::Module, except will search for its modules in the filter subdir
365 class filterModule : public osl::Module
367 public:
368 sal_Bool filterLoad(String &rStr);
371 extern "C" { static void SAL_CALL thisModule() {} }
373 sal_Bool filterModule::filterLoad(String &rStr)
375 sal_Bool bRet=sal_False;
376 SvtPathOptions aOpt;
377 if (aOpt.SearchFile(rStr, SvtPathOptions::PATH_FILTER))
379 rtl::OUString aPathURL;
380 osl::FileBase::getFileURLFromSystemPath(rtl::OUString(rStr),aPathURL);
381 bRet = loadRelative(&thisModule, aPathURL);
383 return bRet;
386 #endif
387 USHORT AutoDetec( const String& rFileName, USHORT & rVersion )
389 ByteString aFileNm( rFileName, ::gsl_getSystemTextEncoding() );
390 USHORT nFileType = 0;
392 #if defined( WNT )
394 typedef int (FAR PASCAL *FNautorec)( LPSTR, int, LPINT );
396 String aAutoRecDLL(RTL_CONSTASCII_STRINGPARAM("autorec.dll"));
397 SvtPathOptions aOpt;
398 if( !aOpt.SearchFile( aAutoRecDLL, SvtPathOptions::PATH_FILTER ))
399 return 0;
401 ByteString sAutoRecDllNm( aAutoRecDLL, ::gsl_getSystemTextEncoding() );
402 HANDLE hDLL = LoadLibrary( (LPSTR)sAutoRecDllNm.GetBuffer() );
403 if( hDLL >= (HANDLE)HINSTANCE_ERROR )
405 FNautorec fnAutorec = (FNautorec)GetProcAddress( (HINSTANCE)hDLL,
406 (LPSTR)"autorec" );
408 long nVersion = 0;
409 if( fnAutorec )
410 nFileType = (*fnAutorec)( (LPSTR)aFileNm.GetBuffer(),
412 (LPINT)&nVersion );
413 rVersion = (USHORT)nVersion;
414 FreeLibrary( (HINSTANCE)hDLL );
416 #else
417 //This is the nice modern code, the other stuff is a bit awful, but for
418 //some reason the different platforms had different argument lists from
419 //eachother, so we can't have super clean code :-(
420 filterModule aAutoRec;
421 String aTmpStr(RTL_CONSTASCII_STRINGPARAM((SVLIBRARY("autorec"))));
422 if (aAutoRec.filterLoad(aTmpStr))
424 typedef int (*autorec_t)(const char*, int*);
425 if (autorec_t autorec = (autorec_t)aAutoRec.getSymbol(String::CreateFromAscii("autorec")))
427 int nVersion;
428 if ((nFileType = (USHORT)autorec(aFileNm.GetBuffer(), &nVersion)))
429 rVersion = (USHORT)nVersion;
432 #endif
434 if( nFileType == 31 ) // Autorec-Bug umpopeln: Eine ASCII-Datei, die nur
435 nFileType = 1; // aus sehr vielen CRs besteht,
436 // wird als VAX Mass-11 erkannt
438 return nFileType == (USHORT)-1 ? 0 : nFileType;
441 bool checkFormat( SvStream* pStream, ::rtl::OUString& rTypeName, ::rtl::OUString& rURL, bool bCheckAll )
443 sal_Char aBuffer[4098];
444 if( pStream && !pStream->GetError() )
446 const ULONG nMaxRead = sizeof(aBuffer) - 2;
447 pStream->Seek(STREAM_SEEK_TO_BEGIN);
448 ULONG nBytesRead = pStream->Read(aBuffer, nMaxRead);
449 pStream->Seek(STREAM_SEEK_TO_BEGIN);
450 if (nBytesRead <= nMaxRead)
452 aBuffer[nBytesRead] = '\0';
453 aBuffer[nBytesRead+1] = '\0';
454 if (nBytesRead & 0x00000001)
455 aBuffer[nBytesRead+2] = '\0';
458 else
459 return false;
460 // clear type name in case nothing gets detected
461 ::rtl::OUString aName( rTypeName );
462 rTypeName = ::rtl::OUString();
464 const sal_Char __FAR_DATA FILTER_SWG[] = "SWG";
465 if ( bCheckAll || aName.equalsAsciiL( aFileTypeList[0].Type, aFileTypeList[0].Length ) )
467 // StarWriter 1.0
468 if ( 0 == strncmp( FILTER_SWG, aBuffer, 3 ) &&
469 '1' == *(aBuffer + 3) )
471 rTypeName = ::rtl::OUString::createFromAscii( aFileTypeList[0].Type );
474 if ( bCheckAll || aName.equalsAsciiL( aFileTypeList[1].Type, aFileTypeList[1].Length ) )
476 // StarWriter 2.0
477 if( 0 == strncmp( FILTER_SWG, aBuffer, 3 ) &&
478 '1' != *(aBuffer + 3) )
480 rTypeName = ::rtl::OUString::createFromAscii( aFileTypeList[1].Type );
483 if ( bCheckAll || aName.equalsAsciiL( aFileTypeList[2].Type, aFileTypeList[2].Length ) )
485 // StarWriter DOS
486 sal_Char __READONLY_DATA sSw6_FormatStt[] = ".\\\\\\ WRITER ";
487 sal_Char __READONLY_DATA sSw6_FormatEnd[] = " \\\\\\";
490 if ( 0 == strncmp( sSw6_FormatStt, aBuffer, 12 ) &&
491 0 == strncmp( sSw6_FormatEnd, aBuffer + 12 + 1, 4 ))
493 rTypeName = ::rtl::OUString::createFromAscii( aFileTypeList[2].Type );
496 if ( bCheckAll || aName.equalsAsciiL( aFileTypeList[3].Type, aFileTypeList[3].Length ) )
498 // writer_Lotus_1_2_3_10_DOS_StarWriter
499 if ( 0 == aBuffer[0] && 0 == aBuffer[1] &&
500 2 == aBuffer[2] && 0 == aBuffer[3] &&
501 ( 4 == aBuffer[4] || 6 == aBuffer[4] ) && 4 == aBuffer[5])
503 rTypeName = ::rtl::OUString::createFromAscii( aFileTypeList[3].Type );
506 if ( bCheckAll || aName.equalsAsciiL( aFileTypeList[4].Type, aFileTypeList[4].Length ) )
508 // writer_Lotus_1_2_3_10_WIN_StarWriter
509 if ( 0 == aBuffer[0] && 0 == aBuffer[1] &&
510 2 == aBuffer[2] && 0 == aBuffer[3] &&
511 ( 4 == aBuffer[4] || 6 == aBuffer[4] ) && 4 == aBuffer[5])
513 rTypeName = ::rtl::OUString::createFromAscii( aFileTypeList[4].Type );
516 //check for W4W at the end of the type name
517 if( rURL.getLength() && (bCheckAll || aName.getLength() > 4 &&
518 String(aName).Copy( xub_StrLen(aName.getLength()) - 4, 4 ).EqualsAscii( "_W4W" )))
519 // aName.equalsAsciiL( aFileTypeList[5].Type, aFileTypeList[5].Length )) )
521 // W4W
522 ::rtl::OUString sFileName = INetURLObject( rURL ).getFSysPath(INetURLObject::FSYS_DETECT);
523 if(sFileName.getLength())
525 //Ami Pro: 0x021
526 USHORT nVersion, nW4WId = AutoDetec( sFileName, nVersion );
527 if(nW4WId > 1)
529 //find Id in aW4WIdentifier and compare to the appropriate filter name
530 for(sal_Int8 nIdentifier = 0; nIdentifier < nW4WFilterCount; ++nIdentifier)
532 if(aW4WIdentifier[nIdentifier] == nW4WId)
534 ::rtl::OUString sTemp = ::rtl::OUString::createFromAscii( aFileTypeList[nIdentifier + nW4WStartOffset].Type );
535 if(!aName.getLength() || aName == sTemp)
537 rTypeName = sTemp;
538 break;
546 return (rTypeName.getLength() != 0);
549 BinFilterDetect::BinFilterDetect( const Reference < ::com::sun::star::lang::XMultiServiceFactory >& xFactory )
550 : m_xFact( xFactory )
554 BinFilterDetect::~BinFilterDetect()
558 ::rtl::OUString SAL_CALL BinFilterDetect::detect( ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& lDescriptor ) throw( ::com::sun::star::uno::RuntimeException )
560 ::vos::OGuard aGuard( Application::GetSolarMutex() );
562 // create MediaDescriptor
563 comphelper::MediaDescriptor aMedium( lDescriptor );
565 // extract preselected type or filter
566 ::rtl::OUString aTypeName, aPreselectedFilterName, aFilterName, aFileName;
567 aTypeName = aMedium.getUnpackedValueOrDefault(comphelper::MediaDescriptor::PROP_TYPENAME() , ::rtl::OUString() );
568 aFilterName = aMedium.getUnpackedValueOrDefault(comphelper::MediaDescriptor::PROP_FILTERNAME(), ::rtl::OUString() );
569 aFileName = aMedium.getUnpackedValueOrDefault(comphelper::MediaDescriptor::PROP_URL() , ::rtl::OUString() );
571 // open stream
572 aMedium.addInputStream();
573 Reference < com::sun::star::io::XInputStream > xInputStream = aMedium.getUnpackedValueOrDefault(comphelper::MediaDescriptor::PROP_INPUTSTREAM(), Reference < com::sun::star::io::XInputStream >() );
575 // no detection without stream.
576 // URL was used already to open stream ... so no further chance to get one.
577 if ( ! xInputStream.is() )
578 return ::rtl::OUString();
582 // get type for preselected filter (will overwrite a possible TypeName)
583 Reference< ::com::sun::star::container::XNameAccess> xFilters ( m_xFact->createInstance( DEFINE_CONST_UNICODE( "com.sun.star.document.FilterFactory" ) ), UNO_QUERY_THROW );
584 if ( aPreselectedFilterName.getLength() )
588 ::comphelper::SequenceAsHashMap( xFilters->getByName( aPreselectedFilterName ) )[DEFINE_CONST_UNICODE("Type")] >>= aTypeName;
590 catch ( com::sun::star::uno::Exception& )
592 // filter name might be wrong
593 aPreselectedFilterName = ::rtl::OUString();
597 // get ClipboardFormat from Storage
598 SvStream* pStream = ::utl::UcbStreamHelper::CreateStream( xInputStream );
599 SotStorageRef aStor = new SotStorage( pStream, FALSE );
600 if ( !aStor->GetError() )
602 // check for the OLE-storage based formats
603 sal_Int32 nClipId = aStor->GetFormat();
604 ::rtl::OUString aFormatName = SotExchange::GetFormatName( nClipId );
606 // check against preselected type
607 ::rtl::OUString aSelectedFormatName;
608 Reference< ::com::sun::star::container::XNameAccess > xTypes ( m_xFact->createInstance( DEFINE_CONST_UNICODE( "com.sun.star.document.TypeDetection" ) ), UNO_QUERY_THROW );
609 if ( aTypeName.getLength() )
613 ::comphelper::SequenceAsHashMap( xTypes->getByName( aTypeName ) )[DEFINE_CONST_UNICODE("ClipboardFormat")] >>= aSelectedFormatName;
615 catch ( com::sun::star::uno::Exception& )
617 // type name might be wrong
618 aTypeName = ::rtl::OUString();
622 // if preselected format doesn't fit check the other ones
623 if ( aSelectedFormatName != aFormatName )
625 // no type detected so far because preselected one didn't match
626 aTypeName = ::rtl::OUString();
628 // check if template type is wanted (template and "normal" document share the MediaType)
629 // a template type will be detected only if the file extension is "vor" (how else?!)
630 INetURLObject aObj( aFileName );
631 sal_Bool bIsTemplate = ( aObj.getExtension().equalsAscii("vor") );
633 // get possible types
634 Reference< ::com::sun::star::container::XContainerQuery > xTypeCFG ( xTypes, UNO_QUERY_THROW );
635 Sequence < com::sun::star::beans::NamedValue > aSeq(1);
636 aSeq[0].Name = ::rtl::OUString::createFromAscii("ClipboardFormat");
637 aSeq[0].Value <<= aFormatName;
638 Reference < com::sun::star::container::XEnumeration > xEnum = xTypeCFG->createSubSetEnumerationByProperties( aSeq );
639 while ( xEnum->hasMoreElements() )
641 Sequence < ::rtl::OUString > aExtensions;
642 ::comphelper::SequenceAsHashMap aHashedProps( xEnum->nextElement() );
643 aHashedProps[DEFINE_CONST_UNICODE("ClipboardFormat")] >>= aSelectedFormatName;
644 aHashedProps[DEFINE_CONST_UNICODE("Extensions")] >>= aExtensions;
645 if ( aSelectedFormatName == aFormatName )
647 // check wether this type specifies a template
648 sal_Bool bIsTemplateType = sal_False;
649 for ( sal_Int32 n=0; n<aExtensions.getLength(); n++ )
650 if ( aExtensions[n].equalsAscii("vor") )
651 bIsTemplateType = sal_True;
653 if ( bIsTemplateType != bIsTemplate )
654 // return it only if the file has the template extension (see comment above)
655 continue;
657 // get the type name from the properties
658 aHashedProps[DEFINE_CONST_UNICODE("Name")] >>= aTypeName;
659 break;
663 else
664 aFilterName = aPreselectedFilterName;
666 else
668 // check for the stream based formats
669 if ( checkFormat( pStream, aTypeName, aFileName, FALSE ) )
670 aFilterName = aPreselectedFilterName;
671 else
672 checkFormat( pStream, aTypeName, aFileName, TRUE );
675 DELETEZ( pStream );
677 catch ( com::sun::star::uno::Exception &)
679 // in case something goes wrong with type detection or filter configuration
680 aTypeName = ::rtl::OUString();
683 /* #i71829# Dont search for any suitable filter during deep detection.
684 A detection service is used to find a suitable type - not filter.
685 Search for a filter is done outside ... recognizing preferred flags;
686 user preselection and some other things too.
689 // only return a type name if it matches to the valid ones
690 // Because stripped binfilter detect EVERY format, which was known before
691 // code was changed ... it can happen that typename represent a format not realy
692 // supported by binfilter component.
693 sal_Bool bSupportedType = sal_False;
694 if ( aTypeName.getLength() )
696 sal_Int32 i = 0;
697 sal_Int32 c = nFileTypeCount;
698 for (i=0; i<c; i++)
700 if ( aTypeName.equalsAsciiL( aFileTypeList[i].Type, aFileTypeList[i].Length ) )
702 bSupportedType = true;
703 break;
708 if ( bSupportedType )
709 aMedium[comphelper::MediaDescriptor::PROP_TYPENAME()] <<= aTypeName;
710 else
711 aTypeName = ::rtl::OUString();
713 lDescriptor = aMedium.getAsConstPropertyValueList();
715 return aTypeName;
718 SFX_IMPL_SINGLEFACTORY( BinFilterDetect )
720 /* XServiceInfo */
721 UNOOUSTRING SAL_CALL BinFilterDetect::getImplementationName() throw( UNORUNTIMEEXCEPTION )
723 return impl_getStaticImplementationName();
726 /* XServiceInfo */
727 sal_Bool SAL_CALL BinFilterDetect::supportsService( const UNOOUSTRING& sServiceName ) throw( UNORUNTIMEEXCEPTION )
729 UNOSEQUENCE< UNOOUSTRING > seqServiceNames = getSupportedServiceNames();
730 const UNOOUSTRING* pArray = seqServiceNames.getConstArray();
731 for ( sal_Int32 nCounter=0; nCounter<seqServiceNames.getLength(); nCounter++ )
733 if ( pArray[nCounter] == sServiceName )
735 return sal_True ;
738 return sal_False ;
741 /* XServiceInfo */
742 UNOSEQUENCE< UNOOUSTRING > SAL_CALL BinFilterDetect::getSupportedServiceNames() throw( UNORUNTIMEEXCEPTION )
744 return impl_getStaticSupportedServiceNames();
747 /* Helper for XServiceInfo */
748 UNOSEQUENCE< UNOOUSTRING > BinFilterDetect::impl_getStaticSupportedServiceNames()
750 UNOMUTEXGUARD aGuard( UNOMUTEX::getGlobalMutex() );
751 UNOSEQUENCE< UNOOUSTRING > seqServiceNames( 1 );
752 seqServiceNames.getArray() [0] = UNOOUSTRING::createFromAscii( "com.sun.star.frame.ExtendedTypeDetection" );
753 return seqServiceNames ;
756 /* Helper for XServiceInfo */
757 UNOOUSTRING BinFilterDetect::impl_getStaticImplementationName()
759 return UNOOUSTRING::createFromAscii( "com.sun.star.comp.sfx2.BinaryFormatDetector" );
762 /* Helper for registry */
763 UNOREFERENCE< UNOXINTERFACE > SAL_CALL BinFilterDetect::impl_createInstance( const UNOREFERENCE< UNOXMULTISERVICEFACTORY >& xServiceManager ) throw( UNOEXCEPTION )
765 return UNOREFERENCE< UNOXINTERFACE >( *new BinFilterDetect( xServiceManager ) );
769 extern "C" {
771 void SAL_CALL component_getImplementationEnvironment( const sal_Char** ppEnvironmentTypeName ,
772 uno_Environment** ppEnvironment )
774 *ppEnvironmentTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME ;
777 sal_Bool SAL_CALL component_writeInfo( void* pServiceManager ,
778 void* pRegistryKey )
780 ::com::sun::star::uno::Reference< XRegistryKey > xKey( reinterpret_cast< XRegistryKey* >( pRegistryKey ) ) ;
782 // Eigentliche Implementierung und ihre Services registrieren
783 ::rtl::OUString aImpl;
784 ::rtl::OUString aTempStr;
785 ::rtl::OUString aKeyStr;
786 REFERENCE< XRegistryKey > xNewKey;
787 REFERENCE< XRegistryKey > xLoaderKey;
789 // frame loader
790 aImpl = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/"));
791 aImpl += ::binfilter::BinFilterDetect::impl_getStaticImplementationName();
793 aTempStr = aImpl;
794 aTempStr += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/UNO/SERVICES"));
795 xNewKey = xKey->createKey( aTempStr );
796 Sequence < ::rtl::OUString > aServices = ::binfilter::BinFilterDetect::impl_getStaticSupportedServiceNames();
797 sal_Int32 nCount = aServices.getLength();
798 for ( sal_Int16 i=0; i<nCount; i++ )
799 xNewKey->createKey( aServices.getConstArray()[i] );
801 return sal_True;
804 void* SAL_CALL component_getFactory( const sal_Char* pImplementationName ,
805 void* pServiceManager ,
806 void* pRegistryKey )
808 // Set default return value for this operation - if it failed.
809 void* pReturn = NULL ;
811 if (
812 ( pImplementationName != NULL ) &&
813 ( pServiceManager != NULL )
816 // Define variables which are used in following macros.
817 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleServiceFactory > xFactory ;
818 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xServiceManager( reinterpret_cast< ::com::sun::star::lang::XMultiServiceFactory* >( pServiceManager ) ) ;
820 //=============================================================================
821 // Add new macro line to handle new service.
823 // !!! ATTENTION !!!
824 // Write no ";" at end of line and dont forget "else" ! (see macro)
825 //=============================================================================
826 IF_NAME_CREATECOMPONENTFACTORY( ::binfilter::BinFilterDetect )
828 // Factory is valid - service was found.
829 if ( xFactory.is() )
831 xFactory->acquire();
832 pReturn = xFactory.get();
835 // Return with result of this operation.
836 return pReturn ;
838 } // extern "C"