From ba5c527b183a40726fad8363fa6a4203d6fcc007 Mon Sep 17 00:00:00 2001 From: IliasHDZ Date: Sun, 25 Aug 2024 12:39:44 +0500 Subject: [PATCH] using `std::array` --- loader/src/platform/windows/main.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/loader/src/platform/windows/main.cpp b/loader/src/platform/windows/main.cpp index 817447ba..e4886417 100644 --- a/loader/src/platform/windows/main.cpp +++ b/loader/src/platform/windows/main.cpp @@ -142,16 +142,21 @@ unsigned int gdTimestamp = 0; // this function will set the current working directory to the game's directory // to avoid the game crashing due to not being able to find the resources static void fixCWD() { - WCHAR cwd[MAX_PATH]; - DWORD size = GetModuleFileNameW(NULL, cwd, sizeof(cwd)); - if (size == sizeof(cwd)) return; - for (int i = size - 1; i >= 0; i--) { + std::array cwd; + + DWORD size = GetModuleFileNameW(NULL, cwd.data(), cwd.size()); + if (size == cwd.size()) return; + + int i; + for (i = (int)size - 1; i >= 0; i--) { if (cwd[i] == '\\') { - cwd[i] = '\0'; + cwd[i] = 0; break; } } - SetCurrentDirectoryW(cwd); + if (i < 0) return; + + SetCurrentDirectoryW(cwd.data()); } int WINAPI gdMainHook(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow) {