void COwnedLostItem::SetHandledViaNetscape() { m_nHandleMethod = OL_OTHER_APP; // Get the app's name. CString netscapeName; char buffer[_MAX_PATH+1]; ::GetModuleFileName(theApp.m_hInstance, buffer, _MAX_PATH); char *pSlash = ::strrchr(buffer, '\\'); netscapeName = (char*)(pSlash+1); netscapeName.MakeUpper(); // Get the app's directory. Adequate heuristic for version-checking Netscape CString directoryName(buffer); directoryName.MakeUpper(); // Special Internet Shortcut check if (IsInternetShortcut()) { CInternetShortcut internetShortcut; if (!internetShortcut.ShellSupport()) { m_nHandleMethod = OL_CURRENT_NETSCAPE; return; } CString fileClass = GetInternetShortcutFileClass(); SetHandleMethodViaFileClass(fileClass, netscapeName, directoryName); return; } CPtrList* allHelpers = &(CHelperApp::m_cplHelpers); for (POSITION pos = allHelpers->GetHeadPosition(); pos != NULL;) { CHelperApp* app = (CHelperApp*)allHelpers->GetNext(pos); CString helperMime(app->cd_item->ci.type); if (helperMime == m_csMimeType) { // Found the helper app. See if Netscape is truly handling this mime type. CString fileClass(app->strFileClass); if (fileClass != "") { SetHandleMethodViaFileClass(fileClass, netscapeName, directoryName); return; } else m_bBroken = TRUE; // Treat as if ignored. Don't want to pop up a dialog over this. if (app->how_handle == HANDLE_VIA_NETSCAPE) m_nHandleMethod = OL_CURRENT_NETSCAPE; else m_nHandleMethod = OL_OTHER_APP; return; } } m_bBroken = TRUE; // Didn't even find this mime type. Don't want to fool with it. }
// // FindURLFromLocalFile // // we are looking for a URL and couldn't find it, try again with looking for // a local file. If we have one, it may either be a normal file or an internet shortcut. // In both cases, however, we can get a URL (it will be a file:// url in the // local file case). // bool nsClipboard :: FindURLFromLocalFile ( IDataObject* inDataObject, UINT inIndex, void** outData, PRUint32* outDataLen ) { bool dataFound = false; nsresult loadResult = GetNativeDataOffClipboard(inDataObject, inIndex, GetFormat(kFileMime), nullptr, outData, outDataLen); if ( NS_SUCCEEDED(loadResult) && *outData ) { // we have a file path in |data|. Is it an internet shortcut or a normal file? const nsDependentString filepath(static_cast<PRUnichar*>(*outData)); nsCOMPtr<nsIFile> file; nsresult rv = NS_NewLocalFile(filepath, true, getter_AddRefs(file)); if (NS_FAILED(rv)) { nsMemory::Free(*outData); return dataFound; } if ( IsInternetShortcut(filepath) ) { nsMemory::Free(*outData); nsCAutoString url; ResolveShortcut( file, url ); if ( !url.IsEmpty() ) { // convert it to unicode and pass it out nsDependentString urlString(UTF8ToNewUnicode(url)); // the internal mozilla URL format, text/x-moz-url, contains // URL\ntitle. We can guess the title from the file's name. nsAutoString title; file->GetLeafName(title); // We rely on IsInternetShortcut check that file has a .url extension. title.SetLength(title.Length() - 4); if (title.IsEmpty()) title = urlString; *outData = ToNewUnicode(urlString + NS_LITERAL_STRING("\n") + title); *outDataLen = NS_strlen(static_cast<PRUnichar*>(*outData)) * sizeof(PRUnichar); dataFound = true; } } else { // we have a normal file, use some Necko objects to get our file path nsCAutoString urlSpec; NS_GetURLSpecFromFile(file, urlSpec); // convert it to unicode and pass it out nsMemory::Free(*outData); *outData = UTF8ToNewUnicode(urlSpec); *outDataLen = NS_strlen(static_cast<PRUnichar*>(*outData)) * sizeof(PRUnichar); dataFound = true; } // else regular file } return dataFound; } // FindURLFromLocalFile
// // FindURLFromLocalFile // // we are looking for a URL and couldn't find it, try again with looking for // a local file. If we have one, it may either be a normal file or an internet shortcut. // In both cases, however, we can get a URL (it will be a file:// url in the // local file case). // PRBool nsClipboard :: FindURLFromLocalFile ( IDataObject* inDataObject, UINT inIndex, void** outData, PRUint32* outDataLen ) { PRBool dataFound = PR_FALSE; nsresult loadResult = GetNativeDataOffClipboard(inDataObject, inIndex, GetFormat(kFileMime), outData, outDataLen); if ( NS_SUCCEEDED(loadResult) && *outData ) { // we have a file path in |data|. Is it an internet shortcut or a normal file? const nsDependentString filepath(static_cast<PRUnichar*>(*outData)); nsCOMPtr<nsILocalFile> file; nsresult rv = NS_NewLocalFile(filepath, PR_TRUE, getter_AddRefs(file)); if (NS_FAILED(rv)) return dataFound; if ( IsInternetShortcut(filepath) ) { nsCAutoString url; ResolveShortcut( file, url ); if ( !url.IsEmpty() ) { // convert it to unicode and pass it out nsMemory::Free(*outData); *outData = UTF8ToNewUnicode(url); *outDataLen = nsCRT::strlen(static_cast<PRUnichar*>(*outData)) * sizeof(PRUnichar); dataFound = PR_TRUE; } } else { // we have a normal file, use some Necko objects to get our file path nsCAutoString urlSpec; NS_GetURLSpecFromFile(file, urlSpec); // convert it to unicode and pass it out nsMemory::Free(*outData); *outData = UTF8ToNewUnicode(urlSpec); *outDataLen = nsCRT::strlen(static_cast<PRUnichar*>(*outData)) * sizeof(PRUnichar); dataFound = PR_TRUE; } // else regular file } return dataFound; } // FindURLFromLocalFile
void COwnedLostItem::FetchPrettyName() { if (IsInternetShortcut()) m_csPrettyName = MakeInternetShortcutName(); CPtrList* allHelpers = &(CHelperApp::m_cplHelpers); for (POSITION pos = allHelpers->GetHeadPosition(); pos != NULL;) { CHelperApp* app = (CHelperApp*)allHelpers->GetNext(pos); CString helperMime(app->cd_item->ci.type); if (helperMime == m_csMimeType) { CString returnString = app->cd_item->ci.desc; if (returnString == "") returnString = "File Type"; if (app->cd_item->num_exts > 0) { returnString += " ("; for (int i = 0; i < app->cd_item->num_exts; i++) { returnString += "*."; returnString += app->cd_item->exts[i]; if (i < app->cd_item->num_exts-1) returnString += "; "; } returnString += ")"; } m_csPrettyName = returnString; } } }
void COwnedLostItem::GiveControlToNetscape() { char buffer[_MAX_PATH]; ::GetModuleFileName(theApp.m_hInstance, buffer, _MAX_PATH); // Get the app's directory into a short file name char shortBuffer[_MAX_PATH]; GetShortPathName(buffer, shortBuffer, _MAX_PATH); CString directoryName(shortBuffer); directoryName.MakeUpper(); // This is what we'll write to the registry CString strValueName, strCmdPath; // Special Internet Shortcut check if (IsInternetShortcut()) { CInternetShortcut internetShortcut; if (internetShortcut.ShellSupport()) { // Need to take over lots of stuff CString strType = GetInternetShortcutFileClass(); // Set the open command path strValueName.Format(strOPEN_CMD_FMT, (const char *)strType); strCmdPath = directoryName + " -h \"%1\""; FEU_RegistryWizard(HKEY_CLASSES_ROOT, strValueName, strCmdPath); // Set the DDE exec value strValueName.Format(strDDE_EXEC_FMT, (const char *)strType); FEU_RegistryWizard(HKEY_CLASSES_ROOT, strValueName, strDDE_EXEC_VALUE); // Set the DDE app name strValueName.Format(strDDE_APP_FMT, (const char *)strType); FEU_RegistryWizard(HKEY_CLASSES_ROOT, strValueName, strDDE_APP_NAME); // Set the DDE topic strValueName.Format(strDDE_TOPIC_FMT, (const char *)strType); CString strDDETopic; strDDETopic.LoadString(IDS_DDE_OPENURL); FEU_RegistryWizard(HKEY_CLASSES_ROOT, strValueName, strDDETopic); // Set the Default Icon CString strIconPath; if ((strType == "news") || (strType == "snews")) { // Use the news icon from URL.DLL ::GetSystemDirectory(buffer, _MAX_PATH); strIconPath = CString(buffer) + "\\URL.DLL,1"; } else { // Use the document icon strIconPath = CString(buffer) + ",1"; } strValueName.Format(strDEF_ICON_FMT, (const char *)strType); FEU_RegistryWizard(HKEY_CLASSES_ROOT, strValueName, strIconPath); // Take over printing (applies to ALL Internet Shortcuts. If we own one, we'll take // over printing for ALL of them). CString csMunge = directoryName + " /print(\"%1\")"; FEU_RegistryWizard(HKEY_CLASSES_ROOT, "InternetShortcut\\shell\\print\\command", csMunge); FEU_RegistryWizard(HKEY_CLASSES_ROOT, "InternetShortcut\\shell\\print\\ddeexec", "[print(\"%1\")]"); FEU_RegistryWizard(HKEY_CLASSES_ROOT, "InternetShortcut\\shell\\print\\ddeexec\\Application", strDDE_APP_NAME); // The PrintTo Command. csMunge = directoryName + " /printto(\"%1\",\"%2\",\"%3\",\"%4\")"; FEU_RegistryWizard(HKEY_CLASSES_ROOT, "InternetShortcut\\shell\\PrintTo\\command", csMunge); FEU_RegistryWizard(HKEY_CLASSES_ROOT, "InternetShortcut\\shell\\PrintTo\\ddeexec", "[printto(\"%1\",\"%2\",\"%3\",\"%4\")]"); FEU_RegistryWizard(HKEY_CLASSES_ROOT, "InternetShortcut\\shell\\PrintTo\\ddeexec\\Application", strDDE_APP_NAME); } return; } CPtrList* allHelpers = &(CHelperApp::m_cplHelpers); for (POSITION pos = allHelpers->GetHeadPosition(); pos != NULL;) { CHelperApp* app = (CHelperApp*)allHelpers->GetNext(pos); CString helperMime(app->cd_item->ci.type); if (helperMime == m_csMimeType) { // Found the helper app. Get the file class. CString fileClass(app->strFileClass); if (fileClass != "") { // We have some registry work to do. // In the case where this is text/html, we point .htm and .html to // NetscapeMarkup. HKEY hKey; DWORD dwDisp; if (m_csMimeType == "text/html") { ::RegCreateKeyEx(HKEY_CLASSES_ROOT, ".htm", 0L, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dwDisp); ::RegSetValueEx(hKey, NULL, 0L, REG_SZ, (const BYTE *)((const char *)strMARKUP_KEY), strMARKUP_KEY.GetLength() + 1); ::RegCloseKey(hKey); ::RegCreateKeyEx(HKEY_CLASSES_ROOT, ".html", 0L, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dwDisp); ::RegSetValueEx(hKey, NULL, 0L, REG_SZ, (const BYTE *)((const char *)strMARKUP_KEY), strMARKUP_KEY.GetLength() + 1); ::RegCloseKey(hKey); } // In the case where this is application/x-unknown-content-type-NetscapeMarkup, // we point .shtml to NetscapeMarkup. else if (m_csMimeType == "application/x-unknown-content-type-NetscapeMarkup") { ::RegCreateKeyEx(HKEY_CLASSES_ROOT, ".shtml", 0L, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dwDisp); ::RegSetValueEx(hKey, NULL, 0L, REG_SZ, (const BYTE *)((const char *)strMARKUP_KEY), strMARKUP_KEY.GetLength() + 1); ::RegCloseKey(hKey); } // In all other cases, we should use the existing file class else { // Need to take over lots of stuff CString strType = fileClass; if (strType == "NetscapeMarkup") return; // Don't let ANYTHING mess with NetscapeMarkup. // Someone might point something to it later, and // we don't want this code changing the stuff that's already there. // Set the open command path strValueName.Format(strOPEN_CMD_FMT, (const char *)strType); strCmdPath = directoryName + " \"%1\""; FEU_RegistryWizard(HKEY_CLASSES_ROOT, strValueName, strCmdPath); // Set the DDE exec value strValueName.Format(strDDE_EXEC_FMT, (const char *)strType); FEU_RegistryWizard(HKEY_CLASSES_ROOT, strValueName, strDDE_EXEC_VALUE); // Set the DDE app name strValueName.Format(strDDE_APP_FMT, (const char *)strType); FEU_RegistryWizard(HKEY_CLASSES_ROOT, strValueName, strDDE_APP_NAME); // Set the DDE topic strValueName.Format(strDDE_TOPIC_FMT, (const char *)strType); CString strDDETopic; strDDETopic.LoadString(IDS_DDE_OPENURL); FEU_RegistryWizard(HKEY_CLASSES_ROOT, strValueName, strDDETopic); // Set the Default Icon CString strIconPath; CString iconString = ",1"; if (m_csMimeType == "text/x-javascript" || m_csMimeType == "application/x-javascript") iconString = ",7"; else if (m_csMimeType.Left(5) == "image") iconString = ",6"; strIconPath = CString(buffer) + iconString; strValueName.Format(strDEF_ICON_FMT, (const char *)strType); FEU_RegistryWizard(HKEY_CLASSES_ROOT, strValueName, strIconPath); } } return; } } }