native = icon;
native = *icon;
InternetSearchDataSource::SaveEngineInfoIntoGraph(nsIFile *file, nsIFile *icon,		const PRUnichar *categoryHint, const PRUnichar *dataUni, PRBool isSystemSearchFile,		PRBool checkMacFileType){	nsresult			rv = NS_OK;	if (!file && !icon)	return(NS_ERROR_UNEXPECTED);	nsCOMPtr<nsIRDFResource>	searchRes;	nsCOMPtr<nsIRDFResource>	categoryRes;	nsCOMPtr<nsIFile>		native;	if (icon != nsnull)	{		native = icon;	}	if (file != nsnull)	{		native = file;	}  PRBool exists;  rv = native->Exists(&exists);	if (NS_FAILED(rv)) return(rv);	if (!exists) return(NS_ERROR_UNEXPECTED);	nsAutoString basename;	rv = native->GetLeafName(basename);	if (NS_FAILED(rv)) return rv;	// ensure that the basename points to the search engine file	PRInt32		extensionOffset;	if ((extensionOffset = basename.RFindChar(PRUnichar('.'))) > 0)	{		basename.Truncate(extensionOffset);		basename.Append(NS_LITERAL_STRING(".src"));	}  nsCAutoString filePath;  rv = native->GetNativePath(filePath);  if (NS_FAILED(rv)) return rv;  	nsAutoString	searchURL;	searchURL.AssignWithConversion(kEngineProtocol);	char		*uriCescaped = nsEscape(filePath.get(), url_Path);	if (!uriCescaped)	return(NS_ERROR_NULL_POINTER);	searchURL.AppendWithConversion(uriCescaped);	nsCRT::free(uriCescaped);	if ((extensionOffset = searchURL.RFindChar(PRUnichar('.'))) > 0)	{		searchURL.Truncate(extensionOffset);		searchURL.Append(NS_LITERAL_STRING(".src"));	}	if (NS_FAILED(rv = gRDFService->GetUnicodeResource(searchURL.get(),		getter_AddRefs(searchRes))))	return(rv);	// save the basename reference	if (basename.Length() > 0)	{		basename.InsertWithConversion(kURINC_SearchCategoryEngineBasenamePrefix, 0);		if (NS_FAILED(rv = gRDFService->GetUnicodeResource(basename.get(),			getter_AddRefs(categoryRes))))	return(rv);		nsCOMPtr<nsIRDFLiteral>	searchLiteral;		if (NS_SUCCEEDED(rv = gRDFService->GetLiteral(basename.get(),				getter_AddRefs(searchLiteral))))		{			if (file)			{				updateAtom(mInner, searchRes, kNC_URL, searchLiteral, nsnull);			}		}	}	if (!searchRes)		return(NS_ERROR_UNEXPECTED);	if (!categoryRes)	return(NS_ERROR_UNEXPECTED);	nsAutoString	iconURL;	if (icon)	{		nsCAutoString iconFileURL;		if (NS_FAILED(rv = NS_GetURLSpecFromFile(icon, iconFileURL)))			return(rv);		iconURL = NS_ConvertUTF8toUCS2(iconFileURL);	}#ifdef XP_MAC	else if (file)	{		nsCAutoString  fileURL;		if (NS_FAILED(rv = NS_GetURLSpecFromFile(file,fileURL)))			return(rv);		iconURL.Assign(NS_LITERAL_STRING("moz-icon:"));		iconURL.Append(NS_ConvertUTF8toUCS2(fileURL));	}#endif	// save icon url (if we have one)	if (iconURL.Length() > 0)	{		nsCOMPtr<nsIRDFLiteral>	iconLiteral;		if (NS_SUCCEEDED(rv = gRDFService->GetLiteral(iconURL.get(),				getter_AddRefs(iconLiteral))))		{			updateAtom(mInner, searchRes, kNC_Icon, iconLiteral, nsnull);		}	}	if (isSystemSearchFile == PR_FALSE)	{		// mark our private search files, so that we can distinguish		// between ours and any that are included with the OS		updateAtom(mInner, searchRes, kNC_SearchType, kNC_Engine, nsnull);	}	if (dataUni != nsnull)	{		updateDataHintsInGraph(searchRes, dataUni);		// finally, if we have a category hint, add this new engine into the category (if it exists)		if (categoryHint && categoryDataSource)		{			nsCOMPtr<nsIRDFLiteral>	catLiteral;			rv = gRDFService->GetLiteral(categoryHint, getter_AddRefs(catLiteral));			nsCOMPtr<nsIRDFResource>	catSrc;			if (catLiteral)			{				rv = categoryDataSource->GetSource(kNC_Title, catLiteral,					PR_TRUE, getter_AddRefs(catSrc));			}			const char		*catURI = nsnull;			if (catSrc)								{				rv = catSrc->GetValueConst(&catURI);			}			nsCOMPtr<nsIRDFResource>	catRes;			if (catURI)			{				nsAutoString	catList;				catList.AssignWithConversion(kURINC_SearchCategoryPrefix);				catList.AppendWithConversion(catURI);				gRDFService->GetUnicodeResource(catList.get(), getter_AddRefs(catRes));			}			nsCOMPtr<nsIRDFContainer> container;			if (catRes)			{				rv = nsComponentManager::CreateInstance(kRDFContainerCID,									nsnull,									NS_GET_IID(nsIRDFContainer),									getter_AddRefs(container));			}			if (container)			{				rv = container->Init(categoryDataSource, catRes);				if (NS_SUCCEEDED(rv))				{					rv = gRDFC->MakeSeq(categoryDataSource, catRes, nsnull);				}				if (NS_SUCCEEDED(rv))				{					PRInt32		searchIndex = -1;					if (NS_SUCCEEDED(rv = container->IndexOf(categoryRes, &searchIndex))						&& (searchIndex < 0))					{						rv = container->AppendElement(categoryRes);					}				}				if (NS_SUCCEEDED(rv))				{					// flush categoryDataSource					nsCOMPtr<nsIRDFRemoteDataSource>	remoteCategoryStore;					remoteCategoryStore = do_QueryInterface(categoryDataSource);					if (remoteCategoryStore)					{						remoteCategoryStore->Flush();					}				}			}		}	}	// Note: add the child relationship last	PRBool	hasChildFlag = PR_FALSE;	if (NS_SUCCEEDED(rv = mInner->HasAssertion(kNC_SearchEngineRoot, kNC_Child, searchRes,		PR_TRUE, &hasChildFlag)) && (hasChildFlag == PR_FALSE))	{		mInner->Assert(kNC_SearchEngineRoot, kNC_Child, searchRes, PR_TRUE);	}	return(NS_OK);}