зеркало из https://github.com/mozilla/gecko-dev.git
Smack the file system datasource (under windows) to munge "IE Favorites" names.
This commit is contained in:
Родитель
931c28f24a
Коммит
bce3c8e167
|
@ -45,6 +45,7 @@
|
||||||
#include "nsFileSpec.h"
|
#include "nsFileSpec.h"
|
||||||
#include "nsIRDFFileSystem.h"
|
#include "nsIRDFFileSystem.h"
|
||||||
#include "nsFileSpec.h"
|
#include "nsFileSpec.h"
|
||||||
|
#include "nsSpecialSystemDirectory.h"
|
||||||
#include "nsEnumeratorUtils.h"
|
#include "nsEnumeratorUtils.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -79,6 +80,10 @@ private:
|
||||||
static nsIRDFResource *kRDF_InstanceOf;
|
static nsIRDFResource *kRDF_InstanceOf;
|
||||||
static nsIRDFResource *kRDF_type;
|
static nsIRDFResource *kRDF_type;
|
||||||
|
|
||||||
|
#ifdef XP_WIN
|
||||||
|
static char *ieFavoritesDir;
|
||||||
|
#endif
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
NS_DECL_ISUPPORTS
|
NS_DECL_ISUPPORTS
|
||||||
|
@ -173,6 +178,10 @@ nsIRDFResource *FileSystemDataSource::kNC_pulse;
|
||||||
nsIRDFResource *FileSystemDataSource::kRDF_InstanceOf;
|
nsIRDFResource *FileSystemDataSource::kRDF_InstanceOf;
|
||||||
nsIRDFResource *FileSystemDataSource::kRDF_type;
|
nsIRDFResource *FileSystemDataSource::kRDF_type;
|
||||||
|
|
||||||
|
#ifdef XP_WIN
|
||||||
|
char *FileSystemDataSource::ieFavoritesDir;
|
||||||
|
#endif
|
||||||
|
|
||||||
static const char kFileProtocol[] = "file://";
|
static const char kFileProtocol[] = "file://";
|
||||||
|
|
||||||
|
|
||||||
|
@ -199,14 +208,25 @@ FileSystemDataSource::isFileURI(nsIRDFResource *r)
|
||||||
|
|
||||||
FileSystemDataSource::FileSystemDataSource(void)
|
FileSystemDataSource::FileSystemDataSource(void)
|
||||||
{
|
{
|
||||||
NS_INIT_REFCNT();
|
NS_INIT_REFCNT();
|
||||||
|
|
||||||
if (gRefCnt++ == 0) {
|
if (gRefCnt++ == 0)
|
||||||
nsresult rv = nsServiceManager::GetService(kRDFServiceCID,
|
{
|
||||||
nsIRDFService::GetIID(),
|
nsresult rv = nsServiceManager::GetService(kRDFServiceCID,
|
||||||
(nsISupports**) &gRDFService);
|
nsIRDFService::GetIID(),
|
||||||
|
(nsISupports**) &gRDFService);
|
||||||
|
|
||||||
PR_ASSERT(NS_SUCCEEDED(rv));
|
PR_ASSERT(NS_SUCCEEDED(rv));
|
||||||
|
|
||||||
|
#ifdef XP_WIN
|
||||||
|
nsSpecialSystemDirectory ieFavoritesFolder(nsSpecialSystemDirectory::Win_Favorites);
|
||||||
|
nsFileURL ieFavoritesURLSpec(ieFavoritesFolder);
|
||||||
|
const char *ieFavoritesURI = ieFavoritesURLSpec.GetAsString();
|
||||||
|
if (ieFavoritesURI)
|
||||||
|
{
|
||||||
|
ieFavoritesDir = nsCRT::strdup(ieFavoritesURI);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
gRDFService->GetResource(kURINC_FileSystemRoot, &kNC_FileSystemRoot);
|
gRDFService->GetResource(kURINC_FileSystemRoot, &kNC_FileSystemRoot);
|
||||||
gRDFService->GetResource(NC_NAMESPACE_URI "child", &kNC_Child);
|
gRDFService->GetResource(NC_NAMESPACE_URI "child", &kNC_Child);
|
||||||
|
@ -218,8 +238,8 @@ FileSystemDataSource::FileSystemDataSource(void)
|
||||||
gRDFService->GetResource(RDF_NAMESPACE_URI "instanceOf", &kRDF_InstanceOf);
|
gRDFService->GetResource(RDF_NAMESPACE_URI "instanceOf", &kRDF_InstanceOf);
|
||||||
gRDFService->GetResource(RDF_NAMESPACE_URI "type", &kRDF_type);
|
gRDFService->GetResource(RDF_NAMESPACE_URI "type", &kRDF_type);
|
||||||
|
|
||||||
gFileSystemDataSource = this;
|
gFileSystemDataSource = this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -233,11 +253,17 @@ FileSystemDataSource::~FileSystemDataSource (void)
|
||||||
NS_RELEASE(kNC_Child);
|
NS_RELEASE(kNC_Child);
|
||||||
NS_RELEASE(kNC_Name);
|
NS_RELEASE(kNC_Name);
|
||||||
NS_RELEASE(kNC_URL);
|
NS_RELEASE(kNC_URL);
|
||||||
NS_RELEASE(kNC_FileSystemObject);
|
NS_RELEASE(kNC_FileSystemObject);
|
||||||
NS_RELEASE(kNC_pulse);
|
NS_RELEASE(kNC_pulse);
|
||||||
NS_RELEASE(kRDF_InstanceOf);
|
NS_RELEASE(kRDF_InstanceOf);
|
||||||
NS_RELEASE(kRDF_type);
|
NS_RELEASE(kRDF_type);
|
||||||
|
|
||||||
|
if (ieFavoritesDir)
|
||||||
|
{
|
||||||
|
nsCRT::free(ieFavoritesDir);
|
||||||
|
ieFavoritesDir = nsnull;
|
||||||
|
}
|
||||||
|
|
||||||
gFileSystemDataSource = nsnull;
|
gFileSystemDataSource = nsnull;
|
||||||
nsServiceManager::ReleaseService(kRDFServiceCID, gRDFService);
|
nsServiceManager::ReleaseService(kRDFServiceCID, gRDFService);
|
||||||
gRDFService = nsnull;
|
gRDFService = nsnull;
|
||||||
|
@ -871,35 +897,7 @@ FileSystemDataSource::GetVolumeList(nsISimpleEnumerator** aResult)
|
||||||
PRBool
|
PRBool
|
||||||
FileSystemDataSource::isVisible(const nsNativeFileSpec& file)
|
FileSystemDataSource::isVisible(const nsNativeFileSpec& file)
|
||||||
{
|
{
|
||||||
PRBool isVisible = PR_TRUE;
|
PRBool isVisible = (!file.IsHidden());
|
||||||
|
|
||||||
isVisible = (!file.IsHidden());
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
#ifdef XP_MAC
|
|
||||||
CInfoPBRec cInfo;
|
|
||||||
OSErr err;
|
|
||||||
|
|
||||||
nsFileSpec fileSpec(file);
|
|
||||||
if (!(err = fileSpec.GetCatInfo(cInfo)))
|
|
||||||
{
|
|
||||||
if (cInfo.hFileInfo.ioFlFndrInfo.fdFlags & kIsInvisible)
|
|
||||||
{
|
|
||||||
isVisible = PR_FALSE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
char *baseFilename = file.GetLeafName();
|
|
||||||
if (nsnull != baseFilename)
|
|
||||||
{
|
|
||||||
if ((!strcmp(baseFilename, ".")) || (!strcmp(baseFilename, "..")))
|
|
||||||
{
|
|
||||||
isVisible = PR_FALSE;
|
|
||||||
}
|
|
||||||
nsCRT::free(baseFilename);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
return(isVisible);
|
return(isVisible);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -908,14 +906,14 @@ FileSystemDataSource::isVisible(const nsNativeFileSpec& file)
|
||||||
nsresult
|
nsresult
|
||||||
FileSystemDataSource::GetFolderList(nsIRDFResource *source, nsISimpleEnumerator** aResult)
|
FileSystemDataSource::GetFolderList(nsIRDFResource *source, nsISimpleEnumerator** aResult)
|
||||||
{
|
{
|
||||||
nsresult rv;
|
nsresult rv;
|
||||||
nsCOMPtr<nsISupportsArray> nameArray;
|
nsCOMPtr<nsISupportsArray> nameArray;
|
||||||
rv = NS_NewISupportsArray(getter_AddRefs(nameArray));
|
rv = NS_NewISupportsArray(getter_AddRefs(nameArray));
|
||||||
if (NS_FAILED(rv)) return rv;
|
if (NS_FAILED(rv)) return rv;
|
||||||
|
|
||||||
nsXPIDLCString uri;
|
const char *uri;
|
||||||
rv = source->GetValue( getter_Copies(uri) );
|
rv = source->GetValueConst(&uri);
|
||||||
if (NS_FAILED(rv)) return rv;
|
if (NS_FAILED(rv)) return(rv);
|
||||||
|
|
||||||
nsFileURL parentDir(uri);
|
nsFileURL parentDir(uri);
|
||||||
nsNativeFileSpec nativeDir(parentDir);
|
nsNativeFileSpec nativeDir(parentDir);
|
||||||
|
@ -948,8 +946,11 @@ FileSystemDataSource::GetFolderList(nsIRDFResource *source, nsISimpleEnumerator*
|
||||||
nsresult
|
nsresult
|
||||||
FileSystemDataSource::GetName(nsIRDFResource *source, nsIRDFLiteral **aResult)
|
FileSystemDataSource::GetName(nsIRDFResource *source, nsIRDFLiteral **aResult)
|
||||||
{
|
{
|
||||||
nsXPIDLCString uri;
|
nsresult rv;
|
||||||
source->GetValue( getter_Copies(uri) );
|
const char *uri;
|
||||||
|
rv = source->GetValueConst(&uri);
|
||||||
|
if (NS_FAILED(rv)) return(rv);
|
||||||
|
|
||||||
nsFileURL url(uri);
|
nsFileURL url(uri);
|
||||||
nsNativeFileSpec native(url);
|
nsNativeFileSpec native(url);
|
||||||
char *baseFilename = native.GetLeafName();
|
char *baseFilename = native.GetLeafName();
|
||||||
|
@ -958,6 +959,25 @@ FileSystemDataSource::GetName(nsIRDFResource *source, nsIRDFLiteral **aResult)
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
return NS_ERROR_OUT_OF_MEMORY;
|
||||||
|
|
||||||
nsAutoString name(baseFilename);
|
nsAutoString name(baseFilename);
|
||||||
|
PRInt32 nameLen = name.Length();
|
||||||
|
|
||||||
|
#ifdef XP_WIN
|
||||||
|
|
||||||
|
// special hack for IE favorites under Windows; strip off the
|
||||||
|
// trailing ".url" or ".lnk" at the end of IE favorites names
|
||||||
|
nsAutoString theURI(uri);
|
||||||
|
if ((theURI.Find(ieFavoritesDir) == 0) && (nameLen > 4))
|
||||||
|
{
|
||||||
|
nsAutoString extension;
|
||||||
|
name.Right(extension, 4);
|
||||||
|
if (extension.EqualsIgnoreCase(".url") ||
|
||||||
|
extension.EqualsIgnoreCase(".lnk"))
|
||||||
|
{
|
||||||
|
name.Truncate(nameLen - 4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
nsIRDFLiteral *literal;
|
nsIRDFLiteral *literal;
|
||||||
gRDFService->GetLiteral(name.GetUnicode(), &literal);
|
gRDFService->GetLiteral(name.GetUnicode(), &literal);
|
||||||
*aResult = literal;
|
*aResult = literal;
|
||||||
|
@ -971,12 +991,15 @@ FileSystemDataSource::GetName(nsIRDFResource *source, nsIRDFLiteral **aResult)
|
||||||
nsresult
|
nsresult
|
||||||
FileSystemDataSource::GetURL(nsIRDFResource *source, nsIRDFLiteral** aResult)
|
FileSystemDataSource::GetURL(nsIRDFResource *source, nsIRDFLiteral** aResult)
|
||||||
{
|
{
|
||||||
nsXPIDLCString uri;
|
nsresult rv;
|
||||||
source->GetValue( getter_Copies(uri) );
|
const char *uri;
|
||||||
nsAutoString url(uri);
|
rv = source->GetValueConst(&uri);
|
||||||
|
if (NS_FAILED(rv)) return(rv);
|
||||||
|
nsAutoString url(uri);
|
||||||
|
|
||||||
nsIRDFLiteral *literal;
|
nsIRDFLiteral *literal;
|
||||||
gRDFService->GetLiteral(url.GetUnicode(), &literal);
|
gRDFService->GetLiteral(url.GetUnicode(), &literal);
|
||||||
*aResult = literal;
|
*aResult = literal;
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче