Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Hutchinson <m.j.hutchinson@gmail.com>2013-04-10 03:15:48 +0400
committerMichael Hutchinson <m.j.hutchinson@gmail.com>2013-04-10 04:20:48 +0400
commit31a030f07d0439f393f932b07ebd2b419c492793 (patch)
tree8beade8f7c92393160af8f57eee3819a0635d233 /main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Desktop
parent2488e957bca342fe87e646150facdfbbd8e44bf8 (diff)
Don't assume unknown files are text/plain mimetype
Instead, return application/octet-stream and use a new utility function DesktopService.GetFileIsText to guess by scanning the first 8k of the file for NUL bytes.
Diffstat (limited to 'main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Desktop')
-rw-r--r--main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Desktop/PlatformService.cs17
1 files changed, 8 insertions, 9 deletions
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Desktop/PlatformService.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Desktop/PlatformService.cs
index 3d84401ca4..b17db01225 100644
--- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Desktop/PlatformService.cs
+++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Desktop/PlatformService.cs
@@ -78,20 +78,19 @@ namespace MonoDevelop.Ide.Desktop
public string GetMimeTypeForUri (string uri)
{
if (!String.IsNullOrEmpty (uri)) {
-// Creating file infos is expensive, should be avoided
-// FileInfo file = new FileInfo (uri);
-// MimeTypeNode mt = FindMimeTypeForFile (file.Name);
MimeTypeNode mt = FindMimeTypeForFile (uri);
if (mt != null)
return mt.Id;
}
- return OnGetMimeTypeForUri (uri) ?? "text/plain";
+ return OnGetMimeTypeForUri (uri) ?? "application/octet-stream";
}
-
+
public string GetMimeTypeDescription (string mimeType)
{
if (mimeType == "text/plain")
return GettextCatalog.GetString ("Text file");
+ if (mimeType == "application/octet-stream")
+ return GettextCatalog.GetString ("Unknown");
MimeTypeNode mt = FindMimeType (mimeType);
if (mt != null && mt.Description != null)
return mt.Description;
@@ -116,14 +115,14 @@ namespace MonoDevelop.Ide.Desktop
{
yield return mimeType;
- while (mimeType != null && mimeType != "text/plain") {
+ while (mimeType != null && mimeType != "text/plain" && mimeType != "application/octet-stream") {
MimeTypeNode mt = FindMimeType (mimeType);
if (mt != null && !string.IsNullOrEmpty (mt.BaseType))
mimeType = mt.BaseType;
else {
- if (mimeType.EndsWith ("+xml"))
+ if (mimeType.EndsWith ("+xml", StringComparison.Ordinal))
mimeType = "application/xml";
- else if (mimeType.StartsWith ("text") || OnGetMimeTypeIsText (mimeType))
+ else if (mimeType.StartsWith ("text/", StringComparison.Ordinal) || OnGetMimeTypeIsText (mimeType))
mimeType = "text/plain";
else
break;
@@ -263,7 +262,7 @@ namespace MonoDevelop.Ide.Desktop
}
return null;
}
-
+
protected virtual string OnGetMimeTypeForUri (string uri)
{
return null;