Skip to content

Commit

Permalink
[Windows] 起動時に必ず実行ファイルのディレクトリをカレントディレクトリにする #1227
Browse files Browse the repository at this point in the history
  • Loading branch information
Reputeless committed Jun 4, 2024
1 parent b20fa22 commit f10b18a
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Siv3D/src/Siv3D-Platform/WindowsDesktop/Siv3D/Siv3DMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
# include <Siv3D/Error.hpp>
# include <Siv3D/Unicode.hpp>
# include <Siv3D/Format.hpp>
# include <Siv3D/System.hpp>
# include <Siv3D/FileSystem.hpp>
# include <Siv3D/EngineLog.hpp>
# include <Siv3D/FreestandingMessageBox/FreestandingMessageBox.hpp>
# include <Siv3D/EngineOptions.hpp>
Expand Down Expand Up @@ -259,6 +261,19 @@ namespace s3d
MainSEH();
}

static void SetWorkingDirectory()
{
if (System::IsRunningInVisualStudio())
{
return;
}

if (const FilePath workingDirectory = FileSystem::ParentPath(FileSystem::ModulePath()))
{
FileSystem::ChangeCurrentDirectory(workingDirectory);
}
}

namespace detail::init
{
void InitCommandLines(int argc, char** argv);
Expand Down Expand Up @@ -286,6 +301,8 @@ int WINAPI WinMain(_In_ HINSTANCE, _In_opt_ HINSTANCE, _In_ LPSTR, _In_ int)
::CoInitializeEx(nullptr, COINIT_MULTITHREADED);
}

SetWorkingDirectory();

std::unique_lock ul(g_mutex); // (0)--

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

0 comments on commit f10b18a

Please sign in to comment.