From 4f29cf7cc7fada13aca41362dbe66e772b95683a Mon Sep 17 00:00:00 2001 From: Robbie Davis Date: Tue, 8 Jun 2021 09:59:47 -0400 Subject: [PATCH] Bugfix/manga reader pad zeros (#288) * Switched to using existing NaturalSortComparer for ordering filenames before we reprocess them to ensure they are in the correct natural reading order. Co-authored-by: Joseph Milazzo --- API/Extensions/DirectoryInfoExtensions.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/API/Extensions/DirectoryInfoExtensions.cs b/API/Extensions/DirectoryInfoExtensions.cs index c41ca9f8b..0eaf6c00a 100644 --- a/API/Extensions/DirectoryInfoExtensions.cs +++ b/API/Extensions/DirectoryInfoExtensions.cs @@ -1,12 +1,12 @@ -using System; -using System.IO; +using System.IO; using System.Linq; -using API.Services; +using API.Comparators; namespace API.Extensions { public static class DirectoryInfoExtensions { + private static readonly NaturalSortComparer Comparer = new NaturalSortComparer(); public static void Empty(this DirectoryInfo directory) { foreach(FileInfo file in directory.EnumerateFiles()) file.Delete(); @@ -49,12 +49,13 @@ namespace API.Extensions if (!root.FullName.Equals(directory.FullName)) { var fileIndex = 1; - foreach (var file in directory.EnumerateFiles()) + + foreach (var file in directory.EnumerateFiles().OrderBy(file => file.FullName, Comparer)) { if (file.Directory == null) continue; var paddedIndex = Parser.Parser.PadZeros(directoryIndex + ""); // We need to rename the files so that after flattening, they are in the order we found them - var newName = $"{paddedIndex}_{fileIndex}.{file.Extension}"; + var newName = $"{paddedIndex}_{Parser.Parser.PadZeros(fileIndex + "")}{file.Extension}"; var newPath = Path.Join(root.FullName, newName); if (!File.Exists(newPath)) file.MoveTo(newPath); fileIndex++;