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.

feat: browser downloads

1644yec495023abba2
diff --git a/src/Filee.App/Assets/i18n/ar.json b/src/Filee.App/Assets/i18n/ar.json
index c3191ee9..2711ccff 100644
--- a/src/Filee.App/Assets/i18n/ar.json
+++ b/src/Filee.App/Assets/i18n/ar.json
@@ -1,4 +1,12 @@
{
+ "general.download_location": "Download save location",
+ "general.download.Default": "Default (Downloads folder)",
+ "general.download.Ask": "Choose a folder every time",
+ "general.download.Custom": "Specified folder",
+ "general.download_hint": "Applies only to Download in the ring. An empty specified folder prompts you to choose; cancelling saves nothing.",
+ "preset.browser_download": "تنزيل",
+ "preset.browser_download_caption": "بدون تحويل",
+
"app.name": "Filee",
"app.tagline": "اسحب، أفلت، وحوّل.",
"nav.home": "الرئيسية",
diff --git a/src/Filee.App/Assets/i18n/de.json b/src/Filee.App/Assets/i18n/de.json
index ac26311f..6b24fb0d 100644
--- a/src/Filee.App/Assets/i18n/de.json
+++ b/src/Filee.App/Assets/i18n/de.json
@@ -1,4 +1,12 @@
{
+ "general.download_location": "Download save location",
+ "general.download.Default": "Default (Downloads folder)",
+ "general.download.Ask": "Choose a folder every time",
+ "general.download.Custom": "Specified folder",
+ "general.download_hint": "Applies only to Download in the ring. An empty specified folder prompts you to choose; cancelling saves nothing.",
+ "preset.browser_download": "Download",
+ "preset.browser_download_caption": "No conversion",
+
"app.name": "Filee",
"app.tagline": "Ziehen, ablegen, fertig.",
"nav.home": "Start",
diff --git a/src/Filee.App/Assets/i18n/en.json b/src/Filee.App/Assets/i18n/en.json
index f562d095..4df6c729 100644
--- a/src/Filee.App/Assets/i18n/en.json
+++ b/src/Filee.App/Assets/i18n/en.json
@@ -1,4 +1,12 @@
{
+ "general.download_location": "Download save location",
+ "general.download.Default": "Default (Downloads folder)",
+ "general.download.Ask": "Choose a folder every time",
+ "general.download.Custom": "Specified folder",
+ "general.download_hint": "Applies only to Download in the ring. An empty specified folder prompts you to choose; cancelling saves nothing.",
+ "preset.browser_download": "Download",
+ "preset.browser_download_caption": "No conversion",
+
"app.name": "Filee",
"app.tagline": "Drag, drop, converted.",
diff --git a/src/Filee.App/Assets/i18n/es.json b/src/Filee.App/Assets/i18n/es.json
index d56c8b15..b72e2143 100644
--- a/src/Filee.App/Assets/i18n/es.json
+++ b/src/Filee.App/Assets/i18n/es.json
@@ -1,4 +1,12 @@
{
+ "general.download_location": "Download save location",
+ "general.download.Default": "Default (Downloads folder)",
+ "general.download.Ask": "Choose a folder every time",
+ "general.download.Custom": "Specified folder",
+ "general.download_hint": "Applies only to Download in the ring. An empty specified folder prompts you to choose; cancelling saves nothing.",
+ "preset.browser_download": "Descargar",
+ "preset.browser_download_caption": "Sin conversión",
+
"app.name": "Filee",
"app.tagline": "Arrastra, suelta y convierte.",
"nav.home": "Inicio",
diff --git a/src/Filee.App/Assets/i18n/fr.json b/src/Filee.App/Assets/i18n/fr.json
index f01e05d9..c1a2df4a 100644
--- a/src/Filee.App/Assets/i18n/fr.json
+++ b/src/Filee.App/Assets/i18n/fr.json
@@ -1,4 +1,12 @@
{
+ "general.download_location": "Download save location",
+ "general.download.Default": "Default (Downloads folder)",
+ "general.download.Ask": "Choose a folder every time",
+ "general.download.Custom": "Specified folder",
+ "general.download_hint": "Applies only to Download in the ring. An empty specified folder prompts you to choose; cancelling saves nothing.",
+ "preset.browser_download": "Télécharger",
+ "preset.browser_download_caption": "Sans conversion",
+
"app.name": "Filee",
"app.tagline": "Glissez, déposez, c'est converti.",
diff --git a/src/Filee.App/Assets/i18n/hi.json b/src/Filee.App/Assets/i18n/hi.json
index 52931e1e..d80894f5 100644
--- a/src/Filee.App/Assets/i18n/hi.json
+++ b/src/Filee.App/Assets/i18n/hi.json
@@ -1,4 +1,12 @@
{
+ "general.download_location": "Download save location",
+ "general.download.Default": "Default (Downloads folder)",
+ "general.download.Ask": "Choose a folder every time",
+ "general.download.Custom": "Specified folder",
+ "general.download_hint": "Applies only to Download in the ring. An empty specified folder prompts you to choose; cancelling saves nothing.",
+ "preset.browser_download": "डाउनलोड",
+ "preset.browser_download_caption": "बिना रूपांतरण",
+
"app.name": "Filee",
"app.tagline": "खींचें, छोड़ें, कन्वर्ट हो गया।",
"nav.home": "होम",
diff --git a/src/Filee.App/Assets/i18n/id.json b/src/Filee.App/Assets/i18n/id.json
index e7c892a0..06052752 100644
--- a/src/Filee.App/Assets/i18n/id.json
+++ b/src/Filee.App/Assets/i18n/id.json
@@ -1,4 +1,12 @@
{
+ "general.download_location": "Download save location",
+ "general.download.Default": "Default (Downloads folder)",
+ "general.download.Ask": "Choose a folder every time",
+ "general.download.Custom": "Specified folder",
+ "general.download_hint": "Applies only to Download in the ring. An empty specified folder prompts you to choose; cancelling saves nothing.",
+ "preset.browser_download": "Download",
+ "preset.browser_download_caption": "No conversion",
+
"app.name": "Filee",
"app.tagline": "Seret, lepas, terkonversi.",
"nav.home": "Beranda",
diff --git a/src/Filee.App/Assets/i18n/it.json b/src/Filee.App/Assets/i18n/it.json
index c7f6ba98..e4aa6d2a 100644
--- a/src/Filee.App/Assets/i18n/it.json
+++ b/src/Filee.App/Assets/i18n/it.json
@@ -1,4 +1,12 @@
{
+ "general.download_location": "Download save location",
+ "general.download.Default": "Default (Downloads folder)",
+ "general.download.Ask": "Choose a folder every time",
+ "general.download.Custom": "Specified folder",
+ "general.download_hint": "Applies only to Download in the ring. An empty specified folder prompts you to choose; cancelling saves nothing.",
+ "preset.browser_download": "Download",
+ "preset.browser_download_caption": "No conversion",
+
"app.name": "Filee",
"app.tagline": "Trascina, rilascia, converti.",
"nav.home": "Home",
diff --git a/src/Filee.App/Assets/i18n/ja.json b/src/Filee.App/Assets/i18n/ja.json
index 507537f8..1b10a85a 100644
--- a/src/Filee.App/Assets/i18n/ja.json
+++ b/src/Filee.App/Assets/i18n/ja.json
@@ -1,4 +1,12 @@
{
+ "general.download_location": "Download save location",
+ "general.download.Default": "Default (Downloads folder)",
+ "general.download.Ask": "Choose a folder every time",
+ "general.download.Custom": "Specified folder",
+ "general.download_hint": "Applies only to Download in the ring. An empty specified folder prompts you to choose; cancelling saves nothing.",
+ "preset.browser_download": "ダウンロード",
+ "preset.browser_download_caption": "変換なし",
+
"app.name": "Filee",
"app.tagline": "ドラッグ。ドロップ。\n変換完了。",
"nav.home": "ホーム",
diff --git a/src/Filee.App/Assets/i18n/ko.json b/src/Filee.App/Assets/i18n/ko.json
index c37fdbed..184b1a59 100644
--- a/src/Filee.App/Assets/i18n/ko.json
+++ b/src/Filee.App/Assets/i18n/ko.json
@@ -1,4 +1,12 @@
{
+ "general.download_location": "Download save location",
+ "general.download.Default": "Default (Downloads folder)",
+ "general.download.Ask": "Choose a folder every time",
+ "general.download.Custom": "Specified folder",
+ "general.download_hint": "Applies only to Download in the ring. An empty specified folder prompts you to choose; cancelling saves nothing.",
+ "preset.browser_download": "다운로드",
+ "preset.browser_download_caption": "변환 안 함",
+
"app.name": "Filee",
"app.tagline": "끌어서 놓으면, 변환 끝.",
diff --git a/src/Filee.App/Assets/i18n/ne.json b/src/Filee.App/Assets/i18n/ne.json
index e7ece85b..6f93aefb 100644
--- a/src/Filee.App/Assets/i18n/ne.json
+++ b/src/Filee.App/Assets/i18n/ne.json
@@ -1,4 +1,12 @@
{
+ "general.download_location": "Download save location",
+ "general.download.Default": "Default (Downloads folder)",
+ "general.download.Ask": "Choose a folder every time",
+ "general.download.Custom": "Specified folder",
+ "general.download_hint": "Applies only to Download in the ring. An empty specified folder prompts you to choose; cancelling saves nothing.",
+ "preset.browser_download": "डाउनलोड",
+ "preset.browser_download_caption": "रूपान्तरण बिना",
+
"app.name": "Filee",
"app.tagline": "तान्नुहोस्, छाड्नुहोस्, रूपान्तरण भयो।",
"nav.home": "गृहपृष्ठ",
diff --git a/src/Filee.App/Assets/i18n/pl.json b/src/Filee.App/Assets/i18n/pl.json
index 3cde8246..91586e7c 100644
--- a/src/Filee.App/Assets/i18n/pl.json
+++ b/src/Filee.App/Assets/i18n/pl.json
@@ -1,4 +1,12 @@
{
+ "general.download_location": "Download save location",
+ "general.download.Default": "Default (Downloads folder)",
+ "general.download.Ask": "Choose a folder every time",
+ "general.download.Custom": "Specified folder",
+ "general.download_hint": "Applies only to Download in the ring. An empty specified folder prompts you to choose; cancelling saves nothing.",
+ "preset.browser_download": "Pobierz",
+ "preset.browser_download_caption": "Bez konwersji",
+
"app.name": "Filee",
"app.tagline": "Przeciągnij, upuść, gotowe.",
diff --git a/src/Filee.App/Assets/i18n/pt-BR.json b/src/Filee.App/Assets/i18n/pt-BR.json
index c04db90d..477b4ab6 100644
--- a/src/Filee.App/Assets/i18n/pt-BR.json
+++ b/src/Filee.App/Assets/i18n/pt-BR.json
@@ -1,4 +1,12 @@
{
+ "general.download_location": "Download save location",
+ "general.download.Default": "Default (Downloads folder)",
+ "general.download.Ask": "Choose a folder every time",
+ "general.download.Custom": "Specified folder",
+ "general.download_hint": "Applies only to Download in the ring. An empty specified folder prompts you to choose; cancelling saves nothing.",
+ "preset.browser_download": "Baixar",
+ "preset.browser_download_caption": "Sem conversão",
+
"app.name": "Filee",
"app.tagline": "Arraste, solte, convertido.",
diff --git a/src/Filee.App/Assets/i18n/pt-PT.json b/src/Filee.App/Assets/i18n/pt-PT.json
index d6cd1498..8039aa1c 100644
--- a/src/Filee.App/Assets/i18n/pt-PT.json
+++ b/src/Filee.App/Assets/i18n/pt-PT.json
@@ -1,4 +1,12 @@
{
+ "general.download_location": "Download save location",
+ "general.download.Default": "Default (Downloads folder)",
+ "general.download.Ask": "Choose a folder every time",
+ "general.download.Custom": "Specified folder",
+ "general.download_hint": "Applies only to Download in the ring. An empty specified folder prompts you to choose; cancelling saves nothing.",
+ "preset.browser_download": "Transferir",
+ "preset.browser_download_caption": "Sem conversão",
+
"app.name": "Filee",
"app.tagline": "Arrasta, larga, convertido.",
diff --git a/src/Filee.App/Assets/i18n/ru.json b/src/Filee.App/Assets/i18n/ru.json
index 7c8dccf0..bb4c6699 100644
--- a/src/Filee.App/Assets/i18n/ru.json
+++ b/src/Filee.App/Assets/i18n/ru.json
@@ -1,4 +1,12 @@
{
+ "general.download_location": "Download save location",
+ "general.download.Default": "Default (Downloads folder)",
+ "general.download.Ask": "Choose a folder every time",
+ "general.download.Custom": "Specified folder",
+ "general.download_hint": "Applies only to Download in the ring. An empty specified folder prompts you to choose; cancelling saves nothing.",
+ "preset.browser_download": "Скачать",
+ "preset.browser_download_caption": "Без преобразования",
+
"app.name": "Filee",
"app.tagline": "Перетащил — и готово.",
diff --git a/src/Filee.App/Assets/i18n/th.json b/src/Filee.App/Assets/i18n/th.json
index 7e7b19eb..9b03f3e2 100644
--- a/src/Filee.App/Assets/i18n/th.json
+++ b/src/Filee.App/Assets/i18n/th.json
@@ -1,4 +1,12 @@
{
+ "general.download_location": "Download save location",
+ "general.download.Default": "Default (Downloads folder)",
+ "general.download.Ask": "Choose a folder every time",
+ "general.download.Custom": "Specified folder",
+ "general.download_hint": "Applies only to Download in the ring. An empty specified folder prompts you to choose; cancelling saves nothing.",
+ "preset.browser_download": "ดาวน์โหลด",
+ "preset.browser_download_caption": "ไม่แปลงไฟล์",
+
"app.name": "Filee",
"app.tagline": "ลาก วาง แปลงไฟล์ทันที",
"nav.home": "หน้าแรก",
diff --git a/src/Filee.App/Assets/i18n/tr.json b/src/Filee.App/Assets/i18n/tr.json
index 8d74f8d4..757c2a88 100644
--- a/src/Filee.App/Assets/i18n/tr.json
+++ b/src/Filee.App/Assets/i18n/tr.json
@@ -1,4 +1,12 @@
{
+ "general.download_location": "Download save location",
+ "general.download.Default": "Default (Downloads folder)",
+ "general.download.Ask": "Choose a folder every time",
+ "general.download.Custom": "Specified folder",
+ "general.download_hint": "Applies only to Download in the ring. An empty specified folder prompts you to choose; cancelling saves nothing.",
+ "preset.browser_download": "İndir",
+ "preset.browser_download_caption": "Dönüştürme yok",
+
"app.name": "Filee",
"app.tagline": "Sürükle, bırak, dönüştür.",
"nav.home": "Ana sayfa",
diff --git a/src/Filee.App/Assets/i18n/zh-CN.json b/src/Filee.App/Assets/i18n/zh-CN.json
index 87f87605..399b4e9a 100644
--- a/src/Filee.App/Assets/i18n/zh-CN.json
+++ b/src/Filee.App/Assets/i18n/zh-CN.json
@@ -1,4 +1,12 @@
{
+ "general.download_location": "圆盘下载保存位置",
+ "general.download.Default": "默认保存(系统下载文件夹)",
+ "general.download.Ask": "每次选择位置",
+ "general.download.Custom": "指定文件夹",
+ "general.download_hint": "仅用于圆盘中的“下载”。指定文件夹为空时会询问;取消选择不会下载。",
+ "preset.browser_download": "下载",
+ "preset.browser_download_caption": "不转换",
+
"app.name": "Filee",
"app.tagline": "拖一拖,放一放,转换完成。",
diff --git a/src/Filee.App/Assets/i18n/zh-TW.json b/src/Filee.App/Assets/i18n/zh-TW.json
index f6308192..5d40c84f 100644
--- a/src/Filee.App/Assets/i18n/zh-TW.json
+++ b/src/Filee.App/Assets/i18n/zh-TW.json
@@ -1,4 +1,12 @@
{
+ "general.download_location": "圓盤下載儲存位置",
+ "general.download.Default": "預設儲存(系統下載資料夾)",
+ "general.download.Ask": "每次選擇位置",
+ "general.download.Custom": "指定資料夾",
+ "general.download_hint": "僅用於圓盤中的「下載」。指定資料夾為空時會詢問;取消選擇不會下載。",
+ "preset.browser_download": "下載",
+ "preset.browser_download_caption": "不轉換",
+
"app.name": "Filee",
"app.tagline": "拖一拖,放一放,轉換完成。",
diff --git a/src/Filee.App/Services/ConversionService.cs b/src/Filee.App/Services/ConversionService.cs
index f7dfc8a5..f21605e2 100644
--- a/src/Filee.App/Services/ConversionService.cs
+++ b/src/Filee.App/Services/ConversionService.cs
@@ -74,10 +74,9 @@ public sealed class ConversionService
/// </param>
/// <param name="toClipboard">The results go on the clipboard when the job has finished (the clipboard shortcut).</param>
/// <returns>The job's view model, or null when there was nothing to convert.</returns>
- public JobViewModel? Start(IReadOnlyList<string> files, Preset preset, bool showInToast = true, WebDrop? web = null,
- bool toClipboard = false)
+ public JobViewModel? Start(IReadOnlyList<string> files, Preset preset, bool showInToast = true, WebDrop? web = null, string? downloadFolder = null, IReadOnlyDictionary<string, string>? savePaths = null, bool toClipboard = false)
{
- if (files.Count == 0 || preset.IsGroup || preset.IsTool)
+ if (files.Count == 0 || preset.IsGroup || preset.IsTool || preset.IsDownload && (web is null || DownloadNeedsPicker && string.IsNullOrWhiteSpace(downloadFolder)))
{
web?.Dispose();
return null;
@@ -90,6 +89,8 @@ public sealed class ConversionService
var options = BrowserDropOptions();
if (web.SaveOnlyConverted is { } only)
options = options with { SaveOnlyConverted = only };
+ if (preset.IsDownload)
+ options = options with { SaveOnlyConverted = false, Folder = downloadFolder ?? DownloadFolderInUse, SavePaths = savePaths };
fetcher = web.CreateFetcher(options, _downloader);
// "Next to the source" is the download folder, also when the original is only kept until converted.
preset = fetcher.Apply(preset);
@@ -179,6 +180,53 @@ public sealed class ConversionService
return new WebDropOptions(folder, settings.SaveOnlyConverted);
}
+ public bool DownloadNeedsPicker => _store.Settings.BrowserDrops.DownloadLocation == DownloadLocation.Ask
+ || _store.Settings.BrowserDrops.DownloadLocation == DownloadLocation.Custom
+ && string.IsNullOrWhiteSpace(_store.Settings.BrowserDrops.DownloadFolder);
+
+ public string DownloadFolderInUse => _store.Settings.BrowserDrops.DownloadLocation == DownloadLocation.Custom
+ && !string.IsNullOrWhiteSpace(_store.Settings.BrowserDrops.DownloadFolder)
+ ? _store.Settings.BrowserDrops.DownloadFolder.Trim() : _platform.DownloadsFolder;
+
+ internal async Task<JobViewModel?> ChooseNamedDownloadAsync(IReadOnlyList<string> files, Preset preset, WebDrop web,
+ Func<string, string, Task<string?>> chooseFile)
+ {
+ try
+ {
+ var folder = _store.Settings.BrowserDrops.LastDownloadFolder;
+ if (!Directory.Exists(folder)) folder = DownloadFolderInUse;
+ var paths = new Dictionary<string, string>();
+ foreach (var file in files)
+ {
+ var path = await chooseFile(folder, Path.GetFileName(file));
+ if (string.IsNullOrWhiteSpace(path)) return null;
+ if (paths.Values.Contains(path, StringComparer.OrdinalIgnoreCase)) return null;
+ paths[file] = path;
+ folder = Path.GetDirectoryName(path)!;
+ }
+ _store.Settings.BrowserDrops.LastDownloadFolder = folder;
+ _store.SaveSettings();
+ var job = Start(files, preset, web: web, downloadFolder: folder, savePaths: paths);
+ web = null!;
+ return job;
+ }
+ finally { web?.Dispose(); }
+ }
+
+ internal async Task<JobViewModel?> ChooseDownloadAsync(IReadOnlyList<string> files, Preset preset, WebDrop web,
+ Func<string, Task<string?>> chooseFolder)
+ {
+ try
+ {
+ var folder = await chooseFolder(DownloadFolderInUse);
+ if (string.IsNullOrWhiteSpace(folder)) return null;
+ var job = Start(files, preset, web: web, downloadFolder: folder);
+ web = null!; // Start owns or disposes it.
+ return job;
+ }
+ finally { web?.Dispose(); }
+ }
+
/// <summary>True when a source file (or folder) is still where it was.</summary>
public static bool Exists(string path) => File.Exists(path) || Directory.Exists(path);
diff --git a/src/Filee.App/Services/RadialController.cs b/src/Filee.App/Services/RadialController.cs
index 05ca6259..2c356e9a 100644
--- a/src/Filee.App/Services/RadialController.cs
+++ b/src/Filee.App/Services/RadialController.cs
@@ -337,6 +337,13 @@ public sealed class RadialController(
return;
}
+ if (preset.IsDownload && web is not null && conversions.DownloadNeedsPicker)
+ {
+ Close(animate: false);
+ _ = DownloadInFolderAsync(sources, preset.Clone(), web);
+ return;
+ }
+
if (preset.IsTool)
{
log.LogInformation("Opening {Preset} for {Count} file(s)", preset.Id, sources.Count);
@@ -368,7 +375,7 @@ public sealed class RadialController(
log.LogInformation("Converting {Count} file(s) with preset {Preset}{Web}{Clipboard}", sources.Count, preset.Id,
web is null ? "" : " (from a browser)", _toClipboard ? " (from the clipboard)" : "");
- var job = conversions.Start(sources, preset, showInToast: false, web, _toClipboard);
+ var job = conversions.Start(sources, preset, showInToast: false, web: web, toClipboard: _toClipboard);
if (job is null || _window is null)
{
Close();
@@ -378,6 +385,13 @@ public sealed class RadialController(
ShowProgress(job);
}
+ private async Task DownloadInFolderAsync(IReadOnlyList<string> files, Preset preset, WebDrop web)
+ {
+ try { await conversions.ChooseNamedDownloadAsync(files, preset, web, windows.ChooseDownloadFileAsync); }
+ catch (Exception ex) when (ex is not OutOfMemoryException)
+ { log.LogError(ex, "Could not choose the download folder"); }
+ }
+
private async Task MergeInOrderAsync(IReadOnlyList<string> files, Preset preset, WebDrop? web, bool toClipboard)
{
try
@@ -654,3 +668,4 @@ public sealed class RadialController(
_web = web;
}
}
+
diff --git a/src/Filee.App/Services/WindowService.cs b/src/Filee.App/Services/WindowService.cs
index 58e65ca1..fdf39c78 100644
--- a/src/Filee.App/Services/WindowService.cs
+++ b/src/Filee.App/Services/WindowService.cs
@@ -87,6 +87,29 @@ public sealed class WindowService(ILocalizer loc, IServiceProvider services, Mem
return dialog.Result;
}
+ public async Task<string?> ChooseDownloadFileAsync(string startFolder, string name)
+ {
+ var owner = new Window
+ {
+ Title = loc["preset.browser_download"],
+ Width = 380,
+ Height = 120,
+ WindowStartupLocation = WindowStartupLocation.CenterScreen,
+ Content = new TextBlock { Text = loc["general.download.Ask"], Margin = new Thickness(24) },
+ };
+ PrepareWindow(owner);
+ owner.Show();
+ owner.Activate();
+ try
+ {
+ var start = await owner.StorageProvider.TryGetFolderFromPathAsync(startFolder);
+ var file = await owner.StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions
+ { Title = loc["preset.browser_download"], SuggestedFileName = name, ShowOverwritePrompt = true, SuggestedStartLocation = start });
+ return file?.TryGetLocalPath();
+ }
+ finally { owner.Close(); }
+ }
+
/// <summary>
/// "Ask every time" (#521): one save dialog for the batch, starting in the first source's folder. One result is
/// saved under a name (<see cref="AskedLocation.ForFile"/>), several go into a folder. Null when cancelled.
diff --git a/src/Filee.App/ViewModels/Pages/GeneralPageViewModel.cs b/src/Filee.App/ViewModels/Pages/GeneralPageViewModel.cs
index c55d3540..699494f3 100644
--- a/src/Filee.App/ViewModels/Pages/GeneralPageViewModel.cs
+++ b/src/Filee.App/ViewModels/Pages/GeneralPageViewModel.cs
@@ -49,6 +49,9 @@ public sealed partial class GeneralPageViewModel : ObservableObject, IDisposable
_keepFileDates = store.Settings.KeepFileDates;
_browserFolder = store.Settings.BrowserDrops.Folder;
_saveOnlyConverted = store.Settings.BrowserDrops.SaveOnlyConverted;
+ DownloadLocations = Enum.GetValues<Filee.Core.Settings.DownloadLocation>().Select(v => new Choice<DownloadLocation>(v, loc[$"general.download.{v}"])).ToList();
+ _downloadLocation = DownloadLocations.FirstOrDefault(v => v.Value == store.Settings.BrowserDrops.DownloadLocation) ?? DownloadLocations[0];
+ _downloadFolder = store.Settings.BrowserDrops.DownloadFolder;
_zipGeoResults = store.Settings.ZipGeoResults;
CloseChoices = Enum.GetValues<CloseAction>().Select(v => new Choice<CloseAction>(v, loc[$"general.close.{v}"])).ToList();
_closeChoice = CloseChoices.First(c => c.Value == store.Settings.CloseAction);
@@ -97,6 +100,18 @@ public sealed partial class GeneralPageViewModel : ObservableObject, IDisposable
/// <summary>Where files dragged from a browser are saved; empty for the Downloads folder.</summary>
[ObservableProperty] private string _browserFolder;
+ public IReadOnlyList<Choice<DownloadLocation>> DownloadLocations { get; }
+ [ObservableProperty, NotifyPropertyChangedFor(nameof(ShowDownloadFolder))]
+ private Choice<DownloadLocation> _downloadLocation;
+ [ObservableProperty] private string _downloadFolder;
+ public bool ShowDownloadFolder => DownloadLocation.Value == Filee.Core.Settings.DownloadLocation.Custom;
+ partial void OnDownloadLocationChanged(Choice<DownloadLocation>? oldValue, Choice<DownloadLocation> newValue)
+ {
+ if (!Choices.Restore(oldValue, newValue, v => DownloadLocation = v))
+ Save(s => s.BrowserDrops.DownloadLocation = newValue.Value);
+ }
+ partial void OnDownloadFolderChanged(string value) => Save(s => s.BrowserDrops.DownloadFolder = value.Trim());
+
[ObservableProperty] private bool _saveOnlyConverted;
/// <summary>The user's Downloads folder, shown while no other folder is set.</summary>
diff --git a/src/Filee.App/ViewModels/RadialViewModel.cs b/src/Filee.App/ViewModels/RadialViewModel.cs
index d03efe10..335dc3c3 100644
--- a/src/Filee.App/ViewModels/RadialViewModel.cs
+++ b/src/Filee.App/ViewModels/RadialViewModel.cs
@@ -10,6 +10,7 @@ using Filee.Core.Localization;
using Filee.Core.Presets;
using Filee.Core.Profiles;
using Filee.Core.Settings;
+using Filee.Core.Web;
namespace Filee.App.ViewModels;
@@ -157,7 +158,7 @@ public sealed partial class RadialViewModel(UserDataStore store, ILocalizer loc,
var profile = ProfileSelector.Select(store.Profiles, counted);
var formats = ProfileSelector.DetectFormats(counted);
// Both faces follow the same rule: a slice that can't convert these files is greyed out and says why.
- _front = BuildFace(profile?.PresetIds ?? [], formats);
+ _front = BuildFace(profile?.PresetIds ?? [], formats, files.Count > 0 && files.All(WebDrop.IsPlaceholder));
(_back, _backIds, _formats) = (null, [.. profile?.BackPresetIds ?? []], formats);
var load = ++_loads;
if (backFace)
@@ -222,13 +223,22 @@ public sealed partial class RadialViewModel(UserDataStore store, ILocalizer loc,
private bool HasGroups(IEnumerable<string> presetIds) => presetIds.Any(id => store.FindPreset(id)?.IsGroup == true);
- private Face BuildFace(IEnumerable<string> presetIds, IReadOnlyList<FileFormat> formats)
+ private Face BuildFace(IEnumerable<string> presetIds, IReadOnlyList<FileFormat> formats, bool download = false)
{
var presets = presetIds
.Select(store.FindPreset)
.OfType<Preset>()
.ToList();
+ if (download)
+ presets.Add(new Preset
+ {
+ Id = "browser-download",
+ NameKey = "preset.browser_download",
+ TargetFormat = "download",
+ Kind = PresetKind.Download
+ });
+
var subPresets = presets
.Select(p => (IReadOnlyList<Preset>)(p.IsGroup ? p.SubPresetIds : [])
.Select(store.FindPreset).OfType<Preset>().Where(c => !c.IsGroup).Take(Preset.MaxSubPresets).ToList())
@@ -236,13 +246,13 @@ public sealed partial class RadialViewModel(UserDataStore store, ILocalizer loc,
DonutItem ItemOf(Preset p, bool caption = true)
{
- var reason = availability.Check(p, formats);
+ var reason = p.IsDownload ? null : availability.Check(p, formats);
return new DonutItem
{
Id = p.Id,
// On a group's ring the group's name gives the context: "Rotate" → Left / Right / 180°.
Label = caption ? loc.DonutName(p) : loc.RingName(p),
- Caption = !caption ? null
+ Caption = p.IsDownload ? loc["preset.browser_download_caption"] : !caption ? null
: p.TargetFormat == BuiltInData.SameAsSource
? string.Join("/", formats.Select(f => f.DisplayName).Take(2))
: FormatLabels.NameOf(loc, p.TargetFormat),
diff --git a/src/Filee.App/Views/Pages/GeneralPage.axaml b/src/Filee.App/Views/Pages/GeneralPage.axaml
index 0d30079c..4c4e4ff4 100644
--- a/src/Filee.App/Views/Pages/GeneralPage.axaml
+++ b/src/Filee.App/Views/Pages/GeneralPage.axaml
@@ -74,6 +74,13 @@
<TextBox Text="{Binding BrowserFolder}" PlaceholderText="{Binding DownloadsFolder}" Width="440" />
</DockPanel>
</StackPanel>
+ <TextBlock Classes="label" Text="{DynamicResource general.download_location}" />
+ <ComboBox ItemsSource="{Binding DownloadLocations}" SelectedItem="{Binding DownloadLocation}" MinWidth="240" />
+ <DockPanel IsVisible="{Binding ShowDownloadFolder}" MaxWidth="560" HorizontalAlignment="Stretch">
+ <Button DockPanel.Dock="Right" Margin="8,0,0,0" Content="{DynamicResource presets.browse}" Click="OnBrowseDownloadFolder" />
+ <TextBox Text="{Binding DownloadFolder}" PlaceholderText="{Binding DownloadsFolder}" />
+ </DockPanel>
+ <TextBlock Classes="caption" TextWrapping="Wrap" Text="{DynamicResource general.download_hint}" />
<CheckBox Content="{DynamicResource general.browser_drops_only_converted}" IsChecked="{Binding SaveOnlyConverted}" />
<TextBlock Classes="caption" TextWrapping="Wrap" Text="{DynamicResource general.browser_drops_only_converted_hint}" Margin="0,-6,0,0" />
</StackPanel>
diff --git a/src/Filee.App/Views/Pages/GeneralPage.axaml.cs b/src/Filee.App/Views/Pages/GeneralPage.axaml.cs
index b880be0e..950acea4 100644
--- a/src/Filee.App/Views/Pages/GeneralPage.axaml.cs
+++ b/src/Filee.App/Views/Pages/GeneralPage.axaml.cs
@@ -48,6 +48,15 @@ public partial class GeneralPage : UserControl
Vm.BrowserFolder = path;
}
+ private async void OnBrowseDownloadFolder(object? sender, RoutedEventArgs e)
+ {
+ if (Vm is null || TopLevel.GetTopLevel(this) is not { } top) return;
+ var start = await top.StorageProvider.TryGetFolderFromPathAsync(
+ string.IsNullOrWhiteSpace(Vm.DownloadFolder) ? Vm.DownloadsFolder : Vm.DownloadFolder.Trim());
+ var folders = await top.StorageProvider.OpenFolderPickerAsync(new FolderPickerOpenOptions { AllowMultiple = false, SuggestedStartLocation = start });
+ if (folders.FirstOrDefault()?.TryGetLocalPath() is { } path) Vm.DownloadFolder = path;
+ }
+
private async void OnImport(object? sender, RoutedEventArgs e)
{
if (Vm is null || TopLevel.GetTopLevel(this) is not { } top)
diff --git a/src/Filee.Core/Conversion/JobQueue.cs b/src/Filee.Core/Conversion/JobQueue.cs
index 2d0de827..eb6c2c1d 100644
--- a/src/Filee.Core/Conversion/JobQueue.cs
+++ b/src/Filee.Core/Conversion/JobQueue.cs
@@ -98,39 +98,52 @@ public sealed class JobQueue : IAsyncDisposable
Directory.CreateDirectory(workDir);
try
{
+ if (job.Preset.IsDownload && job.Fetcher is null)
+ throw new InvalidOperationException("Download requires browser source data.");
if (job.Fetcher is { } fetcher)
await FetchSourcesAsync(job, fetcher);
- var planner = _catalog.CreatePlanner();
- var merge = job.Preset.Pdf.MergeIntoSingle
- && job.Preset.TargetFormat == "pdf"
- && job.Files.Count > 1
- && _pdfMerger is not null;
- // Any files, one of them or many, archives or not: they go into the archive as they are.
- var combine = job.Preset.PacksIntoOneArchive && _combiner is not null;
-
- // One file is enough: a 10-page PDF becomes one 10-page TIFF.
- var multiPageTiff = job.Preset.Image.MultiPageTiff && job.Preset.TargetFormat == "tiff" && _tiffMerger is not null;
- // Clips back to back, or pictures one after the other, in the order they were dropped.
- var join = job.Preset.JoinsIntoOneMedia && _mediaJoiner is not null;
- // Pictures one under another or side by side, in the order they were dropped.
- var imageJoiner = job.Preset.JoinsImages ? _catalog.All.OfType<IImageJoiner>().FirstOrDefault() : null;
-
- if (join)
- await RunJoinedMediaAsync(job, planner, workDir);
- else if (imageJoiner is not null)
- await RunMergedImagesAsync(job, planner, workDir, imageJoiner);
- else if (merge)
- await RunMergedAsync(job, planner, workDir);
- else if (multiPageTiff)
- await RunMultiPageTiffAsync(job, planner, workDir);
- else if (combine)
- await RunCombinedAsync(job, workDir);
+ if (job.Preset.IsDownload)
+ {
+ foreach (var file in job.Files.Where(f => f.Saved && f.State == FileState.Pending))
+ {
+ file.Outputs.Add(file.SourcePath);
+ file.Progress = 1;
+ file.State = FileState.Done;
+ }
+ }
else
- await Parallel.ForEachAsync(
- job.Files.Select((f, i) => (File: f, Index: i + 1)),
- new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount, CancellationToken = CancellationToken.None },
- async (item, _) => await RunFileAsync(job, item.File, item.Index, planner, workDir, finalOutput: true));
+ {
+ var planner = _catalog.CreatePlanner();
+ var merge = job.Preset.Pdf.MergeIntoSingle
+ && job.Preset.TargetFormat == "pdf"
+ && job.Files.Count > 1
+ && _pdfMerger is not null;
+ // Any files, one of them or many, archives or not: they go into the archive as they are.
+ var combine = job.Preset.PacksIntoOneArchive && _combiner is not null;
+
+ // One file is enough: a 10-page PDF becomes one 10-page TIFF.
+ var multiPageTiff = job.Preset.Image.MultiPageTiff && job.Preset.TargetFormat == "tiff" && _tiffMerger is not null;
+ // Clips back to back, or pictures one after the other, in the order they were dropped.
+ var join = job.Preset.JoinsIntoOneMedia && _mediaJoiner is not null;
+
+ var imageJoiner = job.Preset.JoinsImages ? _catalog.All.OfType<IImageJoiner>().FirstOrDefault() : null;
+ if (join)
+ await RunJoinedMediaAsync(job, planner, workDir);
+ else if (imageJoiner is not null)
+ await RunMergedImagesAsync(job, planner, workDir, imageJoiner);
+ else if (merge)
+ await RunMergedAsync(job, planner, workDir);
+ else if (multiPageTiff)
+ await RunMultiPageTiffAsync(job, planner, workDir);
+ else if (combine)
+ await RunCombinedAsync(job, workDir);
+ else
+ await Parallel.ForEachAsync(
+ job.Files.Select((f, i) => (File: f, Index: i + 1)),
+ new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount, CancellationToken = CancellationToken.None },
+ async (item, _) => await RunFileAsync(job, item.File, item.Index, planner, workDir, finalOutput: true));
+ }
job.State = job.CancellationToken.IsCancellationRequested ? JobState.Cancelled
: job.Files.All(f => f.State is FileState.Done or FileState.Skipped) ? JobState.Completed
@@ -179,7 +192,7 @@ public sealed class JobQueue : IAsyncDisposable
if (file.State != FileState.Running || file.Saved)
return;
file.Transfer = p;
- var value = (p.Fraction ?? 0) * FetchShare;
+ var value = (p.Fraction ?? 0) * (job.Preset.IsDownload ? 1 : FetchShare);
if (value > file.Progress)
file.Progress = value;
Notify(job);
@@ -189,7 +202,7 @@ public sealed class JobQueue : IAsyncDisposable
file.SourcePath = await fetcher.FetchAsync(file.SourcePath, progress, job.CancellationToken);
file.Saved = true;
file.State = FileState.Pending;
- file.Progress = FetchShare;
+ file.Progress = job.Preset.IsDownload ? 1 : FetchShare;
}
catch (OperationCanceledException)
{
diff --git a/src/Filee.Core/Presets/Preset.cs b/src/Filee.Core/Presets/Preset.cs
index f71ce2b1..bdccbf1f 100644
--- a/src/Filee.Core/Presets/Preset.cs
+++ b/src/Filee.Core/Presets/Preset.cs
@@ -22,6 +22,9 @@ public enum PresetKind
/// <see cref="Preset.Tool"/>). Like a group, never offered where a conversion is picked.
/// </summary>
Tool,
+
+ /// <summary>Saves browser-supplied files without conversion. Offered only for a live browser drop.</summary>
+ Download,
}
/// <summary>
@@ -142,6 +145,9 @@ public sealed class Preset
[JsonIgnore]
public bool IsGroup => Kind == PresetKind.Group;
+ [JsonIgnore]
+ public bool IsDownload => Kind == PresetKind.Download;
+
/// <summary>True for "Compress into one archive": files and folders go into one archive as they are.</summary>
[JsonIgnore]
public bool PacksIntoOneArchive =>
diff --git a/src/Filee.Core/Settings/AppSettings.cs b/src/Filee.Core/Settings/AppSettings.cs
index ace3a3aa..919fc54c 100644
--- a/src/Filee.Core/Settings/AppSettings.cs
+++ b/src/Filee.Core/Settings/AppSettings.cs
@@ -337,10 +337,15 @@ public sealed class DefaultOutputSettings
}
/// <summary>Files dragged out of a web browser (Settings → General).</summary>
+public enum DownloadLocation { Default, Ask, Custom }
+
public sealed class BrowserDropSettings
{
/// <summary>Where they are saved; empty means the user's Downloads folder (looked up each time, as it can move).</summary>
public string Folder { get; set; } = "";
+ public DownloadLocation DownloadLocation { get; set; }
+ public string DownloadFolder { get; set; } = "";
+ public string LastDownloadFolder { get; set; } = "";
/// <summary>Keep only the converted file: the original goes into a work folder and is deleted after the conversion.</summary>
public bool SaveOnlyConverted { get; set; }
diff --git a/src/Filee.Core/Web/WebDrop.cs b/src/Filee.Core/Web/WebDrop.cs
index 247333e0..910b6b27 100644
--- a/src/Filee.Core/Web/WebDrop.cs
+++ b/src/Filee.Core/Web/WebDrop.cs
@@ -204,7 +204,10 @@ public sealed class WebDrop : IDisposable
/// <summary>Where files dragged from a browser are saved (Settings → General).</summary>
/// <param name="Folder">The download folder; "next to the source" means this folder for these files.</param>
/// <param name="SaveOnlyConverted">The original goes into the work folder and is deleted after the conversion.</param>
-public sealed record WebDropOptions(string Folder, bool SaveOnlyConverted);
+public sealed record WebDropOptions(string Folder, bool SaveOnlyConverted)
+{
+ public IReadOnlyDictionary<string, string>? SavePaths { get; init; }
+}
/// <summary>Saves a <see cref="WebDrop"/>'s files for the job that converts them, and cleans up after it.</summary>
public sealed class WebDropFetcher(WebDrop drop, WebDropOptions options, WebDownloader downloader) : ISourceFetcher
@@ -227,8 +230,16 @@ public sealed class WebDropFetcher(WebDrop drop, WebDropOptions options, WebDown
public bool Fetches(string path) => drop.Holds(path);
- public Task<string> FetchAsync(string placeholder, IProgress<TransferProgress> progress, CancellationToken cancellationToken) =>
- drop.ItemFor(placeholder).SaveAsync(SaveFolder, downloader, progress, cancellationToken);
+ public async Task<string> FetchAsync(string placeholder, IProgress<TransferProgress> progress, CancellationToken cancellationToken)
+ {
+ if (options.SavePaths is null || !options.SavePaths.TryGetValue(placeholder, out var destination))
+ return await drop.ItemFor(placeholder).SaveAsync(SaveFolder, downloader, progress, cancellationToken);
+ var staging = Path.Combine(drop.WorkFolder, "named-downloads");
+ var saved = await drop.ItemFor(placeholder).SaveAsync(staging, downloader, progress, cancellationToken);
+ cancellationToken.ThrowIfCancellationRequested();
+ File.Move(saved, destination, overwrite: true);
+ return destination;
+ }
public void Release(ConversionJob job)
{
@@ -237,3 +248,4 @@ public sealed class WebDropFetcher(WebDrop drop, WebDropOptions options, WebDown
WebDrop.TryDeleteFolder(drop.WorkFolder);
}
}
+
diff --git a/tests/Filee.App.Tests/DownloadTests.cs b/tests/Filee.App.Tests/DownloadTests.cs
new file mode 100644
index 00000000..2200de77
--- /dev/null
+++ b/tests/Filee.App.Tests/DownloadTests.cs
@@ -0,0 +1,65 @@
+using Avalonia.Headless.XUnit;
+using Avalonia.Threading;
+using Filee.App.Services;
+using Filee.Core.Conversion;
+using Filee.Core.Platform;
+using Filee.Core.Presets;
+using Filee.Core.Settings;
+using Filee.Core.Web;
+
+namespace Filee.App.Tests;
+
+public class DownloadTests
+{
+ [AvaloniaFact]
+ public async Task Download_policy_cancel_and_exact_bytes_are_independent_of_conversion_settings()
+ {
+ TestServices.EnsureInitialized("en");
+ var store = AppHost.Get<UserDataStore>();
+ var service = AppHost.Get<ConversionService>();
+ var previous = store.Settings.BrowserDrops;
+ var folder = Path.Combine(Path.GetTempPath(), "filee-download-test-" + Guid.NewGuid().ToString("N"));
+ var bytes = Convert.FromBase64String("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==");
+ var preset = new Preset { Id = "browser-download", Kind = PresetKind.Download, TargetFormat = "download" };
+ WebDrop Drop() => new([WebDropItem.FromBytes("same.png", bytes)], WebDrop.DefaultWorkRoot);
+ try
+ {
+ store.Settings.BrowserDrops = new BrowserDropSettings { Folder = folder + "-unused", SaveOnlyConverted = true };
+ Assert.False(service.DownloadNeedsPicker);
+ Assert.Equal(AppHost.Get<IPlatformServices>().DownloadsFolder, service.DownloadFolderInUse);
+ store.Settings.BrowserDrops.DownloadLocation = DownloadLocation.Custom;
+ Assert.True(service.DownloadNeedsPicker);
+ store.Settings.BrowserDrops.DownloadFolder = folder;
+ Assert.False(service.DownloadNeedsPicker);
+ Assert.Equal(folder, service.DownloadFolderInUse);
+ store.Settings.BrowserDrops.DownloadLocation = DownloadLocation.Ask;
+ var before = service.Jobs.Count;
+ using (var cancel = Drop())
+ {
+ Assert.Null(await service.ChooseDownloadAsync(cancel.Placeholders, preset, cancel, _ => Task.FromResult<string?>(null)));
+ Assert.False(Directory.Exists(cancel.WorkFolder));
+ }
+ Assert.Equal(before, service.Jobs.Count);
+ for (var attempt = 0; attempt < 2; attempt++)
+ {
+ using var drop = Drop();
+ var vm = await service.ChooseDownloadAsync(drop.Placeholders, preset, drop, _ => Task.FromResult<string?>(folder));
+ Assert.NotNull(vm);
+ var until = DateTime.UtcNow.AddSeconds(30);
+ while (vm.Job.State is JobState.Queued or JobState.Running && DateTime.UtcNow < until)
+ { Dispatcher.UIThread.RunJobs(); Thread.Sleep(10); }
+ Assert.Equal(JobState.Completed, vm.Job.State);
+ var output = Assert.Single(vm.Job.Outputs);
+ Assert.Equal(folder, Path.GetDirectoryName(output));
+ Assert.Equal(bytes, File.ReadAllBytes(output));
+ }
+ Assert.Equal(2, Directory.GetFiles(folder).Length);
+ Assert.False(Directory.Exists(folder + "-unused"));
+ }
+ finally
+ {
+ store.Settings.BrowserDrops = previous;
+ if (Directory.Exists(folder)) Directory.Delete(folder, recursive: true);
+ }
+ }
+}