Added the option to open the script csproj via menu bar

This commit is contained in:
Kah Wei 2022-12-20 22:35:47 +08:00
parent 8212ed2280
commit 88e89a226a
3 changed files with 58 additions and 25 deletions

View File

@ -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"))
{ {

View File

@ -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 */
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
@ -612,31 +628,7 @@ namespace SHADE
DWORD SHScriptEngine::execProcess(const std::wstring& path, const std::wstring& args) DWORD SHScriptEngine::execProcess(const std::wstring& path, const std::wstring& args)
{ {
STARTUPINFOW startInfo; PROCESS_INFORMATION procInfo = execProcessNoBlock(path, args);
PROCESS_INFORMATION procInfo;
ZeroMemory(&startInfo, sizeof(startInfo));
ZeroMemory(&procInfo, sizeof(procInfo));
startInfo.cb = sizeof(startInfo);
std::wstring argsWstr = args;
// Start Process
const auto SUCCESS = CreateProcess
(
path.data(), argsWstr.data(),
nullptr, nullptr, false, NULL, nullptr, nullptr,
&startInfo, &procInfo
);
// Error Check
if (!SUCCESS)
{
auto err = GetLastError();
std::ostringstream oss;
oss << "[ScriptEngine] Failed to launch process. Error code: " << std::hex << err
<< " (" << SHStringUtilities::GetWin32ErrorMessage(err) << ")";
throw std::runtime_error(oss.str());
}
// Wait for execution to end // Wait for execution to end
DWORD status; DWORD status;
@ -662,6 +654,37 @@ namespace SHADE
} }
} }
PROCESS_INFORMATION SHScriptEngine::execProcessNoBlock(const std::wstring& path, const std::wstring& args)
{
STARTUPINFOW startInfo;
PROCESS_INFORMATION procInfo;
ZeroMemory(&startInfo, sizeof(startInfo));
ZeroMemory(&procInfo, sizeof(procInfo));
startInfo.cb = sizeof(startInfo);
std::wstring argsWstr = args;
// Start Process
const auto SUCCESS = CreateProcess
(
path.data(), argsWstr.data(),
nullptr, nullptr, false, NULL, nullptr, nullptr,
&startInfo, &procInfo
);
// Error Check
if (!SUCCESS)
{
auto err = GetLastError();
std::ostringstream oss;
oss << "[ScriptEngine] Failed to launch process. Error code: " << std::hex << err
<< " (" << SHStringUtilities::GetWin32ErrorMessage(err) << ")";
throw std::runtime_error(oss.str());
}
return procInfo;
}
std::wstring SHScriptEngine::generateBuildCommand(bool debug) std::wstring SHScriptEngine::generateBuildCommand(bool debug)
{ {
std::wostringstream oss; std::wostringstream oss;

View File

@ -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);
}; };
} }