Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI: Fix single core batch processing #95

Merged
merged 1 commit into from
Feb 13, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 23 additions & 21 deletions src/VGAudio.Cli/Batch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,30 @@ public static bool BatchConvert(Options options)
{
progress.SetTotal(files.Length);

Parallel.ForEach(files, new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount - 1 }, inPath =>
{
string relativePath = inPath.Substring(options.InDir.Length).TrimStart('\\');
string outPath = Path.ChangeExtension(Path.Combine(options.OutDir, relativePath), options.OutTypeName);

var jobFiles = new JobFiles();
jobFiles.InFiles.Add(new AudioFile(inPath));
jobFiles.OutFiles.Add(new AudioFile(outPath));

try
Parallel.ForEach(files,
new ParallelOptions { MaxDegreeOfParallelism = Math.Max(Environment.ProcessorCount - 1, 1) },
inPath =>
{
progress.LogMessage(Path.GetFileName(inPath));
Convert.ConvertFile(options, jobFiles, false);
}
catch (Exception ex)
{
progress.LogMessage($"Error converting {Path.GetFileName(inPath)}");
progress.LogMessage(ex.ToString());
}

progress.ReportAdd(1);
});
string relativePath = inPath.Substring(options.InDir.Length).TrimStart('\\');
string outPath = Path.ChangeExtension(Path.Combine(options.OutDir, relativePath), options.OutTypeName);

var jobFiles = new JobFiles();
jobFiles.InFiles.Add(new AudioFile(inPath));
jobFiles.OutFiles.Add(new AudioFile(outPath));

try
{
progress.LogMessage(Path.GetFileName(inPath));
Convert.ConvertFile(options, jobFiles, false);
}
catch (Exception ex)
{
progress.LogMessage($"Error converting {Path.GetFileName(inPath)}");
progress.LogMessage(ex.ToString());
}

progress.ReportAdd(1);
});
}

return true;
Expand Down