return TRUE;
}
-boolean ExtractZipFileIntoDirectory(char *zip_filename, char *directory,
- int tree_type)
+char *ExtractZipFileIntoDirectory(char *zip_filename, char *directory,
+ int tree_type)
{
boolean zip_file_valid = CheckZipFileForDirectory(zip_filename, directory,
tree_type);
- Error(ERR_DEBUG, "zip file '%s': %s", zip_filename,
- (zip_file_valid ? "EXTRACT" : "REJECT"));
-
if (!zip_file_valid)
- return FALSE;
+ {
+ Error(ERR_WARN, "zip file '%s' rejected!", zip_filename);
+
+ return NULL;
+ }
char **zip_entries = zip_extract(zip_filename, directory);
- boolean zip_file_extracted = (zip_entries != NULL);
+ if (zip_entries == NULL)
+ {
+ Error(ERR_WARN, "zip file '%s' could not be extracted!", zip_filename);
- if (zip_file_extracted)
- Error(ERR_DEBUG, "zip file successfully extracted!");
- else
- Error(ERR_DEBUG, "zip file could not be extracted!");
+ return NULL;
+ }
+
+ Error(ERR_INFO, "zip file '%s' successfully extracted!", zip_filename);
+
+ // first zip file entry contains top level directory
+ char *top_dir = zip_entries[0];
+
+ // remove trailing directory separator from top level directory
+ top_dir[strlen(top_dir) - 1] = '\0';
- return zip_file_extracted;
+ return top_dir;
}
static void ProcessZipFilesInDirectory(char *directory, int tree_type)
if (!fileExists(zip_filename_extracted) &&
!fileExists(zip_filename_rejected))
{
- boolean zip_file_extracted = ExtractZipFileIntoDirectory(zip_filename,
- directory,
- tree_type);
- char *marker_filename = (zip_file_extracted ? zip_filename_extracted :
+ char *top_dir = ExtractZipFileIntoDirectory(zip_filename, directory,
+ tree_type);
+ char *marker_filename = (top_dir != NULL ? zip_filename_extracted :
zip_filename_rejected);
FILE *marker_file;
print_timestamp_done("LoadLevelArtworkInfo");
}
-static boolean AddUserLevelSetToLevelInfoExt(char *level_subdir_new)
+static boolean AddUserTreeSetToTreeInfoExt(char *tree_subdir_new, int type)
{
- // get level info tree node of first (original) user level set
- char *level_subdir_old = getLoginName();
- LevelDirTree *leveldir_old = getTreeInfoFromIdentifier(leveldir_first,
- level_subdir_old);
- if (leveldir_old == NULL) // should not happen
+ TreeInfo **tree_node_first, *tree_node_old, *tree_node_new;
+ char *tree_user_dir = TREE_USERDIR(type);
+
+ if (tree_user_dir == NULL) // should not happen
+ return FALSE;
+
+ // get first node of level or artwork tree
+ tree_node_first = TREE_FIRST_NODE_PTR(type);
+
+ if (tree_node_first == NULL) // should not happen
+ return FALSE;
+
+ if (type == TREE_TYPE_LEVEL_DIR)
+ {
+ // get level info tree node of personal user level set
+ tree_node_old = getTreeInfoFromIdentifier(*tree_node_first, getLoginName());
+ }
+ else
+ {
+ // get artwork info tree node of first artwork set
+ tree_node_old = *tree_node_first;
+ }
+
+ if (tree_node_old == NULL) // should not happen
return FALSE;
int draw_deactivation_mask = GetDrawDeactivationMask();
// override draw deactivation mask (temporarily disable drawing)
SetDrawDeactivationMask(REDRAW_ALL);
- // load new level set config and add it next to first user level set
- LoadLevelInfoFromLevelConf(&leveldir_old->next, NULL,
- leveldir_old->basepath, level_subdir_new);
+ if (type == TREE_TYPE_LEVEL_DIR)
+ {
+ // load new level set config and add it next to first user level set
+ LoadLevelInfoFromLevelConf(&tree_node_old->next, NULL,
+ tree_user_dir, tree_subdir_new);
+ }
+ else
+ {
+ // load new artwork set config and add it next to first artwork set
+ LoadArtworkInfoFromArtworkConf(&tree_node_old->next, NULL,
+ tree_user_dir, tree_subdir_new, type);
+ }
// set draw deactivation mask to previous value
SetDrawDeactivationMask(draw_deactivation_mask);
- // get level info tree node of newly added user level set
- LevelDirTree *leveldir_new = getTreeInfoFromIdentifier(leveldir_first,
- level_subdir_new);
- if (leveldir_new == NULL) // should not happen
+ // get tree info tree node of newly added tree set
+ tree_node_new = getTreeInfoFromIdentifier(*tree_node_first, tree_subdir_new);
+
+ if (tree_node_new == NULL) // should not happen
return FALSE;
// correct top link and parent node link of newly created tree node
- leveldir_new->node_top = leveldir_old->node_top;
- leveldir_new->node_parent = leveldir_old->node_parent;
+ tree_node_new->node_top = tree_node_old->node_top;
+ tree_node_new->node_parent = tree_node_old->node_parent;
- // sort level info tree to adjust position of newly added level set
- sortTreeInfo(&leveldir_first);
+ // sort tree info tree to adjust position of newly added tree set
+ sortTreeInfo(tree_node_first);
return TRUE;
}
+void AddUserTreeSetToTreeInfo(char *tree_subdir_new, int type)
+{
+ if (!AddUserTreeSetToTreeInfoExt(tree_subdir_new, type))
+ Error(ERR_EXIT, "internal tree set structure corrupted -- aborting");
+}
+
void AddUserLevelSetToLevelInfo(char *level_subdir_new)
{
- if (!AddUserLevelSetToLevelInfoExt(level_subdir_new))
- Error(ERR_EXIT, "internal level set structure corrupted -- aborting");
+ AddUserTreeSetToTreeInfo(level_subdir_new, TREE_TYPE_LEVEL_DIR);
}
char *getArtworkIdentifierForUserLevelSet(int type)