Пример #1
0
        public static bool GetConfigSettings(out string error)
        {
            error           = null;
            DacFolder       = string.Empty;
            DumpsFolder     = string.Empty;
            ProcDumpFolder  = string.Empty;
            RecentIndexList = new List <string>();
            RecentAdhocList = new List <string>();
            StringBuilder errors = StringBuilderCache.Acquire(256);

            try
            {
#if DEBUG
                //string myfolder = @"D:\Jerzy\WinDbgStuff\MDRDesk\";
                string myfolder = @"C:\WinDbgStuff\MDRDesk\";
#else
                string myfolder = DumpFileMoniker.MyFolder;
#endif
                string installFolder = DumpFileMoniker.GetParentFolder(myfolder);
                var    config        = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                var    appSettings   = (AppSettingsSection)config.GetSection("appSettings");
                if (appSettings.Settings.Count != 0)
                {
                    foreach (string key in appSettings.Settings.AllKeys)
                    {
                        var ky = key.ToLower();
                        if (Utils.SameStrings(ky, "dacfolder"))
                        {
                            var folder = appSettings.Settings[key].Value.Trim();
                            if (Directory.Exists(folder))
                            {
                                DacFolder = folder;
                            }
                            string path = installFolder + @"mscordacwks";
                            if (Directory.Exists(path))
                            {
                                DacFolder = path;
                            }
                            else
                            {
                                errors.AppendLine("Dac folder does not exist: " + folder);
                            }
                        }
                        else if (Utils.SameStrings(ky, "mapfolder"))
                        {
                            var folder = appSettings.Settings[key].Value.Trim();
                            if (Directory.Exists(folder))
                            {
                                DumpsFolder = folder;
                            }
                            else
                            {
                                // if dumps folder exists, add it to config
                                string path = installFolder + @"dumps";
                                if (Directory.Exists(path))
                                {
                                    DumpsFolder = path;
                                }
                                else
                                {
                                    errors.AppendLine("Dumps folder does not exist: " + folder);
                                }
                            }
                        }
                        else if (Utils.SameStrings(ky, "procdumpfolder"))
                        {
                            var folder = appSettings.Settings[key].Value.Trim();
                            if (Directory.Exists(folder))
                            {
                                ProcDumpFolder = folder;
                            }
                            else
                            {
                                ProcDumpFolder = "";
                            }
//                            else errors.AppendLine("procdum.exe folder does not exist: " + folder);
                        }
                        else if (Utils.SameStrings(ky, "helpfolder"))
                        {
                            var folder = appSettings.Settings[key].Value.Trim();
                            if (Directory.Exists(folder))
                            {
                                HelpFolder = folder;
                            }
                            else
                            {
                                string path = myfolder + @"Documentation";
                                if (Directory.Exists(path))
                                {
                                    HelpFolder = myfolder;
                                }
                                else
                                {
                                    errors.AppendLine("Documentation folder does not exist: " + folder);
                                }
                            }
                        }
                        else if (Utils.SameStrings(ky, "refbuilder"))
                        {
                            var val = appSettings.Settings[key].Value.Trim();
                            CppRefBuilder = string.Compare(val, "c++", StringComparison.OrdinalIgnoreCase) == 0;
                        }
                        else if (Utils.SameStrings(ky, "refreader"))
                        {
                            var val = appSettings.Settings[key].Value.Trim();
                            MapRefReader = string.Compare(val, "map", StringComparison.OrdinalIgnoreCase) == 0;
                        }
                        else if (Utils.SameStrings(ky, "wnddbgfolder"))
                        {
                            var folder = appSettings.Settings[key].Value.Trim();
                            if (Directory.Exists(folder))
                            {
                                WndDbgFolder = folder;
                            }
                            //else errors.AppendLine("help folder does not exist: " + folder);
                        }
                        else if (Utils.SameStrings(ky, "graphproxy"))
                        {
                            GraphDbJar = appSettings.Settings[key].Value.Trim();
                        }
                        else if (Utils.SameStrings(ky, "graphport"))
                        {
                            GraphPort = Int32.Parse(appSettings.Settings[key].Value.Trim());
                        }
                        else if (Utils.SameStrings(ky, "recentindices"))
                        {
                            GetSemicolonDelimitedFolderPaths(RecentIndexList, appSettings.Settings[key].Value);
                        }
                        else if (Utils.SameStrings(ky, "recentadhocs"))
                        {
                            GetSemicolonDelimitedFilePaths(RecentAdhocList, appSettings.Settings[key].Value);
                        }
                        else if (Utils.SameStrings(ky, "typedisplaymode"))
                        {
                            TypesDisplayMode = appSettings.Settings[key].Value.Trim();
                        }
                    }
                }
                else
                {
                    error = "The appSettings section is empty.";
                }
                if (errors.Length > 0)
                {
                    return(false);
                }
                return(true);
            }
            catch (Exception ex)
            {
                error = Utils.GetExceptionErrorString(ex);
                return(false);
            }
            finally
            {
                if (errors.Length > 0)
                {
                    error = "Initialization Failed" + Constants.HeavyGreekCrossPadded
                            + "Setup.GetConfigSettings()" + Constants.HeavyGreekCrossPadded
                            + "MDRDesk application config file is invalid." + Environment.NewLine + "See details." +
                            Constants.HeavyGreekCrossPadded
                            + StringBuilderCache.GetStringAndRelease(errors);
                }
                else
                {
                    StringBuilderCache.Release(errors);
                }
            }
        }