1. Added Get/SetPersistentDescriptor. Use this instead of GetPath/InitWithPath.

2. It is now possible to pass nsnull for the path param to NS_NewLocalFile(). This allows one to create an unspecified file.
r = dougt


git-svn-id: svn://10.0.0.236/trunk@74318 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
conrad%ingress.com
2000-07-17 15:03:05 +00:00
parent a4ee995bf1
commit 14ebd77604
3 changed files with 100 additions and 12 deletions

View File

@@ -35,6 +35,7 @@
#include "prerror.h"
#include "pprio.h" // Include this rather than prio.h so we get def of PR_ImportFile
#include "prmem.h"
#include "plbase64.h"
#include "FullPath.h"
#include "FileCopy.h"
@@ -2063,6 +2064,59 @@ nsLocalFile::GetDirectoryEntries(nsISimpleEnumerator * *entries)
return NS_OK;
}
NS_IMETHODIMP
nsLocalFile::GetPersistentDescriptor(char * *aPersistentDescriptor)
{
NS_ENSURE_ARG_POINTER(aPersistentDescriptor);
*aPersistentDescriptor = nsnull;
nsresult rv = ResolveAndStat( PR_TRUE );
if ( NS_FAILED( rv ) )
return rv;
AliasHandle aliasH;
OSErr err = ::NewAlias(nil, &mTargetSpec, &aliasH);
if (err != noErr)
return MacErrorMapper(err);
PRUint32 bytes = ::GetHandleSize((Handle) aliasH);
HLock((Handle) aliasH);
char* buf = PL_Base64Encode((const char*)*aliasH, bytes, nsnull); // Passing nsnull for dest makes NULL-term string
::DisposeHandle((Handle) aliasH);
NS_ENSURE_TRUE(buf, NS_ERROR_OUT_OF_MEMORY);
*aPersistentDescriptor = buf;
return NS_OK;
}
NS_IMETHODIMP
nsLocalFile::SetPersistentDescriptor(const char * aPersistentDescriptor)
{
NS_ENSURE_ARG(aPersistentDescriptor);
nsresult rv;
PRUint32 dataSize = nsCRT::strlen(aPersistentDescriptor);
char* decodedData = PL_Base64Decode((const char*)aPersistentDescriptor, dataSize, nsnull);
// Cast to an alias record and resolve.
AliasHandle aliasH = nsnull;
if (::PtrToHand(decodedData, &(Handle)aliasH, (dataSize * 3) / 4) != noErr)
rv = NS_ERROR_OUT_OF_MEMORY;
PR_Free(decodedData);
NS_ENSURE_SUCCESS(rv, rv);
Boolean changed;
FSSpec resolvedSpec;
OSErr err;
if ((err = ::ResolveAlias(nsnull, aliasH, &resolvedSpec, &changed)) != noErr)
rv = MacErrorMapper(err);
DisposeHandle((Handle) aliasH);
NS_ENSURE_SUCCESS(rv, rv);
return InitWithFSSpec(&resolvedSpec);
}
#pragma mark -
// a stack-based, exception safe class for an AEDesc
@@ -2649,10 +2703,12 @@ NS_NewLocalFile(const char* path, PRBool followLinks, nsILocalFile* *result)
file->SetFollowLinks(followLinks);
nsresult rv = file->InitWithPath(path);
if (NS_FAILED(rv)) {
NS_RELEASE(file);
return rv;
if (path) {
nsresult rv = file->InitWithPath(path);
if (NS_FAILED(rv)) {
NS_RELEASE(file);
return rv;
}
}
*result = file;
return NS_OK;

View File

@@ -1328,6 +1328,20 @@ nsLocalFile::Load(PRLibrary **_retval)
return NS_OK;
}
NS_IMETHODIMP
nsLocalFile::GetPersistentDescriptor(char * *aPersistentDescriptor)
{
NS_ENSURE_ARG_POINTER(aPersistentDescriptor);
return GetPath(aPersistentDescriptor);
}
NS_IMETHODIMP
nsLocalFile::SetPersistentDescriptor(const char * aPersistentDescriptor)
{
NS_ENSURE_ARG(aPersistentDescriptor);
return InitWithPath(aPersistentDescriptor);
}
nsresult
NS_NewLocalFile(const char* path, PRBool followSymlinks, nsILocalFile* *result)
{
@@ -1336,10 +1350,12 @@ NS_NewLocalFile(const char* path, PRBool followSymlinks, nsILocalFile* *result)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(file);
nsresult rv = file->InitWithPath(path);
if (NS_FAILED(rv)) {
NS_RELEASE(file);
return rv;
if (path) {
nsresult rv = file->InitWithPath(path);
if (NS_FAILED(rv)) {
NS_RELEASE(file);
return rv;
}
}
*result = file;
return NS_OK;

View File

@@ -1835,6 +1835,20 @@ nsLocalFile::GetDirectoryEntries(nsISimpleEnumerator * *entries)
return NS_OK;
}
NS_IMETHODIMP
nsLocalFile::GetPersistentDescriptor(char * *aPersistentDescriptor)
{
NS_ENSURE_ARG_POINTER(aPersistentDescriptor);
return GetPath(aPersistentDescriptor);
}
NS_IMETHODIMP
nsLocalFile::SetPersistentDescriptor(const char * aPersistentDescriptor)
{
NS_ENSURE_ARG(aPersistentDescriptor);
return InitWithPath(aPersistentDescriptor);
}
nsresult
NS_NewLocalFile(const char* path, PRBool followLinks, nsILocalFile* *result)
@@ -1846,10 +1860,12 @@ NS_NewLocalFile(const char* path, PRBool followLinks, nsILocalFile* *result)
file->SetFollowLinks(followLinks);
nsresult rv = file->InitWithPath(path);
if (NS_FAILED(rv)) {
NS_RELEASE(file);
return rv;
if (path) {
nsresult rv = file->InitWithPath(path);
if (NS_FAILED(rv)) {
NS_RELEASE(file);
return rv;
}
}
*result = file;