Skip to content

misterdownloadmanager: The ultimate open-source, clean-room download manager written from scratch in pure Rust for Windows, Mac, and Linux

Download panels: Export and Import for the sites the button stays off (part of #424) (#506)

Ahmed Nefzaoui4f36db5fdead
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8c140753..c9bb4720 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,10 @@ Each release's notes on GitHub come from its section here (`## [X.Y.Z]`, see
## [Unreleased]
+### Added
+
+- Options → General → **Customize MDM Download panels in browsers**: Export... and Import... for the sites the download button stays off, a plain text file with one site a line ([#424](https://github.com/anefzaoui/misterdownloadmanager/issues/424)).
+
### Fixed
- The progress window of a video whose size isn't known says no percentage (it read 0 % in the title and 0.00 % on the Downloaded line), and **File size** stays the file's size at the end (it read 0.1 % too high while yt-dlp finished).
diff --git a/ROADMAP.md b/ROADMAP.md
index 676f746f..5b80dcfb 100644
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@ -549,6 +549,8 @@ These ship in a later version, when they're ready.
([#321](https://github.com/anefzaoui/misterdownloadmanager/issues/321)): fix in review
- 🔄 **Open folder** on a torrent still downloading
([#354](https://github.com/anefzaoui/misterdownloadmanager/issues/354)): fix in review
+- 🔄 Export and Import for the sites the download button stays off
+ ([#424](https://github.com/anefzaoui/misterdownloadmanager/issues/424)): fix in review
- 🔄 Videos in the progress window: no percentage when the size isn't known, and the real file
size at the end: fix in review
- 🔄 X (Twitter) videos from the media list named after the tab instead of a random file name
diff --git a/crates/app/src/options.rs b/crates/app/src/options.rs
index d806d452..552978ae 100644
--- a/crates/app/src/options.rs
+++ b/crates/app/src/options.rs
@@ -38,7 +38,7 @@ enum Sub {
/// Connection → New / Edit exception: (row, server, number).
Exception(Option<usize>, String, String),
/// General → Download panels → Edit...: (the button over videos on, the sites it stays off).
- Panels(bool, String),
+ Panels(bool, String, String),
/// General → Keys...: (also take the files the browser would open).
Keys(bool),
/// General → Test browser integration...: the checks, as found when it opened.
@@ -249,6 +249,7 @@ impl OptionsDialog {
self.sub = Some(Sub::Panels(
self.s.video_panel,
self.s.video_panel_sites.clone(),
+ String::new(),
));
self
}
@@ -646,6 +647,7 @@ impl OptionsDialog {
self.sub = Some(Sub::Panels(
self.s.video_panel,
self.s.video_panel_sites.clone(),
+ String::new(),
));
}
}
@@ -3140,7 +3142,7 @@ impl OptionsDialog {
Outcome::Closed => {}
}
}
- Sub::Panels(mut on, mut sites) => {
+ Sub::Panels(mut on, mut sites, mut said) => {
let out = window(
ctx,
"opt-panels",
@@ -3181,11 +3183,103 @@ impl OptionsDialog {
crate::i18n::t("(separate names by spaces)"),
LIGHT_TEXT(),
);
+ // The list as a file, to keep or carry to a new installation (#424).
+ let [export_at, import_at] = winui::button_row(
+ &p,
+ &[("Export...", 212.0, 73.0), ("Import...", 293.0, 73.0)],
+ 8.0,
+ 160.0,
+ 140.0,
+ )[..] else {
+ unreachable!("two buttons")
+ };
+ if winui::button_light(
+ ui,
+ r(o, export_at.0, 128.0, export_at.1, 21.0),
+ "Export...",
+ ButtonKind::Normal,
+ false,
+ )
+ .clicked()
+ {
+ let title = crate::i18n::t("Export").to_owned();
+ winui::start_pick(ui.ctx(), "opt-panels-export", move || {
+ rfd::FileDialog::new()
+ .set_title(title)
+ .add_filter("TXT", &["txt"])
+ .set_file_name("sites.txt")
+ .save_file()
+ });
+ }
+ if winui::button_light(
+ ui,
+ r(o, import_at.0, 128.0, import_at.1, 21.0),
+ "Import...",
+ ButtonKind::Normal,
+ false,
+ )
+ .clicked()
+ {
+ let title = crate::i18n::t("Import").to_owned();
+ winui::start_pick(ui.ctx(), "opt-panels-import", move || {
+ rfd::FileDialog::new()
+ .set_title(title)
+ .add_filter("TXT", &["txt"])
+ .pick_file()
+ });
+ }
+ if let Some(path) = winui::picked(ui.ctx(), "opt-panels-export") {
+ said = match std::fs::write(
+ &path,
+ mdm_ipc::capture::sites_to_text(&sites),
+ ) {
+ Ok(()) => crate::i18n::tn(
+ sites.split_whitespace().count() as u64,
+ "{n} site saved to the file.",
+ "{n} sites saved to the file.",
+ ),
+ Err(e) => crate::i18n::fmt(
+ crate::i18n::t("The list could not be saved: {error}"),
+ &[("error", &e.to_string())],
+ ),
+ };
+ }
+ if let Some(path) = winui::picked(ui.ctx(), "opt-panels-import") {
+ said = match read_sites_file(&path) {
+ Ok(text) => {
+ let (merged, added) =
+ mdm_ipc::capture::merge_sites(&sites, &text);
+ sites = merged;
+ crate::i18n::tn(
+ added as u64,
+ "{n} site added from the file.",
+ "{n} sites added from the file.",
+ )
+ }
+ Err(e) => crate::i18n::fmt(
+ crate::i18n::t("The file could not be read: {error}"),
+ &[("error", &e.to_string())],
+ ),
+ };
+ }
+ if !said.is_empty() {
+ let (rect, cut) = winui::text_fit(
+ &p,
+ o.x + 14.0,
+ o.y + 163.0,
+ &said,
+ LIGHT_TEXT(),
+ o.x + 205.0,
+ );
+ if cut {
+ winui::full_on_hover(ui, rect, "opt-panels-said", &said);
+ }
+ }
ok_cancel(ui, o, 212.0, 157.0, true)
},
);
match out {
- Outcome::Open => self.sub = Some(Sub::Panels(on, sites)),
+ Outcome::Open => self.sub = Some(Sub::Panels(on, sites, said)),
Outcome::Done(()) => {
self.s.video_panel = on;
self.s.video_panel_sites =
@@ -3894,6 +3988,17 @@ fn open_page(url: &str) {
}
}
+/// A list of sites from a file (Download panels' Import, #424): text, and no more than a list
+/// could be.
+fn read_sites_file(path: &std::path::Path) -> std::io::Result<String> {
+ use std::io::Read as _;
+ let mut text = Vec::new();
+ std::fs::File::open(path)?
+ .take(1 << 20)
+ .read_to_end(&mut text)?;
+ String::from_utf8(text).map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidData, e))
+}
+
fn ok_cancel(ui: &mut Ui, o: Pos2, x: f32, y: f32, valid: bool) -> Outcome<()> {
let kind = if valid {
ButtonKind::Default
@@ -4459,3 +4564,22 @@ fn kept_text(kept: crate::secrets::Kept) -> Option<&'static str> {
),
})
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ /// #424: the list written and read back through a real file: nothing lost, nothing doubled.
+ #[test]
+ fn sites_round_trip_through_a_file() {
+ let dir = tempfile::tempdir().unwrap();
+ let file = dir.path().join("sites.txt");
+ let sites = "a.test *.b.test";
+ std::fs::write(&file, mdm_ipc::capture::sites_to_text(sites)).unwrap();
+ let text = read_sites_file(&file).unwrap();
+ assert_eq!(text, "a.test\n*.b.test\n");
+ let (back, added) = mdm_ipc::capture::merge_sites("", &text);
+ assert_eq!((back.as_str(), added), (sites, 2));
+ assert_eq!(mdm_ipc::capture::merge_sites(sites, &text).1, 0);
+ }
+}
diff --git a/crates/ipc/src/capture.rs b/crates/ipc/src/capture.rs
index 3781d735..87f183f2 100644
--- a/crates/ipc/src/capture.rs
+++ b/crates/ipc/src/capture.rs
@@ -254,6 +254,35 @@ pub fn add_site(sites: &str, host: &str) -> String {
out
}
+/// The sites a list holds (space-separated), as a file: one a line (Options → Download panels,
+/// #424).
+pub fn sites_to_text(sites: &str) -> String {
+ sites.split_whitespace().fold(String::new(), |mut out, s| {
+ out.push_str(s);
+ out.push('\n');
+ out
+ })
+}
+
+/// `sites` with the patterns of a file (one or more names a line, or space-separated) added, those
+/// not there already whatever their case, and how many that was. A name holding anything else
+/// than a host pattern's characters is left out.
+pub fn merge_sites(sites: &str, text: &str) -> (String, usize) {
+ let mut out: Vec<String> = sites.split_whitespace().map(str::to_owned).collect();
+ let mut added = 0;
+ for name in text.split_whitespace().take(5000) {
+ let usable = name.len() <= 253
+ && name.chars().all(|c| {
+ c.is_alphanumeric() || matches!(c, '.' | '-' | '_' | ':' | '[' | ']' | '*' | '/')
+ });
+ if usable && !out.iter().any(|s| s.eq_ignore_ascii_case(name)) {
+ out.push(name.to_owned());
+ added += 1;
+ }
+ }
+ (out.join(" "), added)
+}
+
/// Does `name`'s extension appear in `types` (Options → File types: `EXE ZIP R0*`)?
pub fn type_listed(types: &str, name: &str) -> bool {
let Some((_, ext)) = name.rsplit_once('.') else {
@@ -405,6 +434,21 @@ mod tests {
const EDGE: &str = "Microsoft Edge";
const FIREFOX: &str = "Mozilla Firefox";
+ /// #424: the list of sites as a file and back: one a line, duplicates (whatever their case)
+ /// not added, what isn't a site left out.
+ #[test]
+ fn sites_export_and_import() {
+ assert_eq!(sites_to_text("a.test *.b.test"), "a.test\n*.b.test\n");
+ assert_eq!(sites_to_text(""), "");
+ let (merged, added) = merge_sites(
+ "a.test b.test",
+ "A.TEST\r\nc.test d.test\n*.e.test\nbad<name\n",
+ );
+ assert_eq!(merged, "a.test b.test c.test d.test *.e.test");
+ assert_eq!(added, 3);
+ assert_eq!(merge_sites("a.test", "").0, "a.test");
+ }
+
#[test]
fn browsers_by_name() {
assert_eq!(browser_named(CHROME_UA, &[]), CHROME);
diff --git a/i18n/en.tsv b/i18n/en.tsv
index ea082575..c9869138 100644
--- a/i18n/en.tsv
+++ b/i18n/en.tsv
@@ -76,6 +76,12 @@
#. count in the main window
#. {n} = a number (keep the braces as they are)
@plural {n} selected|{n} selected {n} selected|{n} selected
+#. count in the Options window
+#. {n} = a number (keep the braces as they are)
+@plural {n} site added from the file.|{n} sites added from the file. {n} site added from the file.|{n} sites added from the file.
+#. count in the Options window
+#. {n} = a number (keep the braces as they are)
+@plural {n} site saved to the file.|{n} sites saved to the file. {n} site saved to the file.|{n} sites saved to the file.
#. count in the main window
#. event log entry: trackers were added to the torrent
#. {n} = a number (keep the braces as they are)
@@ -1126,8 +1132,11 @@
#. text in the Options window
#. Options → Accounts: a note that the debrid services' support (Real-Debrid, AllDebrid, Premiumize) is new and not yet tried with real paid accounts
Experimental: built from the services' public API documentation, not yet confirmed with real accounts. Experimental: built from the services' public API documentation, not yet confirmed with real accounts.
-#. message or event log entry in the main window
+#. message or event log entry in the main window; text in the Options window
Export Export
+#. button in the Options window
+#. the trailing ... means it opens a window: keep it
+ Export... Export...
#. text in the Options window
Extend the availability of Manifest 2 Chrome extensions Extend the availability of Manifest 2 Chrome extensions
#. text in categories.rs
@@ -1475,8 +1484,11 @@
If it can't be reached, use the system's DNS If it can't be reached, use the system's DNS
#. checkbox in the Options window
Ignore file modification time changes when resuming a download Ignore file modification time changes when resuming a download
-#. message or event log entry in the main window
+#. message or event log entry in the main window; text in the Options window
Import Import
+#. button in the Options window
+#. the trailing ... means it opens a window: keep it
+ Import... Import...
#. value in a column's filter list in the download list
In a queue In a queue
#. what a keyboard shortcut does in the Help menu's windows (About, updates, shortcuts, Tell a friend)
@@ -3197,7 +3209,7 @@
#. message or event log entry in the main window
#. {error} = an error message (keep the braces as they are)
The file could not be moved: {error} The file could not be moved: {error}
-#. message or event log entry in the main window
+#. message or event log entry in the main window; text in the Options window
#. {error} = an error message (keep the braces as they are)
The file could not be read: {error} The file could not be read: {error}
#. text in the Checksum window
@@ -3233,7 +3245,7 @@
#. text in extension.rs
#. a check of Test browser integration: the browsers are set up, but the small helper program they start (misterdownloadmanager-nmhost) is gone
The helper program the browsers start is missing The helper program the browsers start is missing
-#. message or event log entry in the main window
+#. message or event log entry in the main window; text in the Options window
#. {error} = an error message (keep the braces as they are)
The list could not be saved: {error} The list could not be saved: {error}
#. text in whereis.rs