Skip to content

Commit e21cc54

Browse files
feat(batch): implement nested directory processing
This update introduces user-configurable options for subfolder inclusion in batch operations. File search methods now dynamically adjust between TopDirectoryOnly and AllDirectories based on checkbox state.
1 parent 8dafd8b commit e21cc54

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

BatchConvertToCHD/MainWindow.xaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383

8484
<GroupBox Header="Options" Margin="0,5,0,10" Padding="10">
8585
<StackPanel>
86+
<CheckBox x:Name="SearchSubfoldersConversionCheckBox" Content="Search for files in subfolders" Margin="0,5" HorizontalAlignment="Left" ToolTip="Recursively search for files in all subfolders" />
8687
<CheckBox x:Name="DeleteOriginalsCheckBox" Content="Delete original files after successful conversion" Margin="0,5" HorizontalAlignment="Left" ToolTip="Automatically delete source files once they are successfully converted to CHD" />
8788
<CheckBox x:Name="ProcessSmallerFirstCheckBox" Content="Process smaller files first" Margin="0,5" HorizontalAlignment="Left" ToolTip="Sort files by size and process the smallest ones first" />
8889
<StackPanel Orientation="Horizontal" Margin="0,5">
@@ -113,6 +114,7 @@
113114

114115
<GroupBox Header="Options" Margin="0,5,0,10" Padding="10">
115116
<StackPanel>
117+
<CheckBox x:Name="SearchSubfoldersVerificationCheckBox" Content="Search for files in subfolders" Margin="0,5" HorizontalAlignment="Left" ToolTip="Recursively search for files in all subfolders" />
116118
<CheckBox x:Name="MoveSuccessFilesCheckBox" Content="Move successfully tested CHD files to 'Success' folder" Margin="0,5" HorizontalAlignment="Left" ToolTip="Move CHD files that pass verification into a 'Success' subfolder" />
117119
<CheckBox x:Name="MoveFailedFilesCheckBox" Content="Move failed tested CHD files to 'Failed' folder" Margin="0,5" HorizontalAlignment="Left" ToolTip="Move CHD files that fail verification into a 'Failed' subfolder" />
118120
</StackPanel>

BatchConvertToCHD/MainWindow.xaml.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -550,13 +550,14 @@ private async void StartConversionButton_Click(object sender, RoutedEventArgs e)
550550
var processSmallerFirst = ProcessSmallerFirstCheckBox.IsChecked ?? false;
551551
var forceCd = ForceCreateCdCheckBox.IsChecked ?? false;
552552
var forceDvd = ForceCreateDvdCheckBox.IsChecked ?? false;
553+
var includeSubfolders = SearchSubfoldersConversionCheckBox.IsChecked ?? false;
553554

554555
LogMessage("--- Starting batch conversion process... ---");
555556

