GPAK  1.0.0
A general-purpose archive library

◆ filesystem_tree_add_file()

GPAK_API void filesystem_tree_add_file ( filesystem_tree_node_t _root,
const char *  _path,
const char *  _file_path,
pak_entry_t  _entry 
)
Brief Description:\n Adds a file to the filesystem tree.

This function creates a new file node under the given _root node.

Parameters
_rootA pointer to the root filesystem_tree_node_t.
_pathThe path of the directory where the file will be added.
_file_pathThe file path of the file to add.
_entryThe pak_entry_t associated with the file.

Definition at line 132 of file filesystem_tree.c.

133 {
134  if (!_root || !_path || !*_path)
135  return;
136 
137  char* dir_path = strdup(_path);
138  char* dir_name = strtok(dir_path, "/");
139  char* file_name = NULL;
140 
141  filesystem_tree_node_t* current = _root;
142  while (dir_name)
143  {
144  file_name = strtok(NULL, "/");
145  if (file_name)
146  {
147  filesystem_tree_node_t* found = _find_directory(current, dir_name);
148  if (!found)
149  found = _add_directory(current, dir_name);
150 
151  current = found;
152  dir_name = file_name;
153  }
154  else
155  break;
156  }
157 
158  if (dir_name && !file_name)
159  _add_file(current, dir_name, _file_path, _entry);
160 
161  free(dir_path);
162 }

Referenced by gpak_add_file().