|
4 | 4 | using EventLogExpert.Eventing.EventResolvers; |
5 | 5 | using EventLogExpert.Eventing.Helpers; |
6 | 6 | using EventLogExpert.Eventing.Readers; |
| 7 | +using EventLogExpert.Platforms.Windows; |
7 | 8 | using EventLogExpert.Services; |
8 | 9 | using EventLogExpert.UI; |
9 | 10 | using EventLogExpert.UI.Interfaces; |
@@ -136,21 +137,38 @@ public void Dispose() |
136 | 137 | _cancellationTokenSource.Dispose(); |
137 | 138 | } |
138 | 139 |
|
139 | | - private static async Task<IEnumerable<FileResult?>> GetFilePickerResult() |
| 140 | + private static async Task<IEnumerable<FileResult>> GetFilePickerResultAsync() |
140 | 141 | { |
141 | 142 | var options = new PickOptions |
142 | 143 | { |
143 | 144 | FileTypes = new FilePickerFileType( |
144 | | - new Dictionary<DevicePlatform, IEnumerable<string>> |
145 | | - { |
146 | | - { DevicePlatform.WinUI, [".evtx"] } |
147 | | - } |
148 | | - ) |
| 145 | + new Dictionary<DevicePlatform, IEnumerable<string>> { { DevicePlatform.WinUI, [".evtx"] } }) |
149 | 146 | }; |
150 | 147 |
|
151 | 148 | return await FilePicker.Default.PickMultipleAsync(options); |
152 | 149 | } |
153 | 150 |
|
| 151 | + private static async Task<IEnumerable<FileResult>> GetFolderPickerResultAsync() |
| 152 | + { |
| 153 | + string? folderPath = await FolderPickerHelper.PickFolderAsync(); |
| 154 | + |
| 155 | + if (folderPath is null) |
| 156 | + { |
| 157 | + return []; |
| 158 | + } |
| 159 | + |
| 160 | + List<FileResult> fileResults = []; |
| 161 | + |
| 162 | + foreach (string file in Directory.EnumerateFiles(folderPath, "*.evtx", SearchOption.TopDirectoryOnly)) |
| 163 | + { |
| 164 | + var fileResult = new FileResult(file); |
| 165 | + |
| 166 | + fileResults.Add(fileResult); |
| 167 | + } |
| 168 | + |
| 169 | + return fileResults; |
| 170 | + } |
| 171 | + |
154 | 172 | private async void CheckForUpdates_Clicked(object? sender, EventArgs e) |
155 | 173 | { |
156 | 174 | if (!_currentVersionProvider.IsSupportedOS(DeviceInfo.Version)) |
@@ -326,21 +344,41 @@ private async void OpenFile_Clicked(object sender, EventArgs e) |
326 | 344 |
|
327 | 345 | bool shouldAddLog = item.CommandParameter is true; |
328 | 346 |
|
329 | | - var result = await GetFilePickerResult(); |
| 347 | + var files = await GetFilePickerResultAsync(); |
| 348 | + |
| 349 | + if (!files.Any()) { return; } |
| 350 | + |
| 351 | + if (!shouldAddLog) |
| 352 | + { |
| 353 | + await _cancellationTokenSource.CancelAsync(); |
| 354 | + _fluxorDispatcher.Dispatch(new EventLogAction.CloseAll()); |
| 355 | + } |
| 356 | + |
| 357 | + foreach (var file in files) |
| 358 | + { |
| 359 | + await OpenLog(file.FullPath, PathType.FilePath, shouldAddLog: true); |
| 360 | + } |
| 361 | + } |
| 362 | + |
| 363 | + private async void OpenFolder_Clicked(object sender, EventArgs e) |
| 364 | + { |
| 365 | + if (sender is not MenuFlyoutItem item) { return; } |
| 366 | + |
| 367 | + bool shouldAddLog = item.CommandParameter is true; |
330 | 368 |
|
331 | | - var logs = result.Where(f => f is not null).ToList(); |
| 369 | + var files = await GetFolderPickerResultAsync(); |
332 | 370 |
|
333 | | - if (logs.Count <= 0) { return; } |
| 371 | + if (!files.Any()) { return; } |
334 | 372 |
|
335 | 373 | if (!shouldAddLog) |
336 | 374 | { |
337 | 375 | await _cancellationTokenSource.CancelAsync(); |
338 | 376 | _fluxorDispatcher.Dispatch(new EventLogAction.CloseAll()); |
339 | 377 | } |
340 | 378 |
|
341 | | - foreach (var file in logs) |
| 379 | + foreach (var file in files) |
342 | 380 | { |
343 | | - await OpenLog(file!.FullPath, PathType.FilePath, shouldAddLog: true); |
| 381 | + await OpenLog(file.FullPath, PathType.FilePath, shouldAddLog: true); |
344 | 382 | } |
345 | 383 | } |
346 | 384 |
|
|
0 commit comments