+// ----------------------------------------------------------------------------
+// functions for loading level info and custom artwork info
+// ----------------------------------------------------------------------------
+
+int GetZipFileTreeType(char *zip_filename)
+{
+ static char *top_dir_path = NULL;
+ static char *top_dir_conf_filename[NUM_BASE_TREE_TYPES] = { NULL };
+ static char *conf_basename[NUM_BASE_TREE_TYPES] =
+ {
+ GRAPHICSINFO_FILENAME,
+ SOUNDSINFO_FILENAME,
+ MUSICINFO_FILENAME,
+ LEVELINFO_FILENAME
+ };
+ int j;
+
+ checked_free(top_dir_path);
+ top_dir_path = NULL;
+
+ for (j = 0; j < NUM_BASE_TREE_TYPES; j++)
+ {
+ checked_free(top_dir_conf_filename[j]);
+ top_dir_conf_filename[j] = NULL;
+ }
+
+ char **zip_entries = zip_list(zip_filename);
+
+ // check if zip file successfully opened
+ if (zip_entries == NULL || zip_entries[0] == NULL)
+ return TREE_TYPE_UNDEFINED;
+
+ // first zip file entry is expected to be top level directory
+ char *top_dir = zip_entries[0];
+
+ // check if valid top level directory found in zip file
+ if (!strSuffix(top_dir, "/"))
+ return TREE_TYPE_UNDEFINED;
+
+ // get filenames of valid configuration files in top level directory
+ for (j = 0; j < NUM_BASE_TREE_TYPES; j++)
+ top_dir_conf_filename[j] = getStringCat2(top_dir, conf_basename[j]);
+
+ int tree_type = TREE_TYPE_UNDEFINED;
+ int e = 0;
+
+ while (zip_entries[e] != NULL)
+ {
+ // check if every zip file entry is below top level directory
+ if (!strPrefix(zip_entries[e], top_dir))
+ return TREE_TYPE_UNDEFINED;
+
+ // check if this zip file entry is a valid configuration filename
+ for (j = 0; j < NUM_BASE_TREE_TYPES; j++)
+ {
+ if (strEqual(zip_entries[e], top_dir_conf_filename[j]))
+ {
+ // only exactly one valid configuration file allowed
+ if (tree_type != TREE_TYPE_UNDEFINED)
+ return TREE_TYPE_UNDEFINED;
+
+ tree_type = j;
+ }
+ }
+
+ e++;
+ }
+
+ return tree_type;
+}
+
+static boolean CheckZipFileForDirectory(char *zip_filename, char *directory,
+ int tree_type)
+{
+ static char *top_dir_path = NULL;
+ static char *top_dir_conf_filename = NULL;
+
+ checked_free(top_dir_path);
+ checked_free(top_dir_conf_filename);
+
+ top_dir_path = NULL;
+ top_dir_conf_filename = NULL;
+
+ char *conf_basename = (tree_type == TREE_TYPE_LEVEL_DIR ? LEVELINFO_FILENAME :
+ ARTWORKINFO_FILENAME(tree_type));
+
+ // check if valid configuration filename determined
+ if (conf_basename == NULL || strEqual(conf_basename, ""))
+ return FALSE;
+
+ char **zip_entries = zip_list(zip_filename);
+
+ // check if zip file successfully opened
+ if (zip_entries == NULL || zip_entries[0] == NULL)
+ return FALSE;
+
+ // first zip file entry is expected to be top level directory
+ char *top_dir = zip_entries[0];
+
+ // check if valid top level directory found in zip file
+ if (!strSuffix(top_dir, "/"))
+ return FALSE;
+
+ // get path of extracted top level directory
+ top_dir_path = getPath2(directory, top_dir);
+
+ // remove trailing directory separator from top level directory path
+ // (required to be able to check for file and directory in next step)
+ top_dir_path[strlen(top_dir_path) - 1] = '\0';
+
+ // check if zip file's top level directory already exists in target directory
+ if (fileExists(top_dir_path)) // (checks for file and directory)
+ return FALSE;
+
+ // get filename of configuration file in top level directory
+ top_dir_conf_filename = getStringCat2(top_dir, conf_basename);
+
+ boolean found_top_dir_conf_filename = FALSE;
+ int i = 0;
+
+ while (zip_entries[i] != NULL)
+ {
+ // check if every zip file entry is below top level directory
+ if (!strPrefix(zip_entries[i], top_dir))
+ return FALSE;
+
+ // check if this zip file entry is the configuration filename
+ if (strEqual(zip_entries[i], top_dir_conf_filename))
+ found_top_dir_conf_filename = TRUE;