ArcGIS Pro 获取proConfigX所在目录

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/xiangqiang2015/article/details/84067141

ArcGIS Pro会将我们开发的esriAddInx、proConfigX文件中的dll拷贝到他的缓存目录去运行,然后我们的应用程序往往需要输出日志、成果文件等到我们的程序的组织目录,如何找到程序的组织目录而不是Pro的缓存目录:

 protected override void GetSysDirectory()
        {
            string[] str = Environment.GetCommandLineArgs();
            if (str.Length != 2)
                return;

            string proConfigName = str[1].Split(new char[] { ':' })[1];
            List<string> dirConfig =GetConfigFolders();
            m_SystemDir = dirConfig.Find((item) =>
            {
                DirectoryInfo drcInfo = new DirectoryInfo(item);
                if (drcInfo.Exists)
                {
                    var files = drcInfo.GetFiles(proConfigName + ".proConfigX");
                    return files != null && files.Length > 0;
                }

                return false;
            });
        }

   public List<string> GetConfigFolders()
        {
            List<string> myAddInPathKeys = new List<string>();
            string regPath = string.Format(@"Software\ESRI\ArcGISPro\Settings\Configuration Folders");
            //string path = "";
            string err1 = "This is an error";
            try
            {
                Microsoft.Win32.RegistryKey localKey = Microsoft.Win32.RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, Microsoft.Win32.RegistryView.Registry64);
                Microsoft.Win32.RegistryKey esriKey = localKey.OpenSubKey(regPath);
                if (esriKey == null)
                {
                    localKey = Microsoft.Win32.RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.CurrentUser, Microsoft.Win32.RegistryView.Registry64);
                    esriKey = localKey.OpenSubKey(regPath);
                }
                if (esriKey != null)
                    myAddInPathKeys.AddRange(esriKey.GetValueNames().Select(key => key.ToString()));
            }
            catch (InvalidOperationException ie)
            {
                throw ie;
            }
            catch (Exception ex)
            {
                throw new System.Exception(err1, ex);
            }
            return myAddInPathKeys;
        }

运行结果:

猜你喜欢

转载自blog.csdn.net/xiangqiang2015/article/details/84067141