~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/extensions/manticore/core/MIMEService.cs

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
namespace Silverstone.Manticore.Core
 
3
{
 
4
  using System;
 
5
 
 
6
  using Microsoft.Win32;
 
7
 
 
8
        /// <summary>
 
9
        /// Summary description for MIMEService.
 
10
        /// </summary>
 
11
        public class MIMEService
 
12
        {
 
13
    /// <summary>
 
14
    /// Retrieves the extension associated with the specified content type
 
15
    /// by looking up the type in the Windows Registry. 
 
16
    /// </summary>
 
17
    /// <param name="aMIMEType">content-type to retrieve extension for</param>
 
18
    /// <returns>string containing the extension (".foo") associated with the type</returns>
 
19
    public static string GetExtensionForMIMEType(string aMIMEType)
 
20
    {
 
21
      RegistryKey clsRoot = Registry.ClassesRoot;
 
22
      string extFromMIMEDBKey = "MIME\\Database\\Content Type\\" + aMIMEType;
 
23
      RegistryKey extensionKey = clsRoot.OpenSubKey(extFromMIMEDBKey);
 
24
      return extensionKey.GetValue("Extension") as String;
 
25
    }
 
26
 
 
27
    /// <summary>
 
28
    /// Retrieves the pretty user-readable description of the type by
 
29
    /// looking up the type in the Windows Registry. If no data is found,
 
30
    /// the extension is capitalized and appended with "file", e.g.
 
31
    /// "ZAP file"
 
32
    /// </summary>
 
33
    /// <param name="aMIMEType">content-type to retrieve description for</param>
 
34
    /// <returns>string containing pretty user-readable description of type</returns>
 
35
    public static string GetDescriptionForMIMEType(string aMIMEType)
 
36
    {
 
37
      RegistryKey clsRoot = Registry.ClassesRoot;
 
38
      string extension = GetExtensionForMIMEType(aMIMEType);
 
39
      RegistryKey handlerKey = clsRoot.OpenSubKey(extension);
 
40
      string handler = handlerKey.GetValue("") as String;
 
41
      RegistryKey descriptionKey = clsRoot.OpenSubKey(handler);
 
42
      string description = descriptionKey.GetValue("") as String;
 
43
      if (description == "")
 
44
        description = extension.Substring(1,extension.Length-1).ToUpper() + " file";
 
45
      return description;
 
46
    }
 
47
        }
 
48
}