X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=blobdiff_plain;f=src%2Fevents.c;h=ac9e2ab0f54c429b9b2f996443505305038ee41e;hp=e770480d67a25c14b0b0e7f0bb3fd57172cba206;hb=34df5c161045d8dddfd1c24d7fb1cfa29e0a9746;hpb=0f1e162b9ce8b032e3e50d1cfe9dcc157b4814de diff --git a/src/events.c b/src/events.c index e770480d..ac9e2ab0 100644 --- a/src/events.c +++ b/src/events.c @@ -268,6 +268,14 @@ void HandleOtherEvents(Event *event) HandleJoystickEvent(event); break; + case SDL_DROPFILE: + HandleDropFileEvent(event); + break; + + case SDL_DROPTEXT: + HandleDropTextEvent(event); + break; + default: break; } @@ -1518,6 +1526,54 @@ void HandleClientMessageEvent(ClientMessageEvent *event) CloseAllAndExit(0); } +static void HandleDropFileEventExt(char *filename) +{ + Error(ERR_DEBUG, "DROP FILE EVENT: '%s'", filename); + + // check and extract dropped zip files into correct user data directory + if (strSuffixLower(filename, ".zip")) + { + 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; + } + + char *top_dir = ExtractZipFileIntoDirectory(filename, directory, tree_type); + + if (top_dir != NULL) + { + if (tree_type == TREE_TYPE_LEVEL_DIR) + AddUserLevelSetToLevelInfo(top_dir); + else + AddUserArtworkSetToArtworkInfo(top_dir, tree_type); + } + } +} + +static void HandleDropTextEventExt(char *text) +{ + Error(ERR_DEBUG, "DROP TEXT EVENT: '%s'", text); +} + +void HandleDropFileEvent(Event *event) +{ + HandleDropFileEventExt(event->drop.file); + + SDL_free(event->drop.file); +} + +void HandleDropTextEvent(Event *event) +{ + HandleDropTextEventExt(event->drop.file); + + SDL_free(event->drop.file); +} + void HandleButton(int mx, int my, int button, int button_nr) { static int old_mx = 0, old_my = 0;