Update desktop app to support new persistence config

This commit is contained in:
Igor Katson 2024-08-15 11:39:12 +01:00
parent d77d96bd48
commit 275b3b0185
No known key found for this signature in database
GPG key ID: B4EC22B66D61A3F5
6 changed files with 68 additions and 22 deletions

View file

@ -1,10 +1,10 @@
use std::{
net::{Ipv4Addr, SocketAddr, SocketAddrV4},
path::PathBuf,
path::{Path, PathBuf},
time::Duration,
};
use librqbit::{dht::PersistentDht, Session};
use librqbit::dht::PersistentDht;
use serde::{Deserialize, Serialize};
use serde_with::serde_as;
@ -49,14 +49,35 @@ impl Default for RqbitDesktopConfigTcpListen {
#[serde(default)]
pub struct RqbitDesktopConfigPersistence {
pub disable: bool,
#[serde(default)]
pub folder: PathBuf,
/// Deprecated, but keeping for backwards compat for serialized / deserialized config.
#[serde(default)]
pub filename: PathBuf,
}
impl RqbitDesktopConfigPersistence {
pub(crate) fn fix_backwards_compat(&mut self) {
if self.folder != Path::new("") {
return;
}
if self.filename != Path::new("") {
if let Some(parent) = self.filename.parent() {
self.folder = parent.to_owned();
}
}
}
}
impl Default for RqbitDesktopConfigPersistence {
fn default() -> Self {
let folder = librqbit::SessionPersistenceConfig::default_json_persistence_folder().unwrap();
Self {
disable: false,
filename: Session::default_persistence_filename().unwrap(),
folder,
filename: PathBuf::new(),
}
}
}