Add drag & drop to DirectX versions

This commit is contained in:
MysterD 2023-04-03 20:36:29 -07:00
parent 96e42a6ba4
commit c437b386f6
5 changed files with 29 additions and 11 deletions

View file

@ -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);

View file

@ -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

View file

@ -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();
}

View file

@ -393,6 +393,7 @@ static void mod_extract_fields(struct Mod* mod) {
// no longer in header
if (buffer[0] != '-' || buffer[1] != '-') {
fclose(f);
return;
}

View file

@ -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) {