From f485dfc8047fa3b55eb05fcc16ffe9b42d568814 Mon Sep 17 00:00:00 2001 From: korenkonder Date: Tue, 5 Mar 2024 00:28:12 +0300 Subject: [PATCH] Get full path on read --- src/CRE/data.cpp | 4 ++++ src/KKdLib/io/path.cpp | 21 +++++++++++++++++++++ src/KKdLib/io/path.hpp | 4 +++- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/CRE/data.cpp b/src/CRE/data.cpp index fef336f4..a807b15f 100644 --- a/src/CRE/data.cpp +++ b/src/CRE/data.cpp @@ -935,6 +935,7 @@ static void data_load_inner(stream& s) { data_struct_path& data_path = ds->data_paths.back(); t -= t_len[count - j - 1] + 1; data_path.path.assign(t, t_len[count - j - 1]); + path_get_full_path(data_path.path); } free_def(t_len); @@ -961,6 +962,9 @@ static void data_load_inner(stream& s) { else add_data_rom_path.assign(add_data, add_data_len); + path_get_full_path(main_rom_path); + path_get_full_path(add_data_rom_path); + if (main_rom_path.size() && main_rom_path.back() == '\\') main_rom_path.pop_back(); diff --git a/src/KKdLib/io/path.cpp b/src/KKdLib/io/path.cpp index 7272d454..deb84f91 100644 --- a/src/KKdLib/io/path.cpp +++ b/src/KKdLib/io/path.cpp @@ -393,3 +393,24 @@ std::vector path_get_directories_recursive( } return directories; } + +void path_get_full_path(std::string& str) { + wchar_t buf[MAX_PATH * 2]; + buf[0] = 0; + wchar_t* utf16_temp = utf8_to_utf16(str.c_str()); + if (utf16_temp) + GetFullPathNameW(utf16_temp, MAX_PATH * 2, buf, 0); + free_def(utf16_temp); + + char* utf0_temp = utf16_to_utf8(buf); + if (utf0_temp) + str.assign(utf0_temp); + free_def(utf0_temp); +} + +void path_get_full_path(std::wstring& str) { + wchar_t buf[MAX_PATH * 2]; + buf[0] = 0; + GetFullPathNameW(str.c_str(), MAX_PATH * 2, buf, 0); + str.assign(buf); +} diff --git a/src/KKdLib/io/path.hpp b/src/KKdLib/io/path.hpp index 021ae108..6d4249ba 100644 --- a/src/KKdLib/io/path.hpp +++ b/src/KKdLib/io/path.hpp @@ -24,4 +24,6 @@ extern std::vector path_get_directories( extern std::vector path_get_directories_recursive( const char* path, const char** exclude_list = 0, size_t exclude_count = 0); extern std::vector path_get_directories_recursive( - const wchar_t* path, const wchar_t** exclude_list = 0, size_t exclude_count = 0); \ No newline at end of file + const wchar_t* path, const wchar_t** exclude_list = 0, size_t exclude_count = 0); +extern void path_get_full_path(std::string& str); +extern void path_get_full_path(std::wstring& str);