From bd15ecbb0b7e93c2537aece738576f271df81e9c Mon Sep 17 00:00:00 2001 From: shyguyhex Date: Sun, 8 Aug 2021 05:58:54 -0500 Subject: [PATCH] [Debugger] Fix script directory bugs (fix #2094) (#2095) --- .../Debugger/Debugger-Scripts.cpp | 26 ++++++++++++------- .../UserInterface/Debugger/Debugger-Scripts.h | 4 ++- .../UserInterface/Debugger/ScriptInstance.cpp | 3 ++- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/Source/Project64/UserInterface/Debugger/Debugger-Scripts.cpp b/Source/Project64/UserInterface/Debugger/Debugger-Scripts.cpp index e52726802..585ee30d7 100644 --- a/Source/Project64/UserInterface/Debugger/Debugger-Scripts.cpp +++ b/Source/Project64/UserInterface/Debugger/Debugger-Scripts.cpp @@ -49,11 +49,20 @@ LRESULT CDebugScripts::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*l RefreshList(); - LoadWindowPos(); - WindowCreated(); + m_InstallDir = (std::string)CPath(CPath::MODULE_DIRECTORY); + m_ScriptsDir = m_InstallDir + "Scripts\\"; + + if (!PathFileExistsA(m_ScriptsDir.c_str())) + { + CreateDirectoryA(m_ScriptsDir.c_str(), nullptr); + } m_hQuitScriptDirWatchEvent = CreateEvent(nullptr, TRUE, FALSE, nullptr); m_hScriptDirWatchThread = CreateThread(nullptr, 0, ScriptDirWatchProc, (void*)this, 0, nullptr); + + LoadWindowPos(); + WindowCreated(); + return 0; } @@ -88,7 +97,7 @@ DWORD WINAPI CDebugScripts::ScriptDirWatchProc(void* ctx) HANDLE hEvents[2]; - hEvents[0] = FindFirstChangeNotification(L"Scripts", FALSE, FILE_NOTIFY_CHANGE_FILE_NAME); + hEvents[0] = FindFirstChangeNotification(_this->m_ScriptsDir.ToUTF16().c_str(), FALSE, FILE_NOTIFY_CHANGE_FILE_NAME); if (hEvents[0] == INVALID_HANDLE_VALUE) { @@ -195,7 +204,7 @@ LRESULT CDebugScripts::OnClicked(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl* ConsoleCopy(); break; case IDC_SCRIPTDIR_BTN: - ShellExecute(nullptr, L"open", L"Scripts", nullptr, nullptr, SW_SHOW); + ShellExecuteA(nullptr, "open", m_ScriptsDir.c_str(), nullptr, m_InstallDir.c_str(), SW_SHOW); break; } return FALSE; @@ -221,9 +230,8 @@ void CDebugScripts::RefreshStatus() { INSTANCE_STATE state = m_Debugger->ScriptSystem()->GetInstanceState(m_SelectedScriptName.c_str()); - stdstr statusText; - CPath(stdstr_f("Scripts\\%s", m_SelectedScriptName.c_str())).GetFullyQualified(statusText); - + stdstr statusText = m_ScriptsDir + m_SelectedScriptName; + if (state == STATE_RUNNING) { statusText += " (Running)"; @@ -366,7 +374,7 @@ LRESULT CDebugScripts::OnRefreshList(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /* { int nIndex = m_ScriptList.GetSelectedIndex(); - CPath SearchPath("Scripts", "*"); + CPath SearchPath(m_ScriptsDir, "*"); if (!SearchPath.FindFirst(CPath::FIND_ATTRIBUTE_ALLFILES)) { @@ -464,7 +472,7 @@ void CDebugScripts::ToggleSelected() void CDebugScripts::EditSelected() { - ShellExecute(nullptr, L"edit", stdstr(m_SelectedScriptName).ToUTF16().c_str(), nullptr, L"Scripts", SW_SHOWNORMAL); + ShellExecuteA(nullptr, "edit", m_SelectedScriptName.c_str(), nullptr, m_ScriptsDir.c_str(), SW_SHOWNORMAL); } // Console input diff --git a/Source/Project64/UserInterface/Debugger/Debugger-Scripts.h b/Source/Project64/UserInterface/Debugger/Debugger-Scripts.h index 9f58523e8..b56fefd98 100644 --- a/Source/Project64/UserInterface/Debugger/Debugger-Scripts.h +++ b/Source/Project64/UserInterface/Debugger/Debugger-Scripts.h @@ -84,7 +84,9 @@ private: CEditConsole m_ConsoleEdit; CScriptList m_ScriptList; CStatusBarCtrl m_StatusBar; - std::string m_SelectedScriptName; + stdstr m_SelectedScriptName; + stdstr m_InstallDir; + stdstr m_ScriptsDir; HANDLE m_hQuitScriptDirWatchEvent; HANDLE m_hScriptDirWatchThread; diff --git a/Source/Project64/UserInterface/Debugger/ScriptInstance.cpp b/Source/Project64/UserInterface/Debugger/ScriptInstance.cpp index 47a17e8c0..354bf899b 100644 --- a/Source/Project64/UserInterface/Debugger/ScriptInstance.cpp +++ b/Source/Project64/UserInterface/Debugger/ScriptInstance.cpp @@ -142,7 +142,8 @@ void CScriptInstance::StartScriptProc() if (m_TempPath) { - stdstr fullPath = stdstr_f("Scripts/%s", m_TempPath); + stdstr scriptsDir = (std::string)CPath(CPath::MODULE_DIRECTORY) + "Scripts\\"; + stdstr fullPath = scriptsDir + m_TempPath; duk_int_t scriptresult = duk_peval_file(ctx, fullPath.c_str()); m_TempPath = nullptr;