name = NS_ConvertUTF8toUCS2(leafName);
CopyUTF8toUTF16(leafName, name);
FileSystemDataSource::GetName(nsIRDFResource *source, nsIRDFLiteral **aResult){    nsresult        rv;    const char      *uri = nsnull;    rv = source->GetValueConst(&uri);    if (NS_FAILED(rv))        return(rv);    if (!uri)        return(NS_ERROR_UNEXPECTED);    nsCOMPtr<nsIURI>    aIURI;    if (NS_FAILED(rv = NS_NewURI(getter_AddRefs(aIURI), nsDependentCString(uri))))        return(rv);    nsCOMPtr<nsIFileURL>    fileURL = do_QueryInterface(aIURI);    if (!fileURL)        return(PR_FALSE);    nsCOMPtr<nsIFile>   aFile;    if (NS_FAILED(rv = fileURL->GetFile(getter_AddRefs(aFile))))        return(rv);    if (!aFile)        return(NS_ERROR_UNEXPECTED);    // ensure that we DO NOT resolve aliases    nsCOMPtr<nsILocalFile>  aFileLocal = do_QueryInterface(aFile);    if (aFileLocal)        aFileLocal->SetFollowLinks(PR_FALSE);    nsAutoString name;    if (NS_FAILED(rv = aFile->GetLeafName(name)))        return(rv);    if (name.IsEmpty())        return(NS_ERROR_UNEXPECTED);#ifdef  XP_MAC    nsCOMPtr<nsILocalFileMac>   aMacFile = do_QueryInterface(aFile);    if (aMacFile)    {        PRBool isPackageFlag = PR_FALSE;        rv = aMacFile->IsPackage(&isPackageFlag);        if (NS_SUCCEEDED(rv) && (isPackageFlag == PR_TRUE))        {            // mungle package names under Mac OS 9/X            PRUint32 len = name.Length();            if (name.RFind(".app", PR_TRUE) == len - 4)            {                name.SetLength(len-4);            }        }    }#endif#ifdef  XP_WIN    // special hack for IE favorites under Windows; strip off the    // trailing ".url" or ".lnk" at the end of IE favorites names    PRInt32 nameLen = name.Length();    if ((strncmp(uri, ieFavoritesDir, strlen(ieFavoritesDir)) == 0) && (nameLen > 4))    {        nsAutoString extension;        name.Right(extension, 4);        if (extension.EqualsIgnoreCase(".url") ||            extension.EqualsIgnoreCase(".lnk"))        {            name.Truncate(nameLen - 4);        }    }#endif#ifdef  XP_BEOS    // under BEOS, try and get the "META:title" attribute (if its a file)    if (strstr(uri, netPositiveDir) != 0)    {        PRBool value;        if ((NS_SUCCEEDED(aFileLocal->IsFile(&value) && value)) ||            (NS_SUCCEEDED(aFileLocal->IsDirectory(&value) && value)))        {            nsXPIDLCString nativePath;            aFileLocal->GetNativePath(nativePath);            rv = NS_ERROR_FAILURE;            if (nativePath)             {                BFile   bf(nativePath.get(), B_READ_ONLY);                if (bf.InitCheck() == B_OK)                {                    char        beNameAttr[4096];                    ssize_t     len;                    if ((len = bf.ReadAttr("META:title", B_STRING_TYPE,                        0, beNameAttr, sizeof(beNameAttr)-1)) > 0)                    {                        beNameAttr[len] = '\0';                        name = NS_ConvertUTF8toUCS2(beNameAttr);                        rv = NS_OK;                    }                }            }            if (NS_OK != rv)            {                nsCAutoString leafName;                rv = aFileLocal->GetNativeLeafName(leafName);                if (NS_SUCCEEDED(rv)) {                    name = NS_ConvertUTF8toUCS2(leafName);                    rv = NS_OK;                }            }        }    }#endif    gRDFService->GetLiteral(name.get(), aResult);    return NS_OK;}