mirror of
https://github.com/Dangoware/dmp-core.git
synced 2025-04-18 18:12:53 -05:00
removed config passing in library functions
This commit is contained in:
parent
e97075401d
commit
be9f28e38f
5 changed files with 11 additions and 17 deletions
|
@ -211,12 +211,12 @@ pub mod tests {
|
|||
config.write_file().unwrap();
|
||||
|
||||
let mut lib = MusicLibrary::init(
|
||||
Arc::new(RwLock::from(config.clone())),
|
||||
config.libraries.get_default().unwrap().path.clone(),
|
||||
dbg!(config.libraries.default_library),
|
||||
)
|
||||
.unwrap();
|
||||
lib.scan_folder("test-config/music/").unwrap();
|
||||
lib.save(Arc::new(RwLock::new(config.clone()))).unwrap();
|
||||
lib.save(config.libraries.get_default().unwrap().path.clone()).unwrap();
|
||||
|
||||
(config, lib)
|
||||
}
|
||||
|
@ -227,14 +227,14 @@ pub mod tests {
|
|||
// dbg!(&config);
|
||||
|
||||
let mut lib = MusicLibrary::init(
|
||||
Arc::new(RwLock::from(config.clone())),
|
||||
config.libraries.get_default().unwrap().path.clone(),
|
||||
config.libraries.get_default().unwrap().uuid,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
lib.scan_folder("test-config/music/").unwrap();
|
||||
|
||||
lib.save(Arc::new(RwLock::new(config.clone()))).unwrap();
|
||||
lib.save(config.libraries.get_default().unwrap().path.clone()).unwrap();
|
||||
|
||||
(config, lib)
|
||||
}
|
||||
|
|
|
@ -95,8 +95,9 @@ impl<P: Player + Send + Sync + Sized + 'static> Controller<P> {
|
|||
let config = Config::read_file(config_path)?;
|
||||
let uuid = config.libraries.get_default()?.uuid;
|
||||
|
||||
let library = MusicLibrary::init(config.libraries.get_default()?.path.clone(), uuid)?;
|
||||
let config_ = Arc::new(RwLock::from(config));
|
||||
let library = MusicLibrary::init(config_.clone(), uuid)?;
|
||||
|
||||
|
||||
let queue: Queue<QueueSong, QueueAlbum> = Queue {
|
||||
items: Vec::new(),
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
// Crate things
|
||||
//use crate::music_controller::config::Config;
|
||||
use crate::music_storage::library::URI;
|
||||
use crossbeam_channel::{unbounded, Receiver, Sender};
|
||||
use std::error::Error;
|
||||
|
|
|
@ -348,11 +348,11 @@ mod tests {
|
|||
|
||||
let songs = ITunesLibrary::from_file(Path::new("test-config\\iTunesLib.xml")).to_songs();
|
||||
|
||||
let mut library = MusicLibrary::init(Arc::new(RwLock::from(config.clone())), config_lib.uuid).unwrap();
|
||||
let mut library = MusicLibrary::init(config.libraries.get_default().unwrap().path.clone(), config_lib.uuid).unwrap();
|
||||
|
||||
songs.iter().for_each(|song| library.add_song(song.to_owned()).unwrap());
|
||||
|
||||
config.write_file().unwrap();
|
||||
library.save(Arc::new(RwLock::from(config))).unwrap();
|
||||
library.save(config.libraries.get_default().unwrap().path.clone()).unwrap();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -699,21 +699,16 @@ impl MusicLibrary {
|
|||
/// If the database file already exists, return the [MusicLibrary], otherwise create
|
||||
/// the database first. This needs to be run before anything else to retrieve
|
||||
/// the [MusicLibrary] Vec
|
||||
pub fn init(config: Arc<RwLock<Config>>, uuid: Uuid) -> Result<Self, Box<dyn Error>> {
|
||||
let global_config = &*config.read().unwrap();
|
||||
let path = global_config.libraries.get_library(&uuid)?.path.clone();
|
||||
|
||||
pub fn init(path: PathBuf, uuid: Uuid) -> Result<Self, Box<dyn Error>> {
|
||||
let library: MusicLibrary = match path.exists() {
|
||||
true => read_file(path)?,
|
||||
false => {
|
||||
// If the library does not exist, re-create it
|
||||
let lib = MusicLibrary::new(String::new(), uuid);
|
||||
|
||||
write_file(&lib, path)?;
|
||||
lib
|
||||
}
|
||||
};
|
||||
|
||||
Ok(library)
|
||||
}
|
||||
|
||||
|
@ -743,8 +738,7 @@ impl MusicLibrary {
|
|||
}
|
||||
|
||||
/// Serializes the database out to the file specified in the config
|
||||
pub fn save(&self, config: Arc<RwLock<Config>>) -> Result<(), Box<dyn Error>> {
|
||||
let path = config.read().unwrap().libraries.get_library(&self.uuid)?.path.clone();
|
||||
pub fn save(&self, path: PathBuf) -> Result<(), Box<dyn Error>> {
|
||||
match path.try_exists() {
|
||||
Ok(_) => write_file(self, path)?,
|
||||
Err(error) => return Err(error.into()),
|
||||
|
@ -1229,7 +1223,7 @@ mod test {
|
|||
fn library_init() {
|
||||
let config = Config::read_file(PathBuf::from("test_config/config_test.json")).unwrap();
|
||||
let target_uuid = config.libraries.libraries[0].uuid;
|
||||
let a = MusicLibrary::init(Arc::new(RwLock::from(config)), target_uuid).unwrap();
|
||||
let a = MusicLibrary::init(config.libraries.get_default().unwrap().path.clone(), target_uuid).unwrap();
|
||||
dbg!(a);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue