From e24738fcda9b57633b1992d6a5c2f07f310df3da Mon Sep 17 00:00:00 2001 From: tildearrow Date: Wed, 19 Jan 2022 05:44:19 -0500 Subject: [PATCH] possibly fix a crash when opening file picker with missing directory --- src/gui/gui.cpp | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index d872e8dcd..a10f5ef07 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -23,10 +23,14 @@ #ifdef _WIN32 #include +#include +#include +#include "../utfutils.h" #define LAYOUT_INI "\\layout.ini" #else #include #include +#include #define LAYOUT_INI "/layout.ini" #endif @@ -109,6 +113,8 @@ const char* pitchLabel[11]={ "1/6", "1/5", "1/4", "1/3", "1/2", "1x", "2x", "3x", "4x", "5x", "6x" }; +String getHomeDir(); + void FurnaceGUI::bindEngine(DivEngine* eng) { e=eng; } @@ -2845,7 +2851,19 @@ void FurnaceGUI::keyUp(SDL_Event& ev) { } } +bool dirExists(String what) { +#ifdef _WIN32 + WString ws=utf8To16(what.c_str()); + return (PathIsDirectoryW(ws.c_str())!=FALSE); +#else + struct stat st; + if (stat(what.c_str(),&st)<0) return false; + return (st.st_mode&S_IFDIR); +#endif +} + void FurnaceGUI::openFileDialog(FurnaceGUIFileDialogs type) { + if (!dirExists(workingDir)) workingDir=getHomeDir(); switch (type) { case GUI_FILE_OPEN: ImGuiFileDialog::Instance()->OpenModal("FileDialog","Open File","compatible files{.fur,.dmf},.*",workingDir); @@ -3319,10 +3337,10 @@ bool FurnaceGUI::loop() { if (ImGui::MenuItem("delete","Delete")) doDelete(); if (ImGui::MenuItem("select all","Ctrl-A")) doSelectAll(); ImGui::Separator(); - ImGui::MenuItem("note up","Alt-Q"); - ImGui::MenuItem("note down","Alt-A"); - ImGui::MenuItem("octave up","Alt-Shift-Q"); - ImGui::MenuItem("octave down","Alt-Shift-A"); + if (ImGui::MenuItem("note up","Ctrl-F1")) doTranspose(1); + if (ImGui::MenuItem("note down","Ctrl-F2")) doTranspose(-1); + if (ImGui::MenuItem("octave up","Ctrl-F3")) doTranspose(12); + if (ImGui::MenuItem("octave down","Ctrl-F4")) doTranspose(-12); ImGui::Separator(); ImGui::MenuItem("clear..."); ImGui::EndMenu();