+ Error(ERR_DEBUG, "DROP FILE EVENT: '%s'", filename);
+
+ // check and extract dropped zip files into correct user data directory
+ if (!strSuffixLower(filename, ".zip"))
+ {
+ Error(ERR_WARN, "file '%s' not supported", filename);
+
+ return FALSE;
+ }
+
+ TreeInfo *tree_node = NULL;
+ int tree_type = GetZipFileTreeType(filename);
+ char *directory = TREE_USERDIR(tree_type);
+
+ if (directory == NULL)
+ {
+ Error(ERR_WARN, "zip file '%s' has invalid content!", filename);
+
+ return FALSE;
+ }
+
+ if (tree_type == TREE_TYPE_LEVEL_DIR &&
+ game_status == GAME_MODE_LEVELS &&
+ leveldir_current->node_parent != NULL)
+ {
+ // extract new level set next to currently selected level set
+ tree_node = leveldir_current;
+
+ // get parent directory of currently selected level set directory
+ directory = getLevelDirFromTreeInfo(leveldir_current->node_parent);
+
+ // use private level directory instead of top-level package level directory
+ if (strPrefix(directory, options.level_directory) &&
+ strEqual(leveldir_current->node_parent->fullpath, "."))
+ directory = getUserLevelDir(NULL);
+ }
+
+ // extract level or artwork set from zip file to target directory
+ char *top_dir = ExtractZipFileIntoDirectory(filename, directory, tree_type);
+
+ if (top_dir == NULL)
+ {
+ // error message already issued by "ExtractZipFileIntoDirectory()"
+
+ return FALSE;
+ }
+
+ // add extracted level or artwork set to tree info structure
+ AddTreeSetToTreeInfo(tree_node, directory, top_dir, tree_type);
+
+ // update menu screen (and possibly change current level set)
+ DrawScreenAfterAddingSet(top_dir, tree_type);
+
+ return TRUE;
+}
+
+static void HandleDropTextEvent(char *text)
+{
+ Error(ERR_DEBUG, "DROP TEXT EVENT: '%s'", text);
+}
+
+void HandleDropEvent(Event *event)
+{
+ static int files_succeeded = 0;
+ static int files_failed = 0;
+
+ switch (event->type)
+ {
+ case SDL_DROPBEGIN:
+ {
+ files_succeeded = 0;
+ files_failed = 0;
+
+ break;
+ }
+
+ case SDL_DROPFILE:
+ {
+ boolean success = HandleDropFileEvent(event->drop.file);
+
+ if (success)
+ files_succeeded++;
+ else
+ files_failed++;
+
+ break;
+ }
+
+ case SDL_DROPTEXT:
+ {
+ HandleDropTextEvent(event->drop.file);
+
+ break;
+ }
+
+ case SDL_DROPCOMPLETE:
+ {
+ // only show request dialog if no other request dialog already active
+ if (!game.request_active)
+ {
+ if (files_succeeded > 0 && files_failed > 0)
+ Request("New level or artwork set(s) added, "
+ "but some dropped file(s) failed!", REQ_CONFIRM);
+ else if (files_succeeded > 0)
+ Request("New level or artwork set(s) added!", REQ_CONFIRM);
+ else if (files_failed > 0)
+ Request("Failed to process dropped file(s)!", REQ_CONFIRM);
+ }
+
+ break;
+ }
+ }
+
+ if (event->drop.file != NULL)
+ SDL_free(event->drop.file);