зеркало из https://github.com/mozilla/pjs.git
Make file with no extension have correct type and creator info based on MIME type.
This commit is contained in:
Родитель
deb38085f2
Коммит
ef6872d394
|
@ -64,9 +64,9 @@ public:
|
||||||
// we provide a way to initialize an nsLocalFile with one
|
// we provide a way to initialize an nsLocalFile with one
|
||||||
NS_IMETHOD InitWithFSSpec(const FSSpec *fileSpec) = 0;
|
NS_IMETHOD InitWithFSSpec(const FSSpec *fileSpec) = 0;
|
||||||
|
|
||||||
// Init this filespec to point to an application which is sought by
|
// 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
|
// creator code. If this app is missing, this will fail. It will first
|
||||||
// look for running application with the given creator.
|
// look for running application with the given creator.
|
||||||
NS_IMETHOD InitFindingAppByCreatorCode(OSType aAppCreator) = 0;
|
NS_IMETHOD InitFindingAppByCreatorCode(OSType aAppCreator) = 0;
|
||||||
|
|
||||||
// In case we need to get the FSSpecs at the heart of an nsLocalFileMac
|
// 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 GetFileTypeAndCreator(OSType *type, OSType *creator) = 0;
|
||||||
NS_IMETHOD SetFileTypeAndCreator(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
|
// 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.
|
// by default. Failure is likely on these methods - take it lightly.
|
||||||
NS_IMETHOD SetFileTypeFromSuffix(const char *suffix) = 0;
|
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
|
// 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
|
// 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);
|
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;
|
nsresult rv;
|
||||||
NS_WITH_SERVICE(nsIInternetConfigService, icService, NS_INTERNETCONFIGSERVICE_CONTRACTID, &rv);
|
nsCOMPtr<nsIInternetConfigService> icService(do_GetService
|
||||||
|
(NS_INTERNETCONFIGSERVICE_CONTRACTID, &rv));
|
||||||
|
|
||||||
if (NS_SUCCEEDED(rv))
|
if (NS_SUCCEEDED(rv))
|
||||||
{
|
{
|
||||||
nsCOMPtr<nsIMIMEInfo> mimeInfo;
|
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))
|
if (NS_SUCCEEDED(rv))
|
||||||
{
|
rv = mimeInfo->GetMacType(&fileType);
|
||||||
PRUint32 osType;
|
if (NS_SUCCEEDED(rv))
|
||||||
rv = mimeInfo->GetMacType(&osType);
|
rv = mimeInfo->GetMacCreator(&fileCreator);
|
||||||
if (NS_SUCCEEDED(rv))
|
if (NS_SUCCEEDED(rv))
|
||||||
mType = osType;
|
rv = SetFileTypeAndCreator(fileType, fileCreator);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -72,7 +72,7 @@ public:
|
||||||
NS_IMETHOD SetFileTypeAndCreator(OSType type, OSType creator);
|
NS_IMETHOD SetFileTypeAndCreator(OSType type, OSType creator);
|
||||||
|
|
||||||
NS_IMETHOD SetFileTypeFromSuffix(const char *suffix);
|
NS_IMETHOD SetFileTypeFromSuffix(const char *suffix);
|
||||||
NS_IMETHOD SetFileTypeFromMIMEType(const char *mimetype);
|
NS_IMETHOD SetFileTypeAndCreatorFromMIMEType(const char *aMIMEType);
|
||||||
|
|
||||||
NS_IMETHOD GetFileSizeWithResFork(PRInt64 *aFileSize);
|
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).
|
// Unhook input/output channels (don't need to cancel 'em).
|
||||||
mInputChannel = 0;
|
mInputChannel = 0;
|
||||||
mOutputTransport = 0;
|
mOutputTransport = 0;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче