mirror of
https://github.com/redstrate/Physis.git
synced 2025-05-10 12:27:45 +00:00
Add method to get the *total* patch size on disk
Apparently X-Patch-Length is only for the base repository, and so isn't a reliable indicator. But it's pretty simple to add them all together to get a close number.
This commit is contained in:
parent
f822aabb94
commit
940edac964
1 changed files with 24 additions and 4 deletions
|
@ -2,6 +2,7 @@
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
/// Represents a patch to be downloaded.
|
/// Represents a patch to be downloaded.
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct PatchEntry {
|
pub struct PatchEntry {
|
||||||
/// The URL of the patch file. Usually an HTTP URL.
|
/// The URL of the patch file. Usually an HTTP URL.
|
||||||
pub url: String,
|
pub url: String,
|
||||||
|
@ -23,11 +24,12 @@ pub struct PatchEntry {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A list of patch files the client is requested to download, and install.
|
/// A list of patch files the client is requested to download, and install.
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct PatchList {
|
pub struct PatchList {
|
||||||
/// The id of the patch list.
|
/// The id of the patch list.
|
||||||
// FIXME: this is most likely auto-generated, not set?
|
// FIXME: this is most likely auto-generated, not set?
|
||||||
pub id: String,
|
pub id: String,
|
||||||
/// Size of all the patch files by size (in bytes.)
|
/// Size of the **ffxiv** repository patches only! In bytes.
|
||||||
pub patch_length: u64,
|
pub patch_length: u64,
|
||||||
/// The content location, usually from an HTTP URL.
|
/// The content location, usually from an HTTP URL.
|
||||||
pub content_location: String,
|
pub content_location: String,
|
||||||
|
@ -64,6 +66,14 @@ impl PatchList {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let mut content_location = String::default();
|
||||||
|
if let Some(patch_length_index) = encoded.find("Content-Location: ") {
|
||||||
|
let rest_of_string = &encoded[patch_length_index + 18..];
|
||||||
|
if let Some(end_of_number_index) = rest_of_string.find("\r\n") {
|
||||||
|
content_location = rest_of_string[0..end_of_number_index].to_string();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let parts: Vec<_> = encoded.split("\r\n").collect();
|
let parts: Vec<_> = encoded.split("\r\n").collect();
|
||||||
for i in 5..parts.len() - 2 {
|
for i in 5..parts.len() - 2 {
|
||||||
let patch_parts: Vec<_> = parts[i].split('\t').collect();
|
let patch_parts: Vec<_> = parts[i].split('\t').collect();
|
||||||
|
@ -87,15 +97,15 @@ impl PatchList {
|
||||||
length: patch_parts[0].parse().unwrap(),
|
length: patch_parts[0].parse().unwrap(),
|
||||||
size_on_disk: patch_parts[1].parse().unwrap(),
|
size_on_disk: patch_parts[1].parse().unwrap(),
|
||||||
hashes: patch_parts[7].split(',').map(|x| x.to_string()).collect(),
|
hashes: patch_parts[7].split(',').map(|x| x.to_string()).collect(),
|
||||||
unknown_a: 0,
|
unknown_a: patch_parts[2].parse().unwrap(),
|
||||||
unknown_b: 0,
|
unknown_b: patch_parts[3].parse().unwrap(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
id: "".to_string(),
|
id: "".to_string(),
|
||||||
content_location: "".to_string(),
|
content_location,
|
||||||
requested_version: "".to_string(),
|
requested_version: "".to_string(),
|
||||||
patch_length,
|
patch_length,
|
||||||
patches,
|
patches,
|
||||||
|
@ -172,6 +182,16 @@ impl PatchList {
|
||||||
|
|
||||||
str
|
str
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Size of all the patch files by size (in bytes.)
|
||||||
|
pub fn total_size_downloaded(&self) -> i64 {
|
||||||
|
let mut size = 0;
|
||||||
|
for patch in &self.patches {
|
||||||
|
size += patch.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
return size;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
Loading…
Add table
Reference in a new issue