foobar2000 SDK  2015-01-14
Data Structures | Functions
create_directory_helper Namespace Reference

Data Structures

class  titleformat_text_filter_myimpl
 

Functions

void create_path (const char *p_path, abort_callback &p_abort)
 
static void create_path_internal (const char *p_path, t_size p_base, abort_callback &p_abort)
 
void format_filename (const metadb_handle_ptr &handle, titleformat_hook *p_hook, const char *spec, pfc::string_base &out)
 
void format_filename (const metadb_handle_ptr &handle, titleformat_hook *p_hook, titleformat_object::ptr spec, pfc::string_base &out)
 
void format_filename_ex (const metadb_handle_ptr &handle, titleformat_hook *p_hook, titleformat_object::ptr spec, const char *suffix, pfc::string_base &out)
 
static bool is_bad_dirchar (char c)
 
static bool is_valid_netpath_char (char p_char)
 
void make_path (const char *parent, const char *filename, const char *extension, bool allow_new_dirs, pfc::string8 &out, bool really_create_dirs, abort_callback &p_abort)
 
pfc::string sanitize_formatted_path (pfc::stringp str, bool allowWC=false)
 
static bool test_localpath (const char *p_path)
 
static bool test_netpath (const char *p_path)
 

Function Documentation

void create_directory_helper::create_path ( const char *  p_path,
abort_callback p_abort 
)

Definition at line 38 of file create_directory_helper.cpp.

38  {
39  if (test_localpath(p_path)) {
40  t_size walk = 0;
41  if (pfc::strcmp_partial(p_path,"file://") == 0) walk += strlen("file://");
42  create_path_internal(p_path,walk + 3,p_abort);
43  } else if (test_netpath(p_path)) {
44  t_size walk = 0;
45  if (pfc::strcmp_partial(p_path,"file://") == 0) walk += strlen("file://");
46  while(p_path[walk] == '\\') walk++;
47  while(p_path[walk] != 0 && p_path[walk] != '\\') walk++;
48  while(p_path[walk] == '\\') walk++;
49  while(p_path[walk] != 0 && p_path[walk] != '\\') walk++;
50  while(p_path[walk] == '\\') walk++;
51  create_path_internal(p_path,walk,p_abort);
52  } else {
53  pfc::throw_exception_with_message< exception_io > ("Could not create directory structure; unknown path format");
54  }
55  }
static bool test_netpath(const char *p_path)
static bool test_localpath(const char *p_path)
size_t t_size
Definition: int_types.h:48
static void create_path_internal(const char *p_path, t_size p_base, abort_callback &p_abort)
int strcmp_partial(const char *str, const char *substr)
Definition: string_base.h:1088
static void create_directory_helper::create_path_internal ( const char *  p_path,
t_size  p_base,
abort_callback p_abort 
)
static

Definition at line 5 of file create_directory_helper.cpp.

5  {
7  for(t_size walk = p_base; p_path[walk]; walk++) {
8  if (p_path[walk] == '\\') {
9  temp.set_string(p_path,walk);
10  try {filesystem::g_create_directory(temp.get_ptr(),p_abort);} catch(exception_io_already_exists) {}
11  }
12  }
13  }
size_t t_size
Definition: int_types.h:48
string8_t< pfc::alloc_fast_aggressive > string8_fastalloc
Definition: string_base.h:435
void create_directory_helper::format_filename ( const metadb_handle_ptr handle,
titleformat_hook p_hook,
const char *  spec,
pfc::string_base out 
)

Definition at line 145 of file create_directory_helper.cpp.

146 {
148  if (static_api_ptr_t<titleformat_compiler>()->compile(script,spec)) {
149  format_filename(handle, p_hook, script, out);
150  } else {
151  out.reset();
152  }
153 }
void format_filename(const metadb_handle_ptr &handle, titleformat_hook *p_hook, const char *spec, pfc::string_base &out)
Helper template used to easily access core services. Usage: static_api_ptr_t api; api->doso...
Definition: service.h:533
void create_directory_helper::format_filename ( const metadb_handle_ptr handle,
titleformat_hook p_hook,
titleformat_object::ptr  spec,
pfc::string_base out 
)

Definition at line 142 of file create_directory_helper.cpp.

142  {
143  format_filename_ex(handle, p_hook, spec, "", out);
144 }
void format_filename_ex(const metadb_handle_ptr &handle, titleformat_hook *p_hook, titleformat_object::ptr spec, const char *suffix, pfc::string_base &out)
void create_directory_helper::format_filename_ex ( const metadb_handle_ptr handle,
titleformat_hook p_hook,
titleformat_object::ptr  spec,
const char *  suffix,
pfc::string_base out 
)

Definition at line 135 of file create_directory_helper.cpp.

135  {
136  pfc::string_formatter formatted;
137  titleformat_text_filter_myimpl filter;
138  handle->format_title(p_hook,formatted,spec,&filter);
139  formatted << suffix;
140  out = sanitize_formatted_path(formatted).ptr();
141 }
const char * ptr() const
Definition: stringNew.h:124
string8_fastalloc string_formatter
Definition: string_base.h:614
pfc::string sanitize_formatted_path(pfc::stringp str, bool allowWC=false)
static bool create_directory_helper::is_bad_dirchar ( char  c)
static

