foobar2000 SDK  2015-08-03
file_operation_callback.cpp
Go to the documentation of this file.
1 #include "foobar2000.h"
2 
3 
5 {
6  //static_api_ptr_t<library_manager>()->on_files_deleted_sorted(p_items);
7  static_api_ptr_t<playlist_manager>()->on_files_deleted_sorted(p_items);
8 
9  FB2K_FOR_EACH_SERVICE(file_operation_callback, on_files_deleted_sorted(p_items));
10 }
11 
13 {
14  static_api_ptr_t<playlist_manager>()->on_files_moved_sorted(p_from,p_to);
15  static_api_ptr_t<playlist_manager>()->on_files_deleted_sorted(p_from);
16 
17  FB2K_FOR_EACH_SERVICE(file_operation_callback, on_files_moved_sorted(p_from,p_to));
18 }
19 
21 {
22  FB2K_FOR_EACH_SERVICE(file_operation_callback, on_files_copied_sorted(p_from,p_to));
23 }
24 
26 {
28  t_size count = p_items.get_count();
29  if (count > 0)
30  {
31  if (count == 1) g_on_files_deleted_sorted(p_items);
32  else
33  {
34  pfc::array_t<t_size> order; order.set_size(count);
35  order_helper::g_fill(order);
38  }
39  }
40 }
41 
43 {
45  pfc::dynamic_assert(p_from.get_count() == p_to.get_count());
46  t_size count = p_from.get_count();
47  if (count > 0)
48  {
49  if (count == 1) g_on_files_moved_sorted(p_from,p_to);
50  else
51  {
52  pfc::array_t<t_size> order; order.set_size(count);
53  order_helper::g_fill(order);
56  }
57  }
58 }
59 
61 {
63  {
64  assert(p_from.get_count() == p_to.get_count());
65  t_size count = p_from.get_count();
66  if (count > 0)
67  {
68  if (count == 1) g_on_files_copied_sorted(p_from,p_to);
69  else
70  {
71  pfc::array_t<t_size> order; order.set_size(count);
72  order_helper::g_fill(order);
75  }
76  }
77  }
78 }
80  return pfc::binarySearch<metadb::path_comparator>::run(p_list,0,p_list.get_count(),p_string,p_index);
81 }
82 
85  bool changed = false;
86  itemsAdded.remove_all(); itemsRemoved.remove_all();
87  for(t_size walk = 0; walk < p_list.get_count(); ++walk) {
88  metadb_handle_ptr item = p_list[walk];
89  t_size index;
90  if (g_search_sorted_list(p_from,item->get_path(),index)) {
91  metadb_handle_ptr newItem;
92  api->handle_create_replace_path_canonical(newItem,item,p_to[index]);
93  p_list.replace_item(walk,newItem);
94  changed = true;
95  itemsAdded.add_item(newItem); itemsRemoved.add_item(item);
96  }
97  }
98  return changed;
99 }
102  bool changed = false;
103  for(t_size walk = 0; walk < p_list.get_count(); ++walk) {
104  metadb_handle_ptr item = p_list[walk];
105  t_size index;
106  if (g_search_sorted_list(p_from,item->get_path(),index)) {
107  metadb_handle_ptr newItem;
108  api->handle_create_replace_path_canonical(newItem,item,p_to[index]);
109  p_list.replace_item(walk,newItem);
110  changed = true;
111  }
112  }
113  return changed;
114 }
115 
116 
118  bool found = false;
119  const t_size total = items.get_count();
120  for(t_size walk = 0; walk < total; ++walk) {
121  t_size index;
122  if (g_search_sorted_list(deadPaths,items[walk]->get_path(),index)) {
123  mask.set(walk,true); found = true;
124  } else {
125  mask.set(walk,false);
126  }
127  }
128  return found;
129 }
void ensure_main_thread()
Triggers a bug check if the calling thread is not the main app thread.
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)
const t_item * get_ptr() const
Definition: array.h:213
t_size add_item(const T &item)
Definition: list.h:210
static void g_fill(t_int *p_order, const t_size p_count)
Definition: order_helper.h:38
virtual void replace_item(t_size p_index, const T &p_item)=0
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)
static bool run(const t_container &p_container, t_size p_base, t_size p_count, const t_param &p_param, t_size &p_result)
Definition: binary_search.h:9
static void g_on_files_moved(const pfc::list_base_const_t< const char * > &p_from, const pfc::list_base_const_t< const char * > &p_to)
void dynamic_assert(bool p_condition, const char *p_msg)
Definition: primitives.h:239
virtual void set(t_size n, bool val)=0
size_t t_size
Definition: int_types.h:48
static void g_on_files_deleted(const pfc::list_base_const_t< const char * > &p_items)
void set_size(t_size p_size)
Definition: array.h:104
virtual t_size get_count() const =0
static void g_on_files_deleted_sorted(const pfc::list_base_const_t< const char * > &p_items)
static bool 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)
static bool g_search_sorted_list(const pfc::list_base_const_t< const char * > &p_list, const char *p_string, t_size &p_index)
Bit array interface class, variable version (you can both set and retrieve values). As with the constant version, valid index range depends on the context.
Definition: bit_array.h:40
static int path_compare(const char *p1, const char *p2)
Definition: metadb.h:245
static void g_on_files_copied(const pfc::list_base_const_t< const char * > &p_from, const pfc::list_base_const_t< const char * > &p_to)
bool assert_main_thread()
Tests whether calling thread is main app thread, and shows diagnostic message in debugger output if i...
void remove_all()
Definition: list.h:213
static bool g_update_list_on_moved(metadb_handle_list_ref p_list, t_pathlist p_from, t_pathlist p_to)
void sort_get_permutation_t(t_compare p_compare, t_permutation const &p_permutation) const
Definition: list.h:55
Helper template used to easily access core services. Usage: static_api_ptr_t<myclass> api; api->doso...
Definition: service.h:533
static bool g_mark_dead_entries(metadb_handle_list_cref items, bit_array_var &mask, t_pathlist deadPaths)
Interface to notify component system about files being deleted or moved. Operates in app&#39;s main threa...