diff options
Diffstat (limited to 'src/libui_sdl')
-rw-r--r-- | src/libui_sdl/libui/ui.h | 1 | ||||
-rw-r--r-- | src/libui_sdl/libui/windows/stddialogs.cpp | 2 | ||||
-rw-r--r-- | src/libui_sdl/libui/windows/window.cpp | 6 | ||||
-rw-r--r-- | src/libui_sdl/main.cpp | 74 |
4 files changed, 78 insertions, 5 deletions
diff --git a/src/libui_sdl/libui/ui.h b/src/libui_sdl/libui/ui.h index 7cbc6f8..d072ac2 100644 --- a/src/libui_sdl/libui/ui.h +++ b/src/libui_sdl/libui/ui.h @@ -111,6 +111,7 @@ _UI_EXTERN void uiWindowSetBorderless(uiWindow *w, int borderless); _UI_EXTERN void uiWindowSetChild(uiWindow *w, uiControl *child); _UI_EXTERN int uiWindowMargined(uiWindow *w); _UI_EXTERN void uiWindowSetMargined(uiWindow *w, int margined); +_UI_EXTERN void uiWindowSetDropTarget(uiWindow* w, int drop); _UI_EXTERN uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar); _UI_EXTERN void uiWindowOnContentSizeChanged(uiWindow *w, void (*f)(uiWindow *, void *), void *data); diff --git a/src/libui_sdl/libui/windows/stddialogs.cpp b/src/libui_sdl/libui/windows/stddialogs.cpp index dbd58fe..26d1219 100644 --- a/src/libui_sdl/libui/windows/stddialogs.cpp +++ b/src/libui_sdl/libui/windows/stddialogs.cpp @@ -14,7 +14,7 @@ // - when a dialog is active, tab navigation in other windows stops working // - when adding uiOpenFolder(), use IFileDialog as well - https://msdn.microsoft.com/en-us/library/windows/desktop/bb762115%28v=vs.85%29.aspx -#define windowHWND(w) ((HWND) uiControlHandle(uiControl(w))) +#define windowHWND(w) (w ? (HWND) uiControlHandle(uiControl(w)) : NULL) char *commonItemDialog(HWND parent, REFCLSID clsid, REFIID iid, char* filter, char* initpath, FILEOPENDIALOGOPTIONS optsadd) { diff --git a/src/libui_sdl/libui/windows/window.cpp b/src/libui_sdl/libui/windows/window.cpp index 07496b3..e126efc 100644 --- a/src/libui_sdl/libui/windows/window.cpp +++ b/src/libui_sdl/libui/windows/window.cpp @@ -482,6 +482,12 @@ void uiWindowSetMargined(uiWindow *w, int margined) windowRelayout(w); } + +void uiWindowSetDropTarget(uiWindow* w, int drop) +{ + DragAcceptFiles(w->hwnd, drop?TRUE:FALSE); +} + // see http://blogs.msdn.com/b/oldnewthing/archive/2003/09/11/54885.aspx and http://blogs.msdn.com/b/oldnewthing/archive/2003/09/13/54917.aspx // TODO use clientSizeToWindowSize() static void setClientSize(uiWindow *w, int width, int height, BOOL hasMenubar, DWORD style, DWORD exstyle) diff --git a/src/libui_sdl/main.cpp b/src/libui_sdl/main.cpp index 8d54ea5..89ec551 100644 --- a/src/libui_sdl/main.cpp +++ b/src/libui_sdl/main.cpp @@ -297,7 +297,22 @@ int OnCloseWindow(uiWindow* window, void* blarg) void OnDropFile(uiWindow* window, char* file, void* blarg) { - printf("DROP: %s\n", file); + char* ext = &file[strlen(file)-3]; + + if (!strcasecmp(ext, "nds") || !strcasecmp(ext, "srl")) + { + if (RunningSomething) + { + EmuRunning = 2; + while (EmuStatus != 2); + } + + strncpy(ROMPath, file, 1023); + ROMPath[1023] = '\0'; + + NDS::LoadROM(ROMPath, Config::DirectBoot); + Run(); + } } void OnGetFocus(uiWindow* window, void* blarg) @@ -336,7 +351,6 @@ void OnOpenFile(uiMenuItem* item, uiWindow* window, void* blarg) // so we don't have to free it after use NDS::LoadROM(ROMPath, Config::DirectBoot); - Run(); } @@ -392,6 +406,15 @@ void OnStop(uiMenuItem* item, uiWindow* window, void* blarg) } +bool _fileexists(char* name) +{ + FILE* f = fopen(name, "rb"); + if (!f) return false; + fclose(f); + return true; +} + + int main(int argc, char** argv) { srand(time(NULL)); @@ -420,6 +443,23 @@ int main(int argc, char** argv) Config::Load(); + if (!_fileexists("bios7.bin") || !_fileexists("bios9.bin") || !_fileexists("firmware.bin")) + { + uiMsgBoxError( + NULL, + "BIOS/Firmware not found", + "One or more of the following required files don't exist or couldn't be accessed:\n\n" + "bios7.bin -- ARM7 BIOS\n" + "bios9.bin -- ARM9 BIOS\n" + "firmware.bin -- firmware image\n\n" + "Dump the files from your DS and place them in the directory you run melonDS from.\n" + "Make sure that the files can be accessed."); + + uiUninit(); + SDL_Quit(); + return 0; + } + uiMenu* menu; uiMenuItem* menuitem; @@ -446,7 +486,10 @@ int main(int argc, char** argv) MainWindow = uiNewWindow("melonDS " MELONDS_VERSION, 256, 384, 1); uiWindowOnClosing(MainWindow, OnCloseWindow, NULL); + + uiWindowSetDropTarget(MainWindow, 1); uiWindowOnDropFile(MainWindow, OnDropFile, NULL); + uiWindowOnGetFocus(MainWindow, OnGetFocus, NULL); uiWindowOnLoseFocus(MainWindow, OnLoseFocus, NULL); @@ -469,6 +512,21 @@ int main(int argc, char** argv) RunningSomething = false; EmuThread = SDL_CreateThread(EmuThreadFunc, "melonDS magic", NULL); + if (argc > 1) + { + char* file = argv[1]; + char* ext = &file[strlen(file)-3]; + + if (!strcasecmp(ext, "nds") || !strcasecmp(ext, "srl")) + { + strncpy(ROMPath, file, 1023); + ROMPath[1023] = '\0'; + + NDS::LoadROM(ROMPath, Config::DirectBoot); + Run(); + } + } + uiControlShow(uiControl(MainWindow)); uiControlSetFocus(uiControl(MainDrawArea)); uiMain(); @@ -490,7 +548,7 @@ int main(int argc, char** argv) int CALLBACK WinMain(HINSTANCE hinst, HINSTANCE hprev, LPSTR cmdline, int cmdshow) { char cmdargs[16][256]; - int arg = 0; + int arg = 1; int j = 0; bool inquote = false; int len = strlen(cmdline); @@ -514,8 +572,16 @@ int CALLBACK WinMain(HINSTANCE hinst, HINSTANCE hprev, LPSTR cmdline, int cmdsho } if (j > 255) j = 255; if (arg < 16) cmdargs[arg][j] = '\0'; + if (len > 0) arg++; + + // FIXME!! + strncpy(cmdargs[0], "melonDS.exe", 256); + + char* cmdargptr[16]; + for (int i = 0; i < 16; i++) + cmdargptr[i] = &cmdargs[i][0]; - return main(arg, (char**)cmdargs); + return main(arg, cmdargptr); } #endif |