Definition at line 58 of file create_directory_helper.cpp.

59  {
60  return c==' ' || c=='.';
61  }
static bool create_directory_helper::is_valid_netpath_char ( char  p_char)
static

Definition at line 15 of file create_directory_helper.cpp.

15  {
16  return pfc::char_is_ascii_alphanumeric(p_char) || p_char == '_' || p_char == '-' || p_char == '.';
17  }
bool char_is_ascii_alphanumeric(char p_char)
Definition: string_base.h:104
void create_directory_helper::make_path ( const char *  parent,
const char *  filename,
const char *  extension,
bool  allow_new_dirs,
pfc::string8 out,
bool  really_create_dirs,
abort_callback p_abort 
)

Definition at line 64 of file create_directory_helper.cpp.

65  {
66  out.reset();
67  if (parent && *parent)
68  {
69  out = parent;
70  out.fix_dir_separator('\\');
71  }
72  bool last_char_is_dir_sep = true;
73  while(*filename)
74  {
75 #ifdef WIN32
76  if (allow_new_dirs && is_bad_dirchar(*filename))
77  {
78  const char * ptr = filename+1;
79  while(is_bad_dirchar(*ptr)) ptr++;
80  if (*ptr!='\\' && *ptr!='/') out.add_string(filename,ptr-filename);
81  filename = ptr;
82  if (*filename==0) break;
83  }
84 #endif
85  if (pfc::is_path_bad_char(*filename))
86  {
87  if (allow_new_dirs && (*filename=='\\' || *filename=='/'))
88  {
89  if (!last_char_is_dir_sep)
90  {
91  if (really_create_dirs) try{filesystem::g_create_directory(out,p_abort);}catch(exception_io_already_exists){}
92  out.add_char('\\');
93  last_char_is_dir_sep = true;
94  }
95  }
96  else
97  out.add_char('_');
98  }
99  else
100  {
101  out.add_byte(*filename);
102  last_char_is_dir_sep = false;
103  }
104  filename++;
105  }
106  if (out.length()>0 && out[out.length()-1]=='\\')
107  {
108  out.add_string("noname");
109  }
110  if (extension && *extension)
111  {
112  out.add_char('.');
113  out.add_string(extension);
114  }
115  }
void fix_dir_separator(char c= '\\')
void add_string(const char *p_string, t_size p_length=~0)
Definition: string8_impl.h:4
static bool is_bad_dirchar(char c)
void add_char(t_uint32 c)
Definition: string_base.cpp:5
void add_byte(char c)
Definition: string_base.h:42
bool is_path_bad_char(unsigned c)
Definition: string_base.cpp:64
t_size length() const
For compatibility with old conventions.
Definition: string_base.h:208
pfc::string create_directory_helper::sanitize_formatted_path ( pfc::stringp  str,
bool  allowWC = false 
)

Definition at line 118 of file create_directory_helper.cpp.

118  {
119  pfc::string out;
120  t_size curSegBase = 0;
121  for(t_size walk = 0; ; ++walk) {
122  const char c = formatted[walk];
123  if (c == 0 || pfc::io::path::isSeparator(c)) {
124  if (curSegBase < walk) {
125  pfc::string seg( formatted + curSegBase, walk - curSegBase );
127  }
128  if (c == 0) break;
129  curSegBase = walk + 1;
130  }
131  }
132  return out;
133 };
string combine(string basePath, string fileName)
Definition: pathUtils.cpp:41
string validateFileName(string name, bool allowWC)
Definition: pathUtils.cpp:155
bool isSeparator(char c)
Definition: pathUtils.cpp:53
size_t t_size
Definition: int_types.h:48
New EXPERIMENTAL string class, allowing efficient copies and returning from functions. Does not implement the string_base interface so you still need string8 in many cases. Safe to pass between DLLs, but since a reference is used, objects possibly created by other DLLs must be released before owning DLLs are unloaded.
Definition: stringNew.h:19
static bool create_directory_helper::test_localpath ( const char *  p_path)
static

Definition at line 19 of file create_directory_helper.cpp.

19  {
20  if (pfc::strcmp_partial(p_path,"file://") == 0) p_path += strlen("file://");
21  return pfc::char_is_ascii_alpha(p_path[0]) &&
22  p_path[1] == ':' &&
23  p_path[2] == '\\';
24  }
bool char_is_ascii_alpha(char p_char)
Definition: string_base.h:103
int strcmp_partial(const char *str, const char *substr)
Definition: string_base.h:1088
static bool create_directory_helper::test_netpath ( const char *  p_path)
static

Definition at line 25 of file create_directory_helper.cpp.

25  {
26  if (pfc::strcmp_partial(p_path,"file://") == 0) p_path += strlen("file://");
27  if (*p_path != '\\') return false;
28  p_path++;
29  if (*p_path != '\\') return false;
30  p_path++;
31  if (!is_valid_netpath_char(*p_path)) return false;
32  p_path++;
33  while(is_valid_netpath_char(*p_path)) p_path++;
34  if (*p_path != '\\') return false;
35  return true;
36  }
int strcmp_partial(const char *str, const char *substr)
Definition: string_base.h:1088
static bool is_valid_netpath_char(char p_char)