From 317aa710c4d40a1fd59ae76b0c740eeea0893871 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Fri, 3 Oct 2025 23:41:53 +0300 Subject: [PATCH] test --- src/graphics/ui/GUI.cpp | 8 +++ src/util/platform.cpp | 135 ++++++++++++++++++++-------------------- 2 files changed, 76 insertions(+), 67 deletions(-) diff --git a/src/graphics/ui/GUI.cpp b/src/graphics/ui/GUI.cpp index 3ab438b1..9faed8f7 100644 --- a/src/graphics/ui/GUI.cpp +++ b/src/graphics/ui/GUI.cpp @@ -19,6 +19,7 @@ #include "graphics/core/DrawContext.hpp" #include "graphics/core/Shader.hpp" #include "gui_util.hpp" +#include "util/platform.hpp" #include "window/Camera.hpp" #include "window/Window.hpp" #include "window/input.hpp" @@ -204,6 +205,13 @@ void GUI::act(float delta, const glm::uvec2& vp) { container->act(delta); auto prevfocus = focus; + if (input.jpressed(Keycode::BACKSPACE)) { + platform::new_engine_instance({ + "--res", engine.getPaths().getResourcesFolder().u8string(), + "--dir", engine.getPaths().getUserFilesFolder().u8string() + }); + } + updateTooltip(delta); const auto& cursor = input.getCursor(); diff --git a/src/util/platform.cpp b/src/util/platform.cpp index b36d5eb7..b4d71db4 100644 --- a/src/util/platform.cpp +++ b/src/util/platform.cpp @@ -115,73 +115,6 @@ int platform::get_process_id() { return getpid(); } -void platform::new_engine_instance(const std::vector& args) { - auto executable = get_executable_path(); - -#ifdef _WIN32 - std::stringstream ss; - for (int i = 0; i < args.size(); i++) { - ss << " " << util::quote(args[i]); - } - - auto toWString = [](const std::string& src) { - if (src.empty()) - return L""; - int size = MultiByteToWideChar(CP_UTF8, 0, src.c_str(), -1, nullptr, 0); - if (size == 0) { - throw std::runtime_error( - "MultiByteToWideChar failed with code: " + - std::to_string(GetLastError()) - ) - } - std::vector buffer(size); - MultiByteToWideChar(CP_UTF8, 0, src.c_str(), -1, buffer.data(), size); - return std::wstring(buffer.data()); - }; - - auto executableString = toWString(executable.u8string()); - auto argsString = toWString(ss.str()); - - STARTUPINFOW si = { sizeof(si) }; - PROCESS_INFORMATION pi = { 0 }; - DWORD flags = CREATE_NEW_PROCESS_GROUP | DETACHED_PROCESS; - // | CREATE_NO_WINDOW; - BOOL success = CreateProcessW( - executable.u8string().c_str(), - argsString.c_str(), - nullptr, - nullptr, - FALSE, - flags, - nullptr, - "", - &si, - &pi - ); - if (!success) { - throw std::runtime_error( - "starting an engine instance failed with code: " + - std::to_string(GetLastError()) - ); - } -#else - std::stringstream ss; - ss << executable; - for (int i = 0; i < args.size(); i++) { - ss << " " << util::quote(args[i]); - } - ss << " >/dev/null &"; - - auto command = ss.str(); - if (int res = system(command.c_str())) { - throw std::runtime_error( - "starting an engine instance failed with code: " + - std::to_string(res) - ); - } -#endif -} - bool platform::open_url(const std::string& url) { if (url.empty()) return false; @@ -275,3 +208,71 @@ std::filesystem::path platform::get_executable_path() { throw std::runtime_error("could not get executable path"); #endif } + +void platform::new_engine_instance(const std::vector& args) { + auto executable = get_executable_path(); + +#ifdef _WIN32 + std::stringstream ss; + for (int i = 0; i < args.size(); i++) { + ss << " " << util::quote(args[i]); + } + + auto toWString = [](const std::string& src) -> std::wstring { + if (src.empty()) + return L""; + int size = MultiByteToWideChar(CP_UTF8, 0, src.c_str(), -1, nullptr, 0); + if (size == 0) { + throw std::runtime_error( + "MultiByteToWideChar failed with code: " + + std::to_string(GetLastError()) + ); + } + std::vector buffer(size + 1); + buffer[size] = 0; + MultiByteToWideChar(CP_UTF8, 0, src.c_str(), -1, buffer.data(), size); + return std::wstring(buffer.data(), size); + }; + + auto executableString = toWString(executable.u8string()); + auto argsString = toWString(ss.str()); + + STARTUPINFOW si = { sizeof(si) }; + PROCESS_INFORMATION pi = { 0 }; + DWORD flags = CREATE_NEW_PROCESS_GROUP | DETACHED_PROCESS; + // | CREATE_NO_WINDOW; + BOOL success = CreateProcessW( + executableString.c_str(), + argsString.data(), + nullptr, + nullptr, + FALSE, + flags, + nullptr, + L"", + &si, + &pi + ); + if (!success) { + throw std::runtime_error( + "starting an engine instance failed with code: " + + std::to_string(GetLastError()) + ); + } +#else + std::stringstream ss; + ss << executable; + for (int i = 0; i < args.size(); i++) { + ss << " " << util::quote(args[i]); + } + ss << " >/dev/null &"; + + auto command = ss.str(); + if (int res = system(command.c_str())) { + throw std::runtime_error( + "starting an engine instance failed with code: " + + std::to_string(res) + ); + } +#endif +}