Update ooo320-m1
[ooovba.git] / setup_native / source / win32 / customactions / reg4msdoc / registrationcontextinformation.cxx
blobeb329a890eb31282622d2734d4680f1daf234288
1 //Implementierung der Klasse RegistrationContextInformation.
3 #include <assert.h>
4 #include "registrationcontextinformation.hxx"
5 #include "msihelper.hxx"
7 #define WINDOWS_LEAN_AND_MEAN
8 #include <windows.h>
9 #include <assert.h>
10 #include <algorithm>
12 namespace /* private */
14 const int MAX_REGKEY_LENGTH_WIN9X = 16300;
17 RegistrationContextInformation::RegistrationContextInformation(MSIHANDLE hMsi, const std::wstring& OpenOfficeExecutablePath) :
18 msihandle_(hMsi),
19 m_IsWin9x(true),
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
34 std::wstring str;
35 GetMsiProp(msihandle_, TEXT("STR_MS_WORD_DOCUMENT"), str);
36 if (m_IsWin9x && !IsConvertableToAnsi(str))
37 str = TEXT("Microsoft Word Document");
38 return str;
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
58 std::wstring str;
59 str = TEXT("Microsoft Word 2007 Document");
60 return str;
63 std::wstring RegistrationContextInformation::GetMOOXWordDocumentFileExtension() const
65 return std::wstring(TEXT(".docx"));
68 std::wstring RegistrationContextInformation::GetWordTemplateDisplayName() const
70 std::wstring str;
71 GetMsiProp(msihandle_, TEXT("STR_MS_WORD_TEMPLATE"), str);
72 if (m_IsWin9x && !IsConvertableToAnsi(str))
73 str = TEXT("Microsoft Word Template");
74 return str;
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
94 std::wstring str;
95 GetMsiProp(msihandle_, TEXT("STR_RTF_DOCUMENT"), str);
96 if (m_IsWin9x && !IsConvertableToAnsi(str))
97 str = TEXT("Rich Text Document");
98 return str;
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
118 std::wstring str;
119 GetMsiProp(msihandle_, TEXT("STR_MS_EXCEL_WORKSHEET"), str);
120 if (m_IsWin9x && !IsConvertableToAnsi(str))
121 str = TEXT("Microsoft Excel Worksheet");
122 return str;
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
142 std::wstring str;
143 str = TEXT("Microsoft Excel 2007 Spreadsheet");
144 return str;
147 std::wstring RegistrationContextInformation::GetMOOXExcelSheetFileExtension() const
149 return std::wstring(TEXT(".xlsx"));
152 std::wstring RegistrationContextInformation::GetExcelTemplateDisplayName() const
154 std::wstring str;
155 GetMsiProp(msihandle_, TEXT("STR_MS_EXCEL_TEMPLATE"), str);
156 if (m_IsWin9x && !IsConvertableToAnsi(str))
157 str = TEXT("Microsoft Excel Template");
158 return str;
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
178 std::wstring str;
179 GetMsiProp(msihandle_, TEXT("STR_MS_POWERPOINT_PRESENTATION"), str);
180 if (m_IsWin9x && !IsConvertableToAnsi(str))
181 str = TEXT("Microsoft PowerPoint Presentation");
182 return str;
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
202 std::wstring str;
203 str = TEXT("Microsoft PowerPoint 2007 Presentation");
204 return str;
207 std::wstring RegistrationContextInformation::GetMOOXPowerPointDocumentFileExtension() const
209 return std::wstring(TEXT(".pptx"));
212 std::wstring RegistrationContextInformation::GetPowerPointTemplateDisplayName() const
214 std::wstring str;
215 GetMsiProp(msihandle_, TEXT("STR_MS_POWERPOINT_TEMPLATE"), str);
216 if (m_IsWin9x && !IsConvertableToAnsi(str))
217 str = TEXT("Microsoft PowerPoint Template");
218 return str;
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
238 std::wstring str;
239 GetMsiProp(msihandle_, TEXT("STR_MS_POWERPOINT_SHOW"), str);
240 if (m_IsWin9x && !IsConvertableToAnsi(str))
241 str = TEXT("Microsoft PowerPoint Show");
242 return str;
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
267 std::wstring str;
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))
275 str = TEXT("&New");
277 return 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
286 std::wstring str;
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))
294 str = TEXT("&Edit");
296 return str;
299 std::wstring RegistrationContextInformation::GetOpenOfficeFriendlyAppName() const
301 std::wstring str;
302 GetMsiProp(msihandle_, TEXT("ProductName"), str);
303 return str;
306 std::wstring RegistrationContextInformation::GetOpenOfficeExecutablePath() const
308 return m_OOExecPath;
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
316 return m_OOExecName;
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
324 // for Windows 9x
325 std::wstring cmd_line = std::wstring(TEXT("\"")) + m_OOExecPath + std::wstring(TEXT("\""));
327 switch( OfficeApp )
329 case Writer:
330 cmd_line += std::wstring( TEXT( " -writer" ) );
331 break;
332 case Calc:
333 cmd_line += std::wstring( TEXT( " -calc" ) );
334 break;
335 case Impress:
336 cmd_line += std::wstring( TEXT( " -impress" ) );
337 break;
338 case Office: // default to std command line
339 break;
340 // default: no default to find new added enums at compile time
342 switch(ShellCommand)
344 case New:
345 cmd_line += std::wstring(TEXT(" -n \"%1\""));
346 break;
347 case Open:
348 cmd_line += std::wstring(TEXT(" -o \"%1\""));
349 break;
350 case Print:
351 cmd_line += std::wstring(TEXT(" -p \"%1\""));
352 break;
353 case Printto:
354 cmd_line += std::wstring(TEXT(" -pt \"%2\" \"%1\""));
355 break;
356 // default: no default to find new added enums at compile time
358 return cmd_line;
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)
368 WideCharToMultiByte(
369 CP_ACP,
370 WC_COMPOSITECHECK | WC_DEFAULTCHAR,
371 String.c_str(),
372 static_cast<int>(String.length()),
373 buff,
374 sizeof(buff),
375 NULL,
376 &bUsedDefChar);
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);