Set working directory of the application to be the executable location #16

Merged
Pycorax merged 2 commits from SetWorkingDirectory into main 2022-09-15 01:39:34 +08:00
6 changed files with 83 additions and 6 deletions
Showing only changes of commit 7bc0dfb399 - Show all commits

View File

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

View File

@ -71,7 +71,7 @@
<Link>
<SubSystem>Windows</SubSystem>
<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>
<ImportLibrary>..\bin\Debug\SHADE_Engine.lib</ImportLibrary>
</Link>
@ -99,7 +99,7 @@
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<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>
<ImportLibrary>..\bin\Release\SHADE_Engine.lib</ImportLibrary>
</Link>
@ -180,7 +180,6 @@
<ClInclude Include="src\Graphics\Windowing\Surface\SHVkSurface.h" />
<ClInclude Include="src\Math\SHMath.h" />
<ClInclude Include="src\Math\SHMathHelpers.h" />
<ClInclude Include="src\Math\SHMathHelpers.hpp" />
<ClInclude Include="src\Math\SHMatrix.h" />
<ClInclude Include="src\Math\SHQuaternion.h" />
<ClInclude Include="src\Math\Vector\SHVec2.h" />
@ -197,6 +196,7 @@
<ClInclude Include="src\Scene\SHSceneManager.h" />
<ClInclude Include="src\Tools\SHException.h" />
<ClInclude Include="src\Tools\SHExceptionHandler.h" />
<ClInclude Include="src\Tools\SHFileUtilties.h" />
<ClInclude Include="src\Tools\SHLogger.h" />
<ClInclude Include="src\Tools\SHUtilities.h" />
</ItemGroup>
@ -269,6 +269,7 @@
<ClCompile Include="src\Scene\SHSceneManager.cpp" />
<ClCompile Include="src\Tools\SHException.cpp" />
<ClCompile Include="src\Tools\SHExceptionHandler.cpp" />
<ClCompile Include="src\Tools\SHFileUtilties.cpp" />
<ClCompile Include="src\Tools\SHLogger.cpp" />
</ItemGroup>
<ItemGroup>

View File

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

View File

@ -57,7 +57,8 @@ project "SHADE_Engine"
"reactphysics3d",
"imgui",
"vulkan-1.lib",
"shaderc_shared.lib"
"shaderc_shared.lib",
"shlwapi"
}
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();
};
}