diff --git a/FemDesign.Core/FemDesignConnection.cs b/FemDesign.Core/FemDesignConnection.cs index 3ccfd610..ffbef05a 100644 --- a/FemDesign.Core/FemDesignConnection.cs +++ b/FemDesign.Core/FemDesignConnection.cs @@ -130,42 +130,28 @@ public FemDesignConnection( /// Retrieve the default FEM-Design installation directory or specify a custom directory path for FemDesignConnection. /// /// FEM-Design software installation directory. If set to `null`, the default directory will be used. - /// + /// The installation directory path. /// public string SetFemDesignDirectory(string fdInstallationDir) { - string dir = null; - // Check if specified directory exists - if (fdInstallationDir != null) + if (!string.IsNullOrEmpty(fdInstallationDir) && Directory.Exists(fdInstallationDir)) + return fdInstallationDir; + + var defaultDirs = new List() { - if (Directory.Exists(fdInstallationDir)) - { - dir = fdInstallationDir; - } - } + @"C:\Program Files\StruSoft\FEM-Design 23\", + @"C:\Program Files\StruSoft\FEM-Design 23 Educational\", + @"C:\Program Files\StruSoft\FEM-Design 23 Student\" + }; - if(dir == null) + foreach (var dir in defaultDirs) { - var dirNames = new List() - { - @"C:\Program Files\StruSoft\FEM-Design 23\", - @"C:\Program Files\StruSoft\FEM-Design 23 Educational\", - @"C:\Program Files\StruSoft\FEM-Design 23 Student\" - }; - for (int i = 0; i < dirNames.Count; i++) - { - if (Directory.Exists(dirNames[i])) - { - dir = dirNames[i]; - break; - } - } - if (dir == null) - throw new ArgumentNullException($"Default FEM-Design installation directory is not found. Input directory `{fdInstallationDir}` does not exist!"); + if (Directory.Exists(dir)) + return dir; } - return dir; + throw new ArgumentNullException($"Default FEM-Design installation directory is not found. Input directory `{fdInstallationDir}` does not exist!"); } private void _processExited(object sender, EventArgs e)