1
0
Fork 0
mirror of https://github.com/librespot-org/librespot.git synced 2025-10-04 10:19:27 +02:00

Refactored Cache

Proper error handling, and moving the conversion between
{ credentials, volume } and file into the cache module
This commit is contained in:
johannesd3 2021-01-23 22:37:41 +01:00
parent efabb03631
commit 14a004f84c
4 changed files with 112 additions and 82 deletions

View file

@ -254,18 +254,24 @@ fn setup(args: &[String]) -> Setup {
mapped_volume: !matches.opt_present("mixer-linear-volume"),
};
let cache = matches.opt_str("c").map(|cache_path| {
let use_audio_cache = !matches.opt_present("disable-audio-cache");
let system_cache_directory = matches
.opt_str("system-cache")
.unwrap_or(String::from(cache_path.clone()));
let use_audio_cache = !matches.opt_present("disable-audio-cache");
Cache::new(
PathBuf::from(cache_path),
PathBuf::from(system_cache_directory),
use_audio_cache,
)
});
let cache_directory = matches.opt_str("c").unwrap_or(String::from(""));
let system_cache_directory = matches
.opt_str("system-cache")
.unwrap_or(String::from(cache_directory.clone()));
let cache = match Cache::new(
PathBuf::from(cache_directory),
PathBuf::from(system_cache_directory),
use_audio_cache,
) {
Ok(cache) => Some(cache),
Err(e) => {
warn!("Cannot create cache: {}", e);
None
}
};
let initial_volume = matches
.opt_str("initial-volume")
@ -276,8 +282,9 @@ fn setup(args: &[String]) -> Setup {
}
(volume as i32 * 0xFFFF / 100) as u16
})
.map(Volume)
.or_else(|| cache.as_ref().and_then(Cache::volume))
.unwrap_or(0x8000);
.unwrap_or(Volume(0x8000));
let zeroconf_port = matches
.opt_str("zeroconf-port")