Skip to content

Commit 2c79a87

Browse files
author
BRUNER Patrick
committed
review comments
1 parent a97e78e commit 2c79a87

3 files changed

Lines changed: 21 additions & 27 deletions

File tree

src/LogExpert.Core/Classes/Persister/ProjectFileValidator.cs

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,10 @@ private static List<string> FindAlternativePaths (string fileName, string projec
146146

147147
// Also check subdirectories (one level deep)
148148
var subdirs = Directory.GetDirectories(projectDir);
149-
foreach (var subdir in subdirs)
150-
{
151-
var subdirCandidate = Path.Join(subdir, baseName);
152-
if (File.Exists(subdirCandidate))
153-
{
154-
alternatives.Add(subdirCandidate);
155-
}
156-
}
149+
alternatives.AddRange(
150+
subdirs
151+
.Select(subdir => Path.Join(subdir, baseName))
152+
.Where(File.Exists));
157153
}
158154
}
159155
catch (Exception ex) when (ex is ArgumentException or
@@ -181,10 +177,10 @@ UnauthorizedAccessException or
181177
}
182178
}
183179
catch (Exception ex) when (ex is ArgumentException or
184-
ArgumentNullException or
185-
PathTooLongException or
186-
UnauthorizedAccessException or
187-
IOException)
180+
ArgumentNullException or
181+
PathTooLongException or
182+
UnauthorizedAccessException or
183+
IOException)
188184
{
189185
// Ignore errors when searching in Documents folder
190186
}
@@ -203,23 +199,20 @@ UnauthorizedAccessException or
203199
var originalDrive = Path.GetPathRoot(fileName)?[0];
204200
var pathWithoutDrive = fileName.Length > 3 ? fileName[3..] : string.Empty;
205201

206-
foreach (var drive in driveLetters)
202+
foreach (var drive in driveLetters.Where(drive => drive != originalDrive && !string.IsNullOrEmpty(pathWithoutDrive)))
207203
{
208-
if (drive != originalDrive && !string.IsNullOrEmpty(pathWithoutDrive))
204+
var alternatePath = $"{drive}:\\{pathWithoutDrive}";
205+
if (File.Exists(alternatePath) && !alternatives.Contains(alternatePath))
209206
{
210-
var alternatePath = $"{drive}:\\{pathWithoutDrive}";
211-
if (File.Exists(alternatePath) && !alternatives.Contains(alternatePath))
212-
{
213-
alternatives.Add(alternatePath);
214-
}
207+
alternatives.Add(alternatePath);
215208
}
216209
}
217210
}
218211
catch (Exception ex) when (ex is ArgumentException or
219-
ArgumentNullException or
220-
PathTooLongException or
221-
UnauthorizedAccessException or
222-
IOException)
212+
ArgumentNullException or
213+
PathTooLongException or
214+
UnauthorizedAccessException or
215+
IOException)
223216
{
224217
// Ignore errors when searching on different drives
225218
}

src/LogExpert.Persister.Tests/ProjectFileValidatorTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,8 @@ private void CreatePersistenceFile (string lxpFileName, string logFileName)
102102
/// </summary>
103103
private void DeleteLogFiles (params string[] fileNames)
104104
{
105-
foreach (var fileName in fileNames)
105+
foreach (var filePath in fileNames.Select(fileName => Path.Join(_testDirectory, fileName)))
106106
{
107-
var filePath = Path.Join(_testDirectory, fileName);
108107
if (File.Exists(filePath))
109108
{
110109
File.Delete(filePath);

src/LogExpert.UI/Dialogs/MissingFilesDialog.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,6 @@ private void UpdateSummary ()
266266
/// Opens a file browser dialog for the specified missing file.
267267
/// </summary>
268268
/// <param name="fileItem">The file item to browse for</param>
269-
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Intentionally Left Blank")]
270269
private void BrowseForFile (MissingFileItem fileItem)
271270
{
272271
using var openFileDialog = new OpenFileDialog
@@ -287,7 +286,10 @@ private void BrowseForFile (MissingFileItem fileItem)
287286
openFileDialog.InitialDirectory = directory;
288287
}
289288
}
290-
catch
289+
catch (Exception ex) when (ex is ArgumentException or
290+
PathTooLongException or
291+
NotSupportedException or
292+
UnauthorizedAccessException)
291293
{
292294
// Ignore if path is invalid
293295
}

0 commit comments

Comments
 (0)