From 7bc0dfb399f021c05749aaf68f47e7402c83a647 Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Thu, 15 Sep 2022 00:33:12 +0800 Subject: [PATCH] Set working directory of the application to be the executable location --- .../src/Application/SBApplication.cpp | 4 +- SHADE_Engine/SHADE_Engine.vcxproj | 7 ++-- SHADE_Engine/SHADE_Engine.vcxproj.filters | 7 +++- SHADE_Engine/premake5.lua | 3 +- SHADE_Engine/src/Tools/SHFileUtilties.cpp | 30 +++++++++++++++ SHADE_Engine/src/Tools/SHFileUtilties.h | 38 +++++++++++++++++++ 6 files changed, 83 insertions(+), 6 deletions(-) create mode 100644 SHADE_Engine/src/Tools/SHFileUtilties.cpp create mode 100644 SHADE_Engine/src/Tools/SHFileUtilties.h diff --git a/SHADE_Application/src/Application/SBApplication.cpp b/SHADE_Application/src/Application/SBApplication.cpp index 0cb1ecd1..dc497dbe 100644 --- a/SHADE_Application/src/Application/SBApplication.cpp +++ b/SHADE_Application/src/Application/SBApplication.cpp @@ -7,6 +7,7 @@ #endif // SHEDITOR #include "Tools/SHLogger.h" +#include "Tools/SHFileUtilties.h" #include #include @@ -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); diff --git a/SHADE_Engine/SHADE_Engine.vcxproj b/SHADE_Engine/SHADE_Engine.vcxproj index 2fb0ebb4..752a329c 100644 --- a/SHADE_Engine/SHADE_Engine.vcxproj +++ b/SHADE_Engine/SHADE_Engine.vcxproj @@ -71,7 +71,7 @@ Windows true - vulkan-1.lib;shaderc_shared.lib;assimp-vc142-mtd.lib;ktxd.lib;librttr_core_d.lib;%(AdditionalDependencies) + vulkan-1.lib;shaderc_shared.lib;shlwapi.lib;assimp-vc142-mtd.lib;ktxd.lib;librttr_core_d.lib;%(AdditionalDependencies) libs;$(VULKAN_SDK)\Lib;..\Dependencies\assimp\lib\Debug;..\Dependencies\assimp\lib\Release;..\Dependencies\RTTR\lib;..\Dependencies\ktx\lib\Debug;..\Dependencies\ktx\lib\Release;%(AdditionalLibraryDirectories) ..\bin\Debug\SHADE_Engine.lib @@ -99,7 +99,7 @@ Windows true true - vulkan-1.lib;shaderc_shared.lib;assimp-vc142-mt.lib;ktx.lib;librttr_core.lib;%(AdditionalDependencies) + vulkan-1.lib;shaderc_shared.lib;shlwapi.lib;assimp-vc142-mt.lib;ktx.lib;librttr_core.lib;%(AdditionalDependencies) libs;$(VULKAN_SDK)\Lib;..\Dependencies\assimp\lib\Debug;..\Dependencies\assimp\lib\Release;..\Dependencies\RTTR\lib;..\Dependencies\ktx\lib\Debug;..\Dependencies\ktx\lib\Release;%(AdditionalLibraryDirectories) ..\bin\Release\SHADE_Engine.lib @@ -180,7 +180,6 @@ - @@ -197,6 +196,7 @@ + @@ -269,6 +269,7 @@ + diff --git a/SHADE_Engine/SHADE_Engine.vcxproj.filters b/SHADE_Engine/SHADE_Engine.vcxproj.filters index e92c1d2e..31c76d27 100644 --- a/SHADE_Engine/SHADE_Engine.vcxproj.filters +++ b/SHADE_Engine/SHADE_Engine.vcxproj.filters @@ -377,13 +377,15 @@ Tools + + Tools + Tools Tools - @@ -582,6 +584,9 @@ Tools + + Tools + Tools diff --git a/SHADE_Engine/premake5.lua b/SHADE_Engine/premake5.lua index 41693aa8..4d215f5a 100644 --- a/SHADE_Engine/premake5.lua +++ b/SHADE_Engine/premake5.lua @@ -57,7 +57,8 @@ project "SHADE_Engine" "reactphysics3d", "imgui", "vulkan-1.lib", - "shaderc_shared.lib" + "shaderc_shared.lib", + "shlwapi" } defines diff --git a/SHADE_Engine/src/Tools/SHFileUtilties.cpp b/SHADE_Engine/src/Tools/SHFileUtilties.cpp new file mode 100644 index 00000000..0e75b16a --- /dev/null +++ b/SHADE_Engine/src/Tools/SHFileUtilties.cpp @@ -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 +// External Dependencies +#include // GetModuleFileName, PathRemoveFileSpec + +namespace SHADE +{ + void SHFileUtilities::SetWorkDirToExecDir() + { + TCHAR currentExecFilePath[MAX_PATH] = { '\0' }; + GetModuleFileName(nullptr, currentExecFilePath, MAX_PATH); + PathRemoveFileSpec(currentExecFilePath); + std::filesystem::current_path(currentExecFilePath); + } +} diff --git a/SHADE_Engine/src/Tools/SHFileUtilties.h b/SHADE_Engine/src/Tools/SHFileUtilties.h new file mode 100644 index 00000000..b9ba164b --- /dev/null +++ b/SHADE_Engine/src/Tools/SHFileUtilties.h @@ -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(); + }; +}