556557
try
557558
{
558559
await PerformBatchConversionAsync(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, AppConfig.ChdmanExeName),
559-
inputFolder, outputFolder, deleteFiles, processSmallerFirst, forceCd, forceDvd, _cts.Token);
560+
inputFolder, outputFolder, deleteFiles, processSmallerFirst, forceCd, forceDvd, includeSubfolders, _cts.Token);
560561
}
561562
catch (OperationCanceledException)
562563
{
@@ -606,7 +607,7 @@ private async void StartVerificationButton_Click(object sender, RoutedEventArgs
606607
_operationTimer.Restart();
607608
ResetSpeedCounters();
608609

609-
const bool includeSub = false; // VerificationIncludeSubfoldersCheckBox.IsChecked ?? false; // Disabled to prevent infinite nesting
610+
var includeSubfolders = SearchSubfoldersVerificationCheckBox.IsChecked ?? false;
610611
var moveSuccess = MoveSuccessFilesCheckBox.IsChecked ?? false;
611612
var moveFailed = MoveFailedFilesCheckBox.IsChecked ?? false;
612613
var successFolder = moveSuccess ? Path.Combine(inputFolder, "Success") : string.Empty;
@@ -617,7 +618,7 @@ private async void StartVerificationButton_Click(object sender, RoutedEventArgs
617618
try
618619
{
619620
await PerformBatchVerificationAsync(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, AppConfig.ChdmanExeName),
620-
inputFolder, includeSub, moveSuccess, successFolder, moveFailed, failedFolder, _cts.Token);
621+
inputFolder, includeSubfolders, moveSuccess, successFolder, moveFailed, failedFolder, _cts.Token);
621622
}
622623
catch (OperationCanceledException)
623624
{
@@ -665,14 +666,15 @@ private void SetControlsState(bool enabled)
665666
BrowseConversionInputButton.IsEnabled = enabled;
666667
ConversionOutputFolderTextBox.IsEnabled = enabled;
667668
BrowseConversionOutputButton.IsEnabled = enabled;
669+
SearchSubfoldersConversionCheckBox.IsEnabled = enabled;
668670
DeleteOriginalsCheckBox.IsEnabled = enabled;
669671
ProcessSmallerFirstCheckBox.IsEnabled = enabled;
670672
StartConversionButton.IsEnabled = enabled;
671673
ForceCreateCdCheckBox.IsEnabled = enabled;
672674
ForceCreateDvdCheckBox.IsEnabled = enabled;
673675
VerificationInputFolderTextBox.IsEnabled = enabled;
674676
BrowseVerificationInputButton.IsEnabled = enabled;
675-
// VerificationIncludeSubfoldersCheckBox.IsEnabled = false; // Removed
677+
SearchSubfoldersVerificationCheckBox.IsEnabled = enabled;
676678
StartVerificationButton.IsEnabled = enabled;
677679
MoveSuccessFilesCheckBox.IsEnabled = enabled;
678680
MoveFailedFilesCheckBox.IsEnabled = enabled;
@@ -721,14 +723,14 @@ private void SetControlsState(bool enabled)
721723
return dialog.ShowDialog() == true ? dialog.FolderName : null;
722724
}
723725

724-
private async Task PerformBatchConversionAsync(string chdmanPath, string inputFolder, string outputFolder, bool deleteFiles, bool processSmallerFirst, bool forceCd, bool forceDvd, CancellationToken token)
726+
private async Task PerformBatchConversionAsync(string chdmanPath, string inputFolder, string outputFolder, bool deleteFiles, bool processSmallerFirst, bool forceCd, bool forceDvd, bool includeSubfolders, CancellationToken token)
725727
{
726728
if (!await ValidateExecutableAccessAsync(chdmanPath, "chdman.exe")) return;
727729
if (!await ValidateChdmanCompatibilityAsync(chdmanPath)) return;
728730

729731
var filesToConvert = await Task.Run(() =>
730732
{
731-
var files = Directory.GetFiles(inputFolder, "*.*", SearchOption.TopDirectoryOnly)
733+
var files = Directory.GetFiles(inputFolder, "*.*", includeSubfolders ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly)
732734
.Where(static file => AllSupportedInputExtensionsForConversion.Contains(Path.GetExtension(file).ToLowerInvariant()));
733735

734736
if (processSmallerFirst)
@@ -964,8 +966,8 @@ private async Task PerformBatchVerificationAsync(string chdmanPath, string input
964966
if (!await ValidateExecutableAccessAsync(chdmanPath, "chdman.exe")) return;
965967
if (!await ValidateChdmanCompatibilityAsync(chdmanPath)) return;
966968

967-
// Force TopDirectoryOnly to prevent infinite recursion when moving files to subfolders
968-
var files = await Task.Run(() => Directory.GetFiles(inputFolder, "*.chd", SearchOption.TopDirectoryOnly), token);
969+
// Use includeSub parameter to determine search option
970+
var files = await Task.Run(() => Directory.GetFiles(inputFolder, "*.chd", includeSub ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly), token);
969971
_totalFilesProcessed = files.Length;
970972
UpdateStatsDisplay();
971973
LogMessage($"Found {_totalFilesProcessed} CHD files.");

0 commit comments

Comments
 (0)