Added scripting quality of life features #299
|
@ -120,6 +120,11 @@ namespace SHADE
|
||||||
auto* scriptEngine = static_cast<SHScriptEngine*>(SHSystemManager::GetSystem<SHScriptEngine>());
|
auto* scriptEngine = static_cast<SHScriptEngine*>(SHSystemManager::GetSystem<SHScriptEngine>());
|
||||||
scriptEngine->GenerateScriptsCsProjFile();
|
scriptEngine->GenerateScriptsCsProjFile();
|
||||||
}
|
}
|
||||||
|
if (ImGui::Selectable("Open Visual Studio Project"))
|
||||||
|
{
|
||||||
|
auto* scriptEngine = static_cast<SHScriptEngine*>(SHSystemManager::GetSystem<SHScriptEngine>());
|
||||||
|
scriptEngine->OpenSolution();
|
||||||
|
}
|
||||||
ImGui::BeginDisabled(SHSystemManager::GetSystem<SHEditor>()->editorState != SHEditor::State::STOP);
|
ImGui::BeginDisabled(SHSystemManager::GetSystem<SHEditor>()->editorState != SHEditor::State::STOP);
|
||||||
if (ImGui::Selectable("Build Scripts - Debug"))
|
if (ImGui::Selectable("Build Scripts - Debug"))
|
||||||
{
|
{
|
||||||
|
|
|
@ -306,6 +306,22 @@ namespace SHADE
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SHScriptEngine::OpenSolution()
|
||||||
|
{
|
||||||
|
// Generate csproj file if it doesn't exist
|
||||||
|
if (!std::filesystem::exists(CSPROJ_PATH))
|
||||||
|
{
|
||||||
|
GenerateScriptsCsProjFile(CSPROJ_PATH);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Open it
|
||||||
|
execProcessNoBlock
|
||||||
|
(
|
||||||
|
L"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\Common7\\IDE\\devenv.exe",
|
||||||
|
L"/Edit " + SHStringUtilities::StrToWstr(CSPROJ_PATH)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
/* Event Handler Functions */
|
/* Event Handler Functions */
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
@ -611,6 +627,34 @@ namespace SHADE
|
||||||
}
|
}
|
||||||
|
|
||||||
DWORD SHScriptEngine::execProcess(const std::wstring& path, const std::wstring& args)
|
DWORD SHScriptEngine::execProcess(const std::wstring& path, const std::wstring& args)
|
||||||
|
{
|
||||||
|
PROCESS_INFORMATION procInfo = execProcessNoBlock(path, args);
|
||||||
|
|
||||||
|
// Wait for execution to end
|
||||||
|
DWORD status;
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
const auto EXEC_SUCCESS = GetExitCodeProcess(procInfo.hProcess, &status);
|
||||||
|
if (!EXEC_SUCCESS)
|
||||||
|
{
|
||||||
|
auto err = GetLastError();
|
||||||
|
std::ostringstream oss;
|
||||||
|
oss << "[ScriptEngine] Failed to query process. Error code: " << std::hex << err
|
||||||
|
<< " (" << SHStringUtilities::GetWin32ErrorMessage(err) << ")";
|
||||||
|
throw std::runtime_error(oss.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Break only if process ends
|
||||||
|
if (status != STILL_ACTIVE)
|
||||||
|
{
|
||||||
|
CloseHandle(procInfo.hProcess);
|
||||||
|
CloseHandle(procInfo.hThread);
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
PROCESS_INFORMATION SHScriptEngine::execProcessNoBlock(const std::wstring& path, const std::wstring& args)
|
||||||
{
|
{
|
||||||
STARTUPINFOW startInfo;
|
STARTUPINFOW startInfo;
|
||||||
PROCESS_INFORMATION procInfo;
|
PROCESS_INFORMATION procInfo;
|
||||||
|
@ -638,28 +682,7 @@ namespace SHADE
|
||||||
throw std::runtime_error(oss.str());
|
throw std::runtime_error(oss.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait for execution to end
|
return procInfo;
|
||||||
DWORD status;
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
const auto EXEC_SUCCESS = GetExitCodeProcess(procInfo.hProcess, &status);
|
|
||||||
if (!EXEC_SUCCESS)
|
|
||||||
{
|
|
||||||
auto err = GetLastError();
|
|
||||||
std::ostringstream oss;
|
|
||||||
oss << "[ScriptEngine] Failed to query process. Error code: " << std::hex << err
|
|
||||||
<< " (" << SHStringUtilities::GetWin32ErrorMessage(err) << ")";
|
|
||||||
throw std::runtime_error(oss.str());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Break only if process ends
|
|
||||||
if (status != STILL_ACTIVE)
|
|
||||||
{
|
|
||||||
CloseHandle(procInfo.hProcess);
|
|
||||||
CloseHandle(procInfo.hThread);
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::wstring SHScriptEngine::generateBuildCommand(bool debug)
|
std::wstring SHScriptEngine::generateBuildCommand(bool debug)
|
||||||
|
|
|
@ -217,6 +217,10 @@ namespace SHADE
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="path">File path to the generated file.</param>
|
/// <param name="path">File path to the generated file.</param>
|
||||||
void GenerateScriptsCsProjFile(const std::filesystem::path& path = CSPROJ_PATH) const;
|
void GenerateScriptsCsProjFile(const std::filesystem::path& path = CSPROJ_PATH) const;
|
||||||
|
/// <summary>
|
||||||
|
/// Opens the script solution in Visual Studio 2019.
|
||||||
|
/// </summary>
|
||||||
|
void OpenSolution();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
@ -321,6 +325,7 @@ namespace SHADE
|
||||||
static bool fileExists(const std::filesystem::path& filePath);
|
static bool fileExists(const std::filesystem::path& filePath);
|
||||||
static bool copyFile(const std::filesystem::path& from, const std::filesystem::path& to, const std::filesystem::copy_options options) noexcept;
|
static bool copyFile(const std::filesystem::path& from, const std::filesystem::path& to, const std::filesystem::copy_options options) noexcept;
|
||||||
static DWORD execProcess(const std::wstring& path, const std::wstring& args);
|
static DWORD execProcess(const std::wstring& path, const std::wstring& args);
|
||||||
|
static PROCESS_INFORMATION execProcessNoBlock(const std::wstring& path, const std::wstring& args);
|
||||||
static std::wstring generateBuildCommand(bool debug);
|
static std::wstring generateBuildCommand(bool debug);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue