|
1
|
1 #include "StdAfx.h"
|
|
|
2
|
|
|
3 #include "file_list_helper.h"
|
|
|
4
|
|
|
5 #ifndef _MSC_VER
|
|
|
6 #define _strdup strdup
|
|
|
7 #endif
|
|
|
8
|
|
|
9 static void file_list_remove_duplicates(pfc::ptr_list_t<char> & out)
|
|
|
10 {
|
|
|
11 t_size n, m = out.get_count();
|
|
|
12 out.sort_t(metadb::path_compare);
|
|
|
13 pfc::bit_array_bittable mask(m);
|
|
|
14 t_size duplicates = 0;
|
|
|
15 for(n=1;n<m;n++) {
|
|
|
16 if (!metadb::path_compare(out[n-1],out[n])) {duplicates++;mask.set(n,true);}
|
|
|
17 }
|
|
|
18 if (duplicates>0) {
|
|
|
19 out.free_mask(mask);
|
|
|
20 }
|
|
|
21 }
|
|
|
22
|
|
|
23
|
|
|
24 namespace file_list_helper
|
|
|
25 {
|
|
|
26 t_size file_list_from_metadb_handle_list::g_get_count(metadb_handle_list_cref data, t_size max) {
|
|
|
27 pfc::avltree_t<const char*, metadb::path_comparator> content;
|
|
|
28 const t_size inCount = data.get_size();
|
|
|
29 for(t_size walk = 0; walk < inCount && content.get_count() < max; ++walk) {
|
|
|
30 content += data[walk]->get_path();
|
|
|
31 }
|
|
|
32 return content.get_count();
|
|
|
33 }
|
|
|
34 void file_list_from_metadb_handle_list::_add(const char * p_what) {
|
|
|
35 char * temp = _strdup(p_what);
|
|
|
36 if (temp == NULL) throw std::bad_alloc();
|
|
|
37 try {m_data.add_item(temp); } catch(...) {free(temp); throw;}
|
|
|
38 }
|
|
|
39
|
|
|
40 void file_list_from_metadb_handle_list::init_from_list(const list_base_const_t<metadb_handle_ptr> & p_list)
|
|
|
41 {
|
|
|
42 m_data.free_all();
|
|
|
43
|
|
|
44 t_size n, m = p_list.get_count();
|
|
|
45 for(n=0;n<m;n++) {
|
|
|
46 _add( p_list.get_item(n)->get_path() );
|
|
|
47 }
|
|
|
48 file_list_remove_duplicates(m_data);
|
|
|
49 }
|
|
|
50
|
|
|
51 void file_list_from_metadb_handle_list::init_from_list_display(const list_base_const_t<metadb_handle_ptr> & p_list)
|
|
|
52 {
|
|
|
53 m_data.free_all();
|
|
|
54
|
|
|
55 pfc::string8_fastalloc temp;
|
|
|
56
|
|
|
57 t_size n, m = p_list.get_count();
|
|
|
58 for(n=0;n<m;n++)
|
|
|
59 {
|
|
|
60 filesystem::g_get_display_path(p_list.get_item(n)->get_path(),temp);
|
|
|
61 _add(temp);
|
|
|
62 }
|
|
|
63 file_list_remove_duplicates(m_data);
|
|
|
64 }
|
|
|
65
|
|
|
66 file_list_from_metadb_handle_list::file_list_from_metadb_handle_list(metadb_handle_list_cref lst, bool bDisplayPaths) {
|
|
|
67 if ( bDisplayPaths ) init_from_list_display(lst);
|
|
|
68 else init_from_list( lst );
|
|
|
69 }
|
|
|
70
|
|
|
71 t_size file_list_from_metadb_handle_list::get_count() const {return m_data.get_count();}
|
|
|
72 void file_list_from_metadb_handle_list::get_item_ex(const char * & p_out,t_size n) const {p_out = m_data.get_item(n);}
|
|
|
73
|
|
|
74 file_list_from_metadb_handle_list::~file_list_from_metadb_handle_list()
|
|
|
75 {
|
|
|
76 m_data.free_all();
|
|
|
77 }
|
|
|
78
|
|
|
79 }
|