diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 3b90f60a0b..268d6a3c28 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -1011,7 +1011,7 @@ void OMW::Engine::setScriptConsoleMode(bool enabled) mScriptConsoleMode = enabled; } -void OMW::Engine::setStartupScript(const std::string& path) +void OMW::Engine::setStartupScript(const std::filesystem::path& path) { mStartupScript = path; } diff --git a/apps/openmw/engine.hpp b/apps/openmw/engine.hpp index cf7169bf6d..e9713560f6 100644 --- a/apps/openmw/engine.hpp +++ b/apps/openmw/engine.hpp @@ -165,7 +165,7 @@ namespace OMW int mWarningsMode; std::string mFocusName; bool mScriptConsoleMode; - std::string mStartupScript; + std::filesystem::path mStartupScript; int mActivationDistanceOverride; std::filesystem::path mSaveGameFile; // Grab mouse? @@ -253,7 +253,7 @@ namespace OMW void setScriptConsoleMode(bool enabled); /// Set path for a script that is run on startup in the console. - void setStartupScript(const std::string& path); + void setStartupScript(const std::filesystem::path& path); /// Override the game setting specified activation distance. void setActivationDistanceOverride(int distance); diff --git a/apps/openmw/mwbase/windowmanager.hpp b/apps/openmw/mwbase/windowmanager.hpp index 198be0fdcf..463562a38a 100644 --- a/apps/openmw/mwbase/windowmanager.hpp +++ b/apps/openmw/mwbase/windowmanager.hpp @@ -2,6 +2,7 @@ #define GAME_MWBASE_WINDOWMANAGER_H #include +#include #include #include #include @@ -275,7 +276,7 @@ namespace MWBase virtual void processChangedSettings(const std::set>& changed) = 0; - virtual void executeInConsole(const std::string& path) = 0; + virtual void executeInConsole(const std::filesystem::path& path) = 0; virtual void enableRest() = 0; virtual bool getRestEnabled() = 0; diff --git a/apps/openmw/mwgui/console.cpp b/apps/openmw/mwgui/console.cpp index c376ab87f4..1ac090b379 100644 --- a/apps/openmw/mwgui/console.cpp +++ b/apps/openmw/mwgui/console.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -239,19 +240,20 @@ namespace MWGui } } - void Console::executeFile(const std::string& path) + void Console::executeFile(const std::filesystem::path& path) { - std::ifstream stream((std::filesystem::path(path))); + std::ifstream stream(path); if (!stream.is_open()) - printError("failed to open file: " + path); - else { - std::string line; - - while (std::getline(stream, line)) - execute(line); + printError("Failed to open script file \"" + Files::pathToUnicodeString(path) + + "\": " + std::generic_category().message(errno)); + return; } + + std::string line; + while (std::getline(stream, line)) + execute(line); } void Console::clear() diff --git a/apps/openmw/mwgui/console.hpp b/apps/openmw/mwgui/console.hpp index 611b9577e4..fb31d7477e 100644 --- a/apps/openmw/mwgui/console.hpp +++ b/apps/openmw/mwgui/console.hpp @@ -60,7 +60,7 @@ namespace MWGui void execute(const std::string& command); - void executeFile(const std::string& path); + void executeFile(const std::filesystem::path& path); void updateSelectedObjectPtr(const MWWorld::Ptr& currentPtr, const MWWorld::Ptr& newPtr); diff --git a/apps/openmw/mwgui/windowmanagerimp.cpp b/apps/openmw/mwgui/windowmanagerimp.cpp index 9ed822a1f3..2d4bffdfb9 100644 --- a/apps/openmw/mwgui/windowmanagerimp.cpp +++ b/apps/openmw/mwgui/windowmanagerimp.cpp @@ -1459,7 +1459,7 @@ namespace MWGui return mScalingFactor; } - void WindowManager::executeInConsole(const std::string& path) + void WindowManager::executeInConsole(const std::filesystem::path& path) { mConsole->executeFile(path); } diff --git a/apps/openmw/mwgui/windowmanagerimp.hpp b/apps/openmw/mwgui/windowmanagerimp.hpp index dd5ca85547..74fad4b64f 100644 --- a/apps/openmw/mwgui/windowmanagerimp.hpp +++ b/apps/openmw/mwgui/windowmanagerimp.hpp @@ -296,7 +296,7 @@ namespace MWGui void watchActor(const MWWorld::Ptr& ptr) override; MWWorld::Ptr getWatchedActor() const override; - void executeInConsole(const std::string& path) override; + void executeInConsole(const std::filesystem::path& path) override; void enableRest() override { mRestAllowed = true; } bool getRestEnabled() override;