Skip to content

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

Categories without their own folder follow General's folder; start Add torrent with Torrents' folder (#556, #550) (#554)

鲲侯·星河易道@BigFishMarquisfeeb7133217d
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f417ed91..13bb4674 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -13,6 +13,7 @@ Each release's notes on GitHub come from its section here (`## [X.Y.Z]`, see
### Fixed
+- **Options → Save to**: changing the **General** category's default download directory now moves the default folders of all other categories without their own folder (`Video`, `Music`, `Torrents`, etc.) under it, instead of leaving them under the system's `Downloads` folder ([#556](https://github.com/anefzaoui/misterdownloadmanager/issues/556)). **Add torrent** also starts with the **Torrents** category's folder from the moment it opens (so **Save to** no longer flips when a magnet link's metadata arrives) and remembers a changed folder when **Change folder for this category on last selected** is ticked ([#550](https://github.com/anefzaoui/misterdownloadmanager/issues/550)).
- Windows: dragging a finished file out of **Download complete** (the grip at its bottom right) no longer holds up MDM's windows for as long as the drag lasts, or for as long as the program it is dropped on takes to answer: the drag now runs beside the window, as file dialogs already do ([#561](https://github.com/anefzaoui/misterdownloadmanager/issues/561)).
- Menus: going from an item with a submenu to another item closes the submenu at once, and only the item under the pointer is lit. The submenu stayed open, its item lit as well, until the pointer rested on one item, so as long as it kept moving; going diagonally into the submenu still keeps it open ([#579](https://github.com/anefzaoui/misterdownloadmanager/issues/579)).
- **Download video** without ffmpeg (on macOS and Linux, where MDM doesn't install it): the sound alone comes from a format the site sends as one file when it has one, and a sound or video that came as an HLS stream's pieces is saved as what it is (`.aac`, `.ts`) instead of `.mp4`, which players refused to open ([#569](https://github.com/anefzaoui/misterdownloadmanager/issues/569)).
diff --git a/ROADMAP.md b/ROADMAP.md
index f42febb5..b09cdcae 100644
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@ -535,6 +535,10 @@ These ship in a later version, when they're ready.
### Bugs being looked into
+- 🔄 Categories without their own folder following General's folder (`Video`, `Music`, `Torrents`
+ inside it), and Add torrent starting with the Torrents category's folder instead of flipping
+ from General when metadata arrives ([#556](https://github.com/anefzaoui/misterdownloadmanager/issues/556),
+ [#550](https://github.com/anefzaoui/misterdownloadmanager/issues/550)): fix in review
- 🔄 The window not answering while a file was dragged out of Download complete, for as long as
the program under the pointer took ([#561](https://github.com/anefzaoui/misterdownloadmanager/issues/561)): the drag now runs beside the window; fix
in review, to check with a real drag
diff --git a/crates/app/src/app.rs b/crates/app/src/app.rs
index 130a1a12..1718eba0 100644
--- a/crates/app/src/app.rs
+++ b/crates/app/src/app.rs
@@ -8515,6 +8515,13 @@ impl App {
Outcome::Open => false,
Outcome::Closed => true,
Outcome::Done(add) => {
+ if self.settings.change_folder_on_last
+ && self
+ .settings
+ .keep_category_dir(add.category, &add.dir, &self.downloads)
+ {
+ self.dirty = true;
+ }
self.torrent_dlg = None;
self.add_torrent(add);
true
diff --git a/crates/app/src/categories.rs b/crates/app/src/categories.rs
index db0ff3d1..6234f58d 100644
--- a/crates/app/src/categories.rs
+++ b/crates/app/src/categories.rs
@@ -334,10 +334,15 @@ pub fn apply(settings: &mut Settings, e: CategoryEdit, downloads: &Path) -> Cate
}
};
crate::model::set_custom(&settings.custom_categories);
- let typed = e.folder.trim_end_matches('\\');
- let default = cat.default_folder(downloads).display().to_string();
- let own =
- (!typed.is_empty() && typed != default.trim_end_matches('\\')).then(|| typed.to_owned());
+ let typed = e.folder.trim_end_matches(['\\', '/']);
+ let base = if cat == Category::General {
+ std::borrow::Cow::Borrowed(downloads)
+ } else {
+ crate::model::default_downloads(downloads, &settings.category_dirs)
+ };
+ let default = cat.default_folder(&base).display().to_string();
+ let own = (!typed.is_empty() && typed != default.trim_end_matches(['\\', '/']))
+ .then(|| typed.to_owned());
settings.set_category_dir(cat, own);
crate::model::set_custom(&settings.custom_categories);
cat
@@ -498,7 +503,7 @@ mod tests {
assert_eq!(Category::of("film.mp4"), Category::Video);
assert_eq!(
s.category_dir(Category::Video, downloads),
- downloads.join("Video")
+ Path::new(ALL).join("Video")
);
assert_eq!(s.category_dir(Category::General, downloads), Path::new(ALL));
assert!(Category::all().contains(&books));
diff --git a/crates/app/src/model.rs b/crates/app/src/model.rs
index bb93118a..757f157a 100644
--- a/crates/app/src/model.rs
+++ b/crates/app/src/model.rs
@@ -312,18 +312,32 @@ fn upper_list(exts: &[String]) -> String {
.join(" ")
}
+/// The base folder that categories without their own folder live under (#556): General's
+/// folder when one was chosen in Options → Save to, else `downloads`.
+pub fn default_downloads<'a>(
+ downloads: &'a Path,
+ dirs: &'a [(String, String)],
+) -> std::borrow::Cow<'a, Path> {
+ let general = Category::General.key();
+ dirs.iter()
+ .find(|(c, _)| *c == *general)
+ .map(|(_, d)| std::borrow::Cow::Owned(crate::dialogs::resolve_path(d)))
+ .unwrap_or(std::borrow::Cow::Borrowed(downloads))
+}
+
/// The category's folder: the one chosen in Options → Save to (or remembered from Download
-/// File Info), else the default.
+/// File Info), else the default under [`default_downloads`] (#556).
pub fn category_folder(cat: Category, downloads: &Path, dirs: &[(String, String)]) -> PathBuf {
+ let base = default_downloads(downloads, dirs);
if cat.is_custom() {
- return cat.folder(downloads);
+ return cat.folder(&base);
}
let key = cat.key();
dirs.iter()
.find(|(c, _)| *c == *key)
// A folder may be saved as shown, relative to the user's home.
.map(|(_, d)| crate::dialogs::resolve_path(d))
- .unwrap_or_else(|| cat.folder(downloads))
+ .unwrap_or_else(|| cat.folder(&base))
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
diff --git a/crates/app/src/options.rs b/crates/app/src/options.rs
index 7800fb0b..f15131c9 100644
--- a/crates/app/src/options.rs
+++ b/crates/app/src/options.rs
@@ -976,10 +976,15 @@ impl OptionsDialog {
let Some(&cat) = cats.get(self.category) else {
return;
};
- let default = display_dir(&cat.default_folder(downloads));
+ let base = if cat == Category::General {
+ std::borrow::Cow::Borrowed(downloads)
+ } else {
+ crate::model::default_downloads(downloads, &self.s.category_dirs)
+ };
+ let default = display_dir(&cat.default_folder(&base));
let typed = self.cat_dir.trim();
let own = (!typed.is_empty()
- && typed.trim_end_matches('\\') != default.trim_end_matches('\\'))
+ && typed.trim_end_matches(['\\', '/']) != default.trim_end_matches(['\\', '/']))
.then(|| typed.to_owned());
self.s.set_category_dir(cat, own);
}
diff --git a/crates/app/src/torrentdlg.rs b/crates/app/src/torrentdlg.rs
index b17316dc..1a93d6cc 100644
--- a/crates/app/src/torrentdlg.rs
+++ b/crates/app/src/torrentdlg.rs
@@ -224,7 +224,7 @@ impl TorrentDialog {
.map(|t| t.trim().to_owned())
.unwrap_or_default()
});
- let folder = category_folder(Category::General, &downloads, &category_dirs);
+ let folder = category_folder(Category::Torrents, &downloads, &category_dirs);
let mut d = TorrentDialog {
source,
folder: folder.display().to_string(),
@@ -1809,4 +1809,42 @@ mod tests {
assert_eq!(t[rows[0]].name, "debian.iso");
assert_eq!(t[rows[0]].files, [0]);
}
+
+ #[test]
+ fn categories_without_their_own_folder_follow_general() {
+ // Absolute on every system (a path like "/Volumes/…" is drive-relative on Windows).
+ let root = std::env::temp_dir().join("mdm-554");
+ let at = |p: &str| root.join(p).display().to_string();
+ let dl = root.join("Users/test/Downloads");
+ assert_eq!(
+ category_folder(Category::Torrents, &dl, &[]),
+ dl.join("Torrents")
+ );
+ let general_only = vec![("General".to_owned(), at("Volumes/Data/Downloads"))];
+ let general = root.join("Volumes/Data/Downloads");
+ assert_eq!(
+ category_folder(Category::General, &dl, &general_only),
+ general
+ );
+ assert_eq!(
+ category_folder(Category::Torrents, &dl, &general_only),
+ general.join("Torrents")
+ );
+ assert_eq!(
+ category_folder(Category::Video, &dl, &general_only),
+ general.join("Video")
+ );
+ let both = vec![
+ ("General".to_owned(), at("Volumes/Data/Downloads")),
+ ("Torrents".to_owned(), at("Volumes/NAS/Torrents")),
+ ];
+ assert_eq!(
+ category_folder(Category::Torrents, &dl, &both),
+ root.join("Volumes/NAS/Torrents")
+ );
+ assert_eq!(
+ category_folder(Category::Video, &dl, &both),
+ general.join("Video")
+ );
+ }
}