FileAssociation

using System;
using System.Text;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using Microsoft.Win32;

namespace wsWin
{
    #region [ FileAssociation ]
    public class FileAssociation
    {
        public static string Startpath()
        {
            return System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
        }

        public static void DoAssociate(string extension, string progID, string description, string icon)
        {
            if (FileAssociation.IsAssociated(extension))
            {
                RegistryKey key = Registry.ClassesRoot;
                key.DeleteSubKeyTree(extension);
                key.Close();
            }
            FileAssociation.Associate(extension, progID, description, icon, Application.ExecutablePath);
            FileAssociation.refreshSystem();
        }

        public static void DoAssociate(string extension, string progID, string description, string icon, string application)
        {
            if (FileAssociation.IsAssociated(extension))
            {
                RegistryKey key = Registry.ClassesRoot;
                key.DeleteSubKeyTree(extension);
                key.Close();
            }
            FileAssociation.Associate(extension, progID, description, icon, application);
            FileAssociation.refreshSystem();
        }

        public static void UnAssociate(string extension)
        {
            if (FileAssociation.IsAssociated(extension))
            {
                RegistryKey key = Registry.ClassesRoot;
                key.DeleteSubKeyTree(extension);
                key.Close();
                FileAssociation.refreshSystem();
            }
        }

        // Associate file extension with progID, description, icon and application
        public static void Associate(string extension, string progID, string description, string icon, string application)
        {
            Registry.ClassesRoot.CreateSubKey(extension).SetValue("", progID);
            if (progID != null && progID.Length > 0)
                using (RegistryKey key = Registry.ClassesRoot.CreateSubKey(progID))
                {
                    if (description != null)
                        key.SetValue("", description);
                    if (icon != null)
                        key.CreateSubKey("DefaultIcon").SetValue("", ToShortPathName(icon));
                    if (application != null)
                        key.CreateSubKey(@"Shell\Open\Command").SetValue("",
                                    ToShortPathName(application) + " \"%1\"");
                }
        }

        // Return true if extension already associated in registry
        public static bool IsAssociated(string extension)
        {
            return (Registry.ClassesRoot.OpenSubKey(extension, false) != null);
        }

        public static void refreshSystem()
        {
            SHChangeNotify(HChangeNotifyEventID.SHCNE_ASSOCCHANGED, HChangeNotifyFlags.SHCNF_IDLIST, IntPtr.Zero, IntPtr.Zero);
        }

        [DllImport("Kernel32.dll")]
        private static extern uint GetShortPathName(string lpszLongPath,
            [Out] StringBuilder lpszShortPath, uint cchBuffer);

        [DllImport("shell32.dll")]
        static extern void SHChangeNotify(HChangeNotifyEventID wEventId, HChangeNotifyFlags uFlags, IntPtr dwItem1, IntPtr dwItem2);

        // Return short path format of a file name
        private static string ToShortPathName(string longName)
        {
            StringBuilder s = new StringBuilder(1000);
            uint iSize = (uint)s.Capacity;
            uint iRet = GetShortPathName(longName, s, iSize);
            return s.ToString();
        }
    }

    #region public enum HChangeNotifyFlags

    [Flags]
    public enum HChangeNotifyFlags
    {

        SHCNF_DWORD = 0x0003,
        SHCNF_IDLIST = 0x0000,

        SHCNF_PATHA = 0x0001,

        SHCNF_PATHW = 0x0005,

        SHCNF_PRINTERA = 0x0002,

        SHCNF_PRINTERW = 0x0006,
        SHCNF_FLUSH = 0x1000,
        SHCNF_FLUSHNOWAIT = 0x2000
    }
    #endregion // enum HChangeNotifyFlags
    #region enum HChangeNotifyEventID
    [Flags]
    enum HChangeNotifyEventID
    {
        SHCNE_ALLEVENTS = 0x7FFFFFFF,

        SHCNE_ASSOCCHANGED = 0x08000000,

        SHCNE_ATTRIBUTES = 0x00000800,

        SHCNE_CREATE = 0x00000002,

        SHCNE_DELETE = 0x00000004,

        SHCNE_DRIVEADD = 0x00000100,

        SHCNE_DRIVEADDGUI = 0x00010000,

        SHCNE_DRIVEREMOVED = 0x00000080,

        SHCNE_EXTENDED_EVENT = 0x04000000,

        SHCNE_FREESPACE = 0x00040000,

        SHCNE_MEDIAINSERTED = 0x00000020,

        SHCNE_MEDIAREMOVED = 0x00000040,

        SHCNE_MKDIR = 0x00000008,

        SHCNE_NETSHARE = 0x00000200,

        SHCNE_NETUNSHARE = 0x00000400,

        SHCNE_RENAMEFOLDER = 0x00020000,

        SHCNE_RENAMEITEM = 0x00000001,

        SHCNE_RMDIR = 0x00000010,

        SHCNE_SERVERDISCONNECT = 0x00004000,

        SHCNE_UPDATEDIR = 0x00001000,

        SHCNE_UPDATEIMAGE = 0x00008000,

    }
    #endregion // enum HChangeNotifyEventID

    #endregion
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
"vivado2017 no user accessible processors found for elf file association" 这个错误提示说明在Vivado 2017中,没有找到可供用户访问的处理器来进行elf文件关联。 在Vivado开发环境中,elf文件是一种可执行文件格式,通常用于嵌入式系统中的程序运行。当我们尝试将elf文件与适当的处理器进行关联时,Vivado需要找到适用于该文件的处理器模型,以正确解析和执行程序。 然而,这个错误提示表明在Vivado 2017中,并没有找到合适的处理器模型来与此elf文件进行关联。可能的原因有以下几种: 1. Vivado 2017版本并不直接支持该elf文件所对应的处理器模型。在这种情况下,我们可以尝试升级到更高版本的Vivado,或者查找其他工具来支持我们的处理器模型。 2. Vivado 2017中已安装了所需的处理器模型,但其路径配置不正确。在这种情况下,我们可以检查Vivado的配置文件,确认处理器模型的路径是否正确,并进行相应的修复。 3. 我们在使用Vivado 2017时,可能未正确设置或加载所需的处理器模型。在这种情况下,我们可以确保在项目配置中正确选择和加载所需的处理器模型。 综上所述,如果在Vivado 2017中出现"vivado2017 no user accessible processors found for elf file association"错误提示,我们需要检查所需处理器模型的可用性、配置文件路径和项目设置,以确认是否满足正确关联elf文件所需的条件。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值