I've run into a bug when generating a cue sheet from a set of flac files.
I'm working off a Samba 3.0.x share mounted as a drive. When I generate a cue sheet on this share, the files appear out of order in the cue sheet I have to sort it manually. This problem does not occur on a local hard drive.
I've traced the problem to the ScanFolder method in the CUESheet class in CUETools.processor\Processor.cs. This method relies on the files parameter to be a sorted IEnumerable. However, the System.IO.DirectoryInfo.GetFileSystemInfos() method used to generated this IEnumerable does not guarantee sorting. This means ScanFolder needs to sort the files first.
The following fixes the problem for me:
diff --git a/CUETools.Processor/Processor.cs b/CUETools.Processor/Processor.cs
index 6b91342..54ce9c4 100644
--- a/CUETools.Processor/Processor.cs
+++ b/CUETools.Processor/Processor.cs
@@ -4847,6 +4847,18 @@ return processor.Go();
}
}
+ public static int CompareFileSystemInfo(FileSystemInfo x, FileSystemInfo y)
+ {
+ return x.Name.CompareTo(y.Name);
+ }
+
+ public static IEnumerable<FileSystemInfo> SortFiles(IEnumerable<FileSystemInfo> files)
+ {
+ List<FileSystemInfo> sortedFiles = new List<FileSystemInfo>(files);
+ sortedFiles.Sort(CompareFileSystemInfo);
+ return sortedFiles;
+ }
+
public static List<FileGroupInfo> ScanFolder(CUEConfig _config, string path)
{
DirectoryInfo dir = new DirectoryInfo(path);
@@ -4856,6 +4868,7 @@ return processor.Go();
public static List<FileGroupInfo> ScanFolder(CUEConfig _config, IEnumerable<FileSystemInfo> files)
{
List<FileGroupInfo> fileGroups = new List<FileGroupInfo>();
+ files = SortFiles(files);
foreach (FileSystemInfo file in files)
{
if ((file.Attributes & FileAttributes.Hidden) != 0)
This problem also showed up in the Folder browser and Multiselect browser, and this change fixes those also.