//---------------------------------------------------------------------------------------- nsresult nsFileSpec::MoveToDir(const nsFileSpec& inNewParentDirectory) //---------------------------------------------------------------------------------------- { // We can only copy into a directory, and (for now) can not copy entire directories nsresult result = NS_FILE_FAILURE; if (inNewParentDirectory.IsDirectory() && !IsDirectory()) { char *leafname = GetLeafName(); nsSimpleCharString destPath(inNewParentDirectory.GetCString()); destPath += "/"; destPath += leafname; nsCRT::free(leafname); result = NS_FILE_RESULT(CrudeFileCopy(GetCString(), (const char*)destPath)); if (result == NS_OK) { // cast to fix const-ness ((nsFileSpec*)this)->Delete(PR_FALSE); *this = inNewParentDirectory + GetLeafName(); } } return result; }
//---------------------------------------------------------------------------------------- void nsPersistentFileDescriptor::operator = (const nsFileSpec& inSpec) //---------------------------------------------------------------------------------------- { #if defined(XP_MAC) if (inSpec.Error()) return; AliasHandle aliasH; OSErr err = NewAlias(nil, inSpec.GetFSSpecPtr(), &aliasH); if (err != noErr) return; PRUint32 bytes = GetHandleSize((Handle) aliasH); HLock((Handle) aliasH); char* buf = PL_Base64Encode((const char*)*aliasH, bytes, nsnull); DisposeHandle((Handle) aliasH); mDescriptorString = buf; PR_Free(buf); #elif defined(XP_MACOSX) if (inSpec.Error()) return; FSRef fileRef; Boolean isDir; OSErr err = ::FSPathMakeRef((const UInt8*)inSpec.GetCString(), &fileRef, &isDir); if (err != noErr) return; AliasHandle aliasH; err = ::FSNewAlias(nsnull, &fileRef, &aliasH); if (err != noErr) return; PRUint32 bytes = ::GetHandleSize((Handle) aliasH); ::HLock((Handle)aliasH); char* buf = PL_Base64Encode((const char*)*aliasH, bytes, nsnull); ::DisposeHandle((Handle) aliasH); mDescriptorString = buf; PR_Free(buf); #else mDescriptorString = inSpec.GetCString(); #endif // XP_MAC } // nsPersistentFileDescriptor::operator =
//---------------------------------------------------------------------------------------- nsresult nsFileSpec::CopyToDir(const nsFileSpec& inParentDirectory) const //---------------------------------------------------------------------------------------- { // We can only copy into a directory, and (for now) can not copy entire directories nsresult result = NS_FILE_FAILURE; if (inParentDirectory.IsDirectory() && (! IsDirectory() ) ) { char *leafname = GetLeafName(); nsSimpleCharString destPath(inParentDirectory.GetCString()); destPath += "/"; destPath += leafname; nsCRT::free(leafname); result = NS_FILE_RESULT(CrudeFileCopy(GetCString(), destPath)); } return result; } // nsFileSpec::CopyToDir
//---------------------------------------------------------------------------------------- nsresult nsFileSpec::CopyToDir(const nsFileSpec& inParentDirectory) const //---------------------------------------------------------------------------------------- { // We can only copy into a directory, and (for now) can not copy entire directories if (inParentDirectory.IsDirectory() && (! IsDirectory() ) ) { char *leafname = GetLeafName(); nsSimpleCharString destPath(inParentDirectory.GetCString()); destPath += "\\"; destPath += leafname; nsCRT::free(leafname); // CopyFile returns non-zero if succeeds int copyOK = CopyFile(GetCString(), destPath, PR_TRUE); if (copyOK) return NS_OK; } return NS_FILE_FAILURE; } // nsFileSpec::CopyToDir