Exemplo n.º 1
0
		public static string QueryAssociationString (string assoc, AssociationString str, AssociationFlags flags, string extra = null)
		{
			if (assoc == null)
				throw new ArgumentNullException("assoc");

			flags |= AssociationFlags.NoTruncate;

			const uint E_POINTER = 0x80004003;
			const uint E_NO_ASSOCIATION = 0x80070483;

			var builder = new StringBuilder (512);
			int size = builder.Length;

			var result = Win32.AssocQueryStringW (flags, str, assoc, extra, builder, ref size);

			if (result == unchecked((int)E_POINTER)) {
				builder.Length = size;
				result = Win32.AssocQueryStringW (flags, str, assoc, extra, builder, ref size);
			}

			if (result == unchecked((int)E_NO_ASSOCIATION)) {
				return null;
			}

			Marshal.ThrowExceptionForHR (result);
			return builder.ToString ();
		}
Exemplo n.º 2
0
 public static extern HResult AssocQueryStringByKeyW(
     AssociationFlags flags,
     AssociationString str,
     RegistryKeyHandle hkAssoc,
     string pszExtra,
     SafeHandle pszOut,
     ref uint pcchOut);
Exemplo n.º 3
0
        public static string AssocQueryString(AssociationFlags flags, AssociationString @string, string association, string extraInfo)
        {
            return(BufferHelper.BufferInvoke((StringBuffer buffer) =>
            {
                flags |= AssociationFlags.NoTruncate;

                HResult result;
                uint count = buffer.CharCapacity;
                while ((result = Imports.AssocQueryStringW(flags, @string, association, extraInfo, buffer, ref count)) == HResult.E_POINTER)
                {
                    buffer.EnsureCharCapacity(count);
                }

                result.ThrowIfFailed(association);

                // Count includes the null
                buffer.Length = count - 1;
                return buffer.ToString();
            }));
        }
Exemplo n.º 4
0
		static WindowsDesktopApplication WindowsAppFromName (string appName, bool isDefault, AssociationFlags flags)
		{
			try {
				string displayName = QueryAssociationString (appName, AssociationString.FriendlyAppName, flags, "open");
				string exePath = QueryAssociationString (appName, AssociationString.Executable, flags, "open");
				//ignore apps with missing information, it's not worth logging
				if (exePath == null || displayName == null)
					return null;
				if (System.Reflection.Assembly.GetEntryAssembly ().Location != exePath)
					return new WindowsDesktopApplication (appName, displayName, exePath, isDefault);
			} catch (Exception ex) {
				LoggingService.LogError (string.Format ("Failed to read info for {0} '{1}'", flags == AssociationFlags.None ? "ProgId" : "ExeName", appName), ex);
			}
			return null;
		}
Exemplo n.º 5
0
		public static string QueryAssociationString (string assoc, AssociationString str, AssociationFlags flags, string extra = null)
		{
			if (assoc == null)
				throw new ArgumentNullException("assoc");

			flags |= AssociationFlags.NoTruncate;

			const uint E_POINTER = 0x80004003;
			const uint E_NO_ASSOCIATION = 0x80070483;

			var builder = new StringBuilder (512);
			int size = builder.Length;

			var result = Win32.AssocQueryStringW (flags, str, assoc, extra, builder, ref size);

			if (result == unchecked((int)E_POINTER)) {
				builder.Length = size;
				result = Win32.AssocQueryStringW (flags, str, assoc, extra, builder, ref size);
			}

			if (result == unchecked((int)E_NO_ASSOCIATION)) {
				return null;
			}

			Marshal.ThrowExceptionForHR (result);
			return builder.ToString ();
		}
Exemplo n.º 6
0
 public static extern HResult AssocQueryKeyW(
     AssociationFlags flags,
     AssociationKey key,
     string pszAssoc,
     string pszExtra,
     out RegistryKeyHandle phkeyOut);
Exemplo n.º 7
0
	 public static extern int AssocQueryStringW (AssociationFlags flags, AssociationString str, string assoc, string extra, StringBuilder outBuffer, ref int outBufferSize);
Exemplo n.º 8
0
 static WindowsDesktopApplication WindowsAppFromName(string appName, bool isDefault, AssociationFlags flags)
 {
     try {
         string displayName = QueryAssociationString(appName, AssociationString.FriendlyAppName, flags, "open");
         string exePath     = QueryAssociationString(appName, AssociationString.Executable, flags, "open");
         //ignore apps with missing information, it's not worth logging
         if (exePath == null || displayName == null)
         {
             return(null);
         }
         if (System.Reflection.Assembly.GetEntryAssembly().Location != exePath)
         {
             return(new WindowsDesktopApplication(appName, displayName, exePath, isDefault));
         }
     } catch (Exception ex) {
         LoggingService.LogError(string.Format("Failed to read info for {0} '{1}'", flags == AssociationFlags.None ? "ProgId" : "ExeName", appName), ex);
     }
     return(null);
 }
Exemplo n.º 9
0
 private static extern int AssocQueryString(AssociationFlags flags,
                                            AssociationStringType stringType,
                                            string filePath,
                                            string extra,
                                            [Out] StringBuilder result,
                                            [In][Out] ref int size);
Exemplo n.º 10
0
 public static extern int AssocQueryStringW(AssociationFlags flags, AssociationString str, string assoc, string extra, StringBuilder outBuffer, ref int outBufferSize);
Exemplo n.º 11
0
 public static RegistryKeyHandle AssocQueryKey(AssociationFlags flags, AssociationKey key, string association, string extraInfo)
 {
     Imports.AssocQueryKeyW(flags, key, association, extraInfo, out RegistryKeyHandle handle)
     .ThrowIfFailed();
     return(handle);
 }
Exemplo n.º 12
0
 static WindowsDesktopApplication WindowsAppFromName(string appName, string defaultApp, AssociationFlags flags)
 {
     try {
         string displayName = QueryAssociationString(appName, AssociationString.FriendlyAppName, flags, "open");
         string exePath     = QueryAssociationString(appName, AssociationString.Executable, flags, "open");
         if (System.Reflection.Assembly.GetEntryAssembly().Location != exePath)
         {
             return(new WindowsDesktopApplication(appName, displayName, exePath, appName.Equals(defaultApp)));
         }
     } catch (Exception ex) {
         LoggingService.LogError(string.Format("Failed to read info for {0} '{1}'", flags == AssociationFlags.None ? "ProgId" : "ExeName", appName), ex);
     }
     return(null);
 }
Exemplo n.º 13
0
        static IEnumerable <DesktopApplication> GetAppFromRegistry(RegistryKey key, string defaultApp, HashSet <string> uniqueAppsSet, AssociationFlags flags, AppOpenWithRegistryType type)
        {
            if (key != null)
            {
                var apps = new string[0];
                if (type == AppOpenWithRegistryType.FromValue)
                {
                    apps = key.GetValueNames();
                }
                else if (type == AppOpenWithRegistryType.FromSubkey)
                {
                    apps = key.GetSubKeyNames();
                }
                else if (type == AppOpenWithRegistryType.FromMRUList)
                {
                    string list = (string)key.GetValue("MRUList");
                    apps = list.Select(c => (string)key.GetValue(c.ToString())).ToArray();
                }

                foreach (string appName in apps)
                {
                    var app = WindowsAppFromName(appName, defaultApp, flags);
                    if (app != null && uniqueAppsSet.Add(app.ExePath))
                    {
                        yield return(app);
                    }
                }
            }
        }