mirror of
https://github.com/Yuyi-Oak/BlueArchiveToolkit.git
synced 2026-07-22 08:26:44 +08:00
feat: support cancellable official sync
This commit is contained in:
@@ -332,6 +332,17 @@ impl OfficialResourcePullService {
|
||||
&self,
|
||||
plan: &OfficialResourcePullPlan,
|
||||
mut progress: impl FnMut(OfficialResourcePullProgress),
|
||||
) -> Result<OfficialResourcePullReport, String> {
|
||||
self.pull_with_progress_and_cancellation(plan, &mut progress, || false)
|
||||
}
|
||||
|
||||
/// Executes the plan, emits URL progress, and aborts between URLs when
|
||||
/// `should_cancel` returns true.
|
||||
pub fn pull_with_progress_and_cancellation(
|
||||
&self,
|
||||
plan: &OfficialResourcePullPlan,
|
||||
mut progress: impl FnMut(OfficialResourcePullProgress),
|
||||
mut should_cancel: impl FnMut() -> bool,
|
||||
) -> Result<OfficialResourcePullReport, String> {
|
||||
fs::create_dir_all(&self.output_root).map_err(|error| {
|
||||
format!(
|
||||
@@ -347,6 +358,10 @@ impl OfficialResourcePullService {
|
||||
let total = urls.len();
|
||||
let mut items = Vec::new();
|
||||
for (offset, url) in urls.into_iter().enumerate() {
|
||||
if should_cancel() {
|
||||
return Err("official resource pull interrupted by shutdown request".to_string());
|
||||
}
|
||||
|
||||
let index = offset + 1;
|
||||
progress(OfficialResourcePullProgress::started(
|
||||
index,
|
||||
@@ -400,6 +415,10 @@ impl OfficialResourcePullService {
|
||||
});
|
||||
}
|
||||
|
||||
if should_cancel() {
|
||||
return Err("official resource pull interrupted by shutdown request".to_string());
|
||||
}
|
||||
|
||||
let verified_hashes = self.verify_downloaded_official_hashes(&official_hash_pairs)?;
|
||||
|
||||
Ok(OfficialResourcePullReport {
|
||||
|
||||
Reference in New Issue
Block a user