Make file with no extension have correct type and creator info based on MIME type.

This commit is contained in:
sgehani%netscape.com 2001-05-03 01:12:15 +00:00
Родитель 83c92f04f4
Коммит 4bc3b220ee
4 изменённых файлов: 45 добавлений и 16 удалений

Просмотреть файл

@ -64,9 +64,9 @@ public:
// we provide a way to initialize an nsLocalFile with one
NS_IMETHOD InitWithFSSpec(const FSSpec *fileSpec) = 0;
// Init this filespec to point to an application which is sought by
// creator code. If this app is missing, this will fail. It will first
// look for running application with the given creator.
// Init this filespec to point to an application which is sought by
// creator code. If this app is missing, this will fail. It will first
// look for running application with the given creator.
NS_IMETHOD InitFindingAppByCreatorCode(OSType aAppCreator) = 0;
// In case we need to get the FSSpecs at the heart of an nsLocalFileMac
@ -85,11 +85,15 @@ public:
NS_IMETHOD GetFileTypeAndCreator(OSType *type, OSType *creator) = 0;
NS_IMETHOD SetFileTypeAndCreator(OSType type, OSType creator) = 0;
// Methods for setting the file type from other means. Just setting the
// Method for setting the file type by suffix. Just setting the
// type is probably enough. The creator is set to that of the current process
// by default. Failure is likely on these methods - take it lightly.
NS_IMETHOD SetFileTypeFromSuffix(const char *suffix) = 0;
NS_IMETHOD SetFileTypeFromMIMEType(const char *mimetype) = 0;
// Method for setting the file type and creator by MIME type. Internet
// Config is consulted for the mapping of MIME type to the appropriate file
// type and creator pair.
NS_IMETHOD SetFileTypeAndCreatorFromMIMEType(const char *aMIMEType) = 0;
// Since Mac files can consist of both a data and resource fork we have a
// method that will return the combined size of both forks rather than just the

Просмотреть файл

@ -2822,24 +2822,30 @@ NS_IMETHODIMP nsLocalFile::SetFileTypeFromSuffix(const char *suffix)
return SetOSTypeAndCreatorFromExtension(suffix);
}
NS_IMETHODIMP nsLocalFile::SetFileTypeFromMIMEType(const char *mimetype)
NS_IMETHODIMP nsLocalFile::SetFileTypeAndCreatorFromMIMEType(const char *aMIMEType)
{
NS_ENSURE_ARG(mimetype);
NS_ENSURE_ARG(aMIMEType);
nsresult rv;
NS_WITH_SERVICE(nsIInternetConfigService, icService, NS_INTERNETCONFIGSERVICE_CONTRACTID, &rv);
nsCOMPtr<nsIInternetConfigService> icService(do_GetService
(NS_INTERNETCONFIGSERVICE_CONTRACTID, &rv));
if (NS_SUCCEEDED(rv))
{
nsCOMPtr<nsIMIMEInfo> mimeInfo;
rv = icService->FillInMIMEInfo(mimetype, nsnull, getter_AddRefs(mimeInfo));
PRUint32 fileType = 'TEXT';
PRUint32 fileCreator = nsILocalFileMac::CURRENT_PROCESS_CREATOR;
rv = icService->FillInMIMEInfo(aMIMEType,
nsnull, getter_AddRefs(mimeInfo));
if (NS_SUCCEEDED(rv))
{
PRUint32 osType;
rv = mimeInfo->GetMacType(&osType);
if (NS_SUCCEEDED(rv))
mType = osType;
}
rv = mimeInfo->GetMacType(&fileType);
if (NS_SUCCEEDED(rv))
rv = mimeInfo->GetMacCreator(&fileCreator);
if (NS_SUCCEEDED(rv))
rv = SetFileTypeAndCreator(fileType, fileCreator);
}
return rv;
}

Просмотреть файл

@ -72,7 +72,7 @@ public:
NS_IMETHOD SetFileTypeAndCreator(OSType type, OSType creator);
NS_IMETHOD SetFileTypeFromSuffix(const char *suffix);
NS_IMETHOD SetFileTypeFromMIMEType(const char *mimetype);
NS_IMETHOD SetFileTypeAndCreatorFromMIMEType(const char *aMIMEType);
NS_IMETHOD GetFileSizeWithResFork(PRInt64 *aFileSize);

Просмотреть файл

@ -473,6 +473,25 @@ nsStreamXferOp::OnStopRequest( nsIRequest *request,
}
}
#ifdef XP_MAC
// Mac only: set the file type and creator based on Internet Config settings
if (mInputChannel)
{
// Get the content type
nsXPIDLCString contentType;
rv = mInputChannel->GetContentType(getter_Copies(contentType));
if (NS_SUCCEEDED(rv))
{
// Set the creator and file type on the output file
nsCOMPtr<nsILocalFileMac> macFile = do_QueryInterface(mOutputFile);
if (contentType.get() && *contentType.get() && macFile)
macFile->SetFileTypeAndCreatorFromMIMEType(contentType.get());
}
}
#endif // XP_MAC
// Unhook input/output channels (don't need to cancel 'em).
mInputChannel = 0;
mOutputTransport = 0;