/// <summary> /// Adds single <see cref="ProgramVerb"/> that define the verb supported by this ProgID. /// </summary> /// <param name="verb">Single <see cref="ProgramVerb"/> that contains supported verb.</param> protected void AddVerbInternal(ProgramVerb verb) { RegistryKey root = Registry.ClassesRoot; RegistryKey key = root.OpenSubKey(this.progId).OpenSubKey("shell", true); if (key == null) { key = root.OpenSubKey(this.progId, true).CreateSubKey("shell"); } RegistryKey tmpkey = key.OpenSubKey(verb.Name, true); if (tmpkey == null) { tmpkey = key.CreateSubKey(verb.Name); } key = tmpkey; tmpkey = key.OpenSubKey("command", true); if (tmpkey == null) { tmpkey = key.CreateSubKey("command"); } tmpkey.SetValue(string.Empty, verb.Command, RegistryValueKind.ExpandString); tmpkey.Close(); key.Close(); root.Close(); ShellNotification.NotifyOfChange(); }
/// <summary> /// Removes single <see cref="ProgramVerb"/> that define the verb supported by this ProgID. /// </summary> /// <param name="verb">Single <see cref="ProgramVerb"/> that contains supported verb.</param> public void RemoveVerb(ProgramVerb verb) { if (verb == null) { throw new NullReferenceException(); } RemoveVerb(verb.Name); }
/// <summary> /// Adds single <see cref="ProgramVerb"/> that define the verb supported by this ProgID. /// </summary> /// <param name="verb">Single <see cref="ProgramVerb"/> that contains supported verb.</param> public void AddVerb(ProgramVerb verb) { AddVerbInternal(verb); }
/// <summary> /// Creates actual Programmatic Identifier key in registry that is used by other extensions. /// </summary> /// <param name="description">Friendly description of file type.</param> /// <param name="editFlags"><see cref="EditFlags"/> for program file type.</param> /// <param name="verb">Single <see cref="ProgramVerb"/> that contains supported verbs.</param> /// <returns><see cref="ProgramAssociationInfo"/> instance referring to specified extension.</returns> public ProgramAssociationInfo Create(string description, EditFlags editFlags, ProgramVerb verb) { return(Create(description, editFlags, new ProgramVerb[] { verb })); }
/// <summary> /// Register file association /// </summary> /// <param name="exts">Extensions, for ex: *.png;*.jpg</param> /// <param name="appPath">Executable file</param> public static void RegisterAssociation(string appPath, string exts) { string[] ext_list = exts.Replace("*", "").Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); foreach (string ext in ext_list) { FileAssociationInfo fa = new FileAssociationInfo(ext); if (!fa.Exists) { return; } ProgramAssociationInfo pa = new ProgramAssociationInfo(fa.ProgID); if (!pa.Exists) { return; } ProgramVerb[] verbs = pa.Verbs; List<ProgramVerb> l = new List<ProgramVerb>(); l.AddRange(verbs); //remove existed verb ProgramVerb openVerb = l.SingleOrDefault(v => v.Name == "open"); if (openVerb != null) { l.Remove(openVerb); } //add new value openVerb = new ProgramVerb("open", "\"" + appPath + "\" \"%1\""); l.Add(openVerb); //save & apply changes pa.Verbs = l.ToArray(); GlobalSetting.SetConfig("ContextMenuExtensions", exts); } }
/// <summary> /// Creates actual Programmatic Identifier key in registry that is used by other extensions. /// </summary> /// <param name="verb">Single <see cref="ProgramVerb"/> that contains supported verb.</param> /// <returns><see cref="ProgramAssociationInfo"/> instance referring to specified extension.</returns> public ProgramAssociationInfo Create(ProgramVerb verb) { return(Create(string.Empty, EditFlags.None, new ProgramVerb[] { verb })); }
/// <summary> /// Adds single <see cref="ProgramVerb"/> that define the verb supported by this ProgID. /// </summary> /// <param name="verb">Single <see cref="ProgramVerb"/> that contains supported verb.</param> protected void AddVerbInternal(ProgramVerb verb) { RegistryKey root = Registry.ClassesRoot; RegistryKey key = root.OpenSubKey(progId).OpenSubKey("shell", true); if (key == null) { key = root.OpenSubKey(progId, true).CreateSubKey("shell"); } RegistryKey tmpkey = key.OpenSubKey(verb.Name, true); if (tmpkey == null) { tmpkey = key.CreateSubKey(verb.Name); } key = tmpkey; tmpkey = key.OpenSubKey("command", true); if (tmpkey == null) { tmpkey = key.CreateSubKey("command"); } tmpkey.SetValue(string.Empty, verb.Command, RegistryValueKind.ExpandString); tmpkey.Close(); key.Close(); root.Close(); ShellNotification.NotifyOfChange(); }
/// <summary> /// Sets an array of <see cref="ProgramVerb"/> that define the verbs supported by this ProgID /// </summary> /// <param name="verbs">Array of <see cref="ProgramVerb"/> that contains verbs to be set.</param> protected void SetVerbs(ProgramVerb[] verbs) { if (!Exists) throw new Exception("Extension does not exist"); RegistryKey root = Registry.ClassesRoot; RegistryKey key = root.OpenSubKey(progId, true); RegistryKey tmpKey = key.OpenSubKey("shell", true); if (tmpKey != null) { key.DeleteSubKeyTree("shell"); } tmpKey = key.CreateSubKey("shell"); foreach (ProgramVerb verb in verbs) { RegistryKey newVerb = tmpKey.CreateSubKey(verb.Name.ToLower()); RegistryKey command = newVerb.CreateSubKey("command"); command.SetValue(string.Empty, verb.Command, RegistryValueKind.ExpandString); command.Close(); newVerb.Close(); } ShellNotification.NotifyOfChange(); }
/// <summary> /// Creates actual Programmatic Identifier key in registry that is used by other extensions. /// </summary> /// <param name="description">Friendly description of file type.</param> /// <param name="editFlags"><see cref="EditFlags"/> for program file type.</param> /// <param name="verbs">Array of <see cref="ProgramVerb"/> that contains supported verbs.</param> /// <returns><see cref="ProgramAssociationInfo"/> instance referring to specified extension.</returns> public ProgramAssociationInfo Create(string description, EditFlags editFlags, ProgramVerb[] verbs) { if (Exists) { Delete(); } Create(); if (description != string.Empty) Description = description; if (editFlags != EditFlags.None) EditFlags = editFlags; Verbs = verbs; return this; }
/// <summary> /// Removes single <see cref="ProgramVerb"/> that define the verb supported by this ProgID. /// </summary> /// <param name="verb">Single <see cref="ProgramVerb"/> that contains supported verb.</param> public void RemoveVerb(ProgramVerb verb) { if (verb == null) throw new NullReferenceException(); RemoveVerb(verb.Name); }
/// <summary> /// Creates actual Programmatic Identifier key in registry that is used by other extensions. /// </summary> /// <param name="description">Friendly description of file type.</param> /// <param name="editFlags"><see cref="EditFlags"/> for program file type.</param> /// <param name="verb">Single <see cref="ProgramVerb"/> that contains supported verbs.</param> /// <returns><see cref="ProgramAssociationInfo"/> instance referring to specified extension.</returns> public ProgramAssociationInfo Create(string description, EditFlags editFlags, ProgramVerb verb) { return Create(description, editFlags, new ProgramVerb[] { verb }); }
/// <summary> /// Creates actual Programmatic Identifier key in registry that is used by other extensions. /// </summary> /// <param name="description">Friendly description of file type.</param> /// <param name="verbs">Array of <see cref="ProgramVerb"/> that contains supported verbs.</param> /// <returns><see cref="ProgramAssociationInfo"/> instance referring to specified extension.</returns> public ProgramAssociationInfo Create(string description, ProgramVerb[] verbs) { return Create(description, EditFlags.None, verbs); }
/// <summary> /// Creates actual Programmatic Identifier key in registry that is used by other extensions. /// </summary> /// <param name="verbs">Array of <see cref="ProgramVerb"/> that contains supported verbs.</param> /// <returns><see cref="ProgramAssociationInfo"/> instance referring to specified extension.</returns> public ProgramAssociationInfo Create(ProgramVerb[] verbs) { return Create(string.Empty, EditFlags.None, verbs); }
/// <summary> /// Creates actual Programmatic Identifier key in registry that is used by other extensions. /// </summary> /// <param name="verb">Single <see cref="ProgramVerb"/> that contains supported verb.</param> /// <returns><see cref="ProgramAssociationInfo"/> instance referring to specified extension.</returns> public ProgramAssociationInfo Create(ProgramVerb verb) { return Create(string.Empty, EditFlags.None, new ProgramVerb[] { verb }); }