Skip to content

Commit

Permalink
[Windows, macOS, Linux] プログラムが IDE で実行されているかを取得する関数 #1230
Browse files Browse the repository at this point in the history
  • Loading branch information
Reputeless committed Jun 4, 2024
1 parent 2531657 commit b20fa22
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Siv3D/include/Siv3D/System.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,16 @@ namespace s3d
/// @param fileName ファイル名 | File name
/// @return テキストエディタの起動に成功した場合 true, それ以外の場合は false | Returns true if the text editor was launched successfully, otherwise false.
bool LaunchFileWithTextEditor(FilePathView fileName);

/// @brief プログラムが Visual Studio で実行されているかを返します。 | Returns whether the program is running in Visual Studio.
/// @return プログラムが Visual Studio で実行されている場合 true, それ以外の場合は false | Returns true if the program is running in Visual Studio, false otherwise
[[nodiscard]]
bool IsRunningInVisualStudio();

/// @brief プログラムが Xcode で実行されているかを返します。 | Returns whether the program is running in Xcode.
/// @return プログラムが Xcode で実行されている場合 true, それ以外の場合は false | Returns true if the program is running in Xcode, false otherwise
[[nodiscard]]
bool IsRunningInXcode();
}

# if SIV3D_PLATFORM(WEB)
Expand Down
10 changes: 10 additions & 0 deletions Siv3D/src/Siv3D-Platform/Linux/Siv3D/System/SivSystem_Linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,5 +231,15 @@ namespace s3d

return (std::system(command.c_str()) == 0);
}

bool IsRunningInVisualStudio()
{
return false;
}

bool IsRunningInXcode()
{
return false;
}
}
}
10 changes: 10 additions & 0 deletions Siv3D/src/Siv3D-Platform/Web/Siv3D/System/SivSystem_Web.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ namespace s3d
{
return false;
}

bool IsRunningInVisualStudio()
{
return false;
}

bool IsRunningInXcode()
{
return false;
}
}

namespace Platform::Web::System
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,26 @@

namespace s3d
{
namespace
{
[[nodiscard]]
static bool IsRunningInVisualStudio_impl()
{
wchar_t* pValue;
size_t len;
errno_t err = ::_wdupenv_s(&pValue, &len, L"VisualStudioVersion");

if (err || (not pValue))
{
return false;
}

std::free(pValue);

return true;
}
}

namespace System
{
void Sleep(const int32 milliseconds)
Expand Down Expand Up @@ -177,5 +197,17 @@ namespace s3d

return (::ShellExecuteExW(&sei) != 0);
}

bool IsRunningInVisualStudio()
{
static const bool result = IsRunningInVisualStudio_impl();

return result;
}

bool IsRunningInXcode()
{
return false;
}
}
}
18 changes: 18 additions & 0 deletions Siv3D/src/Siv3D-Platform/macOS/Siv3D/System/SivSystem_macOS.mm
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ static bool MacOS_OpenHTMLInBrowser(const char* _path)
}

}

[[nodiscard]]
static bool IsRunningInXcode_impl()
{
return (std::getenv("__XCODE_BUILT_PRODUCTS_DIR_PATHS") != nullptr);
}
}

namespace System
Expand Down Expand Up @@ -190,5 +196,17 @@ bool LaunchFileWithTextEditor(const FilePathView fileName)

return (std::system(command.c_str()) == 0);
}

bool IsRunningInVisualStudio()
{
return false;
}

bool IsRunningInXcode()
{
static const bool result = detail::IsRunningInXcode_impl();

return result;
}
}
}

0 comments on commit b20fa22

Please sign in to comment.