1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
use crate::{
common::paths::SearchPath,
ctrl::UiUpdateMsg,
data::{
self, audio_info::Container, collection::Collection, ipc::IPC,
IFInternalCollectionOutputData,
},
net::Net,
};
use crossbeam::{
channel::{Receiver, Sender},
sync::WaitGroup,
};
use rayon::prelude::{IndexedParallelIterator, IntoParallelRefIterator, ParallelIterator};
use std::{
error::Error,
sync::{Arc, Mutex},
};
pub fn collection_search(
collection_handler: Arc<Mutex<Collection>>,
search_path: Arc<Mutex<SearchPath>>,
sender_handler: Arc<Mutex<Sender<UiUpdateMsg>>>,
has_ui: bool,
) -> IFInternalCollectionOutputData {
let output_data = IFInternalCollectionOutputData::new();
let output_data_handle = Arc::new(Mutex::new(output_data));
let output_data_handle2 = output_data_handle.clone();
let handle_container = Arc::new(Mutex::new(Container::new()));
let current_search_path = search_path.lock().unwrap().read();
¤t_search_path
.par_iter()
.enumerate()
.for_each(|(index, elem)| {
let sender_loop = sender_handler.clone();
let collection_data_in_iterator = collection_handler.clone();
let single_path_collection_data = data::search_in_single_path(
has_ui,
handle_container.clone(),
collection_data_in_iterator,
sender_loop,
index,
elem,
);
{
let mut locker = output_data_handle.lock().unwrap();
locker.nr_found_songs += single_path_collection_data.nr_found_songs;
locker.nr_internal_duplicates += single_path_collection_data.nr_internal_duplicates;
locker.nr_searched_files += single_path_collection_data.nr_searched_files;
}
});
let out = &*output_data_handle2.lock().unwrap();
out.clone()
}
pub async fn net_search(
wait_net: WaitGroup,
net_system_messages: Option<Sender<UiUpdateMsg>>,
ipc_receive: Receiver<IPC>,
) -> Result<(), Box<dyn Error>> {
info!("net started!!");
let mut network = Net {};
wait_net.wait();
network.lookup(net_system_messages, ipc_receive).await
}