1 //Implementierung der Klasse RegistrationContextInformation.
4 #include "registrationcontextinformation.hxx"
5 #include "msihelper.hxx"
7 #define WINDOWS_LEAN_AND_MEAN
12 namespace /* private */
14 const int MAX_REGKEY_LENGTH_WIN9X
= 16300;
17 RegistrationContextInformation::RegistrationContextInformation(MSIHANDLE hMsi
, const std::wstring
& OpenOfficeExecutablePath
) :
20 m_OOExecPath(OpenOfficeExecutablePath
)
22 OSVERSIONINFOA osverinfo
;
23 ZeroMemory(&osverinfo
, sizeof(osverinfo
));
24 osverinfo
.dwOSVersionInfoSize
= sizeof(osverinfo
);
25 GetVersionExA(&osverinfo
);
27 m_IsWin9x
= (osverinfo
.dwPlatformId
== VER_PLATFORM_WIN32_WINDOWS
);
28 assert(m_OOExecPath
.length());
29 ExtractOpenOfficeExecNameFromPath();
32 std::wstring
RegistrationContextInformation::GetWordDocumentDisplayName() const
35 GetMsiProp(msihandle_
, TEXT("STR_MS_WORD_DOCUMENT"), str
);
36 if (m_IsWin9x
&& !IsConvertableToAnsi(str
))
37 str
= TEXT("Microsoft Word Document");
41 std::wstring
RegistrationContextInformation::GetWordDocumentFileExtension() const
43 return std::wstring(TEXT(".doc"));
46 std::wstring
RegistrationContextInformation::GetWordDocumentDefaultIconEntry() const
48 return m_OOExecPath
+ std::wstring(TEXT(",1"));
51 std::wstring
RegistrationContextInformation::GetWordDocumentDefaultShellCommand() const
53 return std::wstring(TEXT("open"));
56 std::wstring
RegistrationContextInformation::GetMOOXWordDocumentDisplayName() const
59 str
= TEXT("Microsoft Word 2007 Document");
63 std::wstring
RegistrationContextInformation::GetMOOXWordDocumentFileExtension() const
65 return std::wstring(TEXT(".docx"));
68 std::wstring
RegistrationContextInformation::GetWordTemplateDisplayName() const
71 GetMsiProp(msihandle_
, TEXT("STR_MS_WORD_TEMPLATE"), str
);
72 if (m_IsWin9x
&& !IsConvertableToAnsi(str
))
73 str
= TEXT("Microsoft Word Template");
77 std::wstring
RegistrationContextInformation::GetWordTemplateFileExtension() const
79 return std::wstring(TEXT(".dot"));
82 std::wstring
RegistrationContextInformation::GetWordTemplateDefaultIconEntry() const
84 return m_OOExecPath
+ std::wstring(TEXT(",2"));
87 std::wstring
RegistrationContextInformation::GetWordTemplateDefaultShellCommand() const
89 return std::wstring(TEXT("new"));
92 std::wstring
RegistrationContextInformation::GetRtfDocumentDisplayName() const
95 GetMsiProp(msihandle_
, TEXT("STR_RTF_DOCUMENT"), str
);
96 if (m_IsWin9x
&& !IsConvertableToAnsi(str
))
97 str
= TEXT("Rich Text Document");
101 std::wstring
RegistrationContextInformation::GetRtfDocumentFileExtension() const
103 return std::wstring(TEXT(".rtf"));
106 std::wstring
RegistrationContextInformation::GetRtfDocumentDefaultIconEntry() const
108 return m_OOExecPath
+ std::wstring(TEXT(",1"));
111 std::wstring
RegistrationContextInformation::GetRtfDocumentDefaultShellCommand() const
113 return std::wstring(TEXT("open"));
116 std::wstring
RegistrationContextInformation::GetExcelSheetDisplayName() const
119 GetMsiProp(msihandle_
, TEXT("STR_MS_EXCEL_WORKSHEET"), str
);
120 if (m_IsWin9x
&& !IsConvertableToAnsi(str
))
121 str
= TEXT("Microsoft Excel Worksheet");
125 std::wstring
RegistrationContextInformation::GetExcelSheetFileExtension() const
127 return std::wstring(TEXT(".xls"));
130 std::wstring
RegistrationContextInformation::GetExcelSheetDefaultIconEntry() const
132 return m_OOExecPath
+ std::wstring(TEXT(",3"));
135 std::wstring
RegistrationContextInformation::GetExcelSheetDefaultShellCommand() const
137 return std::wstring(TEXT("open"));
140 std::wstring
RegistrationContextInformation::GetMOOXExcelSheetDisplayName() const
143 str
= TEXT("Microsoft Excel 2007 Spreadsheet");
147 std::wstring
RegistrationContextInformation::GetMOOXExcelSheetFileExtension() const
149 return std::wstring(TEXT(".xlsx"));
152 std::wstring
RegistrationContextInformation::GetExcelTemplateDisplayName() const
155 GetMsiProp(msihandle_
, TEXT("STR_MS_EXCEL_TEMPLATE"), str
);
156 if (m_IsWin9x
&& !IsConvertableToAnsi(str
))
157 str
= TEXT("Microsoft Excel Template");
161 std::wstring
RegistrationContextInformation::GetExcelTemplateFileExtension() const
163 return std::wstring(TEXT(".xlt"));
166 std::wstring
RegistrationContextInformation::GetExcelTemplateDefaultIconEntry() const
168 return m_OOExecPath
+ std::wstring(TEXT(",4"));
171 std::wstring
RegistrationContextInformation::GetExcelTemplateDefaultShellCommand() const
173 return std::wstring(TEXT("new"));
176 std::wstring
RegistrationContextInformation::GetPowerPointDocumentDisplayName() const
179 GetMsiProp(msihandle_
, TEXT("STR_MS_POWERPOINT_PRESENTATION"), str
);
180 if (m_IsWin9x
&& !IsConvertableToAnsi(str
))
181 str
= TEXT("Microsoft PowerPoint Presentation");
185 std::wstring
RegistrationContextInformation::GetPowerPointDocumentFileExtension() const
187 return std::wstring(TEXT(".ppt"));
190 std::wstring
RegistrationContextInformation::GetPowerPointDocumentDefaultIconEntry() const
192 return m_OOExecPath
+ std::wstring(TEXT(",7"));
195 std::wstring
RegistrationContextInformation::GetPowerPointDocumentDefaultShellCommand() const
197 return std::wstring(TEXT("open"));
200 std::wstring
RegistrationContextInformation::GetMOOXPowerPointDocumentDisplayName() const
203 str
= TEXT("Microsoft PowerPoint 2007 Presentation");
207 std::wstring
RegistrationContextInformation::GetMOOXPowerPointDocumentFileExtension() const
209 return std::wstring(TEXT(".pptx"));
212 std::wstring
RegistrationContextInformation::GetPowerPointTemplateDisplayName() const
215 GetMsiProp(msihandle_
, TEXT("STR_MS_POWERPOINT_TEMPLATE"), str
);
216 if (m_IsWin9x
&& !IsConvertableToAnsi(str
))
217 str
= TEXT("Microsoft PowerPoint Template");
221 std::wstring
RegistrationContextInformation::GetPowerPointTemplateFileExtension() const
223 return std::wstring(TEXT(".pot"));
226 std::wstring
RegistrationContextInformation::GetPowerPointTemplateDefaultIconEntry() const
228 return m_OOExecPath
+ std::wstring(TEXT(",8"));
231 std::wstring
RegistrationContextInformation::GetPowerPointTemplateDefaultShellCommand() const
233 return std::wstring(TEXT("new"));
236 std::wstring
RegistrationContextInformation::GetPowerPointShowDisplayName() const
239 GetMsiProp(msihandle_
, TEXT("STR_MS_POWERPOINT_SHOW"), str
);
240 if (m_IsWin9x
&& !IsConvertableToAnsi(str
))
241 str
= TEXT("Microsoft PowerPoint Show");
245 std::wstring
RegistrationContextInformation::GetPowerPointShowFileExtension() const
247 return std::wstring(TEXT(".pps"));
250 std::wstring
RegistrationContextInformation::GetPowerPointShowDefaultIconEntry() const
252 return m_OOExecPath
+ std::wstring(TEXT(",7"));
255 std::wstring
RegistrationContextInformation::GetPowerPointShowDefaultShellCommand() const
257 return std::wstring(TEXT("open"));
260 //----------------------------------------------
261 /** The string for the "New" command that should appear
262 in the Explorer context menu when someone right
263 clicks a Microsoft document
265 std::wstring
RegistrationContextInformation::ShellNewCommandDisplayName() const
268 GetMsiProp(msihandle_
, TEXT("STR_NEW_DISPLAY_NAME"), str
);
269 std::wstring::size_type idx
= str
.find(TEXT("~"));
271 if(std::wstring::npos
!= idx
)
272 str
.replace(idx
, 1, TEXT("&"));
274 if (m_IsWin9x
&& !IsConvertableToAnsi(str
))
280 /** The string for the "Edit" command that should
281 appear in the Explorer context menu when someone
282 right clicks a document
284 std::wstring
RegistrationContextInformation::ShellEditCommandDisplayName() const
287 GetMsiProp(msihandle_
, TEXT("STR_EDIT"), str
);
288 std::wstring::size_type idx
= str
.find(TEXT("~"));
290 if(std::wstring::npos
!= idx
)
291 str
.replace(idx
, 1, TEXT("&"));
293 if (m_IsWin9x
&& !IsConvertableToAnsi(str
))
299 std::wstring
RegistrationContextInformation::GetOpenOfficeFriendlyAppName() const
302 GetMsiProp(msihandle_
, TEXT("ProductName"), str
);
306 std::wstring
RegistrationContextInformation::GetOpenOfficeExecutablePath() const
311 //----------------------------------------------
312 /** The name of the executable (currently "soffice.exe"
313 but may change in the future, who knows) */
314 std::wstring
RegistrationContextInformation::GetOpenOfficeExecutableName() const
319 /** A command line for the specified shell command */
320 std::wstring
RegistrationContextInformation::GetOpenOfficeCommandline(SHELL_COMMAND ShellCommand
,
321 OFFICE_APPLICATION OfficeApp
) const
323 // quote the path to OpenOffice, this is important
325 std::wstring cmd_line
= std::wstring(TEXT("\"")) + m_OOExecPath
+ std::wstring(TEXT("\""));
330 cmd_line
+= std::wstring( TEXT( " -writer" ) );
333 cmd_line
+= std::wstring( TEXT( " -calc" ) );
336 cmd_line
+= std::wstring( TEXT( " -impress" ) );
338 case Office
: // default to std command line
340 // default: no default to find new added enums at compile time
345 cmd_line
+= std::wstring(TEXT(" -n \"%1\""));
348 cmd_line
+= std::wstring(TEXT(" -o \"%1\""));
351 cmd_line
+= std::wstring(TEXT(" -p \"%1\""));
354 cmd_line
+= std::wstring(TEXT(" -pt \"%2\" \"%1\""));
356 // default: no default to find new added enums at compile time
361 bool RegistrationContextInformation::IsConvertableToAnsi(const std::wstring
& String
) const
363 char buff
[MAX_REGKEY_LENGTH_WIN9X
];
364 BOOL bUsedDefChar
= 0;
366 if (String
.length() > 0)
370 WC_COMPOSITECHECK
| WC_DEFAULTCHAR
,
372 static_cast<int>(String
.length()),
378 return !bUsedDefChar
;
381 void RegistrationContextInformation::ExtractOpenOfficeExecNameFromPath()
383 std::wstring::size_type idx
= m_OOExecPath
.find_last_of(TEXT('\\'));
384 assert(idx
!= std::wstring::npos
); // assert valid path
385 m_OOExecName
= m_OOExecPath
.substr(idx
+ 1);