Set working directory of the application to be the executable location

This commit is contained in:
Kah Wei 2022-09-15 00:33:12 +08:00
parent becce86160
commit 7bc0dfb399
6 changed files with 83 additions and 6 deletions

View File

@ -7,6 +7,7 @@
#endif // SHEDITOR #endif // SHEDITOR
#include "Tools/SHLogger.h" #include "Tools/SHLogger.h"
#include "Tools/SHFileUtilties.h"
#include <chrono> #include <chrono>
#include <ratio> #include <ratio>
@ -23,7 +24,8 @@ namespace Sandbox
_In_ INT nCmdShow _In_ INT nCmdShow
) )
{ {
SHLOG_TITLE("Initialising SBApplication") // Set working directory
SHADE::SHFileUtilities::SetWorkDirToExecDir();
window.Create(hInstance, hPrevInstance, lpCmdLine, nCmdShow); window.Create(hInstance, hPrevInstance, lpCmdLine, nCmdShow);

View File

@ -71,7 +71,7 @@
<Link> <Link>
<SubSystem>Windows</SubSystem> <SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>vulkan-1.lib;shaderc_shared.lib;assimp-vc142-mtd.lib;ktxd.lib;librttr_core_d.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>vulkan-1.lib;shaderc_shared.lib;shlwapi.lib;assimp-vc142-mtd.lib;ktxd.lib;librttr_core_d.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>libs;$(VULKAN_SDK)\Lib;..\Dependencies\assimp\lib\Debug;..\Dependencies\assimp\lib\Release;..\Dependencies\RTTR\lib;..\Dependencies\ktx\lib\Debug;..\Dependencies\ktx\lib\Release;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> <AdditionalLibraryDirectories>libs;$(VULKAN_SDK)\Lib;..\Dependencies\assimp\lib\Debug;..\Dependencies\assimp\lib\Release;..\Dependencies\RTTR\lib;..\Dependencies\ktx\lib\Debug;..\Dependencies\ktx\lib\Release;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<ImportLibrary>..\bin\Debug\SHADE_Engine.lib</ImportLibrary> <ImportLibrary>..\bin\Debug\SHADE_Engine.lib</ImportLibrary>
</Link> </Link>
@ -99,7 +99,7 @@
<SubSystem>Windows</SubSystem> <SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding> <EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences> <OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>vulkan-1.lib;shaderc_shared.lib;assimp-vc142-mt.lib;ktx.lib;librttr_core.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>vulkan-1.lib;shaderc_shared.lib;shlwapi.lib;assimp-vc142-mt.lib;ktx.lib;librttr_core.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>libs;$(VULKAN_SDK)\Lib;..\Dependencies\assimp\lib\Debug;..\Dependencies\assimp\lib\Release;..\Dependencies\RTTR\lib;..\Dependencies\ktx\lib\Debug;..\Dependencies\ktx\lib\Release;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> <AdditionalLibraryDirectories>libs;$(VULKAN_SDK)\Lib;..\Dependencies\assimp\lib\Debug;..\Dependencies\assimp\lib\Release;..\Dependencies\RTTR\lib;..\Dependencies\ktx\lib\Debug;..\Dependencies\ktx\lib\Release;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<ImportLibrary>..\bin\Release\SHADE_Engine.lib</ImportLibrary> <ImportLibrary>..\bin\Release\SHADE_Engine.lib</ImportLibrary>
</Link> </Link>
@ -180,7 +180,6 @@
<ClInclude Include="src\Graphics\Windowing\Surface\SHVkSurface.h" /> <ClInclude Include="src\Graphics\Windowing\Surface\SHVkSurface.h" />
<ClInclude Include="src\Math\SHMath.h" /> <ClInclude Include="src\Math\SHMath.h" />
<ClInclude Include="src\Math\SHMathHelpers.h" /> <ClInclude Include="src\Math\SHMathHelpers.h" />
<ClInclude Include="src\Math\SHMathHelpers.hpp" />
<ClInclude Include="src\Math\SHMatrix.h" /> <ClInclude Include="src\Math\SHMatrix.h" />
<ClInclude Include="src\Math\SHQuaternion.h" /> <ClInclude Include="src\Math\SHQuaternion.h" />
<ClInclude Include="src\Math\Vector\SHVec2.h" /> <ClInclude Include="src\Math\Vector\SHVec2.h" />
@ -197,6 +196,7 @@
<ClInclude Include="src\Scene\SHSceneManager.h" /> <ClInclude Include="src\Scene\SHSceneManager.h" />
<ClInclude Include="src\Tools\SHException.h" /> <ClInclude Include="src\Tools\SHException.h" />
<ClInclude Include="src\Tools\SHExceptionHandler.h" /> <ClInclude Include="src\Tools\SHExceptionHandler.h" />
<ClInclude Include="src\Tools\SHFileUtilties.h" />
<ClInclude Include="src\Tools\SHLogger.h" /> <ClInclude Include="src\Tools\SHLogger.h" />
<ClInclude Include="src\Tools\SHUtilities.h" /> <ClInclude Include="src\Tools\SHUtilities.h" />
</ItemGroup> </ItemGroup>
@ -269,6 +269,7 @@
<ClCompile Include="src\Scene\SHSceneManager.cpp" /> <ClCompile Include="src\Scene\SHSceneManager.cpp" />
<ClCompile Include="src\Tools\SHException.cpp" /> <ClCompile Include="src\Tools\SHException.cpp" />
<ClCompile Include="src\Tools\SHExceptionHandler.cpp" /> <ClCompile Include="src\Tools\SHExceptionHandler.cpp" />
<ClCompile Include="src\Tools\SHFileUtilties.cpp" />
<ClCompile Include="src\Tools\SHLogger.cpp" /> <ClCompile Include="src\Tools\SHLogger.cpp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -377,13 +377,15 @@
<ClInclude Include="src\Tools\SHExceptionHandler.h"> <ClInclude Include="src\Tools\SHExceptionHandler.h">
<Filter>Tools</Filter> <Filter>Tools</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="src\Tools\SHFileUtilties.h">
<Filter>Tools</Filter>
</ClInclude>
<ClInclude Include="src\Tools\SHLogger.h"> <ClInclude Include="src\Tools\SHLogger.h">
<Filter>Tools</Filter> <Filter>Tools</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="src\Tools\SHUtilities.h"> <ClInclude Include="src\Tools\SHUtilities.h">
<Filter>Tools</Filter> <Filter>Tools</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="src\Math\SHMathHelpers.hpp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="src\ECS_Base\Components\SHComponent.cpp"> <ClCompile Include="src\ECS_Base\Components\SHComponent.cpp">
@ -582,6 +584,9 @@
<ClCompile Include="src\Tools\SHExceptionHandler.cpp"> <ClCompile Include="src\Tools\SHExceptionHandler.cpp">
<Filter>Tools</Filter> <Filter>Tools</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="src\Tools\SHFileUtilties.cpp">
<Filter>Tools</Filter>
</ClCompile>
<ClCompile Include="src\Tools\SHLogger.cpp"> <ClCompile Include="src\Tools\SHLogger.cpp">
<Filter>Tools</Filter> <Filter>Tools</Filter>
</ClCompile> </ClCompile>

View File

@ -57,7 +57,8 @@ project "SHADE_Engine"
"reactphysics3d", "reactphysics3d",
"imgui", "imgui",
"vulkan-1.lib", "vulkan-1.lib",
"shaderc_shared.lib" "shaderc_shared.lib",
"shlwapi"
} }
defines defines

