1. 程式人生 > >ArcGIS Pro 獲取proConfigX所在目錄

ArcGIS Pro 獲取proConfigX所在目錄

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;
        }

執行結果: