Skip to content

Commit b20fa22

Browse files
committed
[Windows, macOS, Linux] プログラムが IDE で実行されているかを取得する関数 #1230
1 parent 2531657 commit b20fa22

File tree

5 files changed

+80
-0
lines changed

5 files changed

+80
-0
lines changed

Siv3D/include/Siv3D/System.hpp

+10
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,16 @@ namespace s3d
104104
/// @param fileName ファイル名 | File name
105105
/// @return テキストエディタの起動に成功した場合 true, それ以外の場合は false | Returns true if the text editor was launched successfully, otherwise false.
106106
bool LaunchFileWithTextEditor(FilePathView fileName);
107+
108+
/// @brief プログラムが Visual Studio で実行されているかを返します。 | Returns whether the program is running in Visual Studio.
109+
/// @return プログラムが Visual Studio で実行されている場合 true, それ以外の場合は false | Returns true if the program is running in Visual Studio, false otherwise
110+
[[nodiscard]]
111+
bool IsRunningInVisualStudio();
112+
113+
/// @brief プログラムが Xcode で実行されているかを返します。 | Returns whether the program is running in Xcode.
114+
/// @return プログラムが Xcode で実行されている場合 true, それ以外の場合は false | Returns true if the program is running in Xcode, false otherwise
115+
[[nodiscard]]
116+
bool IsRunningInXcode();
107117
}
108118

109119
# if SIV3D_PLATFORM(WEB)

Siv3D/src/Siv3D-Platform/Linux/Siv3D/System/SivSystem_Linux.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -231,5 +231,15 @@ namespace s3d
231231

232232
return (std::system(command.c_str()) == 0);
233233
}
234+
235+
bool IsRunningInVisualStudio()
236+
{
237+
return false;
238+
}
239+
240+
bool IsRunningInXcode()
241+
{
242+
return false;
243+
}
234244
}
235245
}

Siv3D/src/Siv3D-Platform/Web/Siv3D/System/SivSystem_Web.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,16 @@ namespace s3d
5252
{
5353
return false;
5454
}
55+
56+
bool IsRunningInVisualStudio()
57+
{
58+
return false;
59+
}
60+
61+
bool IsRunningInXcode()
62+
{
63+
return false;
64+
}
5565
}
5666

5767
namespace Platform::Web::System

Siv3D/src/Siv3D-Platform/WindowsDesktop/Siv3D/System/SivSystem_Windows.cpp

+32
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,26 @@
1919

2020
namespace s3d
2121
{
22+
namespace
23+
{
24+
[[nodiscard]]
25+
static bool IsRunningInVisualStudio_impl()
26+
{
27+
wchar_t* pValue;
28+
size_t len;
29+
errno_t err = ::_wdupenv_s(&pValue, &len, L"VisualStudioVersion");
30+
31+
if (err || (not pValue))
32+
{
33+
return false;
34+
}
35+
36+
std::free(pValue);
37+
38+
return true;
39+
}
40+
}
41+
2242
namespace System
2343
{
2444
void Sleep(const int32 milliseconds)
@@ -177,5 +197,17 @@ namespace s3d
177197

178198
return (::ShellExecuteExW(&sei) != 0);
179199
}
200+
201+
bool IsRunningInVisualStudio()
202+
{
203+
static const bool result = IsRunningInVisualStudio_impl();
204+
205+
return result;
206+
}
207+
208+
bool IsRunningInXcode()
209+
{
210+
return false;
211+
}
180212
}
181213
}

Siv3D/src/Siv3D-Platform/macOS/Siv3D/System/SivSystem_macOS.mm

+18
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ static bool MacOS_OpenHTMLInBrowser(const char* _path)
4747
}
4848

4949
}
50+
51+
[[nodiscard]]
52+
static bool IsRunningInXcode_impl()
53+
{
54+
return (std::getenv("__XCODE_BUILT_PRODUCTS_DIR_PATHS") != nullptr);
55+
}
5056
}
5157

5258
namespace System
@@ -190,5 +196,17 @@ bool LaunchFileWithTextEditor(const FilePathView fileName)
190196

191197
return (std::system(command.c_str()) == 0);
192198
}
199+
200+
bool IsRunningInVisualStudio()
201+
{
202+
return false;
203+
}
204+
205+
bool IsRunningInXcode()
206+
{
207+
static const bool result = detail::IsRunningInXcode_impl();
208+
209+
return result;
210+
}
193211
}
194212
}

0 commit comments

Comments
 (0)