10 node->
name_ = strdup(_name);
30 file->
name_ = strdup(_name);
31 file->
path_ = strdup(_file_path);
47 if (!_root || !_path || !*_path)
50 if (strcmp(_root->
name_, _path) == 0)
65 if (!_directory || !_file_name || !*_file_name)
68 for (
size_t i = 0; i < _directory->
num_files_; i++)
70 if (strcmp(_directory->
files_[i]->
name_, _file_name) == 0)
71 return _directory->
files_[i];
95 _free_file(_node->
files_[i]);
107 return _create_node(
"", NULL);
112 if (!_root || !_path || !*_path)
115 char* dir_path = strdup(_path);
116 char* dir_name = strtok(dir_path,
"/");
123 found = _add_directory(current, dir_name);
126 dir_name = strtok(NULL,
"/");
134 if (!_root || !_path || !*_path)
137 char* dir_path = strdup(_path);
138 char* dir_name = strtok(dir_path,
"/");
139 char* file_name = NULL;
144 file_name = strtok(NULL,
"/");
149 found = _add_directory(current, dir_name);
152 dir_name = file_name;
158 if (dir_name && !file_name)
159 _add_file(current, dir_name, _file_path, _entry);
166 if (!_root || !_path || !*_path)
169 char* dir_path = strdup(_path);
170 char* dir_name = strtok(dir_path,
"/");
175 current = _find_directory(current, dir_name);
178 dir_name = strtok(NULL,
"/");
186 if (!_root || !_path || !*_path)
189 char* dir_path = strdup(_path);
190 char* dir_name = strtok(dir_path,
"/");
191 char* file_name = NULL;
196 file_name = strtok(NULL,
"/");
207 dir_name = file_name;
214 if (dir_name && !file_name)
215 file = _find_file(current, dir_name);
227 size_t path_length = strlen(parent_path) + strlen(_node->
name_) + 2;
228 char* path = (
char*)malloc(path_length *
sizeof(
char));
230 snprintf(path, path_length,
"%s%s/", parent_path, _node->
name_);
238 if (!_node || !_file)
242 size_t path_length = strlen(dir_path) + strlen(_file->
name_) + 1;
243 char* file_path = (
char*)malloc(path_length *
sizeof(
char));
245 snprintf(file_path, path_length,
"%s%s", dir_path, _file->
name_);
311 _iterator_stack_push(_iterator, child_state);
313 return next_directory;
318 _iterator_stack_pop(_iterator);
339 return next_directory;
GPAK_API filesystem_tree_node_t * filesystem_tree_find_directory(filesystem_tree_node_t *_root, const char *_path)
GPAK_API filesystem_tree_node_t * filesystem_iterator_next_subling_directory(filesystem_tree_iterator_t *_iterator)
GPAK_API char * filesystem_tree_file_path(filesystem_tree_node_t *_node, filesystem_tree_file_t *_file)
GPAK_API filesystem_tree_node_t * filesystem_tree_create()
GPAK_API filesystem_tree_node_t * filesystem_iterator_next_directory(filesystem_tree_iterator_t *_iterator)
GPAK_API void filesystem_iterator_free(filesystem_tree_iterator_t *_iterator)
GPAK_API void filesystem_tree_delete(filesystem_tree_node_t *_root)
GPAK_API char * filesystem_tree_directory_path(filesystem_tree_node_t *_node)
GPAK_API void filesystem_tree_add_file(filesystem_tree_node_t *_root, const char *_path, const char *_file_path, pak_entry_t _entry)
GPAK_API void filesystem_tree_add_directory(filesystem_tree_node_t *_root, const char *_path)
GPAK_API filesystem_tree_iterator_t * filesystem_iterator_create(filesystem_tree_node_t *_root)
GPAK_API filesystem_tree_file_t * filesystem_iterator_next_file(filesystem_tree_iterator_t *_iterator)
GPAK_API filesystem_tree_file_t * filesystem_tree_find_file(filesystem_tree_node_t *_root, const char *_path)
filesystem_tree_node_t * node_
filesystem_iterator_state_t * stack_
struct filesystem_tree_node * parent_
struct filesystem_tree_node ** children_
filesystem_tree_file_t ** files_