Skip to content

Commit

Permalink
♻️ refactor SetFemDesignDirectory()
Browse files Browse the repository at this point in the history
  • Loading branch information
lorinczandrea committed Jul 18, 2024
1 parent 8528575 commit bf639f5
Showing 1 changed file with 13 additions and 27 deletions.
40 changes: 13 additions & 27 deletions FemDesign.Core/FemDesignConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,42 +130,28 @@ public FemDesignConnection(
/// Retrieve the default FEM-Design installation directory or specify a custom directory path for FemDesignConnection.
/// </summary>
/// <param name="fdInstallationDir">FEM-Design software installation directory. If set to `null`, the default directory will be used.</param>
/// <returns></returns>
/// <returns>The installation directory path.</returns>
/// <exception cref="ArgumentNullException"></exception>
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<string>()
{
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<string>()
{
@"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)
Expand Down

0 comments on commit bf639f5

Please sign in to comment.