comparison foosdk/sdk/foobar2000/SDK/file_operation_callback.cpp @ 1:20d02a178406 default tip

*: check in everything else yay
author Paper <paper@tflc.us>
date Mon, 05 Jan 2026 02:15:46 -0500
parents
children
comparison
equal deleted inserted replaced
0:e9bb126753e7 1:20d02a178406
1 #include "foobar2000-sdk-pch.h"
2 #include "file_operation_callback.h"
3 #include "playlist.h"
4 #include "metadb.h"
5
6
7 static void g_on_files_deleted_sorted(const pfc::list_base_const_t<const char *> & p_items)
8 {
9 //library_manager::get()->on_files_deleted_sorted(p_items);
10 playlist_manager::get()->on_files_deleted_sorted(p_items);
11
12 FB2K_FOR_EACH_SERVICE(file_operation_callback, on_files_deleted_sorted(p_items));
13 }
14
15 static void g_on_files_moved_sorted(const pfc::list_base_const_t<const char *> & p_from,const pfc::list_base_const_t<const char *> & p_to)
16 {
17 {
18 auto api = playlist_manager::get();
19 api->on_files_moved_sorted(p_from,p_to);
20 api->on_files_deleted_sorted(p_from);
21 }
22 FB2K_FOR_EACH_SERVICE(file_operation_callback, on_files_moved_sorted(p_from,p_to));
23 }
24
25 static void g_on_files_copied_sorted(const pfc::list_base_const_t<const char *> & p_from,const pfc::list_base_const_t<const char *> & p_to)
26 {
27 FB2K_FOR_EACH_SERVICE(file_operation_callback, on_files_copied_sorted(p_from,p_to));
28 }
29
30 void file_operation_callback::g_on_files_deleted(const pfc::list_base_const_t<const char *> & p_items)
31 {
32 core_api::ensure_main_thread();
33 t_size count = p_items.get_count();
34 if (count > 0)
35 {
36 if (count == 1) g_on_files_deleted_sorted(p_items);
37 else
38 {
39 pfc::array_t<t_size> order; order.set_size(count);
40 order_helper::g_fill(order);
41 p_items.sort_get_permutation_t(metadb::path_compare,order.get_ptr());
42 g_on_files_deleted_sorted(pfc::list_permutation_t<const char*>(p_items,order.get_ptr(),count));
43 }
44 }
45 }
46
47 void file_operation_callback::g_on_files_moved(const pfc::list_base_const_t<const char *> & p_from,const pfc::list_base_const_t<const char *> & p_to)
48 {
49 core_api::ensure_main_thread();
50 pfc::dynamic_assert(p_from.get_count() == p_to.get_count());
51 t_size count = p_from.get_count();
52 if (count > 0)
53 {
54 if (count == 1) g_on_files_moved_sorted(p_from,p_to);
55 else
56 {
57 pfc::array_t<t_size> order; order.set_size(count);
58 order_helper::g_fill(order);
59 p_from.sort_get_permutation_t(metadb::path_compare,order.get_ptr());
60 g_on_files_moved_sorted(pfc::list_permutation_t<const char*>(p_from,order.get_ptr(),count),pfc::list_permutation_t<const char*>(p_to,order.get_ptr(),count));
61 }
62 }
63 }
64
65 void file_operation_callback::g_on_files_copied(const pfc::list_base_const_t<const char *> & p_from,const pfc::list_base_const_t<const char *> & p_to)
66 {
67 if (core_api::assert_main_thread())
68 {
69 assert(p_from.get_count() == p_to.get_count());
70 t_size count = p_from.get_count();
71 if (count > 0)
72 {
73 if (count == 1) g_on_files_copied_sorted(p_from,p_to);
74 else
75 {
76 pfc::array_t<t_size> order; order.set_size(count);
77 order_helper::g_fill(order);
78 p_from.sort_get_permutation_t(metadb::path_compare,order.get_ptr());
79 g_on_files_copied_sorted(pfc::list_permutation_t<const char*>(p_from,order.get_ptr(),count),pfc::list_permutation_t<const char*>(p_to,order.get_ptr(),count));
80 }
81 }
82 }
83 }
84 bool file_operation_callback::g_search_sorted_list(const pfc::list_base_const_t<const char*> & p_list,const char * p_string,t_size & p_index) {
85 return pfc::binarySearch<metadb::path_comparator>::run(p_list,0,p_list.get_count(),p_string,p_index);
86 }
87
88 bool file_operation_callback::g_update_list_on_moved_ex(metadb_handle_list_ref p_list,t_pathlist p_from,t_pathlist p_to, metadb_handle_list_ref itemsAdded, metadb_handle_list_ref itemsRemoved) {
89 auto api = metadb::get();
90 bool changed = false;
91 itemsAdded.remove_all(); itemsRemoved.remove_all();
92 for(t_size walk = 0; walk < p_list.get_count(); ++walk) {
93 metadb_handle_ptr item = p_list[walk];
94 t_size index;
95 if (g_search_sorted_list(p_from,item->get_path(),index)) {
96 metadb_handle_ptr newItem;
97 api->handle_create_replace_path_canonical(newItem,item,p_to[index]);
98 p_list.replace_item(walk,newItem);
99 changed = true;
100 itemsAdded.add_item(newItem); itemsRemoved.add_item(item);
101 }
102 }
103 return changed;
104 }
105 bool file_operation_callback::g_update_list_on_moved(metadb_handle_list_ref p_list,const pfc::list_base_const_t<const char *> & p_from,const pfc::list_base_const_t<const char *> & p_to) {
106 auto api = metadb::get();
107 bool changed = false;
108 for(t_size walk = 0; walk < p_list.get_count(); ++walk) {
109 metadb_handle_ptr item = p_list[walk];
110 t_size index;
111 if (g_search_sorted_list(p_from,item->get_path(),index)) {
112 metadb_handle_ptr newItem;
113 api->handle_create_replace_path_canonical(newItem,item,p_to[index]);
114 p_list.replace_item(walk,newItem);
115 changed = true;
116 }
117 }
118 return changed;
119 }
120
121
122 bool file_operation_callback::g_mark_dead_entries(metadb_handle_list_cref items, bit_array_var & mask, t_pathlist deadPaths) {
123 bool found = false;
124 const t_size total = items.get_count();
125 for(t_size walk = 0; walk < total; ++walk) {
126 t_size index;
127 if (g_search_sorted_list(deadPaths,items[walk]->get_path(),index)) {
128 mask.set(walk,true); found = true;
129 } else {
130 mask.set(walk,false);
131 }
132 }
133 return found;
134 }