diff --git a/src/pc/djui/djui_panel_dynos.c b/src/pc/djui/djui_panel_dynos.c index d389db9ec..c28c9231d 100644 --- a/src/pc/djui/djui_panel_dynos.c +++ b/src/pc/djui/djui_panel_dynos.c @@ -10,8 +10,6 @@ static void djui_panel_dynos_apply(struct DjuiBase* caller) { } void djui_panel_dynos_create(struct DjuiBase* caller) { - dynos_packs_init(); - int packCount = dynos_pack_get_count(); struct DjuiThreePanel* panel = djui_panel_menu_create(DLANG(DYNOS, DYNOS)); struct DjuiBase* body = djui_three_panel_get_body(panel); diff --git a/src/pc/djui/djui_panel_host_mods.c b/src/pc/djui/djui_panel_host_mods.c index 36e324c82..54d4f3c23 100644 --- a/src/pc/djui/djui_panel_host_mods.c +++ b/src/pc/djui/djui_panel_host_mods.c @@ -90,8 +90,6 @@ static void djui_panel_host_mods_destroy(struct DjuiBase* base) { void djui_panel_host_mods_create(struct DjuiBase* caller) { bool isRomHacks = (caller->tag == 1); - - mods_refresh_local(); mods_update_selectable(); struct DjuiThreePanel* panel = djui_panel_menu_create(isRomHacks diff --git a/src/pc/gfx/gfx_dxgi.cpp b/src/pc/gfx/gfx_dxgi.cpp index 529a0e1f0..caefebdbc 100644 --- a/src/pc/gfx/gfx_dxgi.cpp +++ b/src/pc/gfx/gfx_dxgi.cpp @@ -23,6 +23,10 @@ #include "../configfile.h" #include "../pc_main.h" +extern "C" { +#include "src/pc/mods/mod_import.h" +} + #include "gfx_window_manager_api.h" #include "gfx_rendering_api.h" #include "gfx_direct3d_common.h" @@ -294,6 +298,18 @@ static LRESULT CALLBACK gfx_dxgi_wnd_proc(HWND h_wnd, UINT message, WPARAM w_par } else { return DefWindowProcW(h_wnd, message, w_param, l_param); } + case WM_DROPFILES: { + HDROP hDrop = (HDROP)w_param; + UINT nFiles = DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0); + for (UINT i = 0; i < nFiles; i++) + { + char szFileName[MAX_PATH] = { 0 }; + DragQueryFile(hDrop, i, szFileName, MAX_PATH); + mod_import_file(szFileName); + } + DragFinish(hDrop); + } + break; default: return DefWindowProcW(h_wnd, message, w_param, l_param); } @@ -368,6 +384,10 @@ static void gfx_dxgi_init(const char *window_title) { ShowCursor(FALSE); } + // enable drag & drop + DragAcceptFiles(dxgi.h_wnd, TRUE); + SetWindowLongPtr(dxgi.h_wnd, GWL_EXSTYLE, GetWindowLongPtr(dxgi.h_wnd, GWL_EXSTYLE) | WS_EX_ACCEPTFILES); + update_screen_settings(); } diff --git a/src/pc/mods/mod.c b/src/pc/mods/mod.c index 6de74c9dc..0ac0c44a8 100644 --- a/src/pc/mods/mod.c +++ b/src/pc/mods/mod.c @@ -393,6 +393,7 @@ static void mod_extract_fields(struct Mod* mod) { // no longer in header if (buffer[0] != '-' || buffer[1] != '-') { + fclose(f); return; } diff --git a/src/pc/mods/mod_import.c b/src/pc/mods/mod_import.c index 538255e3e..a4b6cb853 100644 --- a/src/pc/mods/mod_import.c +++ b/src/pc/mods/mod_import.c @@ -40,14 +40,14 @@ static bool mod_import_lua(char* src) { } } while ((rbytes > 0) && (rbytes == wbytes)); + fclose(fout); + fclose(fin); + if (wbytes) { LOG_ERROR("Write error on lua mod import"); return false; } - fclose(fout); - fclose(fin); - LOG_INFO("Imported lua mod: '%s' -> '%s'", src, dst); return true; @@ -137,7 +137,7 @@ static bool mod_import_zip(char* path, bool* isLua, bool* isDynos) { if (!p) { LOG_ERROR("mz_zip_reader_extract_file_to_heap() failed!"); mz_zip_reader_end(&zip_archive); - return EXIT_FAILURE; + return false; } // Make sure the extraction really succeeded. @@ -145,7 +145,7 @@ static bool mod_import_zip(char* path, bool* isLua, bool* isDynos) { LOG_ERROR("mz_zip_reader_extract_file_to_heap() failed to extract the proper data"); mz_free((void*)p); mz_zip_reader_end(&zip_archive); - return EXIT_FAILURE; + return false; } // Write the data @@ -155,13 +155,13 @@ static bool mod_import_zip(char* path, bool* isLua, bool* isDynos) { return false; } + fclose(fout); + size_t wbytes = fwrite(p, 1, uncompSize, fout); if (wbytes != uncompSize) { LOG_ERROR("Write error on zip mod import"); } - fclose(fout); - LOG_INFO("Successfully extracted file \"%s\", size %u", file_stat.m_filename, (u32)uncompSize); // We're done. @@ -194,6 +194,7 @@ bool mod_import_file(char* path) { if (ret) { if (isLua) { + mods_refresh_local(); djui_language_replace(DLANG(NOTIF, IMPORT_MOD_SUCCESS), msg, SYS_MAX_PATH, '@', basename); djui_popup_create(msg, 2); } else if (isDynos) {