View File

@ -0,0 +1,30 @@
/************************************************************************************//*!
\file SHFileUtilities.cpp
\author Tng Kah Wei, kahwei.tng, 390009620
\par email: kahwei.tng\@digipen.edu
\date Sep 15, 2022
\brief Contains the definition of functions of the SHFileUtilities static class.
Copyright (C) 2022 DigiPen Institute of Technology.
Reproduction or disclosure of this file or its contents without the prior written consent
of DigiPen Institute of Technology is prohibited.
*//*************************************************************************************/
// Precompiled Header
#include "SHpch.h"
// Primary Header
#include "SHFileUtilties.h"
// Standard Libraries
#include <filesystem>
// External Dependencies
#include <shlwapi.h> // GetModuleFileName, PathRemoveFileSpec
namespace SHADE
{
void SHFileUtilities::SetWorkDirToExecDir()
{
TCHAR currentExecFilePath[MAX_PATH] = { '\0' };
GetModuleFileName(nullptr, currentExecFilePath, MAX_PATH);
PathRemoveFileSpec(currentExecFilePath);
std::filesystem::current_path(currentExecFilePath);
}
}

View File

@ -0,0 +1,38 @@
/************************************************************************************//*!
\file SHFileUtilities.h
\author Tng Kah Wei, kahwei.tng, 390009620
\par email: kahwei.tng\@digipen.edu
\date Sep 15, 2022
\brief Contains the SHFileUtilities static class.
Copyright (C) 2022 DigiPen Institute of Technology.
Reproduction or disclosure of this file or its contents without the prior written consent
of DigiPen Institute of Technology is prohibited.
*//*************************************************************************************/
// Project Headers
#include "SH_API.h"
namespace SHADE
{
/*!************************************************************************************
\class SHFileUtilities
\brief
Static class that contains functions for working with files and directories.
**************************************************************************************/
class SH_API SHFileUtilities
{
public:
/*!**********************************************************************************
\brief
Sets the application's current working directory to the application executable's
directory.
************************************************************************************/
static void SetWorkDirToExecDir();
};
}