Try and ensure that we're actually looking at proper search datasets by checking file type and creator on Mac.

This commit is contained in:
rjc%netscape.com 1999-06-16 06:46:51 +00:00
Родитель d5c13bb733
Коммит 29c5b09136
1 изменённых файлов: 38 добавлений и 18 удалений

Просмотреть файл

@ -57,6 +57,10 @@
#include "nsIStreamListener.h" #include "nsIStreamListener.h"
#include "nsIRDFSearch.h" #include "nsIRDFSearch.h"
#ifdef XP_MAC
#include "Files.h"
#endif
#ifdef XP_WIN #ifdef XP_WIN
#include "windef.h" #include "windef.h"
#include "winbase.h" #include "winbase.h"
@ -996,7 +1000,7 @@ SearchDataSource::GetSearchEngineList()
#ifdef XP_MAC #ifdef XP_MAC
// on Mac, use system's search files // on Mac, use system's search files
nsSpecialSystemDirectory searchSitesDir(nsSpecialSystemDirectory::Mac_InternetSearchDirectory); nsSpecialSystemDirectory searchSitesDir(nsSpecialSystemDirectory::Mac_InternetSearchDirectory);
nsNativeFileSpec nativeDir(searchSitesDir); nsFileSpec nativeDir(searchSitesDir);
#else #else
// on other platforms, use our search files // on other platforms, use our search files
nsSpecialSystemDirectory searchSitesDir(nsSpecialSystemDirectory::OS_CurrentProcessDirectory); nsSpecialSystemDirectory searchSitesDir(nsSpecialSystemDirectory::OS_CurrentProcessDirectory);
@ -1004,27 +1008,41 @@ SearchDataSource::GetSearchEngineList()
searchSitesDir += "res"; searchSitesDir += "res";
searchSitesDir += "rdf"; searchSitesDir += "rdf";
searchSitesDir += "search"; searchSitesDir += "search";
nsNativeFileSpec nativeDir(searchSitesDir); nsFileSpec nativeDir(searchSitesDir);
#endif #endif
for (nsDirectoryIterator i(nativeDir); i.Exists(); i++) for (nsDirectoryIterator i(nativeDir); i.Exists(); i++)
{ {
const nsNativeFileSpec nativeSpec = (const nsNativeFileSpec &)i; const nsFileSpec fileSpec = (const nsFileSpec &)i;
if (!isVisible(nativeSpec)) continue; const char *childURL = fileSpec;
nsFileURL fileURL(nativeSpec); if (!isVisible(fileSpec)) continue;
const char *childURL = fileURL.GetAsString();
if (childURL != nsnull) if (childURL != nsnull)
{ {
nsAutoString uri(childURL); nsAutoString uri(childURL);
PRInt32 len = uri.Length(); PRInt32 len = uri.Length();
if (len > 4) if (len > 4)
{ {
#ifdef XP_MAC
// be sure to resolve aliases in case we encounter one
CInfoPBRec cInfo;
OSErr err;
PRBool wasAliased = PR_FALSE;
fileSpec.ResolveAlias(wasAliased);
err = fileSpec.GetCatInfo(cInfo);
if ((!err) && (cInfo.hFileInfo.ioFlFndrInfo.fdType == 'issp') &&
(cInfo.hFileInfo.ioFlFndrInfo.fdCreator == 'fndf'))
#else
nsAutoString extension; nsAutoString extension;
if ((uri.Right(extension, 4) == 4) && (extension.EqualsIgnoreCase(".src"))) if ((uri.Right(extension, 4) == 4) && (extension.EqualsIgnoreCase(".src")))
#endif
{ {
PRInt32 slashOffset = uri.RFind("/"); #ifdef XP_MAC
if (slashOffset > 0) PRInt32 separatorOffset = uri.RFind(":");
#else
PRInt32 separatorOffset = uri.RFind("/");
#endif
if (separatorOffset > 0)
{ {
uri.Cut(0, slashOffset+1); uri.Cut(0, separatorOffset+1);
nsAutoString searchURL("engine://"); nsAutoString searchURL("engine://");
searchURL += uri; searchURL += uri;
@ -1142,18 +1160,20 @@ SearchDataSource::ReadFileContents(char *basename, nsString& sourceContents)
#endif XP_MAC #endif XP_MAC
nsInputFileStream searchFile(searchEngine); nsInputFileStream searchFile(searchEngine);
if (! searchFile.is_open()) if (searchFile.is_open())
{ {
NS_ERROR("unable to open file"); nsRandomAccessInputStream stream(searchFile);
return(NS_ERROR_FAILURE); char buffer[1024];
while (!stream.eof())
{
stream.readline(buffer, sizeof(buffer)-1 );
sourceContents += buffer;
sourceContents += "\n";
}
} }
nsRandomAccessInputStream stream(searchFile); else
char buffer[1024];
while (!stream.eof())
{ {
stream.readline(buffer, sizeof(buffer)-1 ); rv = NS_ERROR_FAILURE;
sourceContents += buffer;
sourceContents += "\n";
} }
return(rv); return(rv);
} }