From 8f7910168046a32357fe1e6a9db2c1c7e2ff80b9 Mon Sep 17 00:00:00 2001 From: Tom Picton Date: Tue, 24 Aug 2021 08:49:08 -0700 Subject: [PATCH 1/2] Search user dolphin-data directory for scripts --- Source/Core/Common/CommonPaths.h | 1 + Source/Core/Common/FileUtil.cpp | 1 + Source/Core/Common/FileUtil.h | 1 + Source/Core/Core/LUA/Lua.cpp | 7 +++---- Source/Core/DolphinWX/LaunchLuaScript.cpp | 4 ++-- Source/Core/UICommon/UICommon.cpp | 1 + 6 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Source/Core/Common/CommonPaths.h b/Source/Core/Common/CommonPaths.h index c6d559e..180d306 100644 --- a/Source/Core/Common/CommonPaths.h +++ b/Source/Core/Common/CommonPaths.h @@ -74,6 +74,7 @@ #define ANAGLYPH_DIR "Anaglyph" #define PIPES_DIR "Pipes" #define MEMORYWATCHER_DIR "MemoryWatcher" +#define SCRIPTS_DIR "Scripts" // This one is only used to remove it if it was present #define SHADERCACHE_LEGACY_DIR "ShaderCache" diff --git a/Source/Core/Common/FileUtil.cpp b/Source/Core/Common/FileUtil.cpp index c4563c3..a58e440 100644 --- a/Source/Core/Common/FileUtil.cpp +++ b/Source/Core/Common/FileUtil.cpp @@ -808,6 +808,7 @@ static void RebuildUserDirectories(unsigned int dir_index) s_user_paths[F_GCSRAM_IDX] = s_user_paths[D_GCUSER_IDX] + GC_SRAM; s_user_paths[D_MEMORYWATCHER_IDX] = s_user_paths[D_USER_IDX] + MEMORYWATCHER_DIR DIR_SEP; + s_user_paths[D_SCRIPTS_IDX] = s_user_paths[D_USER_IDX] + SCRIPTS_DIR DIR_SEP; s_user_paths[F_MEMORYWATCHERLOCATIONS_IDX] = s_user_paths[D_MEMORYWATCHER_IDX] + MEMORYWATCHER_LOCATIONS; s_user_paths[F_MEMORYWATCHERSOCKET_IDX] = s_user_paths[D_MEMORYWATCHER_IDX] + MEMORYWATCHER_SOCKET; diff --git a/Source/Core/Common/FileUtil.h b/Source/Core/Common/FileUtil.h index fcc3c20..54e026d 100644 --- a/Source/Core/Common/FileUtil.h +++ b/Source/Core/Common/FileUtil.h @@ -43,6 +43,7 @@ enum { D_THEMES_IDX, D_PIPES_IDX, D_MEMORYWATCHER_IDX, + D_SCRIPTS_IDX, F_DOLPHINCONFIG_IDX, F_DEBUGGERCONFIG_IDX, F_LOGGERCONFIG_IDX, diff --git a/Source/Core/Core/LUA/Lua.cpp b/Source/Core/Core/LUA/Lua.cpp index a5412f3..f8d1517 100644 --- a/Source/Core/Core/LUA/Lua.cpp +++ b/Source/Core/Core/LUA/Lua.cpp @@ -303,7 +303,7 @@ int GetGameID(lua_State* L) int GetScriptsDir(lua_State* L) { - lua_pushstring(L, (SYSDATA_DIR "/Scripts/")); + lua_pushstring(L, File::GetUserPath(D_SCRIPTS_IDX)); return 1; } @@ -899,8 +899,7 @@ namespace Lua //Auto launch Scripts that start with _ - - std::vector rFilenames = DoFileSearch({".lua"}, {SYSDATA_DIR "/Scripts"}); + std::vector rFilenames = DoFileSearch({".lua"}, {File::GetUserPath(D_SCRIPTS_IDX)}); if (rFilenames.size() > 0) { @@ -1019,7 +1018,7 @@ namespace Lua //Unique to normal Scripts lua_register(it->luaState, "CancelScript", CancelScript); - std::string file = SYSDATA_DIR "/Scripts/" + it->fileName; + std::string file = File::GetUserPath(D_SCRIPTS_IDX) + it->fileName; status = luaL_dofile(it->luaState, file.c_str()); diff --git a/Source/Core/DolphinWX/LaunchLuaScript.cpp b/Source/Core/DolphinWX/LaunchLuaScript.cpp index 1f04543..a85d5c7 100644 --- a/Source/Core/DolphinWX/LaunchLuaScript.cpp +++ b/Source/Core/DolphinWX/LaunchLuaScript.cpp @@ -119,7 +119,7 @@ void LuaWindow::OnButtonPressed(wxCommandEvent& event) if (event.GetId() == 2) //Start { - if (File::Exists(SYSDATA_DIR "/Scripts/" + FileName) == false) + if (File::Exists(File::GetUserPath(D_SCRIPTS_IDX) + FileName) == false) { wxMessageBox("Script file does not exist anymore!"); return; @@ -152,7 +152,7 @@ void LuaWindow::Shown() m_choice_script->Clear(); //Find all Lua files - std::vector rFilenames = DoFileSearch({".lua"}, {SYSDATA_DIR "/Scripts" }); + std::vector rFilenames = DoFileSearch({".lua"}, {File::GetUserPath(D_SCRIPTS_IDX)}); if (rFilenames.size() > 0) { diff --git a/Source/Core/UICommon/UICommon.cpp b/Source/Core/UICommon/UICommon.cpp index 9d85ebb..a160ceb 100644 --- a/Source/Core/UICommon/UICommon.cpp +++ b/Source/Core/UICommon/UICommon.cpp @@ -65,6 +65,7 @@ void CreateDirectories() File::CreateFullPath(File::GetUserPath(D_SCREENSHOTS_IDX)); File::CreateFullPath(File::GetUserPath(D_SHADERS_IDX)); File::CreateFullPath(File::GetUserPath(D_SHADERS_IDX) + ANAGLYPH_DIR DIR_SEP); + File::CreateFullPath(File::GetUserPath(D_SCRIPTS_IDX)); File::CreateFullPath(File::GetUserPath(D_STATESAVES_IDX)); File::CreateFullPath(File::GetUserPath(D_THEMES_IDX)); } From 141d9f8a604798a2a7e8fe0f7ee77919685ab033 Mon Sep 17 00:00:00 2001 From: Tom Picton Date: Sat, 28 Aug 2021 16:09:03 -0700 Subject: [PATCH 2/2] Copy default scripts into user dir --- Source/Core/UICommon/UICommon.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Source/Core/UICommon/UICommon.cpp b/Source/Core/UICommon/UICommon.cpp index a160ceb..83c5c23 100644 --- a/Source/Core/UICommon/UICommon.cpp +++ b/Source/Core/UICommon/UICommon.cpp @@ -49,6 +49,10 @@ void CreateDirectories() File::CopyDir(File::GetSysDirectory() + WII_USER_DIR, File::GetUserPath(D_WIIROOT_IDX)); + // Copy built-in scripts. + File::CopyDir(File::GetSysDirectory() + SCRIPTS_DIR, + File::GetUserPath(D_SCRIPTS_IDX)); + File::CreateFullPath(File::GetUserPath(D_USER_IDX)); File::CreateFullPath(File::GetUserPath(D_CACHE_IDX)); File::CreateFullPath(File::GetUserPath(D_CONFIG_IDX)); @@ -65,7 +69,6 @@ void CreateDirectories() File::CreateFullPath(File::GetUserPath(D_SCREENSHOTS_IDX)); File::CreateFullPath(File::GetUserPath(D_SHADERS_IDX)); File::CreateFullPath(File::GetUserPath(D_SHADERS_IDX) + ANAGLYPH_DIR DIR_SEP); - File::CreateFullPath(File::GetUserPath(D_SCRIPTS_IDX)); File::CreateFullPath(File::GetUserPath(D_STATESAVES_IDX)); File::CreateFullPath(File::GetUserPath(D_THEMES_IDX)); }