Skip to content

armgit / Filee

Public Imported from GitHub
0

Free, open-source file converter. Convert 263 formats offline by drag & drop — images, PDF, Word, Excel, PowerPoint, HWP/HWPX, video, audio, e-books and archives. No upload, no Office needed.

Dragged folders only go into one archive and keep their name

Sonica Reddy175147ecee7b
diff --git a/src/Filee.App/Services/DraggedFiles.cs b/src/Filee.App/Services/DraggedFiles.cs
index 43a6818f..aba233a4 100644
--- a/src/Filee.App/Services/DraggedFiles.cs
+++ b/src/Filee.App/Services/DraggedFiles.cs
@@ -11,14 +11,14 @@ namespace Filee.App.Services;
internal static class DraggedFiles
{
- /// <summary>Whether the drag offers files in a form Filee reads (they may still turn out to be folders).</summary>
+ /// <summary>Whether the drag offers files or folders in a form Filee reads (they may still be missing).</summary>
public static bool Offered(IDataTransfer data) =>
data.Contains(DataFormat.File) || data.Items.Any(item => item.Formats.Any(IsFilenames));
/// <summary>
/// Local file and folder paths in the drag (virtual items are ignored). A shortcut counts as the file or folder it
/// points to. Folders go into "Compress into one archive" like on the command line (issue #186); other presets
- /// report them as unsupported.
+ /// leave them out. A trailing separator is removed, and a drive or the file system root is ignored.
/// </summary>
public static IReadOnlyList<string> Local(IDataTransfer data) =>
Local(data, IsFileOrFolder, AppHost.Get<IPlatformServices>().ResolveShortcuts);
@@ -30,12 +30,19 @@ internal static class DraggedFiles
Func<IReadOnlyList<string>, IReadOnlyList<string>>? resolveShortcuts = null)
{
IReadOnlyList<string> Usable(IReadOnlyList<string> paths) =>
- (resolveShortcuts?.Invoke(paths) ?? paths).Where(exists).Distinct(FileSystemPaths.Comparer).ToList();
+ (resolveShortcuts?.Invoke(paths) ?? paths)
+ .Select(path => Path.TrimEndingDirectorySeparator(path))
+ .Where(path => exists(path) && !IsRoot(path))
+ .Distinct(FileSystemPaths.Comparer).ToList();
var files = Usable((data.TryGetFiles() ?? []).Select(item => item.TryGetLocalPath()).OfType<string>().ToList());
return files.Count > 0 ? files : Usable(Filenames(data).ToList());
}
+ /// <summary>Whether <paramref name="path"/> is a drive or the file system root ("C:\", "/").</summary>
+ internal static bool IsRoot(string path) =>
+ string.Equals(Path.GetPathRoot(path), path, FileSystemPaths.Comparison);
+
/// <summary>The formats a drag offers, for the log when Filee finds no files in it.</summary>
public static string Describe(IDataTransfer data) =>
data.Formats.Count == 0 ? "nothing" : string.Join(", ", data.Formats.Select(format => format.Identifier).Distinct());
diff --git a/src/Filee.App/Services/RadialController.cs b/src/Filee.App/Services/RadialController.cs
index cc7dcb9c..97f996be 100644
--- a/src/Filee.App/Services/RadialController.cs
+++ b/src/Filee.App/Services/RadialController.cs
@@ -265,7 +265,11 @@ public sealed class RadialController(
/// <summary>Converts with slice <paramref name="index"/>, or with slice <paramref name="sub"/> of that group's ring.</summary>
private void Convert(int index, int sub, IReadOnlyList<string> files)
{
- if (viewModel.PresetAt(index, sub) is not { } preset || files.Count == 0)
+ var preset = viewModel.PresetAt(index, sub);
+ // Folders only go into "Compress into one archive"; any other preset converts the files beside them (#186).
+ if (preset is { PacksIntoOneArchive: false })
+ files = files.Where(path => !Directory.Exists(path)).ToList();
+ if (preset is null || files.Count == 0)
{
Close();
return;
diff --git a/src/Filee.Core/Presets/Preset.cs b/src/Filee.Core/Presets/Preset.cs
index 1c2feb27..722541d1 100644
--- a/src/Filee.Core/Presets/Preset.cs
+++ b/src/Filee.Core/Presets/Preset.cs
@@ -120,6 +120,13 @@ public sealed class Preset
[JsonIgnore]
public bool IsGroup => Kind == PresetKind.Group;
+ /// <summary>True for "Compress into one archive": files and folders go into one archive as they are.</summary>
+ [JsonIgnore]
+ public bool PacksIntoOneArchive =>
+ Archive.CombineIntoOne
+ && Formats.FormatRegistry.FindById(TargetFormat) is { Category: Formats.FormatCategory.Archive } archive
+ && archive.Id != Formats.FormatRegistry.Folder;
+
/// <summary>
/// True if converting a <paramref name="sourceFormat"/> file saves every frame as a picture
/// (<see cref="MediaOptions.SaveEveryFrame"/>): the file is a video and the target one of
diff --git a/tests/Filee.App.Tests/OtherFileManagerTests.cs b/tests/Filee.App.Tests/OtherFileManagerTests.cs
index 78ffb946..1d34c5f7 100644
--- a/tests/Filee.App.Tests/OtherFileManagerTests.cs
+++ b/tests/Filee.App.Tests/OtherFileManagerTests.cs
@@ -52,11 +52,20 @@ public class OtherFileManagerTests
{
Directory.Delete(folder, recursive: true);
}
+ }
- // Issue #186: files and folders dragged together all stay in the list.
- using var data = Drag(PasteboardPaths.FilenamesType, Encoding.UTF8.GetBytes(Plist));
- HashSet<string> existing = ["/Users/a/1.png", "/Users/a/folder"];
- Assert.Equal(["/Users/a/1.png", "/Users/a/folder"], DraggedFiles.Local(data, existing.Contains));
+ [Fact]
+ public void A_dragged_folder_loses_its_trailing_slash_and_a_dragged_root_is_ignored()
+ {
+ const string plist = """
+ <plist version="1.0"><array><string>/Users/a/folder/</string><string>/</string><string>/Users/a/1.png</string></array></plist>
+ """;
+ using var data = Drag(PasteboardPaths.FilenamesType, Encoding.UTF8.GetBytes(plist));
+ HashSet<string> existing = ["/Users/a/folder", "/", "/Users/a/1.png"];
+
+ Assert.Equal(["/Users/a/folder", "/Users/a/1.png"], DraggedFiles.Local(data, existing.Contains));
+ Assert.True(DraggedFiles.IsRoot(Path.GetPathRoot(Path.GetTempPath())!));
+ Assert.False(DraggedFiles.IsRoot(Path.GetTempPath()));
}
[Fact]
diff --git a/tests/Filee.Core.Tests/SmallParsersTests.cs b/tests/Filee.Core.Tests/SmallParsersTests.cs
index 4ef9f44f..a4bec326 100644
--- a/tests/Filee.Core.Tests/SmallParsersTests.cs
+++ b/tests/Filee.Core.Tests/SmallParsersTests.cs
@@ -93,6 +93,17 @@ public class BuiltInDataTests
Assert.DoesNotContain(BuiltInData.CreateProfiles(), p => p.PresetIds.Any(id => presets[id].IsGroup));
}
+ [Fact]
+ public void Only_compress_into_one_archive_presets_take_folders()
+ {
+ var presets = BuiltInData.CreatePresets().ToDictionary(p => p.Id);
+ Assert.True(presets["zip-all"].PacksIntoOneArchive);
+ Assert.False(presets["to-zip"].PacksIntoOneArchive); // one archive for each file
+ Assert.False(presets["extract"].PacksIntoOneArchive); // a folder is no archive to pack into
+ Assert.False(presets["to-pdf"].PacksIntoOneArchive);
+ Assert.False(new Preset { TargetFormat = "pdf", Archive = { CombineIntoOne = true } }.PacksIntoOneArchive);
+ }
+
[Fact]
public void Preset_ids_are_unique()
{