Skip to content

Commit f10b18a

Browse files
committed
[Windows] 起動時に必ず実行ファイルのディレクトリをカレントディレクトリにする #1227
1 parent b20fa22 commit f10b18a

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Siv3D/src/Siv3D-Platform/WindowsDesktop/Siv3D/Siv3DMain.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
# include <Siv3D/Error.hpp>
1515
# include <Siv3D/Unicode.hpp>
1616
# include <Siv3D/Format.hpp>
17+
# include <Siv3D/System.hpp>
18+
# include <Siv3D/FileSystem.hpp>
1719
# include <Siv3D/EngineLog.hpp>
1820
# include <Siv3D/FreestandingMessageBox/FreestandingMessageBox.hpp>
1921
# include <Siv3D/EngineOptions.hpp>
@@ -259,6 +261,19 @@ namespace s3d
259261
MainSEH();
260262
}
261263

264+
static void SetWorkingDirectory()
265+
{
266+
if (System::IsRunningInVisualStudio())
267+
{
268+
return;
269+
}
270+
271+
if (const FilePath workingDirectory = FileSystem::ParentPath(FileSystem::ModulePath()))
272+
{
273+
FileSystem::ChangeCurrentDirectory(workingDirectory);
274+
}
275+
}
276+
262277
namespace detail::init
263278
{
264279
void InitCommandLines(int argc, char** argv);
@@ -286,6 +301,8 @@ int WINAPI WinMain(_In_ HINSTANCE, _In_opt_ HINSTANCE, _In_ LPSTR, _In_ int)
286301
::CoInitializeEx(nullptr, COINIT_MULTITHREADED);
287302
}
288303

304+
SetWorkingDirectory();
305+
289306
std::unique_lock ul(g_mutex); // (0)--
290307

291308
const std::future<void> f = std::async(std::launch::async, MainThread);

0 commit comments

Comments
 (0)