Skip to content

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

Torrents: Checking % during rechecks, finished torrents release their files, Torrent → Files…, rechecks that finish (#331)

Marwan Hamada515cd55de24d
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ada4b521..f889f044 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -41,6 +41,7 @@ Each release's notes on GitHub come from its section here (`## [X.Y.Z]`, see
- Windows: no more crash when a screen is unplugged, turned off or rearranged while MDM runs ([#335](https://github.com/anefzaoui/misterdownloadmanager/issues/335)).
### Added
+- **Torrent → Files…**: the list of a torrent's files for any torrent, running, stopped or finished, with a box to choose each (also a Files… button in File Properties).
- **Two columns for torrents in the download list** ([#357](https://github.com/anefzaoui/misterdownloadmanager/issues/357)): **Peers** (those a torrent has connected while it runs, seeders and leechers alike) and **Share ratio** (what it has sent against what it took), after **Transfer rate**. A layout saved before them gets them there.
- The extension's **Media on this page** can name a file after its page: **Prefix media file names with the page title** puts the page's title before the file's own name. Off as installed.
- **Far more file types taken from the browser by default** ([#382](https://github.com/anefzaoui/misterdownloadmanager/issues/382)): AI models and datasets (GGUF, SAFETENSORS, CKPT, PT, ONNX, PARQUET...), 3D and CAD (GLB, FBX, OBJ, STL, BLEND, STEP...), design and camera RAW files, ebooks, Office files, DAT, disk images and split archives. A list you never edited gains them; one you edited stays yours.
@@ -50,6 +51,8 @@ Each release's notes on GitHub come from its section here (`## [X.Y.Z]`, see
### Fixed
+- A finished torrent that isn't being shared lets go of its files, so they can be moved or deleted while MDM runs.
+- A torrent says **Checking 42%** while its files are read and checked, and a Recheck no longer stops partway and stays there.
- Video downloads: the progress no longer says 100 % while a video is still coming, when the site gives no total size, or between a video and its separate sound ([#344](https://github.com/anefzaoui/misterdownloadmanager/issues/344)). A video yt-dlp only knows by its address is named after the page, not a long hash ([#345](https://github.com/anefzaoui/misterdownloadmanager/issues/345)).
- **A YouTube playlist in Add URL** ([#338](https://github.com/anefzaoui/misterdownloadmanager/issues/338)) opens the video window with its videos, instead of saving the page as a file named "playlist".
- **Dailymotion's embedded player** ([#359](https://github.com/anefzaoui/misterdownloadmanager/issues/359)): its address is looked up as the video's own page, so the download button works on sites that embed one.
diff --git a/ROADMAP.md b/ROADMAP.md
index 13d0f315..0d0f40e0 100644
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@ -327,8 +327,10 @@ Everything below ships together, in version 0.5.0.
protected, never downloaded ([#38](https://github.com/anefzaoui/misterdownloadmanager/issues/38))
- ✅ Torrents: RSS feeds with download rules (words, episodes, each episode once, a folder per rule)
([#39](https://github.com/anefzaoui/misterdownloadmanager/issues/39))
-- ✅ Torrents: Recheck, Reannounce, Add trackers and Copy magnet link; files chosen while a
- torrent runs; a `.torrent` file's web address opens Add torrent ([#39](https://github.com/anefzaoui/misterdownloadmanager/issues/39))
+- ✅ Torrents: Recheck, Reannounce, Add trackers and Copy magnet link; choose files while a
+ torrent runs, or in Torrent → Files… for any torrent (stopped or complete too); a check of the
+ files says "Checking 42%"; a finished torrent that isn't shared lets go of its files; a
+ `.torrent` file's web address opens Add torrent ([#39](https://github.com/anefzaoui/misterdownloadmanager/issues/39))
- ✅ Link grabber: links in packages, looked up for name and size; archives (zip and tar
built in; 7z and RAR need 7-Zip) extracted when they are downloaded
([#37](https://github.com/anefzaoui/misterdownloadmanager/issues/37)); collecting copied links
diff --git a/crates/app/src/app.rs b/crates/app/src/app.rs
index c93a46f1..53f23070 100644
--- a/crates/app/src/app.rs
+++ b/crates/app/src/app.rs
@@ -153,6 +153,7 @@ enum Cmd {
TorrentInOrder,
TorrentEndsFirst,
TorrentAddTrackers,
+ TorrentFiles,
TorrentCopyMagnet,
/// Tasks → RSS feeds… (also the Add Torrent button's arrow), #39: true opens it on its
/// Download rules tab.
@@ -510,6 +511,7 @@ pub struct App {
torrent_settings: Option<crate::torrentdlg::TorrentSettings>,
/// Right-click → Torrent → Add trackers… (#39).
add_trackers: Option<crate::torrentdlg::AddTrackers>,
+ torrent_files: Option<crate::torrentfiles::TorrentFiles>,
/// RSS feeds and their download rules (#39, rss.rs), kept in rss.json; the window; the
/// feeds being fetched; what the fetches and look-ups sent back (`rss_tick`).
rss: crate::rss::Store,
@@ -1096,6 +1098,7 @@ impl App {
torrent_dlg: None,
torrent_settings: None,
add_trackers: None,
+ torrent_files: None,
rss: crate::rss::Store::path()
.map(|p| crate::rss::Store::load(&p))
.unwrap_or_default(),
@@ -1809,6 +1812,11 @@ impl App {
self.account_at += Duration::from_secs(dt);
}
let Some(t) = self.torrent_host.get() else {
+ // No session: no check is running, whatever the last numbers said.
+ self.torrent_resync.clear();
+ for i in self.items.iter_mut() {
+ i.torrent_check = None;
+ }
crate::torrents::clear_peers(self.items.iter_mut().filter_map(|i| i.torrent.as_mut()));
return;
};
@@ -1821,9 +1829,15 @@ impl App {
};
hashes.insert(spec.hash.clone());
let Ok(st) = t.stats(&spec.hash) else {
+ // Out of the session (released when it finished): no check is running.
+ i.torrent_check = None;
spec.peers = 0;
continue;
};
+ // Keep the session's in-memory checking progress visible for stopped/complete
+ // torrents too; normal download progress is restored when initialization ends.
+ i.torrent_check = (st.phase == mdm_torrent::Phase::Checking)
+ .then_some((st.checked.unwrap_or(st.done), st.total));
let sent = self.accountant.sent(&spec.hash, st.uploaded);
if sent > 0 {
spec.uploaded += sent;
@@ -1844,12 +1858,14 @@ impl App {
{
let (t2, hash) = (t.clone(), spec.hash.clone());
self.rt.spawn(async move {
- let _ = t2.pause(&hash).await;
+ let _ = t2.remove(&hash, false).await;
});
stopped = Some(why);
changed = true;
}
let (hash, up) = (spec.hash.clone(), spec.upload_limit);
+ let stop_after_recheck = !self.settings.torrent_keep_sharing
+ || crate::torrents::sharing_limit_reached(spec, st.done, limits).is_some();
if i.live.is_none() {
let _ = t.set_torrent_limits(&hash, None, up);
}
@@ -1880,6 +1896,12 @@ impl App {
let whole = st.total > 0 && st.done >= st.total;
if whole {
i.status = Status::Complete;
+ if report && i.live.is_none() && stop_after_recheck {
+ let t2 = t.clone();
+ self.rt.spawn(async move {
+ let _ = t2.remove(&hash, false).await;
+ });
+ }
} else if i.status == Status::Complete {
i.status = Status::Stopped;
let t2 = t.clone();
@@ -1918,7 +1940,18 @@ impl App {
.items
.iter()
.any(|i| i.torrent.is_some() && i.status == Status::Complete);
+ // A torrent being checked (a Recheck of one that isn't running, its action still going,
+ // or its result not read yet) needs the session too: stopped as idle after a minute,
+ // the check died where it was and the list said "Checking 17%" for good.
+ let checking = !self.torrent_resync.is_empty()
+ || self.items.iter().any(|i| {
+ i.torrent_check.is_some()
+ || i.torrent
+ .as_ref()
+ .is_some_and(|t| self.torrent_host.busy(&t.hash))
+ });
let busy = sharing
+ || checking
|| self.torrent_dlg.is_some()
|| self
.items
@@ -3577,7 +3610,7 @@ impl App {
}
}
- /// The info hashes of the torrents in the list (the torrent session keeps only these).
+ /// The info hashes of every torrent in the list (also used to prevent duplicate adds).
fn torrent_hashes(&self) -> std::collections::HashSet<String> {
self.items
.iter()
@@ -3585,6 +3618,23 @@ impl App {
.collect()
}
+ /// The hashes librqbit should keep or restore in its session.
+ fn session_hashes(&self) -> std::collections::HashSet<String> {
+ let limits = self.settings.sharing_limits();
+ self.items
+ .iter()
+ .filter(|i| {
+ i.status != Status::Complete
+ || (self.settings.torrent_keep_sharing
+ && i.torrent.as_ref().is_some_and(|spec| {
+ crate::torrents::sharing_limit_reached(spec, i.downloaded, limits)
+ .is_none()
+ }))
+ })
+ .filter_map(|i| i.torrent.as_ref().map(|t| t.hash.clone()))
+ .collect()
+ }
+
/// The list's finished torrents (what "keep sharing" shares).
/// The finished torrents to share (Torrent settings' "Keep sharing"): those that haven't
/// reached a seeding limit.
@@ -3636,7 +3686,7 @@ impl App {
source,
remote,
self.torrent_host.clone(),
- self.torrent_hashes(),
+ self.session_hashes(),
self.downloads.clone(),
self.settings.category_dirs.clone(),
&self.rt,
@@ -3838,11 +3888,17 @@ impl App {
/// Start a torrent: the session adds or resumes it.
fn start_torrent(&mut self, id: u64, show: bool) {
- let known = self.torrent_hashes();
- let share = self.settings.torrent_keep_sharing;
+ let auto_share = self.settings.torrent_keep_sharing;
+ let known = self.session_hashes();
let limit = self.settings.speed_limit();
let (host, rt) = (self.torrent_host.clone(), self.rt.clone());
let Some(item) = self.item(id) else { return };
+ // An explicit Start on a completed download means seed it, even when automatic
+ // keep sharing is off. It remains in the session until Stop or a sharing limit.
+ let share = auto_share
+ || item
+ .size
+ .is_some_and(|size| size > 0 && item.downloaded >= size);
// Its own remembered limit first, as a file download's (#39).
let limit = item.own_limit.or(limit);
let Some(spec) = item.torrent.clone() else {
@@ -3957,7 +4013,7 @@ impl App {
fn rss_look_up(&mut self, rule: u64, feed: u64, article: crate::rss::Article) {
let (host, known, out) = (
self.torrent_host.clone(),
- self.torrent_hashes(),
+ self.session_hashes(),
self.rss_events.clone(),
);
self.rt.spawn(async move {
@@ -4115,7 +4171,7 @@ impl App {
}
fn torrent_act(&mut self, id: u64, act: crate::torrents::Act) {
- let known = self.torrent_hashes();
+ let known = self.session_hashes();
let Some(spec) = self
.items
.iter()
@@ -4465,7 +4521,7 @@ impl App {
let (out, host, known) = (
slot.clone(),
self.torrent_host.clone(),
- self.torrent_hashes(),
+ self.session_hashes(),
);
self.rt.spawn(async move {
let res = match host.session(known).await {
@@ -5227,6 +5283,12 @@ impl App {
Some(crate::torrentdlg::AddTrackers::new(i.id, &i.file_name));
}
}
+ Cmd::TorrentFiles => {
+ if let Some(item) = target.and_then(|id| self.items.iter().find(|i| i.id == id)) {
+ self.torrent_files =
+ crate::torrentfiles::TorrentFiles::new(item, &self.torrent_host);
+ }
+ }
Cmd::TorrentCopyMagnet => {
// With its trackers, from the .torrent kept for it; else the list's address.
let found = target.and_then(|id| self.items.iter().find(|i| i.id == id));
@@ -6102,6 +6164,9 @@ impl App {
"Torrent",
true,
vec![
+ // i18n: right-click → Torrent submenu: open the selected torrent's file list
+ I("Files...", Cmd::TorrentFiles, true, false),
+ Sep,
// i18n: right-click → Torrent: read every piece of the torrent's files again and check it
I(
"Recheck files",
@@ -8096,6 +8161,7 @@ impl App {
}
}
let mut changes = Vec::new();
+ let mut files_requested = Vec::new();
let items = &self.items;
let icons = &mut self.icons;
self.properties.retain_mut(|pr| {
@@ -8103,7 +8169,12 @@ impl App {
return false;
};
match pr.show(ctx, icons, item) {
- Outcome::Open => true,
+ Outcome::Open => {
+ if pr.take_files_requested() {
+ files_requested.push(pr.id);
+ }
+ true
+ }
Outcome::Closed => false,
Outcome::Done(c) => {
changes.push(c);
@@ -8114,6 +8185,12 @@ impl App {
for c in changes {
self.apply_properties(c);
}
+ for id in files_requested {
+ if let Some(item) = self.items.iter().find(|i| i.id == id) {
+ self.torrent_files =
+ crate::torrentfiles::TorrentFiles::new(item, &self.torrent_host);
+ }
+ }
let mut hashes = Vec::new();
self.checksums.retain_mut(|c| match c.show(ctx) {
Outcome::Open => true,
@@ -8163,7 +8240,7 @@ impl App {
if self.settings.torrent_keep_sharing {
self.torrent_host.set_sharing(
&self.rt,
- self.torrent_hashes(),
+ self.session_hashes(),
self.complete_torrents(),
true,
);
@@ -8202,7 +8279,7 @@ impl App {
{
self.torrent_host.set_sharing(
&self.rt,
- self.torrent_hashes(),
+ self.session_hashes(),
self.complete_torrents(),
true,
);
@@ -8211,7 +8288,7 @@ impl App {
self.settings.torrent_keep_sharing = share;
self.torrent_host.set_sharing(
&self.rt,
- self.torrent_hashes(),
+ self.session_hashes(),
self.complete_torrents(),
share,
);
@@ -8273,6 +8350,19 @@ impl App {
}
}
}
+ let mut torrent_files_selection = None;
+ if let Some(d) = &mut self.torrent_files {
+ match d.show(ctx) {
+ Outcome::Open => {
+ torrent_files_selection = d.take_selection().map(|selection| (d.id, selection));
+ }
+ Outcome::Closed => self.torrent_files = None,
+ Outcome::Done(_) => self.torrent_files = None,
+ }
+ }
+ if let Some((id, (files, all, size))) = torrent_files_selection {
+ self.choose_files(id, files, all, size);
+ }
if let Some(t) = &mut self.torrent_dlg {
match t.show(ctx, &self.rt) {
Outcome::Open => {}
diff --git a/crates/app/src/main.rs b/crates/app/src/main.rs
index 0cdc7268..12ee797d 100644
--- a/crates/app/src/main.rs
+++ b/crates/app/src/main.rs
@@ -55,6 +55,7 @@ mod theme;
mod themefile;
mod themeicons;
mod torrentdlg;
+mod torrentfiles;
mod torrents;
mod transfer;
mod tray;
diff --git a/crates/app/src/model.rs b/crates/app/src/model.rs
index 6b2f6fa3..89d5e6e7 100644
--- a/crates/app/src/model.rs
+++ b/crates/app/src/model.rs
@@ -399,6 +399,9 @@ pub struct Item {
pub remote: Option<RemoteSpec>,
#[serde(skip)]
pub live: Option<Live>,
+ /// The session's temporary view while a torrent is being checked; never saved.
+ #[serde(skip)]
+ pub torrent_check: Option<(u64, u64)>,
/// The engine's last view of this download (segments, connections).
#[serde(skip)]
pub snap: Option<mdm_engine::Snapshot>,
@@ -698,6 +701,7 @@ impl Item {
direct: false,
remote: None,
live: None,
+ torrent_check: None,
snap: None,
login: None,
context: Default::default(),
@@ -846,6 +850,9 @@ impl Item {
}
self.notices = notices;
self.live = None;
+ // The session's last check numbers belong to the run just ended (a finished
+ // torrent leaves the session): not left saying "Checking" until the next tick.
+ self.torrent_check = None;
true
}
None => false,
@@ -890,10 +897,38 @@ impl Item {
))
}
+ /// "Checking 42%" while a torrent's files are read and checked (added over files already
+ /// there, Recheck): a running one from its live numbers (librqbit counts the bytes checked),
+ /// one not running from the session's (`torrent_check`, every 2 s). Whole percents: the
+ /// list's Status column is narrow.
+ pub fn torrent_checking(&self) -> Option<String> {
+ self.torrent.as_ref()?;
+ let (checked, total) = match (&self.live, &self.snap) {
+ (Some(_), Some(s)) if s.state == State::Verifying => {
+ (s.downloaded, s.size.unwrap_or(0))
+ }
+ (Some(_), _) => return None,
+ (None, _) => self.torrent_check?,
+ };
+ let ratio = if total > 0 {
+ checked as f64 / total as f64
+ } else {
+ 0.0
+ };
+ Some(crate::i18n::fmt(
+ // i18n: a torrent's status while its files are read and checked; {percent} is how much is checked, e.g. "42%"
+ crate::i18n::t("Checking {percent}"),
+ &[("percent", &crate::i18n::percent(ratio.min(1.0), 0))],
+ ))
+ }
+
pub fn status_text(&self) -> String {
if let Some(at) = self.at_service() {
return at;
}
+ if let Some(checking) = self.torrent_checking() {
+ return checking;
+ }
if self
.snap
.as_ref()
diff --git a/crates/app/src/progress.rs b/crates/app/src/progress.rs
index b5151c6b..b2cb6d71 100644
--- a/crates/app/src/progress.rs
+++ b/crates/app/src/progress.rs
@@ -972,6 +972,8 @@ fn status_page(ui: &Ui, o: Pos2, item: &Item, snap: Option<&Snapshot>, frac: f64
winui::copyable(ui, rect, key, s, cut);
};
let status = match item.status {
+ // A torrent reading and checking its files says so, not "Receiving data" (#39).
+ _ if let Some(checking) = item.torrent_checking() => checking,
// A torrent its debrid service is downloading (#44).
Status::Downloading if item.at_service().is_some() => item.at_service().unwrap_or_default(),
Status::Downloading => {
@@ -1200,22 +1202,7 @@ impl Progress {
})
.collect();
let ticks: Vec<bool> = d.files.iter().map(|f| f.2).collect();
- let clicked = table(
- ui,
- p,
- o,
- "t-files",
- // i18n: column titles: File (name), Size, Done (how much is downloaded)
- &[
- (25.0, crate::i18n::mark("File")),
- (335.0, crate::i18n::mark("Size")),
- (430.0, crate::i18n::mark("Done")),
- ],
- &[330.0, 425.0],
- &rows,
- true,
- Some(&ticks),
- );
+ let clicked = files_table(ui, p, o, "t-files", &rows, &ticks, 6);
// A box ticked or unticked (#39): the torrent downloads those files from now
// on; the last one ticked can't be unticked (a torrent of nothing).
if let Some(row) = clicked {
@@ -1499,6 +1486,40 @@ fn piece_grid(p: &egui::Painter, o: Pos2, pieces: &[bool]) {
}
}
+/// The Files tab's table of a torrent's files, ticked or not: the progress window's (`shown`: 6
+/// rows) and the Files window's (torrentfiles.rs, taller). The row whose box was clicked.
+pub(crate) fn files_table(
+ ui: &mut Ui,
+ p: &egui::Painter,
+ o: Pos2,
+ id: &str,
+ rows: &[Vec<String>],
+ checks: &[bool],
+ shown: usize,
+) -> Option<usize> {
+ table_sized(
+ ui,
+ p,
+ o,
+ id,
+ &[
+ (25.0, crate::i18n::mark("File")),
+ (335.0, crate::i18n::mark("Size")),
+ (430.0, crate::i18n::mark("Done")),
+ ],
+ &[330.0, 425.0],
+ rows,
+ true,
+ Some(checks),
+ shown,
+ )
+}
+
+/// The height of a [`table_sized`] of `shown` rows' body (the progress window's 6: 100 px).
+pub(crate) fn table_body_height(shown: usize) -> f32 {
+ 17.0 * shown as f32 - 2.0
+}
+
/// A table in the connections table's frame: headers at x, column lines at `seps`, rows of
/// text cut to their column (whole on hover), scrolled by the wheel. `checks`: a check box
/// before each row's icon, ticked or not (the Files tab); the row whose box was clicked.
@@ -1513,16 +1534,41 @@ fn table(
rows: &[Vec<String>],
icons: bool,
checks: Option<&[bool]>,
+) -> Option<usize> {
+ table_sized(ui, p, o, id, heads, seps, rows, icons, checks, 6)
+}
+
+/// [`table`] showing `shown` rows: it grows down from the same top.
+#[allow(clippy::too_many_arguments)]
+fn table_sized(
+ ui: &mut Ui,
+ p: &egui::Painter,
+ o: Pos2,
+ id: &str,
+ heads: &[(f32, &str)],
+ seps: &[f32],
+ rows: &[Vec<String>],
+ icons: bool,
+ checks: Option<&[bool]>,
+ shown: usize,
) -> Option<usize> {
let mut clicked = None;
- let outer = r(o, 17.0, 273.0, 513.0, 128.0);
+ let body_h = table_body_height(shown);
+ let outer = r(o, 17.0, 273.0, 513.0, body_h + 28.0);
winui::solid(p, outer, winui::FIELD_EDGE());
let (bg, head, line) = (
winui::FIELD(),
winui::LIST_HEADER(),
crate::theme::colors().header_sep,
);
- fill(p, o.x + 18.0, o.y + 274.0, o.x + 528.0, o.y + 399.0, bg);
+ fill(
+ p,
+ o.x + 18.0,
+ o.y + 274.0,
+ o.x + 528.0,
+ o.y + 299.0 + body_h,
+ bg,
+ );
fill(p, o.x + 19.0, o.y + 275.0, o.x + 527.0, o.y + 298.0, head);
for x in seps {
fill(p, o.x + x, o.y + 275.0, o.x + x, o.y + 298.0, line);
@@ -1530,7 +1576,7 @@ fn table(
for (x, h) in heads {
text(p, o.x + x, o.y + 290.0, crate::i18n::t(h), winui::TEXT());
}
- let visible = 6usize;
+ let visible = shown;
// Per window: each progress window scrolls its own tables.
let key = egui::Id::unique(("torrent-table", id, ui.ctx().viewport_id()));
let max_first = rows.len().saturating_sub(visible);
@@ -1539,9 +1585,9 @@ fn table(
.data(|d| d.get_temp::<usize>(key))
.unwrap_or(0)
.min(max_first);
- let body = r(o, 19.0, 299.0, 508.0, 100.0);
+ let body = r(o, 19.0, 299.0, 508.0, body_h);
if ui.rect_contains_pointer(body) {
- let step = winui::wheel_steps(ui, key, 100.0 / visible as f32, visible as f32);
+ let step = winui::wheel_steps(ui, key, body_h / visible as f32, visible as f32);
first = first.saturating_add_signed(step).min(max_first);
ui.ctx().data_mut(|d| d.insert_temp(key, first));
}
@@ -1587,7 +1633,7 @@ fn table(
if crate::scrollbar::bar(
ui,
key.with("bar"),
- r(o, 511.0, 275.0, 17.0, 124.0),
+ r(o, 511.0, 275.0, 17.0, body_h + 24.0),
true,
rows.len() as f32,
visible as f32,
diff --git a/crates/app/src/properties.rs b/crates/app/src/properties.rs
index c8440dee..c5bfdeb4 100644
--- a/crates/app/src/properties.rs
+++ b/crates/app/src/properties.rs
@@ -36,6 +36,7 @@ pub struct Properties {
/// The debrid accounts (#44): "Through …" shows while one takes the address.
route: crate::debrid::Route,
direct: bool,
+ files_requested: bool,
}
impl Properties {
@@ -52,9 +53,14 @@ impl Properties {
error: None,
route,
direct: item.direct,
+ files_requested: false,
}
}
+ pub fn take_files_requested(&mut self) -> bool {
+ std::mem::take(&mut self.files_requested)
+ }
+
/// `item` is read every frame, so status and size stay live.
pub fn show(
&mut self,
@@ -432,6 +438,19 @@ impl Properties {
if open && complete {
crate::dialogs::open_file(&item.dest);
}
+ if item.torrent.is_some()
+ && winui::button_light(
+ ui,
+ r(o, 170.0, 390.0, 78.0, 21.0),
+ // i18n: File Properties button that opens the selected torrent's file list
+ "Files...",
+ ButtonKind::Normal,
+ false,
+ )
+ .clicked()
+ {
+ self.files_requested = true;
+ }
let ok = winui::button_light(
ui,
r(o, 393.0, 390.0, 73.0, 21.0),
diff --git a/crates/app/src/torrentfiles.rs b/crates/app/src/torrentfiles.rs
new file mode 100644
index 00000000..3e66ebfb
--- /dev/null
+++ b/crates/app/src/torrentfiles.rs
@@ -0,0 +1,273 @@
+//! File list for any torrent, including ones no longer held in the torrent session.
+use std::path::PathBuf;
+
+use crate::{
+ dialogs::{self, Outcome},
+ model::{Item, Status},
+ winui::{self, ButtonKind, LIGHT_BG, r},
+};
+
+pub struct TorrentFiles {
+ pub id: u64,
+ rows: Vec<(usize, mdm_torrent::FileEntry, bool, u64)>,
+ base: PathBuf,
+ complete: bool,
+ pending: Option<(Vec<usize>, bool, u64)>,
+ /// The torrent's name, and how many files and bytes it holds (the window's first line).
+ heading: String,
+}
+
+/// Rows the list shows at once.
+const SHOWN: usize = 15;
+/// The progress window's table sits at y 273; this window's starts near the top.
+const TABLE_DY: f32 = 36.0 - 273.0;
+
+impl TorrentFiles {
+ pub fn new(item: &Item, host: &crate::torrents::Host) -> Option<Self> {
+ let spec = item.torrent.as_ref()?;
+ let session = host.get().and_then(|t| {
+ let (files, chosen, _) = t.files(&spec.hash)?;
+ let file_done = t
+ .stats(&spec.hash)
+ .map(|stats| stats.file_done)
+ .unwrap_or_default();
+ Some((files, chosen, file_done))
+ });
+ let (files, chosen, session_done) = if let Some((files, chosen, file_done)) = session {
+ (files, chosen, Some(file_done))
+ } else {
+ let bytes = std::fs::read(crate::torrents::torrent_file(&spec.hash)?).ok()?;
+ (
+ mdm_torrent::files_from_bytes(&bytes).ok()?,
+ spec.files.clone(),
+ None,
+ )
+ };
+ // `folder` already holds a torrent of several files' own folder (Meta::folder_in).
+ let root = spec.folder.clone();
+ let complete = item.status == Status::Complete;
+ let rows: Vec<_> = files
+ .into_iter()
+ .enumerate()
+ .filter(|(_, f)| !f.padding)
+ .map(|(i, f)| {
+ let chosen = chosen.as_ref().is_none_or(|v| v.contains(&i));
+ let done = if complete {
+ f.size
+ } else if let Some(file_done) = &session_done {
+ file_done.get(i).copied().unwrap_or(0).min(f.size)
+ } else {
+ std::fs::metadata(root.join(&f.path))
+ .map(|m| m.len().min(f.size))
+ .unwrap_or(0)
+ };
+ (i, f, chosen, done)
+ })
+ .collect();
+ let total: u64 = rows
+ .iter()
+ .map(|r: &(usize, mdm_torrent::FileEntry, bool, u64)| r.1.size)
+ .sum();
+ let heading = format!(
+ "{} ({}, {})",
+ item.file_name,
+ crate::i18n::tn(rows.len() as u64, "{n} file", "{n} files"),
+ crate::model::size(total)
+ );
+ Some(Self {
+ id: item.id,
+ heading,
+ rows,
+ base: root,
+ complete,
+ pending: None,
+ })
+ }
+
+ pub fn take_selection(&mut self) -> Option<(Vec<usize>, bool, u64)> {
+ self.pending.take()
+ }
+
+ pub fn show(&mut self, ctx: &egui::Context) -> Outcome<Option<(Vec<usize>, bool, u64)>> {
+ let mut changed = None;
+ let outcome = dialogs::window(
+ ctx,
+ &format!("torrent-files-{}", self.id),
+ // i18n: title of the separate window listing a torrent's files
+ "Torrent files",
+ [548.0, 430.0],
+ false,
+ LIGHT_BG(),
+ |ui, o| {
+ let p = ui.painter().clone();
+ let (head_rect, head_cut) = winui::text_fit(
+ &p,
+ o.x + 18.0,
+ o.y + 24.0,
+ &self.heading,
+ winui::TEXT(),
+ o.x + 528.0,
+ );
+ winui::copyable(
+ ui,
+ head_rect,
+ "torrent-files-heading",
+ &self.heading,
+ head_cut,
+ );
+ let table_o = o + egui::vec2(0.0, TABLE_DY);
+ let body_top = table_o.y + 299.0;
+ let body_bottom = body_top + crate::progress::table_body_height(SHOWN);
+ let mut all = self.rows.iter().all(|r| r.2);
+ // i18n: check or uncheck all file rows in the torrent file list
+ let response = winui::checkbox(
+ ui,
+ egui::pos2(o.x + 20.0, body_bottom + 12.0),
+ &mut all,
+ crate::i18n::t("Select all"),
+ true,
+ );
+ if response.changed() {
+ for row in &mut self.rows {
+ row.2 = all;
+ }
+ if !all && let Some(last) = self.rows.last_mut() {
+ last.2 = true;
+ }
+ }
+ let table_rows: Vec<Vec<String>> = self
+ .rows
+ .iter()
+ .map(|(_, f, on, done)| {
+ vec![
+ f.path.display().to_string(),
+ crate::model::size(f.size),
+ if !on {
+ // i18n: status of a torrent file the user chose not to download
+ crate::i18n::t("Skipped").into()
+ } else {
+ crate::i18n::percent(
+ if f.size == 0 {
+ 1.0
+ } else {
+ *done as f64 / f.size as f64
+ },
+ 1,
+ )
+ },
+ ]
+ })
+ .collect();
+ let ticks: Vec<bool> = self.rows.iter().map(|r| r.2).collect();
+ if let Some(row) = crate::progress::files_table(
+ ui,
+ &p,
+ table_o,
+ "torrent-files",
+ &table_rows,
+ &ticks,
+ SHOWN,
+ ) {
+ self.rows[row].2 = !self.rows[row].2;
+ if !self.rows.iter().any(|row| row.2) {
+ self.rows[row].2 = true;
+ }
+ }
+ let double = ui.input(|i| {
+ i.pointer
+ .button_double_clicked(egui::PointerButton::Primary)
+ .then(|| i.pointer.interact_pos())
+ .flatten()
+ });
+ if self.complete
+ && let Some(pos) = double
+ {
+ let viewport = ui.ctx().viewport_id();
+ let table_id = egui::Id::unique(("torrent-table", "torrent-files", viewport));
+ let first = ui
+ .ctx()
+ .data(|d| d.get_temp::<usize>(table_id))
+ .unwrap_or(0);
+ let row = ((pos.y - body_top) / 17.0).floor() as isize + first as isize;
+ // Past the row's check box and short of the scroll bar.
+ let on_a_name = pos.x >= o.x + 42.0 && pos.x < o.x + 511.0;
+ if on_a_name
+ && pos.y >= body_top
+ && pos.y < body_bottom
+ && row >= 0
+ && let Some((_, file, _, _)) = self.rows.get(row as usize)
+ {
+ dialogs::open_file(&self.base.join(&file.path));
+ }
+ }
+ let (open_at, folder_at, close_at) = (18.0, 380.0, 458.0);
+ let open = winui::button(
+ ui,
+ r(o, open_at, 407.0, 75.0, 22.0),
+ "Open",
+ // Nothing says which of several files: those open by a double click.
+ if self.complete && self.rows.len() == 1 {
+ ButtonKind::Normal
+ } else {
+ ButtonKind::Disabled
+ },
+ false,
+ None,
+ )
+ .clicked();
+ if open
+ && self.complete
+ && self.rows.len() == 1
+ && let Some((_, f, _, _)) = self.rows.first()
+ {
+ dialogs::open_file(&self.base.join(&f.path));
+ }
+ if winui::button(
+ ui,
+ r(o, folder_at, 407.0, 75.0, 22.0),
+ // i18n: button that opens the torrent's containing folder in the file manager
+ "Open folder",
+ ButtonKind::Normal,
+ false,
+ None,
+ )
+ .clicked()
+ {
+ dialogs::show_in_folder(&self.base);
+ }
+ let close = winui::button(
+ ui,
+ r(o, close_at, 407.0, 72.0, 22.0),
+ // i18n: button that closes the torrent file list window
+ "Close",
+ ButtonKind::Normal,
+ false,
+ None,
+ )
+ .clicked();
+ if winui::escape_pressed(ui) || close {
+ Outcome::Closed
+ } else if response.changed()
+ || !ticks.iter().zip(&self.rows).all(|(a, b)| *a == b.2)
+ {
+ let chosen = self.rows.iter().filter(|r| r.2);
+ let files = chosen.clone().map(|r| r.0).collect::<Vec<_>>();
+ let all = files.len() == self.rows.len();
+ let size = chosen.map(|r| r.1.size).sum();
+ changed = Some((files, all, size));
+ Outcome::Open
+ } else {
+ Outcome::Open
+ }
+ },
+ );
+ match outcome {
+ Outcome::Open => {
+ self.pending = changed;
+ Outcome::Open
+ }
+ Outcome::Closed => Outcome::Closed,
+ Outcome::Done(()) => Outcome::Done(None),
+ }
+ }
+}
diff --git a/crates/app/src/torrents.rs b/crates/app/src/torrents.rs
index 79f2a3cb..5a983aef 100644
--- a/crates/app/src/torrents.rs
+++ b/crates/app/src/torrents.rs
@@ -499,18 +499,31 @@ impl Host {
Ok(Done::Rechecking)
}
Act::Reannounce => {
- if let Some(t) = self.get() {
+ if let Some(t) = self.get().filter(|t| t.has(hash)) {
t.reannounce(hash).await.map_err(err)?;
}
Ok(Done::Reannounced)
}
Act::Choose { files, pause } => {
- if let Some(t) = self.get().filter(|t| t.has(hash)) {
+ if let Some(t) = self.get() {
+ if !t.has(hash) {
+ let file = torrent_file(hash).ok_or(crate::i18n::t("no data folder"))?;
+ let bytes = std::fs::read(&file)
+ .map_err(|_| crate::i18n::t("the .torrent file kept for it is gone"))?;
+ t.add(&bytes, &spec.folder, Some(files.clone()), Vec::new(), pause)
+ .await
+ .map_err(err)?;
+ return Ok(Done::Chosen);
+ }
t.choose(hash, &files.into_iter().collect())
.await
.map_err(err)?;
if pause {
- t.pause(hash).await.map_err(err)?;
+ if t.stats(hash).is_ok_and(|s| s.phase == Phase::Finished) {
+ t.remove(hash, false).await.map_err(err)?;
+ } else {
+ t.pause(hash).await.map_err(err)?;
+ }
}
}
Ok(Done::Chosen)
@@ -648,7 +661,7 @@ impl Host {
let _ = if on {
t.resume(&h).await
} else {
- t.pause(&h).await
+ t.remove(&h, false).await
};
}
});
@@ -892,6 +905,13 @@ impl Run {
RunState::Ready(t) => t.clone(),
};
let Ok(st) = t.stats(&self.hash) else {
+ let (done, size) = *self.last.lock().unwrap();
+ if size.is_some_and(|total| total > 0 && done >= total) {
+ s.state = State::Done;
+ s.downloaded = done;
+ s.size = size;
+ return s;
+ }
s.state = State::Failed;
// i18n: an error: the torrent is gone from the torrent session
s.error = Some(crate::i18n::t("the torrent is no longer there").into());
@@ -912,7 +932,7 @@ impl Run {
// Done: it stops sharing (a download manager finishes downloads; D-018), unless the
// person chose to keep sharing.
if s.state == State::Done && !self.keep_sharing {
- self.pause_in_background(&t);
+ self.remove_in_background(&t);
}
s
}
@@ -924,11 +944,24 @@ impl Run {
});
}
- /// Stop: pause it (the pieces stay; starting again continues).
+ fn remove_in_background(&self, t: &Arc<Torrents>) {
+ let (t, hash) = (t.clone(), self.hash.clone());
+ self.rt.spawn(async move {
+ let _ = t.remove(&hash, false).await;
+ });
+ }
+
+ /// Stop: a completed run leaves the session; an incomplete one pauses to resume later.
pub fn cancel(&self) {
*self.stopped.lock().unwrap() = true;
if let Some(t) = self.session() {
- self.pause_in_background(&t);
+ if t.stats(&self.hash)
+ .is_ok_and(|s| s.phase == Phase::Finished)
+ {
+ self.remove_in_background(&t);
+ } else {
+ self.pause_in_background(&t);
+ }
}
}
diff --git a/crates/torrent/src/lib.rs b/crates/torrent/src/lib.rs
index 1386d942..fca53c67 100644
--- a/crates/torrent/src/lib.rs
+++ b/crates/torrent/src/lib.rs
@@ -93,6 +93,21 @@ pub fn magnet_link(torrent: &[u8]) -> Option<String> {
Some(link)
}
+/// Read the safe file list from a saved torrent without starting a session.
+pub fn files_from_bytes(torrent: &[u8]) -> Result<Vec<FileEntry>, TorrentError> {
+ check_bytes(torrent)?;
+ let meta = librqbit::torrent_from_bytes(torrent).map_err(|_| TorrentError::NotATorrent)?;
+ let info = meta.info.data.validate().map_err(engine)?;
+ Ok(info
+ .iter_file_details()
+ .map(|f| FileEntry {
+ path: f.filename.to_pathbuf(),
+ size: f.len,
+ padding: f.attrs().padding,
+ })
+ .collect())
+}
+
/// Before librqbit restores its saved torrents (`session.json` and a `<hash>.torrent` for each,
/// in `dir`), take out the ones the name check refuses, and those saved without their .torrent
/// (whose names it can't check): the app adds those again itself, through `add` and its own
@@ -270,6 +285,8 @@ pub enum Phase {
#[derive(Clone, Debug, PartialEq)]
pub struct Stats {
pub phase: Phase,
+ /// Bytes read and verified so far while the session is initializing or rechecking.
+ pub checked: Option<u64>,
/// Bytes of the chosen files that are there and checked.
pub done: u64,
/// Bytes of the chosen files.
@@ -441,8 +458,17 @@ pub struct Torrents {
adding: tokio::sync::Mutex<()>,
/// librqbit's saved state (`session.json`, and each torrent's .torrent and piece map).
session_dir: PathBuf,
+ /// Each checking torrent's bytes checked and when they last moved: librqbit leaves a check
+ /// it was asked to pause in Initializing, its count frozen, which isn't checking any more.
+ checks: std::sync::Mutex<std::collections::HashMap<String, (u64, std::time::Instant)>>,
+ /// Torrents waiting for their check to end before they pause ([`Torrents::pause`]); a Start
+ /// meanwhile takes the pause back ([`Torrents::resume`]).
+ pause_after_check: Arc<std::sync::Mutex<std::collections::HashSet<String>>>,
}
+/// A paused torrent whose checked bytes haven't moved for this long has stopped checking.
+const CHECK_HALTED_AFTER: Duration = Duration::from_secs(5);
+
/// The lowest limit a torrent can have, bytes/s: librqbit's limiter holds one second's budget
/// and asks it for a whole 16 KiB block at once; under that, every request fails and each peer
/// is dropped, so the torrent would stall instead of going slowly.
@@ -565,6 +591,8 @@ impl Torrents {
proxied,
adding: tokio::sync::Mutex::new(()),
session_dir: cfg.state_dir.join("session"),
+ checks: Default::default(),
+ pause_after_check: Default::default(),
})
}
@@ -698,14 +726,25 @@ impl Torrents {
let live = s.live.as_ref();
let mib = |m: f64| m * 1024.0 * 1024.0;
let phase = match s.state {
- TorrentStatsState::Initializing { .. } => Phase::Checking,
+ // Paused while checking: librqbit stopped the check (it stays Initializing).
+ TorrentStatsState::Initializing { paused } => {
+ if paused && self.check_halted(hash, s.progress_bytes) {
+ Phase::Paused
+ } else {
+ Phase::Checking
+ }
+ }
TorrentStatsState::Paused => Phase::Paused,
TorrentStatsState::Error => Phase::Error,
TorrentStatsState::Live if s.finished => Phase::Finished,
TorrentStatsState::Live => Phase::Downloading,
};
+ if !matches!(s.state, TorrentStatsState::Initializing { .. }) {
+ self.checks.lock().unwrap().remove(hash);
+ }
Ok(Stats {
phase,
+ checked: (phase == Phase::Checking).then_some(s.progress_bytes),
done: s.progress_bytes,
total: s.total_bytes,
uploaded: s.uploaded_bytes,
@@ -780,10 +819,40 @@ impl Torrents {
pub async fn pause(&self, hash: &str) -> Result<(), TorrentError> {
let h = self.session.get(id(hash)?).ok_or(TorrentError::Unknown)?;
- if matches!(h.stats().state, TorrentStatsState::Paused) {
- return Ok(());
+ match h.stats().state {
+ TorrentStatsState::Paused => Ok(()),
+ // librqbit pausing a check stops it where it is and leaves the torrent Initializing
+ // for good (a Recheck stuck at 17 %): the check ends first, then it is paused.
+ TorrentStatsState::Initializing { .. } => {
+ let session = self.session.clone();
+ let (wanted, hash) = (self.pause_after_check.clone(), hash.to_owned());
+ wanted.lock().unwrap().insert(hash.clone());
+ tokio::spawn(async move {
+ let checked = h.wait_until_initialized().await.is_ok();
+ let still_wanted = wanted.lock().unwrap().remove(&hash);
+ if checked
+ && still_wanted
+ && !matches!(h.stats().state, TorrentStatsState::Paused)
+ {
+ let _ = session.pause(&h).await;
+ }
+ });
+ Ok(())
+ }
+ _ => self.session.pause(&h).await.map_err(engine),
+ }
+ }
+
+ /// Whether a paused torrent's check has stopped: its bytes checked haven't moved for
+ /// [`CHECK_HALTED_AFTER`].
+ fn check_halted(&self, hash: &str, checked: u64) -> bool {
+ let now = std::time::Instant::now();
+ let mut checks = self.checks.lock().unwrap();
+ let seen = checks.entry(hash.to_owned()).or_insert((checked, now));
+ if seen.0 != checked {
+ *seen = (checked, now);
}
- self.session.pause(&h).await.map_err(engine)
+ now.duration_since(seen.1) >= CHECK_HALTED_AFTER
}
/// Start it again. One still checking its files (added paused, or restored at start) is
@@ -791,10 +860,17 @@ impl Torrents {
/// stayed paused (seen on Linux, where the check took longer than the call).
pub async fn resume(&self, hash: &str) -> Result<(), TorrentError> {
let h = self.session.get(id(hash)?).ok_or(TorrentError::Unknown)?;
- if matches!(h.stats().state, TorrentStatsState::Initializing { .. }) {
+ // A pause waiting for the check to end is taken back: the last click wins.
+ self.pause_after_check.lock().unwrap().remove(hash);
+ let st = h.stats();
+ // A check librqbit stopped (paused while checking) never ends by itself: starting the
+ // torrent starts the check again. One still checking is waited for, as above.
+ let halted = matches!(st.state, TorrentStatsState::Initializing { paused: true })
+ && self.check_halted(hash, st.progress_bytes);
+ if matches!(st.state, TorrentStatsState::Initializing { .. }) && !halted {
h.wait_until_initialized().await.map_err(engine)?;
}
- if !matches!(h.stats().state, TorrentStatsState::Paused) {
+ if !halted && !matches!(h.stats().state, TorrentStatsState::Paused) {
return Ok(());
}
self.session.unpause(&h).await.map_err(engine)
@@ -1555,6 +1631,164 @@ mod tests {
leecher.stop().await;
}
+ /// The app's Recheck of a finished torrent that left the session: added again paused, it
+ /// checks every piece and ends Paused and whole. Also after a restart of the session.
+ #[tokio::test(flavor = "multi_thread", worker_threads = 4)]
+ async fn recheck_of_a_released_torrent_checks_it_all() {
+ let tmp = tempfile::tempdir().unwrap();
+ let src = tmp.path().join("seed");
+ std::fs::create_dir_all(&src).unwrap();
+ std::fs::write(src.join("big.bin"), vec![9u8; 512 * 1024 * 1024]).unwrap();
+ let torrent = make_torrent(&src).await;
+ let state = tmp.path().join("session");
+ let wait = |t: &Torrents, hash: &str, what: &str| {
+ let deadline = std::time::Instant::now() + Duration::from_secs(60);
+ let mut last = None;
+ loop {
+ let st = t.stats(hash).unwrap();
+ if st.phase == Phase::Paused && st.done == st.total {
+ return;
+ }
+ if last.as_ref() != Some(&(st.phase, st.done)) {
+ eprintln!("{what}: {:?} {} / {}", st.phase, st.done, st.total);
+ last = Some((st.phase, st.done));
+ }
+ assert!(
+ std::time::Instant::now() < deadline,
+ "{what}: stuck at {st:?}"
+ );
+ std::thread::sleep(Duration::from_millis(50));
+ }
+ };
+ let s1 = Torrents::start(offline(&state)).await.unwrap();
+ let hash = s1
+ .add(&torrent, &src, None, Vec::new(), true)
+ .await
+ .unwrap();
+ wait(&s1, &hash, "first check");
+ // Released when finished, then Recheck adds it again paused.
+ s1.remove(&hash, false).await.unwrap();
+ s1.add(&torrent, &src, None, Vec::new(), true)
+ .await
+ .unwrap();
+ wait(&s1, &hash, "recheck after release");
+ // Recheck while it is in the session (readd).
+ s1.readd(&hash, &torrent, true).await.unwrap();
+ wait(&s1, &hash, "recheck in session");
+ s1.stop().await;
+ // A new session restores it (session.json); the app removes it, then Recheck adds it.
+ let s2 = Torrents::start(offline(&state)).await.unwrap();
+ for h in s2.hashes() {
+ s2.remove(&h, false).await.unwrap();
+ }
+ s2.add(&torrent, &src, None, Vec::new(), true)
+ .await
+ .unwrap();
+ wait(&s2, &hash, "recheck after restart");
+ s2.stop().await;
+ }
+
+ /// Paused while it checks its files, a torrent finishes the check and is then paused:
+ /// librqbit's own pause stopped the check and left it Initializing for good, which the app
+ /// showed as "Checking 17%" forever.
+ #[tokio::test(flavor = "multi_thread", worker_threads = 4)]
+ async fn pausing_during_the_check_lets_it_finish() {
+ let tmp = tempfile::tempdir().unwrap();
+ let src = tmp.path().join("seed");
+ std::fs::create_dir_all(&src).unwrap();
+ std::fs::write(src.join("big.bin"), vec![7u8; 256 * 1024 * 1024]).unwrap();
+ let torrent = make_torrent(&src).await;
+ let session = Torrents::start(offline(&tmp.path().join("session")))
+ .await
+ .unwrap();
+ let hash = session
+ .add(&torrent, &src, None, Vec::new(), false)
+ .await
+ .unwrap();
+ session.pause(&hash).await.unwrap();
+ let deadline = std::time::Instant::now() + Duration::from_secs(60);
+ loop {
+ let st = session.stats(&hash).unwrap();
+ if st.phase == Phase::Paused && st.done == st.total {
+ break;
+ }
+ assert!(
+ std::time::Instant::now() < deadline,
+ "the check never finished: {st:?}"
+ );
+ tokio::time::sleep(Duration::from_millis(100)).await;
+ }
+ session.stop().await;
+ }
+
+ /// A Start clicked during the check takes back the pause clicked before it.
+ #[tokio::test(flavor = "multi_thread", worker_threads = 4)]
+ async fn starting_during_the_check_takes_the_pause_back() {
+ let tmp = tempfile::tempdir().unwrap();
+ let src = tmp.path().join("seed");
+ std::fs::create_dir_all(&src).unwrap();
+ std::fs::write(src.join("big.bin"), vec![5u8; 256 * 1024 * 1024]).unwrap();
+ let torrent = make_torrent(&src).await;
+ let session = Torrents::start(offline(&tmp.path().join("session")))
+ .await
+ .unwrap();
+ let hash = session
+ .add(&torrent, &src, None, Vec::new(), false)
+ .await
+ .unwrap();
+ session.pause(&hash).await.unwrap();
+ session.resume(&hash).await.unwrap();
+ let deadline = std::time::Instant::now() + Duration::from_secs(60);
+ loop {
+ let st = session.stats(&hash).unwrap();
+ if st.phase == Phase::Finished {
+ break;
+ }
+ assert!(st.phase != Phase::Paused, "the Start was lost: {st:?}");
+ assert!(
+ std::time::Instant::now() < deadline,
+ "never finished: {st:?}"
+ );
+ tokio::time::sleep(Duration::from_millis(100)).await;
+ }
+ // And it stays started.
+ tokio::time::sleep(Duration::from_secs(2)).await;
+ assert_eq!(session.stats(&hash).unwrap().phase, Phase::Finished);
+ session.stop().await;
+ }
+
+ #[tokio::test(flavor = "multi_thread", worker_threads = 4)]
+ async fn removing_finished_torrent_releases_file_while_session_runs() {
+ let tmp = tempfile::tempdir().unwrap();
+ let src = tmp.path().join("seed");
+ std::fs::create_dir_all(&src).unwrap();
+ std::fs::write(src.join("data.bin"), vec![42u8; 64 * 1024]).unwrap();
+ let torrent = make_torrent(&src).await;
+ let session = Torrents::start(offline(&tmp.path().join("session")))
+ .await
+ .unwrap();
+ let hash = session
+ .add(&torrent, &src, None, Vec::new(), false)
+ .await
+ .unwrap();
+ let deadline = std::time::Instant::now() + Duration::from_secs(20);
+ while session.stats(&hash).unwrap().phase != Phase::Finished {
+ assert!(
+ std::time::Instant::now() < deadline,
+ "torrent never finished"
+ );
+ tokio::time::sleep(Duration::from_millis(50)).await;
+ }
+
+ session.remove(&hash, false).await.unwrap();
+ let original = src.join("data.bin");
+ let moved = src.join("released.bin");
+ std::fs::rename(&original, &moved).unwrap();
+ assert!(moved.is_file());
+ assert!(session.listen_addr().is_some(), "session remains running");
+ session.stop().await;
+ }
+
/// #39: a torrent's piece order is librqbit's in-order one until set; set, it is kept when
/// the torrent is added again (Add trackers, Recheck).
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
diff --git a/i18n/en.tsv b/i18n/en.tsv
index 842b0f54..9ca7d236 100644
--- a/i18n/en.tsv
+++ b/i18n/en.tsv
@@ -56,7 +56,7 @@
#. in a download's log, after extracting: entries of the archive not written (links, names that would leave the folder)
#. {n} = a number (keep the braces as they are)
@plural {n} entry was left out (a link, or a name leading outside the folder)|{n} entries were left out (links, or names leading outside the folder) {n} entry was left out (a link, or a name leading outside the folder)|{n} entries were left out (links, or names leading outside the folder)
-#. count in the Batch download window; count in the Link grabber window; count in the Add torrent window
+#. count in the Batch download window; count in the Link grabber window; count in the Add torrent window; count in torrentfiles.rs
#. how many files the pattern gives in all
#. Link grabber: a package's row: {n} is its number of links
#. {n} = a number (keep the braces as they are)
@@ -643,6 +643,9 @@
#. {name} = a file name; {n} = a number (keep the braces as they are)
#. the trailing ... means it is still going on: keep it
Checking {name} ({n} of {total})... Checking {name} ({n} of {total})...
+#. text in the download list (sizes, speeds, status)
+#. a torrent's status while its files are read and checked; {percent} is how much is checked, e.g. "42%"
+ Checking {percent} Checking {percent}
#. text in the Checksum window; text in the Link grabber window
#. the trailing ... means it is still going on: keep it
Checking... Checking...
@@ -676,11 +679,12 @@
Client Client
#. text in the Options window
Clock: Clock:
-#. text in the Checksum window; text in the main window (menus, toolbar, Categories pane); button in crashui.rs; button in a dialog box; button in extension.rs; button in the Help menu's windows (About, updates, shortcuts, Tell a friend); button in helpers.rs; button in the download list; button in the Options window; button in rssdlg.rs; text in standard windows
+#. text in the Checksum window; text in the main window (menus, toolbar, Categories pane); button in crashui.rs; button in a dialog box; button in extension.rs; button in the Help menu's windows (About, updates, shortcuts, Tell a friend); button in helpers.rs; button in the download list; button in the Options window; button in rssdlg.rs; button in torrentfiles.rs; text in standard windows
#. both verbs: Verify = check the file now; Close = close the window
#. tooltip of the × that closes the Categories pane
#. verb: closes this window
#. verb: closes the filter box
+#. button that closes the torrent file list window
#. a window's title-bar button: closes the window
Close Close
#. what a keyboard shortcut does in the Help menu's windows (About, updates, shortcuts, Tell a friend)
@@ -1204,6 +1208,10 @@
Files go to: {folder} Files go to: {folder}
#. text in the Scheduler window; tab in the Scheduler window
Files in the queue Files in the queue
+#. button in a download's Properties window
+#. File Properties button that opens the selected torrent's file list
+#. the trailing ... means it opens a window: keep it
+ Files... Files...
#. button in the Find window
#. verb: button that starts the search
Find Find
@@ -2264,13 +2272,14 @@
Only the first {n} videos are listed. Only the first {n} videos are listed.
#. checkbox in a dialog box
Only while I'm using the computer Only while I'm using the computer
-#. button in a dialog box; text in a dialog box; button in a download's Properties window
+#. button in a dialog box; text in a dialog box; button in a download's Properties window; button in torrentfiles.rs
#. verb: opens the downloaded file
#. title of the message when a downloaded file can't be opened
#. verb: opens the file
Open Open
-#. button in crashui.rs; button in a dialog box
+#. button in crashui.rs; button in a dialog box; button in torrentfiles.rs
#. crash report window button: show the report's file in its folder
+#. button that opens the torrent's containing folder in the file manager
Open folder Open folder
#. checkbox in the Add torrent window
Open magnet links and .torrent files with Mister Download Manager Open magnet links and .torrent files with Mister Download Manager
@@ -2673,7 +2682,7 @@
#. text in a dialog box
#. title of the folder picker
Select a folder Select a folder
-#. button in playlistdlg.rs; button in the Add torrent window
+#. button in playlistdlg.rs; button in the Add torrent window; text in torrentfiles.rs
#. button in Download video for a playlist: tick every video
Select all Select all
#. what a keyboard shortcut does in the Help menu's windows (About, updates, shortcuts, Tell a friend)
@@ -2857,8 +2866,9 @@
size unknown size unknown
#. text in a download's Properties window
Size: Size:
-#. text in a download's progress window
+#. text in a download's progress window; text in torrentfiles.rs
#. a torrent file the user chose not to download
+#. status of a torrent file the user chose not to download
Skipped Skipped
#. text in the queues
#. what the computer does when the queue is done (verb: put it to sleep)
@@ -3459,8 +3469,9 @@
Torrent Torrent
#. text in the download list (sizes, speeds, status)
Torrent downloads (magnet links and .torrent files) Torrent downloads (magnet links and .torrent files)
-#. message or event log entry in the main window; text in the Add torrent window
+#. message or event log entry in the main window; text in the Add torrent window; window title in torrentfiles.rs
#. the kind of file the Open dialog lists
+#. title of the separate window listing a torrent's files
Torrent files Torrent files
#. window title in the Add torrent window
Torrent settings Torrent settings
@@ -4633,6 +4644,10 @@ menu Edit queue Edit queue
#. verb: unpack the downloaded archive (zip, 7z, rar) into its folder
menu Extract Extract
#. menu command in the main window
+#. right-click → Torrent submenu: open the selected torrent's file list
+#. the trailing ... means it opens a window: keep it
+menu Files... Files...
+#. menu command in the main window
menu Find (Ctrl-F) Find (Ctrl-F)
#. menu command in the main window
menu Find Next (F3) Find Next (F3)