1 //Implementierung der Klasse RegistrationContextInformation. 2 3 #include <assert.h> 4 #include "registrationcontextinformation.hxx" 5 #include "msihelper.hxx" 6 7 #define WINDOWS_LEAN_AND_MEAN 8 #include <windows.h> 9 #include <assert.h> 10 #include <algorithm> 11 12 namespace /* private */ 13 { 14 const int MAX_REGKEY_LENGTH_WIN9X = 16300; 15 } 16 17 RegistrationContextInformation::RegistrationContextInformation(MSIHANDLE hMsi, const std::wstring& OpenOfficeExecutablePath) : 18 msihandle_(hMsi), 19 m_IsWin9x(true), 20 m_OOExecPath(OpenOfficeExecutablePath) 21 { 22 OSVERSIONINFOA osverinfo; 23 ZeroMemory(&osverinfo, sizeof(osverinfo)); 24 osverinfo.dwOSVersionInfoSize = sizeof(osverinfo); 25 GetVersionExA(&osverinfo); 26 27 m_IsWin9x = (osverinfo.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS); 28 assert(m_OOExecPath.length()); 29 ExtractOpenOfficeExecNameFromPath(); 30 } 31 32 std::wstring RegistrationContextInformation::GetWordDocumentDisplayName() const 33 { 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; 39 } 40 41 std::wstring RegistrationContextInformation::GetWordDocumentFileExtension() const 42 { 43 return std::wstring(TEXT(".doc")); 44 } 45 46 std::wstring RegistrationContextInformation::GetWordDocumentDefaultIconEntry() const 47 { 48 return m_OOExecPath + std::wstring(TEXT(",1")); 49 } 50 51 std::wstring RegistrationContextInformation::GetWordDocumentDefaultShellCommand() const 52 { 53 return std::wstring(TEXT("open")); 54 } 55 56 std::wstring RegistrationContextInformation::GetWordTemplateDisplayName() const 57 { 58 std::wstring str; 59 GetMsiProp(msihandle_, TEXT("STR_MS_WORD_TEMPLATE"), str); 60 if (m_IsWin9x && !IsConvertableToAnsi(str)) 61 str = TEXT("Microsoft Word Template"); 62 return str; 63 } 64 65 std::wstring RegistrationContextInformation::GetWordTemplateFileExtension() const 66 { 67 return std::wstring(TEXT(".dot")); 68 } 69 70 std::wstring RegistrationContextInformation::GetWordTemplateDefaultIconEntry() const 71 { 72 return m_OOExecPath + std::wstring(TEXT(",2")); 73 } 74 75 std::wstring RegistrationContextInformation::GetWordTemplateDefaultShellCommand() const 76 { 77 return std::wstring(TEXT("new")); 78 } 79 80 std::wstring RegistrationContextInformation::GetRtfDocumentDisplayName() const 81 { 82 std::wstring str; 83 GetMsiProp(msihandle_, TEXT("STR_RTF_DOCUMENT"), str); 84 if (m_IsWin9x && !IsConvertableToAnsi(str)) 85 str = TEXT("Rich Text Document"); 86 return str; 87 } 88 89 std::wstring RegistrationContextInformation::GetRtfDocumentFileExtension() const 90 { 91 return std::wstring(TEXT(".rtf")); 92 } 93 94 std::wstring RegistrationContextInformation::GetRtfDocumentDefaultIconEntry() const 95 { 96 return m_OOExecPath + std::wstring(TEXT(",1")); 97 } 98 99 std::wstring RegistrationContextInformation::GetRtfDocumentDefaultShellCommand() const 100 { 101 return std::wstring(TEXT("open")); 102 } 103 104 std::wstring RegistrationContextInformation::GetExcelSheetDisplayName() const 105 { 106 std::wstring str; 107 GetMsiProp(msihandle_, TEXT("STR_MS_EXCEL_WORKSHEET"), str); 108 if (m_IsWin9x && !IsConvertableToAnsi(str)) 109 str = TEXT("Microsoft Excel Worksheet"); 110 return str; 111 } 112 113 std::wstring RegistrationContextInformation::GetExcelSheetFileExtension() const 114 { 115 return std::wstring(TEXT(".xls")); 116 } 117 118 std::wstring RegistrationContextInformation::GetExcelSheetDefaultIconEntry() const 119 { 120 return m_OOExecPath + std::wstring(TEXT(",3")); 121 } 122 123 std::wstring RegistrationContextInformation::GetExcelSheetDefaultShellCommand() const 124 { 125 return std::wstring(TEXT("open")); 126 } 127 128 std::wstring RegistrationContextInformation::GetExcelTemplateDisplayName() const 129 { 130 std::wstring str; 131 GetMsiProp(msihandle_, TEXT("STR_MS_EXCEL_TEMPLATE"), str); 132 if (m_IsWin9x && !IsConvertableToAnsi(str)) 133 str = TEXT("Microsoft Excel Template"); 134 return str; 135 } 136 137 std::wstring RegistrationContextInformation::GetExcelTemplateFileExtension() const 138 { 139 return std::wstring(TEXT(".xlt")); 140 } 141 142 std::wstring RegistrationContextInformation::GetExcelTemplateDefaultIconEntry() const 143 { 144 return m_OOExecPath + std::wstring(TEXT(",4")); 145 } 146 147 std::wstring RegistrationContextInformation::GetExcelTemplateDefaultShellCommand() const 148 { 149 return std::wstring(TEXT("new")); 150 } 151 152 std::wstring RegistrationContextInformation::GetPowerPointDocumentDisplayName() const 153 { 154 std::wstring str; 155 GetMsiProp(msihandle_, TEXT("STR_MS_POWERPOINT_PRESENTATION"), str); 156 if (m_IsWin9x && !IsConvertableToAnsi(str)) 157 str = TEXT("Microsoft PowerPoint Presentation"); 158 return str; 159 } 160 161 std::wstring RegistrationContextInformation::GetPowerPointDocumentFileExtension() const 162 { 163 return std::wstring(TEXT(".ppt")); 164 } 165 166 std::wstring RegistrationContextInformation::GetPowerPointDocumentDefaultIconEntry() const 167 { 168 return m_OOExecPath + std::wstring(TEXT(",7")); 169 } 170 171 std::wstring RegistrationContextInformation::GetPowerPointDocumentDefaultShellCommand() const 172 { 173 return std::wstring(TEXT("open")); 174 } 175 176 std::wstring RegistrationContextInformation::GetPowerPointTemplateDisplayName() const 177 { 178 std::wstring str; 179 GetMsiProp(msihandle_, TEXT("STR_MS_POWERPOINT_TEMPLATE"), str); 180 if (m_IsWin9x && !IsConvertableToAnsi(str)) 181 str = TEXT("Microsoft PowerPoint Template"); 182 return str; 183 } 184 185 std::wstring RegistrationContextInformation::GetPowerPointTemplateFileExtension() const 186 { 187 return std::wstring(TEXT(".pot")); 188 } 189 190 std::wstring RegistrationContextInformation::GetPowerPointTemplateDefaultIconEntry() const 191 { 192 return m_OOExecPath + std::wstring(TEXT(",8")); 193 } 194 195 std::wstring RegistrationContextInformation::GetPowerPointTemplateDefaultShellCommand() const 196 { 197 return std::wstring(TEXT("new")); 198 } 199 200 std::wstring RegistrationContextInformation::GetPowerPointShowDisplayName() const 201 { 202 std::wstring str; 203 GetMsiProp(msihandle_, TEXT("STR_MS_POWERPOINT_SHOW"), str); 204 if (m_IsWin9x && !IsConvertableToAnsi(str)) 205 str = TEXT("Microsoft PowerPoint Show"); 206 return str; 207 } 208 209 std::wstring RegistrationContextInformation::GetPowerPointShowFileExtension() const 210 { 211 return std::wstring(TEXT(".pps")); 212 } 213 214 std::wstring RegistrationContextInformation::GetPowerPointShowDefaultIconEntry() const 215 { 216 return m_OOExecPath + std::wstring(TEXT(",7")); 217 } 218 219 std::wstring RegistrationContextInformation::GetPowerPointShowDefaultShellCommand() const 220 { 221 return std::wstring(TEXT("open")); 222 } 223 224 //---------------------------------------------- 225 /** The string for the "New" command that should appear 226 in the Explorer context menu when someone right 227 clicks a Microsoft document 228 */ 229 std::wstring RegistrationContextInformation::ShellNewCommandDisplayName() const 230 { 231 std::wstring str; 232 GetMsiProp(msihandle_, TEXT("STR_NEW_DISPLAY_NAME"), str); 233 std::wstring::size_type idx = str.find(TEXT("~")); 234 235 if(std::wstring::npos != idx) 236 str.replace(idx, 1, TEXT("&")); 237 238 if (m_IsWin9x && !IsConvertableToAnsi(str)) 239 str = TEXT("&New"); 240 241 return str; 242 } 243 244 /** The string for the "Edit" command that should 245 appear in the Explorer context menu when someone 246 right clicks a document 247 */ 248 std::wstring RegistrationContextInformation::ShellEditCommandDisplayName() const 249 { 250 std::wstring str; 251 GetMsiProp(msihandle_, TEXT("STR_EDIT"), str); 252 std::wstring::size_type idx = str.find(TEXT("~")); 253 254 if(std::wstring::npos != idx) 255 str.replace(idx, 1, TEXT("&")); 256 257 if (m_IsWin9x && !IsConvertableToAnsi(str)) 258 str = TEXT("&Edit"); 259 260 return str; 261 } 262 263 std::wstring RegistrationContextInformation::GetOpenOfficeFriendlyAppName() const 264 { 265 std::wstring str; 266 GetMsiProp(msihandle_, TEXT("ProductName"), str); 267 return str; 268 } 269 270 std::wstring RegistrationContextInformation::GetOpenOfficeExecutablePath() const 271 { 272 return m_OOExecPath; 273 } 274 275 //---------------------------------------------- 276 /** The name of the executable (currently "soffice.exe" 277 but may change in the future, who knows) */ 278 std::wstring RegistrationContextInformation::GetOpenOfficeExecutableName() const 279 { 280 return m_OOExecName; 281 } 282 283 /** A command line for the specified shell command */ 284 std::wstring RegistrationContextInformation::GetOpenOfficeCommandline(SHELL_COMMAND ShellCommand, 285 OFFICE_APPLICATION OfficeApp) const 286 { 287 // quote the path to OpenOffice, this is important 288 // for Windows 9x 289 std::wstring cmd_line = std::wstring(TEXT("\"")) + m_OOExecPath + std::wstring(TEXT("\"")); 290 291 switch( OfficeApp ) 292 { 293 case Writer: 294 cmd_line += std::wstring( TEXT( " -writer" ) ); 295 break; 296 case Calc: 297 cmd_line += std::wstring( TEXT( " -calc" ) ); 298 break; 299 case Impress: 300 cmd_line += std::wstring( TEXT( " -impress" ) ); 301 break; 302 case Office: // default to std command line 303 break; 304 // default: no default to find new added enums at compile time 305 } 306 switch(ShellCommand) 307 { 308 case New: 309 cmd_line += std::wstring(TEXT(" -n \"%1\"")); 310 break; 311 case Open: 312 cmd_line += std::wstring(TEXT(" -o \"%1\"")); 313 break; 314 case Print: 315 cmd_line += std::wstring(TEXT(" -p \"%1\"")); 316 break; 317 case Printto: 318 cmd_line += std::wstring(TEXT(" -pt \"%2\" \"%1\"")); 319 break; 320 // default: no default to find new added enums at compile time 321 } 322 return cmd_line; 323 } 324 325 bool RegistrationContextInformation::IsConvertableToAnsi(const std::wstring& String) const 326 { 327 char buff[MAX_REGKEY_LENGTH_WIN9X]; 328 BOOL bUsedDefChar = 0; 329 330 if (String.length() > 0) 331 { 332 WideCharToMultiByte( 333 CP_ACP, 334 WC_COMPOSITECHECK | WC_DEFAULTCHAR, 335 String.c_str(), 336 static_cast<int>(String.length()), 337 buff, 338 sizeof(buff), 339 NULL, 340 &bUsedDefChar); 341 } 342 return !bUsedDefChar; 343 } 344 345 void RegistrationContextInformation::ExtractOpenOfficeExecNameFromPath() 346 { 347 std::wstring::size_type idx = m_OOExecPath.find_last_of(TEXT('\\')); 348 assert(idx != std::wstring::npos); // assert valid path 349 m_OOExecName = m_OOExecPath.substr(idx + 1); 350 } 351 352